repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
|---|---|---|---|---|---|---|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationReadyTestBase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import java.io.IOException;
import java.net.URL;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup({MicroProfileHealthApplicationReadySetupTask.class})
public abstract class MicroProfileHealthApplicationReadyTestBase {
abstract void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException;
@Deployment(name = "MicroProfileHealthApplicationReadyTestBaseSetup")
public static Archive<?> deploySetup() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "MicroProfileHealthApplicationReadyTestBaseSetup.war")
.addClass(MicroProfileHealthApplicationReadySetupTask.class);
return war;
}
@Deployment(name = "MicroProfileHealthApplicationReadyTestBase", managed = false)
public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "MicroProfileHealthApplicationReadyTestBase.war")
.addClass(MyReadyProbe.class)
.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml");
return war;
}
@ContainerResource
ManagementClient managementClient;
@ArquillianResource
private Deployer deployer;
@Test
@InSequence(1)
public void testApplicationReadinessBeforeDeployment() throws Exception {
checkGlobalOutcome(managementClient, "check-ready", false, null);
// deploy the archive
deployer.deploy("MicroProfileHealthApplicationReadyTestBase");
}
@Test
@InSequence(2)
@OperateOnDeployment("MicroProfileHealthApplicationReadyTestBase")
public void testApplicationReadinessAfterDeployment(@ArquillianResource URL url) throws Exception {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
checkGlobalOutcome(managementClient, "check-ready", true, "myReadyProbe");
}
}
@Test
@InSequence(3)
public void testHealthCheckAfterUndeployment() throws Exception {
deployer.undeploy("MicroProfileHealthApplicationReadyTestBase");
checkGlobalOutcome(managementClient, "check-ready", false, null);
}
}
| 4,180
| 39.592233
| 145
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationWithoutReadinessOperationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import static org.jboss.as.controller.operations.common.Util.getEmptyOperation;
import java.io.IOException;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.dmr.ModelNode;
import static org.wildfly.test.integration.microprofile.health.MicroProfileHealthUtils.testManagementOperation;
/**
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2019 Red Hat inc.
*/
public class MicroProfileHealthApplicationWithoutReadinessOperationTestCase extends MicroProfileHealthApplicationReadyTestBase {
void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException {
final ModelNode address = new ModelNode();
address.add("subsystem", "microprofile-health-smallrye");
ModelNode checkOp = getEmptyOperation(operation, address);
ModelNode response = managementClient.getControllerClient().execute(checkOp);
testManagementOperation(response, mustBeUP, probeName);
}
}
| 2,096
| 42.6875
| 137
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationStartupHTTPEndpointTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.jboss.as.arquillian.container.ManagementClient;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.wildfly.test.integration.microprofile.health.MicroProfileHealthUtils.testHttpEndPoint;
/**
* @author <a href="http://xstefank.io/">Martin Stefanko</a> (c) 2021 Red Hat inc.
*/
public class MicroProfileHealthApplicationStartupHTTPEndpointTestCase extends MicroProfileHealthApplicationStartupTestBase {
void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException {
assertEquals("check-started", operation);
final String httpEndpoint = "/health/started";
final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + httpEndpoint;
testHttpEndPoint(healthURL, mustBeUP, probeName);
}
}
| 1,984
| 43.111111
| 137
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MyLiveProbe.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Liveness;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
/**
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2018 Red Hat inc.
*/
@Liveness
public class MyLiveProbe implements HealthCheck {
// Inject a property whose value is configured in a ConfigSource
// inside the deployment to check that MP Config properly injects properties
// when HealthChecks are called in WildFly management endpoints.
@Inject
@ConfigProperty
Provider<Boolean> propertyConfiguredByTheDeployment;
static boolean up = true;
@Override
public HealthCheckResponse call() {
if (!propertyConfiguredByTheDeployment.get()) {
return HealthCheckResponse.named("myLiveProbe")
.down()
.build();
}
return HealthCheckResponse.named("myLiveProbe")
.status(up)
.build();
}
}
| 2,217
| 34.206349
| 80
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationLiveTestBase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2018 Red Hat inc.
*/
@RunWith(Arquillian.class)
@RunAsClient
public abstract class MicroProfileHealthApplicationLiveTestBase {
abstract void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException;
@Deployment(name = "MicroProfileHealthTestCase", managed = false)
public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "MicroProfileHealthTestCase.war")
.addClasses(TestApplication.class, TestApplication.Resource.class, MyLiveProbe.class, HealthConfigSource.class)
.addAsServiceProvider(ConfigSource.class, HealthConfigSource.class)
.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml");
return war;
}
@ContainerResource
ManagementClient managementClient;
@ArquillianResource
private Deployer deployer;
@Test
@InSequence(1)
public void testHealthCheckBeforeDeployment() throws Exception {
checkGlobalOutcome(managementClient, "check", true, null);
checkGlobalOutcome(managementClient, "check-live", true, null);
// deploy the archive
deployer.deploy("MicroProfileHealthTestCase");
}
@Test
@InSequence(2)
@OperateOnDeployment("MicroProfileHealthTestCase")
public void testHealthCheckAfterDeployment(@ArquillianResource URL url) throws Exception {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
checkGlobalOutcome(managementClient, "check", true, "myLiveProbe");
checkGlobalOutcome(managementClient, "check-live", true, "myLiveProbe");
HttpPost request = new HttpPost(url + "microprofile/myApp");
List<NameValuePair> nvps = new ArrayList<>();
nvps.add(new BasicNameValuePair("up", "false"));
request.setEntity(new UrlEncodedFormEntity(nvps));
CloseableHttpResponse response = client.execute(request);
assertEquals(200, response.getStatusLine().getStatusCode());
checkGlobalOutcome(managementClient, "check", false, "myLiveProbe");
checkGlobalOutcome(managementClient, "check-live", false, "myLiveProbe");
}
}
@Test
@InSequence(3)
public void testHealthCheckAfterUndeployment() throws Exception {
deployer.undeploy("MicroProfileHealthTestCase");
checkGlobalOutcome(managementClient, "check", true, null);
checkGlobalOutcome(managementClient, "check-live", true, null);
}
}
| 5,068
| 39.879032
| 145
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationReadyHTTPEndpointTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.jboss.as.arquillian.container.ManagementClient;
import static org.wildfly.test.integration.microprofile.health.MicroProfileHealthUtils.testHttpEndPoint;
/**
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2019 Red Hat inc.
*/
public class MicroProfileHealthApplicationReadyHTTPEndpointTestCase extends MicroProfileHealthApplicationReadyTestBase {
void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException {
assertEquals("check-ready", operation);
final String httpEndpoint = "/health/ready";
final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + httpEndpoint;
testHttpEndPoint(healthURL, mustBeUP, probeName);
}
}
| 1,975
| 40.166667
| 137
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthSecuredHTTPEndpointEmptyMgmtUsersTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import static org.junit.Assert.assertEquals;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup({MicroProfileHealthSecuredHTTPEndpointSetupTask.class, EmptyMgmtUsersSetupTask.class})
public class MicroProfileHealthSecuredHTTPEndpointEmptyMgmtUsersTestCase {
@ContainerResource
ManagementClient managementClient;
@Deployment
public static Archive<?> deployment() {
final Archive<?> deployment = ShrinkWrap.create(JavaArchive.class, "MicroProfileHealthSecuredHTTPEndpointEmptyMgmtUsersTestCase.jar")
.addClasses(MicroProfileHealthSecuredHTTPEndpointSetupTask.class, EmptyMgmtUsersSetupTask.class);
return deployment;
}
@Test
public void securedHTTPEndpointWithoutUserDefined() throws Exception {
final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + "/health";
try (CloseableHttpClient client = HttpClients.createDefault()) {
CloseableHttpResponse resp = client.execute(new HttpGet(healthURL));
assertEquals(401, resp.getStatusLine().getStatusCode());
resp.close();
}
}
}
| 2,974
| 41.5
| 141
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationWithoutStartupTestBase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException;
import java.net.URL;
/**
* Test that an application without any startup probe got one setup by WildFly so that the application
* is considered started when it is deployed
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup({MicroProfileHealthApplicationStartupSetupTask.class})
public abstract class MicroProfileHealthApplicationWithoutStartupTestBase {
abstract void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException;
@Deployment(name = "MicroProfileHealthApplicationWithoutStartupTestBaseSetup")
public static Archive<?> deploySetup() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "MicroProfileHealthApplicationWithoutStartupTestBaseSetup.war")
.addClass(MicroProfileHealthApplicationStartupSetupTask.class);
return war;
}
// deployment does not define any startup probe
@Deployment(name = "MicroProfileHealthApplicationWithoutStartupTestBase", managed = false)
public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "MicroProfileHealthApplicationWithoutStartupTestBase.war")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return war;
}
@ContainerResource
ManagementClient managementClient;
@ArquillianResource
private Deployer deployer;
@Test
@InSequence(1)
public void testApplicationStartupBeforeDeployment() throws Exception {
checkGlobalOutcome(managementClient, "check-started", false, null);
// deploy the archive
deployer.deploy("MicroProfileHealthApplicationWithoutStartupTestBase");
}
@Test
@InSequence(2)
@OperateOnDeployment("MicroProfileHealthApplicationWithoutStartupTestBase")
public void testApplicationStartupAfterDeployment(@ArquillianResource URL url) throws Exception {
checkGlobalOutcome(managementClient, "check-started", true, "started-deployment.MicroProfileHealthApplicationWithoutStartupTestBase.war");
}
@Test
@InSequence(3)
public void testApplicationStartupAfterUndeployment() throws Exception {
deployer.undeploy("MicroProfileHealthApplicationWithoutStartupTestBase");
checkGlobalOutcome(managementClient, "check-started", false, null);
}
}
| 4,245
| 40.223301
| 150
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthSecuredHTTPEndpointSetupTask.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.dmr.ModelNode;
public class MicroProfileHealthSecuredHTTPEndpointSetupTask implements ServerSetupTask {
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
final ModelNode address = Operations.createAddress("subsystem", "microprofile-health-smallrye");
final ModelNode op = Operations.createWriteAttributeOperation(address, "security-enabled", true );
managementClient.getControllerClient().execute(op);
ServerReload.reloadIfRequired(managementClient);
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
final ModelNode address = Operations.createAddress("subsystem", "microprofile-health-smallrye");
final ModelNode op = Operations.createWriteAttributeOperation(address, "security-enabled", false );
managementClient.getControllerClient().execute(op);
ServerReload.reloadIfRequired(managementClient);
}
}
| 2,322
| 44.54902
| 107
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationWithoutStartupOperationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.dmr.ModelNode;
import java.io.IOException;
import static org.wildfly.test.integration.microprofile.health.MicroProfileHealthUtils.testManagementOperation;
import static org.jboss.as.controller.operations.common.Util.getEmptyOperation;
/**
* @author <a href="http://xstefank.io/">Martin Stefanko</a> (c) 2021 Red Hat inc.
*/
public class MicroProfileHealthApplicationWithoutStartupOperationTestCase extends MicroProfileHealthApplicationWithoutStartupTestBase {
void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException {
final ModelNode address = new ModelNode();
address.add("subsystem", "microprofile-health-smallrye");
ModelNode checkOp = getEmptyOperation(operation, address);
ModelNode response = managementClient.getControllerClient().execute(checkOp);
testManagementOperation(response, mustBeUP, probeName);
}
}
| 2,106
| 43.829787
| 137
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/TestApplication.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.Response;
/**
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2018 Red Hat inc.
*/
@ApplicationPath("/microprofile")
public class TestApplication extends Application {
@Path("/myApp")
public static class Resource {
@POST
@Produces("text/plain")
public Response changeProbeOutcome(@FormParam("up") boolean up) {
MyLiveProbe.up = up;
return Response.ok().build();
}
}
}
| 1,757
| 33.470588
| 78
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthUtils.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.StringReader;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jboss.dmr.ModelNode;
import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonReader;
import jakarta.json.JsonValue;
public class MicroProfileHealthUtils {
static void testHttpEndPoint(String healthURL, boolean mustBeUP, String probeName) throws IOException {
try (CloseableHttpClient client = HttpClients.createDefault()) {
CloseableHttpResponse resp = client.execute(new HttpGet(healthURL));
String content = EntityUtils.toString(resp.getEntity());
resp.close();
assertEquals(content, mustBeUP ? 200 : 503, resp.getStatusLine().getStatusCode());
try (
JsonReader jsonReader = Json.createReader(new StringReader(content))
) {
JsonObject payload = jsonReader.readObject();
String outcome = payload.getString("status");
assertEquals(mustBeUP ? "UP" : "DOWN", outcome);
if (probeName != null) {
for (JsonValue check : payload.getJsonArray("checks")) {
if (probeName.equals(check.asJsonObject().getString("name"))) {
// probe name found
assertEquals(mustBeUP ? "UP" : "DOWN", check.asJsonObject().getString("status"));
return;
}
}
fail("Probe named " + probeName + " not found in " + content);
}
}
}
}
static void testManagementOperation(ModelNode response, boolean mustBeUP, String probeName) {
final String opOutcome = response.get("outcome").asString();
assertEquals("success", opOutcome);
ModelNode result = response.get("result");
assertEquals(mustBeUP ? "UP" : "DOWN", result.get("status").asString());
if (probeName != null) {
for (ModelNode check : result.get("checks").asList()) {
if (probeName.equals(check.get("name").asString())) {
// probe name found
// global outcome is driven by this probe state
assertEquals(mustBeUP ? "UP" : "DOWN", check.get("status").asString());
return;
}
}
fail("Probe named " + probeName + " not found in " + result);
}
}
}
| 3,891
| 38.714286
| 109
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/EmptyMgmtUsersSetupTask.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import java.io.File;
import java.nio.file.Files;
public class EmptyMgmtUsersSetupTask implements ServerSetupTask {
static File mgmtUsersFile;
byte[] bytes;
static {
String jbossHome = System.getProperty("jboss.home", null);
if (jbossHome == null) {
throw new IllegalStateException("jboss.home not set");
}
mgmtUsersFile = new File(jbossHome + File.separatorChar + "standalone" + File.separatorChar
+ "configuration" + File.separatorChar + "mgmt-users.properties");
if (!mgmtUsersFile.exists()) {
throw new IllegalStateException("Determined mgmt-users.properties path " + mgmtUsersFile + " does not exist");
}
if (!mgmtUsersFile.isFile()) {
throw new IllegalStateException("Determined mgmt-users.properties path " + mgmtUsersFile + " is not a file");
}
}
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
bytes = Files.readAllBytes(mgmtUsersFile.toPath());
Files.write(mgmtUsersFile.toPath(), "".getBytes());
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
Files.write(mgmtUsersFile.toPath(), bytes);
}
}
| 2,497
| 38.650794
| 122
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationReadySetupTask.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.dmr.ModelNode;
public class MicroProfileHealthApplicationReadySetupTask implements ServerSetupTask {
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
final ModelNode address = Operations.createAddress("subsystem", "microprofile-health-smallrye");
final ModelNode op = Operations.createWriteAttributeOperation(address, "empty-readiness-checks-status", "DOWN" );
managementClient.getControllerClient().execute(op);
ServerReload.reloadIfRequired(managementClient);
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
final ModelNode address = Operations.createAddress("subsystem", "microprofile-health-smallrye");
final ModelNode op = Operations.createUndefineAttributeOperation(address, "empty-readiness-checks-status");
managementClient.getControllerClient().execute(op);
ServerReload.reloadIfRequired(managementClient);
}
}
| 2,341
| 44.921569
| 121
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationStartupSetupTask.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.dmr.ModelNode;
public class MicroProfileHealthApplicationStartupSetupTask implements ServerSetupTask {
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
final ModelNode address = Operations.createAddress("subsystem", "microprofile-health-smallrye");
final ModelNode op = Operations.createWriteAttributeOperation(address, "empty-startup-checks-status", "DOWN");
managementClient.getControllerClient().execute(op);
ServerReload.reloadIfRequired(managementClient);
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
final ModelNode address = Operations.createAddress("subsystem", "microprofile-health-smallrye");
final ModelNode op = Operations.createUndefineAttributeOperation(address, "empty-startup-checks-status");
managementClient.getControllerClient().execute(op);
ServerReload.reloadIfRequired(managementClient);
}
}
| 2,338
| 44.862745
| 118
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationStartupTestBase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException;
import java.net.URL;
/**
* Test that an application with startup probe is correctly recognized by WildFly.
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup({MicroProfileHealthApplicationStartupSetupTask.class})
public abstract class MicroProfileHealthApplicationStartupTestBase {
abstract void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException;
@Deployment(name = "MicroProfileHealthApplicationStartupTestBaseSetup")
public static Archive<?> deploySetup() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "MicroProfileHealthApplicationStartupTestBaseSetup.war")
.addClass(MicroProfileHealthApplicationStartupSetupTask.class);
return war;
}
@Deployment(name = "MicroProfileHealthApplicationStartupTestBase", managed = false)
public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "MicroProfileHealthApplicationStartupTestBase.war")
.addClass(SuccessfulStartupProbe.class)
.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml");
return war;
}
@ContainerResource
ManagementClient managementClient;
@ArquillianResource
private Deployer deployer;
@Test
@InSequence(1)
public void testApplicationStartupBeforeDeployment() throws Exception {
checkGlobalOutcome(managementClient, "check-started", false, null);
// deploy the archive
deployer.deploy("MicroProfileHealthApplicationStartupTestBase");
}
@Test
@InSequence(2)
@OperateOnDeployment("MicroProfileHealthApplicationStartupTestBase")
public void testApplicationStartupAfterDeployment(@ArquillianResource URL url) throws Exception {
checkGlobalOutcome(managementClient, "check-started", true, "successfulStartupProbe");
}
@Test
@InSequence(3)
public void testApplicationStartupAfterUndeployment() throws Exception {
deployer.undeploy("MicroProfileHealthApplicationStartupTestBase");
checkGlobalOutcome(managementClient, "check-started", false, null);
}
}
| 4,115
| 39.752475
| 145
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationWithoutReadinessHTTPEndpointTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.jboss.as.arquillian.container.ManagementClient;
import static org.wildfly.test.integration.microprofile.health.MicroProfileHealthUtils.testHttpEndPoint;
/**
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2019 Red Hat inc.
*/
public class MicroProfileHealthApplicationWithoutReadinessHTTPEndpointTestCase extends MicroProfileHealthApplicationWithoutReadinessTestBase {
void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException {
assertEquals("check-ready", operation);
final String httpEndpoint = "/health/ready";
final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + httpEndpoint;
testHttpEndPoint(healthURL, mustBeUP, probeName);
}
}
| 1,994
| 43.333333
| 142
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationWithoutStartupHTTPEndpointTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.jboss.as.arquillian.container.ManagementClient;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.wildfly.test.integration.microprofile.health.MicroProfileHealthUtils.testHttpEndPoint;
/**
* @author <a href="http://xstefank.io/">Martin Stefanko</a> (c) 2021 Red Hat inc.
*/
public class MicroProfileHealthApplicationWithoutStartupHTTPEndpointTestCase extends MicroProfileHealthApplicationWithoutStartupTestBase {
void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException {
assertEquals("check-started", operation);
final String httpEndpoint = "/health/started";
final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + httpEndpoint;
testHttpEndPoint(healthURL, mustBeUP, probeName);
}
}
| 1,999
| 42.478261
| 138
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationReadyOperationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import static org.jboss.as.controller.operations.common.Util.getEmptyOperation;
import java.io.IOException;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.dmr.ModelNode;
import static org.wildfly.test.integration.microprofile.health.MicroProfileHealthUtils.testManagementOperation;
/**
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2019 Red Hat inc.
*/
public class MicroProfileHealthApplicationReadyOperationTestCase extends MicroProfileHealthApplicationReadyTestBase {
void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException {
final ModelNode address = new ModelNode();
address.add("subsystem", "microprofile-health-smallrye");
ModelNode checkOp = getEmptyOperation(operation, address);
ModelNode response = managementClient.getControllerClient().execute(checkOp);
testManagementOperation(response, mustBeUP, probeName);
}
}
| 2,084
| 43.361702
| 137
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/SuccessfulStartupProbe.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Startup;
/**
* @author <a href="http://xstefank.io/">Martin Stefanko</a> (c) 2019 Red Hat inc.
*/
@Startup
public class SuccessfulStartupProbe implements HealthCheck {
@Override
public HealthCheckResponse call() {
return HealthCheckResponse.named("successfulStartupProbe")
.up()
.build();
}
}
| 1,583
| 36.714286
| 82
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthSecuredHTTPEndpointTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup({MicroProfileHealthSecuredHTTPEndpointSetupTask.class})
public class MicroProfileHealthSecuredHTTPEndpointTestCase {
@ContainerResource
ManagementClient managementClient;
@Deployment
public static Archive<?> deployment() {
final Archive<?> deployment = ShrinkWrap.create(JavaArchive.class, "MicroProfileHealthSecuredHTTPEndpointTestCase.jar")
.addClasses(MicroProfileHealthSecuredHTTPEndpointSetupTask.class);
return deployment;
}
@Test
public void securedHTTPEndpointWithoutUserDefined() throws Exception {
final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + "/health";
try (CloseableHttpClient client = HttpClients.createDefault()) {
CloseableHttpResponse resp = client.execute(new HttpGet(healthURL));
assertEquals(401, resp.getStatusLine().getStatusCode());
String content = EntityUtils.toString(resp.getEntity());
resp.close();
assertTrue("'401 - Unauthorized' message is expected", content.contains("401 - Unauthorized"));
}
}
@Test
public void securedHTTPEndpoint() throws Exception {
final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + "/health";
try (CloseableHttpClient client = HttpClients.createDefault()) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("testSuite", "testSuitePassword"));
HttpClientContext hcContext = HttpClientContext.create();
hcContext.setCredentialsProvider(credentialsProvider);
CloseableHttpResponse resp = client.execute(new HttpGet(healthURL), hcContext);
assertEquals(200, resp.getStatusLine().getStatusCode());
String content = EntityUtils.toString(resp.getEntity());
resp.close();
assertTrue("'UP' message is expected", content.contains("UP"));
}
}
}
| 4,386
| 44.226804
| 130
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MyReadyProbe.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Readiness;
/**
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2019 Red Hat inc.
*/
@Readiness
public class MyReadyProbe implements HealthCheck {
@Override
public HealthCheckResponse call() {
return HealthCheckResponse.named("myReadyProbe")
.up()
.build();
}
}
| 1,562
| 37.121951
| 78
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/HealthConfigSource.java
|
package org.wildfly.test.integration.microprofile.health;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.eclipse.microprofile.config.spi.ConfigSource;
public class HealthConfigSource implements ConfigSource {
private final HashMap<String, String> props;
public HealthConfigSource() {
props = new HashMap<>();
props.put("org.wildfly.test.integration.microprofile.health.MyLiveProbe.propertyConfiguredByTheDeployment", Boolean.TRUE.toString());
}
@Override
public Map<String, String> getProperties() {
return props;
}
@Override
public String getValue(String propertyName) {
return props.get(propertyName);
}
@Override
public String getName() {
return "ConfigSource local to the deployment";
}
@Override
public Set<String> getPropertyNames() {
return props.keySet();
}
}
| 919
| 23.210526
| 141
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationLiveHTTPEndpointTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import java.io.IOException;
import org.jboss.as.arquillian.container.ManagementClient;
import static org.wildfly.test.integration.microprofile.health.MicroProfileHealthUtils.testHttpEndPoint;
/**
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2018 Red Hat inc.
*/
public class MicroProfileHealthApplicationLiveHTTPEndpointTestCase extends MicroProfileHealthApplicationLiveTestBase {
void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException {
final String httpEndpoint;
switch(operation) {
case "check-live":
httpEndpoint = "/health/live";
break;
case "check-ready":
httpEndpoint = "/health/ready";
break;
case "check":
default:
httpEndpoint = "/health";
}
final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + httpEndpoint;
testHttpEndPoint(healthURL, mustBeUP, probeName);
}
}
| 2,190
| 39.574074
| 137
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/health/MicroProfileHealthApplicationLiveOperationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.health;
import static org.jboss.as.controller.operations.common.Util.getEmptyOperation;
import java.io.IOException;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.dmr.ModelNode;
import static org.wildfly.test.integration.microprofile.health.MicroProfileHealthUtils.testManagementOperation;
/**
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2018 Red Hat inc.
*/
public class MicroProfileHealthApplicationLiveOperationTestCase extends MicroProfileHealthApplicationLiveTestBase {
void checkGlobalOutcome(ManagementClient managementClient, String operation, boolean mustBeUP, String probeName) throws IOException {
final ModelNode address = new ModelNode();
address.add("subsystem", "microprofile-health-smallrye");
ModelNode checkOp = getEmptyOperation(operation, address);
ModelNode response = managementClient.getControllerClient().execute(checkOp);
testManagementOperation(response, mustBeUP, probeName);
}
}
| 2,082
| 43.319149
| 137
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/TokenUtil.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2020 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.test.integration.microprofile.jwt;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
import java.util.UUID;
import com.nimbusds.jose.JOSEObjectType;
import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jose.JWSHeader;
import com.nimbusds.jose.JWSObject;
import com.nimbusds.jose.JWSSigner;
import com.nimbusds.jose.Payload;
import com.nimbusds.jose.crypto.RSASSASigner;
import jakarta.json.Json;
import jakarta.json.JsonArrayBuilder;
import jakarta.json.JsonObjectBuilder;
public class TokenUtil {
private static PrivateKey loadPrivateKey(final String fileName) throws Exception {
try (InputStream is = new FileInputStream(fileName)) {
byte[] contents = new byte[4096];
int length = is.read(contents);
String rawKey = new String(contents, 0, length, StandardCharsets.UTF_8)
.replaceAll("-----BEGIN (.*)-----", "")
.replaceAll("-----END (.*)----", "")
.replaceAll("\r\n", "").replaceAll("\n", "")
.trim();
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(rawKey));
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePrivate(keySpec);
}
}
public static String generateJWT(final String keyLocation, final String principal, final String birthdate,
final String... groups) throws Exception {
PrivateKey privateKey = loadPrivateKey(keyLocation);
JWSSigner signer = new RSASSASigner(privateKey);
JsonArrayBuilder groupsBuilder = Json.createArrayBuilder();
for (String group : groups) {
groupsBuilder.add(group);
}
long currentTime = System.currentTimeMillis() / 1000;
JsonObjectBuilder claimsBuilder = Json.createObjectBuilder()
.add("sub", principal)
.add("upn", principal)
.add("iss", "quickstart-jwt-issuer")
.add("aud", "jwt-audience")
.add("groups", groupsBuilder.build())
.add("birthdate", birthdate)
.add("jti", UUID.randomUUID().toString())
.add("iat", currentTime)
.add("exp", currentTime + 14400);
JWSObject jwsObject = new JWSObject(
new JWSHeader.Builder(JWSAlgorithm.RS256).type(new JOSEObjectType("jwt")).keyID("Test Key").build(),
new Payload(claimsBuilder.build().toString()));
jwsObject.sign(signer);
return jwsObject.serialize();
}
}
| 3,507
| 37.130435
| 116
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/ClockSkewTest.java
|
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.wildfly.test.integration.microprofile.jwt;
import com.nimbusds.jose.JOSEObjectType;
import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jose.JWSHeader;
import com.nimbusds.jose.JWSObject;
import com.nimbusds.jose.Payload;
import com.nimbusds.jose.crypto.RSASSASigner;
import jakarta.json.Json;
import jakarta.json.JsonObjectBuilder;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.Response;
import java.io.File;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.PrivateKey;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.FileAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.common.iteration.CodePointIterator;
import org.wildfly.security.pem.Pem;
import org.wildfly.test.integration.microprofile.jwt.norealm.App;
import static jakarta.ws.rs.core.MediaType.TEXT_PLAIN;
/**
* Tests for mp.jwt.verify.clock.skew property introduced in MP JWT 2.1
*/
@RunAsClient
@RunWith(Arquillian.class)
public class ClockSkewTest {
@ArquillianResource
private URL baseURL;
@Deployment(testable = false)
public static WebArchive createDeployment() {
return ShrinkWrap
.create(WebArchive.class, "ClockSkewTest.war")
.addClasses(App.class, SampleEndPoint.class, BaseCase.class)
.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml")
.addAsManifestResource(new FileAsset(new File("src/test/resources/jwt/microprofile-config-with-clock-skew.properties")),
"microprofile-config.properties")
.addAsManifestResource(new FileAsset(new File("src/test/resources/jwt/public.pem")), "public.pem");
}
@Test
public void testClockSkewTokenNotExpired() throws Exception {
String token = createJwt();
Thread.sleep(3000); // exp is 3 seconds but request will be accepted because the clock skew is set to 2 seconds
callEchoAndExpectStatus(token, HttpURLConnection.HTTP_OK);
}
@Test
public void testClockSkewExpired() throws Exception {
String token = createJwt();
Thread.sleep(5000); // exp + clock skew is 5 seconds, so wait 5 seconds and test that request will be unauthorized
callEchoAndExpectStatus(token, HttpURLConnection.HTTP_UNAUTHORIZED);
}
private void callEchoAndExpectStatus(String token, int status) {
Response response = callEcho(token);
Assert.assertEquals(status, response.getStatus());
}
private Response callEcho(String token) {
String uri = baseURL.toExternalForm() + "/rest/Sample/subscription";
WebTarget echoEndpointTarget = ClientBuilder.newClient().target(uri);
return echoEndpointTarget.request(TEXT_PLAIN).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
}
public static int currentTimeInSecs() {
long currentTimeMS = System.currentTimeMillis();
return (int) (currentTimeMS / 1000);
}
public String createJwt() throws Exception {
JsonObjectBuilder claimsBuilder = Json.createObjectBuilder()
.add("sub", "testSubject")
.add("iss", "quickstart-jwt-issuer")
.add("aud", "testAud")
.add("groups", Json.createArrayBuilder().add("Subscriber").build())
.add("iat", ((System.currentTimeMillis() / 1000)))
.add("exp", ((System.currentTimeMillis() / 1000) + 3)); // exp is 3 seconds from now
JWSObject jwsObject = new JWSObject(new JWSHeader.Builder(JWSAlgorithm.RS256)
.type(new JOSEObjectType("jwt")).build(), new Payload(claimsBuilder.build().toString()));
String pemContent = Files.readString(Path.of("src/test/resources/jwt/private.pem"));
PrivateKey privateKey = Pem.parsePemContent(CodePointIterator.ofString(pemContent)).next().tryCast(PrivateKey.class);
jwsObject.sign(new RSASSASigner(privateKey));
return jwsObject.serialize();
}
}
| 5,268
| 37.459854
| 136
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/BaseCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.jwt;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.wildfly.test.integration.microprofile.jwt.TokenUtil.generateJWT;
import java.net.URL;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.junit.Test;
/**
* A base for MicroProfile JWT test cases.
*
* @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
public abstract class BaseCase {
private static final String KEY_LOCATION = "src/test/resources/jwt/private.pem";
private static final String ROOT_PATH = "/rest/Sample/";
private static final String SUBSCRIPTION = "subscription";
private static final String DATE = "2017-09-15";
private static final String ECHOER_GROUP = "Echoer";
private static final String SUBSCRIBER_GROUP = "Subscriber";
private static final String PRINCIPAL_NAME = "testUser";
private static final String AUTHORIZATION = "Authorization";
private static final String BEARER = "Bearer";
private final CloseableHttpClient httpClient = HttpClientBuilder.create().build();
@ArquillianResource
private URL deploymentUrl;
@Test
public void testAuthorizationRequired() throws Exception {
HttpGet httpGet = new HttpGet(deploymentUrl.toString() + ROOT_PATH + SUBSCRIPTION);
CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
assertEquals("Authorization required", 403, httpResponse.getStatusLine().getStatusCode());
httpResponse.close();
}
@Test
public void testAuthorized() throws Exception {
String jwtToken = generateJWT(KEY_LOCATION, PRINCIPAL_NAME, DATE, ECHOER_GROUP, SUBSCRIBER_GROUP);
HttpGet httpGet = new HttpGet(deploymentUrl.toString() + ROOT_PATH + SUBSCRIPTION);
httpGet.addHeader(AUTHORIZATION, BEARER + " " + jwtToken);
CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
assertEquals("Successful call", 200, httpResponse.getStatusLine().getStatusCode());
String body = EntityUtils.toString(httpResponse.getEntity());
assertTrue("Call was authenticated", body.contains(PRINCIPAL_NAME));
httpResponse.close();
}
}
| 3,549
| 37.586957
| 106
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/SampleEndPoint.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.jwt;
import java.security.Principal;
import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.SecurityContext;
import org.eclipse.microprofile.jwt.JsonWebToken;
@Path("/Sample")
public class SampleEndPoint {
@Inject
JsonWebToken jwt;
@GET()
@Path("/subscription")
@RolesAllowed({ "Subscriber" })
public String helloRolesAllowed(@Context SecurityContext ctx) {
Principal caller = ctx.getUserPrincipal();
String name = caller == null ? "anonymous" : caller.getName();
boolean hasJWT = jwt.getClaimNames() != null;
String helloReply = String.format("hello + %s, hasJWT: %s", name, hasJWT);
return helloReply;
}
}
| 1,894
| 34.754717
| 82
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/ejb/JWTEJBTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.jwt.ejb;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.wildfly.test.integration.microprofile.jwt.TokenUtil.generateJWT;
import java.io.File;
import java.net.URL;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.FileAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* A test case for an Jakarta Enterprise Beans endpoint secured using the MP-JWT mechanism and invoking a
* second Jakarta Enterprise Beans with role restrictions.
*
* @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
public class JWTEJBTestCase {
private static final String DEPLOYMENT_NAME = JWTEJBTestCase.class.getSimpleName() + ".war";
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME)
.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml")
.addClasses(JWTEJBTestCase.class)
.addClasses(App.class, BeanEndPoint.class, TargetBean.class)
.addAsManifestResource(new FileAsset(
new File("src/test/resources/jwt/microprofile-config.properties")),
"microprofile-config.properties")
.addAsManifestResource(
new FileAsset(new File("src/test/resources/jwt/public.pem")),
"public.pem");
}
private static final String KEY_LOCATION = "src/test/resources/jwt/private.pem";
private static final String ROOT_PATH = "/rest/Sample/";
private static final String SUBSCRIPTION = "subscription";
private static final String DATE = "2017-09-15";
private static final String ECHOER_GROUP = "Echoer";
private static final String SUBSCRIBER_GROUP = "Subscriber";
private static final String PRINCIPAL_NAME = "testUser";
private static final String AUTHORIZATION = "Authorization";
private static final String BEARER = "Bearer";
private final CloseableHttpClient httpClient = HttpClientBuilder.create().build();
@ArquillianResource
private URL deploymentUrl;
@Test
public void testAuthorized() throws Exception {
String jwtToken = generateJWT(KEY_LOCATION, PRINCIPAL_NAME, DATE, ECHOER_GROUP, SUBSCRIBER_GROUP);
HttpGet httpGet = new HttpGet(deploymentUrl.toString() + ROOT_PATH + SUBSCRIPTION);
httpGet.addHeader(AUTHORIZATION, BEARER + " " + jwtToken);
CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
assertEquals("Successful call", 200, httpResponse.getStatusLine().getStatusCode());
String body = EntityUtils.toString(httpResponse.getEntity());
assertTrue("Call was authenticated", body.contains(PRINCIPAL_NAME));
httpResponse.close();
}
}
| 4,575
| 40.225225
| 106
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/ejb/package-info.java
|
/**
* Package to contain a test case and required classes to test MP-JWT identity
* propagation into a co-packaged Jakarta Enterprise Beans within the deployment.
*/
package org.wildfly.test.integration.microprofile.jwt.ejb;
| 228
| 37.166667
| 81
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/ejb/App.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.jwt.ejb;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
import org.eclipse.microprofile.auth.LoginConfig;
@ApplicationPath("/rest")
@LoginConfig(authMethod="MP-JWT", realmName="MP JWT Realm")
public class App extends Application {}
| 1,339
| 39.606061
| 70
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/ejb/TargetBean.java
|
/*
* Copyright 2020 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.test.integration.microprofile.jwt.ejb;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.Stateless;
/**
*
* @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
@Stateless
public class TargetBean {
@RolesAllowed({ "Subscriber" })
public boolean successfulCall() {
return true;
}
}
| 967
| 25.162162
| 75
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/ejb/BeanEndPoint.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.jwt.ejb;
import java.security.Principal;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.SecurityContext;
import org.eclipse.microprofile.jwt.JsonWebToken;
/**
* A simple Jakarta RESTful Web Services endpoint deployed as an Jakarta Enterprise Beans.
*
* @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
@Path("/Sample")
@Stateless
public class BeanEndPoint {
@Inject
JsonWebToken jwt;
@EJB
TargetBean targetBean;
@GET()
@Path("/subscription")
public String helloRolesAllowed(@Context SecurityContext ctx) {
Principal caller = ctx.getUserPrincipal();
String name = caller == null ? "anonymous" : caller.getName();
boolean hasJWT = jwt.getClaimNames() != null;
String helloReply = String.format("hello + %s, hasJWT: %s, canCallTarget: %b", name, hasJWT, targetBean.successfulCall());
return helloReply;
}
}
| 2,141
| 32.46875
| 130
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/norealm/package-info.java
|
/**
* Package to contain test classes for a deployment using the {@see org.eclipse.microprofile.auth.LoginConfig}
* annotation without speciynig a realm name.
*/
package org.wildfly.test.integration.microprofile.jwt.norealm;
| 227
| 44.6
| 110
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/norealm/App.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.jwt.norealm;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
import org.eclipse.microprofile.auth.LoginConfig;
@ApplicationPath("/rest")
@LoginConfig(authMethod="MP-JWT")
public class App extends Application {}
| 1,317
| 38.939394
| 70
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/norealm/JWTNoRealmTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.jwt.norealm;
import java.io.File;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.FileAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.runner.RunWith;
import org.wildfly.test.integration.microprofile.jwt.BaseCase;
import org.wildfly.test.integration.microprofile.jwt.SampleEndPoint;
/**
* A smoke test case for a simple JWT deployment and invocation.
*
* @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
public class JWTNoRealmTestCase extends BaseCase {
private static final String DEPLOYMENT_NAME = JWTNoRealmTestCase.class.getSimpleName() + ".war";
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME)
.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml")
.addClasses(BaseCase.class, JWTNoRealmTestCase.class)
.addClasses(App.class, SampleEndPoint.class)
.addAsWebInfResource(new FileAsset(new File("src/test/resources/jwt/web.xml")), "web.xml")
.addAsManifestResource(new FileAsset(new File("src/test/resources/jwt/microprofile-config.properties")), "microprofile-config.properties")
.addAsManifestResource(new FileAsset(new File("src/test/resources/jwt/public.pem")), "public.pem");
}
}
| 2,725
| 42.967742
| 154
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/smoke/package-info.java
|
/**
* Simple smoke test of a JWT deployment to verify invocations are accepted.
*/
package org.wildfly.test.integration.microprofile.jwt.smoke;
| 145
| 35.5
| 76
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/smoke/App.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.jwt.smoke;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
import org.eclipse.microprofile.auth.LoginConfig;
@ApplicationPath("/rest")
@LoginConfig(authMethod="MP-JWT", realmName="MP JWT Realm")
public class App extends Application {}
| 1,341
| 39.666667
| 70
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/jwt/smoke/JWTSmokeTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.jwt.smoke;
import java.io.File;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.FileAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.runner.RunWith;
import org.wildfly.test.integration.microprofile.jwt.BaseCase;
import org.wildfly.test.integration.microprofile.jwt.SampleEndPoint;
/**
* A smoke test case for a simple JWT deployment and invocation.
*
* @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
public class JWTSmokeTestCase extends BaseCase {
private static final String DEPLOYMENT_NAME = JWTSmokeTestCase.class.getSimpleName() + ".war";
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME)
.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml")
.addClasses(BaseCase.class, JWTSmokeTestCase.class)
.addClasses(App.class, SampleEndPoint.class)
.addAsWebInfResource(new FileAsset(new File("src/test/resources/jwt/web.xml")), "web.xml")
.addAsManifestResource(new FileAsset(new File("src/test/resources/jwt/microprofile-config.properties")), "microprofile-config.properties")
.addAsManifestResource(new FileAsset(new File("src/test/resources/jwt/public.pem")), "public.pem");
}
}
| 2,717
| 42.83871
| 154
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/restclient/TestClient.java
|
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.test.integration.microprofile.restclient;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.rest.client.annotation.ClientHeaderParam;
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
@RegisterRestClient()
@Path("api")
@Produces(MediaType.APPLICATION_JSON)
@RegisterClientHeaders()
public interface TestClient {
@GET
@Path("headers")
@ClientHeaderParam(name = "TestClientHeader", value = "client-value")
Response headers();
}
| 1,491
| 32.155556
| 77
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/restclient/HeaderPropagationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.test.integration.microprofile.restclient;
import java.net.URI;
import jakarta.json.JsonArray;
import jakarta.json.JsonObject;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.core.UriBuilder;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.test.shared.TestSuiteEnvironment;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
public class HeaderPropagationTestCase {
private static final String CONFIG_PROPERTIES = "org.eclipse.microprofile.rest.client.propagateHeaders=TestPropagated\n" +
"org.wildfly.test.integration.microprofile.restclient.TestClient/mp-rest/uri=http://" +
TestSuiteEnvironment.getHttpAddress() + ":" + TestSuiteEnvironment.getHttpPort() + "/" + HeaderPropagationTestCase.class.getSimpleName() + "\n";
@ArquillianResource
private URI uri;
@Deployment
public static WebArchive deployment() {
return ShrinkWrap.create(WebArchive.class, HeaderPropagationTestCase.class.getSimpleName() + ".war")
.addClasses(
Headers.class,
ClientResource.class,
ServerResource.class,
TestClient.class,
TestApplication.class
)
.addAsManifestResource(new StringAsset(CONFIG_PROPERTIES), "microprofile-config.properties")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
/**
* Tests that the TestPropagated header is in the HTTP request from the REST client and that it is propagated to the
* {@linkplain TestClient MP REST client}. The MP REST client should also contain a header defined in the
* {@link TestClient} itself.
*/
@Test
public void checkTestPropagatedHeader() {
try (Client client = ClientBuilder.newClient()) {
final JsonObject json = client.target(UriBuilder.fromUri(uri).path("api/client"))
.request()
.header("TestPropagated", "test-value")
.get(JsonObject.class);
// We should have the TestPropagated header listed in the config properties
Assert.assertEquals("TestPropagated", json.getString("org.eclipse.microprofile.rest.client.propagateHeaders"));
// The incoming headers should include the TestPropagated header with the value "test-value"
Assert.assertEquals("test-value", getHeaderValue(json.getJsonObject("incomingRequestHeaders"), "TestPropagated"));
// The serverResponse should also have this header, plus the TestClientHeader
final JsonObject serverHeaders = json.getJsonObject("serverResponse");
Assert.assertEquals("test-value", getHeaderValue(serverHeaders, "TestPropagated"));
Assert.assertEquals("client-value", getHeaderValue(serverHeaders, "TestClientHeader"));
}
}
private String getHeaderValue(final JsonObject json, final String headerName) {
final JsonArray array = json.getJsonArray(headerName);
Assert.assertNotNull(String.format("Header %s was not found in %s", headerName, json), array);
Assert.assertFalse(String.format("Header %s has no values: %s", headerName, json), array.isEmpty());
return array.getString(0);
}
}
| 4,597
| 44.98
| 156
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/restclient/Headers.java
|
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.test.integration.microprofile.restclient;
import jakarta.inject.Inject;
import jakarta.json.Json;
import jakarta.json.JsonObjectBuilder;
import jakarta.ws.rs.core.HttpHeaders;
/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
public abstract class Headers {
@Inject
private HttpHeaders headers;
/**
* Creates a new JSON object based on the HTTP request headers. The name of the header is the key and the value is
* an array of the header values.
*
* @return an object of the request headers
*/
protected JsonObjectBuilder generateHeaders() {
final JsonObjectBuilder builder = Json.createObjectBuilder();
headers.getRequestHeaders().forEach((name, value) -> builder.add(name, Json.createArrayBuilder(value)));
return builder;
}
}
| 1,559
| 32.913043
| 118
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/restclient/TestApplication.java
|
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.test.integration.microprofile.restclient;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
@ApplicationPath("/api")
public class TestApplication extends Application {
}
| 1,007
| 31.516129
| 75
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/restclient/ServerResource.java
|
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.test.integration.microprofile.restclient;
import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
@Path("headers")
@RequestScoped
public class ServerResource extends Headers {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response headers() {
return Response.ok(generateHeaders().build()).build();
}
}
| 1,291
| 29.761905
| 75
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/restclient/ClientResource.java
|
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.test.integration.microprofile.restclient;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonObjectBuilder;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RestClient;
/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
@Path("client")
@RequestScoped
public class ClientResource extends Headers {
@Inject
@RestClient
private TestClient testClient;
@Inject
@ConfigProperty(name = "org.eclipse.microprofile.rest.client.propagateHeaders", defaultValue = "n/a")
private String propagation;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response invokeTestClient() {
final JsonObjectBuilder builder = Json.createObjectBuilder()
// Add the config property
.add("org.eclipse.microprofile.rest.client.propagateHeaders", propagation)
// Add the incoming headers
.add("incomingRequestHeaders", generateHeaders());
try (Response infosResponse = testClient.headers()) {
builder.add("serverResponse", infosResponse.readEntity(JsonObject.class));
}
return Response.ok(builder.build()).build();
}
}
| 2,229
| 33.84375
| 105
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/OpenAPIMultiModuleDeploymentTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.openapi;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.test.integration.microprofile.openapi.service.TestApplication;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
/**
* Validates OpenAPI endpoint for a multi-module deployment.
* @author Paul Ferraro
*/
@RunWith(Arquillian.class)
@RunAsClient
public class OpenAPIMultiModuleDeploymentTestCase {
private static final String DEPLOYMENT_NAME = OpenAPIMultiModuleDeploymentTestCase.class.getSimpleName() + ".war";
private static final String PARENT_DEPLOYMENT_NAME = OpenAPIMultiModuleDeploymentTestCase.class.getSimpleName() + ".ear";
@Deployment
public static Archive<?> deploy() {
WebArchive jaxrs = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME)
.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml")
.addPackage(TestApplication.class.getPackage())
;
WebArchive web = ShrinkWrap.create(WebArchive.class, "web.war")
.setWebXML(TestApplication.class.getPackage(), "web.xml")
;
return ShrinkWrap.create(EnterpriseArchive.class, PARENT_DEPLOYMENT_NAME).addAsModules(jaxrs, web);
}
@Test
public void test(@ArquillianResource URL baseURL) throws IOException, URISyntaxException {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
try (CloseableHttpResponse response = client.execute(new HttpGet(baseURL.toURI().resolve("/openapi")))) {
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
List<String> urls = validateContent(response);
// Ensure relative urls are valid
for (String url : urls) {
try (CloseableHttpResponse r = client.execute(new HttpGet(baseURL.toURI().resolve(url + "/test/echo/foo")))) {
Assert.assertEquals(HttpServletResponse.SC_OK, r.getStatusLine().getStatusCode());
Assert.assertEquals("foo", EntityUtils.toString(r.getEntity()));
}
}
}
}
}
private static List<String> validateContent(HttpResponse response) throws IOException {
Assert.assertEquals("application/yaml", response.getEntity().getContentType().getValue());
JsonNode node = new ObjectMapper(new YAMLFactory()).reader().readTree(response.getEntity().getContent());
JsonNode info = node.get("info");
Assert.assertNotNull(info);
Assert.assertEquals(DEPLOYMENT_NAME, info.get("title").asText());
Assert.assertNull(info.findValue("description"));
JsonNode servers = node.required("servers");
List<String> result = new LinkedList<>();
for (JsonNode server : servers) {
result.add(server.required("url").asText());
}
Assert.assertFalse(result.isEmpty());
return result;
}
}
| 5,112
| 43.850877
| 130
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/OpenAPIFormatTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.openapi;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.test.integration.microprofile.openapi.service.TestApplication;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Validates retrieval of JSON OpenAPI document via format parameter.
* @author Paul Ferraro
*/
@RunWith(Arquillian.class)
@RunAsClient
public class OpenAPIFormatTestCase {
private static final String DEPLOYMENT_NAME = OpenAPIFormatTestCase.class.getSimpleName() + ".war";
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME)
.addPackage(TestApplication.class.getPackage())
.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml")
.setWebXML(TestApplication.class.getPackage(), "web.xml")
;
}
@Test
public void test(@ArquillianResource URL baseURL) throws IOException, URISyntaxException {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
HttpUriRequest request = new HttpGet(baseURL.toURI().resolve("/openapi?format=JSON"));
try (CloseableHttpResponse response = client.execute(request)) {
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
List<String> urls = validateContent(response);
// Ensure relative urls are valid
for (String url : urls) {
try (CloseableHttpResponse r = client.execute(new HttpGet(baseURL.toURI().resolve(url + "/test/echo/foo")))) {
Assert.assertEquals(HttpServletResponse.SC_OK, r.getStatusLine().getStatusCode());
Assert.assertEquals("foo", EntityUtils.toString(r.getEntity()));
}
}
}
// Validate return type honors Accept header
request.setHeader("Accept", "application/json");
try (CloseableHttpResponse response = client.execute(request)) {
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
List<String> urls = validateContent(response);
// Ensure relative urls are valid
for (String url : urls) {
try (CloseableHttpResponse r = client.execute(new HttpGet(baseURL.toURI().resolve(url + "/test/echo/foo")))) {
Assert.assertEquals(HttpServletResponse.SC_OK, r.getStatusLine().getStatusCode());
Assert.assertEquals("foo", EntityUtils.toString(r.getEntity()));
}
}
}
// Validate return type honors complex, but unambiguous Accept header
request.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9,application/json;q=0.99, application/yaml;q=0.98");
try (CloseableHttpResponse response = client.execute(request)) {
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
List<String> urls = validateContent(response);
// Ensure relative urls are valid
for (String url : urls) {
try (CloseableHttpResponse r = client.execute(new HttpGet(baseURL.toURI().resolve(url + "/test/echo/foo")))) {
Assert.assertEquals(HttpServletResponse.SC_OK, r.getStatusLine().getStatusCode());
Assert.assertEquals("foo", EntityUtils.toString(r.getEntity()));
}
}
}
// Ensure format parameter is still read when Accept header is not sufficiently specific
request.setHeader("Accept", "*/*, application/*");
try (CloseableHttpResponse response = client.execute(request)) {
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
List<String> urls = validateContent(response);
// Ensure relative urls are valid
for (String url : urls) {
try (CloseableHttpResponse r = client.execute(new HttpGet(baseURL.toURI().resolve(url + "/test/echo/foo")))) {
Assert.assertEquals(HttpServletResponse.SC_OK, r.getStatusLine().getStatusCode());
Assert.assertEquals("foo", EntityUtils.toString(r.getEntity()));
}
}
}
// Test unacceptable accept header
request.setHeader("Accept", "application/json-patch+json");
try (CloseableHttpResponse response = client.execute(request)) {
Assert.assertEquals(HttpServletResponse.SC_NOT_ACCEPTABLE, response.getStatusLine().getStatusCode());
}
}
}
private static List<String> validateContent(HttpResponse response) throws IOException {
Assert.assertEquals("application/json", response.getEntity().getContentType().getValue());
JsonNode node = new ObjectMapper().reader().readTree(response.getEntity().getContent());
JsonNode info = node.get("info");
Assert.assertEquals("Test application", info.get("title").asText());
Assert.assertEquals("This is my test application description", info.get("description").asText());
JsonNode servers = node.required("servers");
List<String> result = new LinkedList<>();
for (JsonNode server : servers) {
result.add(server.required("url").asText());
}
Assert.assertFalse(result.isEmpty());
return result;
}
}
| 7,821
| 49.141026
| 217
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/OpenAPIRESTlessTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.openapi;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Validates that a RESTless deployment without OpenAPI configuration does not register an OpenAPI endpoint.
* @author Paul Ferraro
*/
@RunWith(Arquillian.class)
@RunAsClient
public class OpenAPIRESTlessTestCase {
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(WebArchive.class, "openapi-RESTless.war")
.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml")
;
}
@Test
public void test(@ArquillianResource URL baseURL) throws IOException, URISyntaxException {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
try (CloseableHttpResponse response = client.execute(new HttpGet(baseURL.toURI().resolve("/openapi")))) {
Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
}
}
}
}
| 2,814
| 38.647887
| 117
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/OpenAPIMultiModuleDeploymentIndexTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.openapi;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import jakarta.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.test.integration.microprofile.openapi.service.TestApplication;
import org.wildfly.test.integration.microprofile.openapi.service.multimodule.TestEjb;
import org.wildfly.test.integration.microprofile.openapi.service.multimodule.TestRequest;
import org.wildfly.test.integration.microprofile.openapi.service.multimodule.TestResource;
import org.wildfly.test.integration.microprofile.openapi.service.multimodule.TestResponse;
/**
* Validates OpenAPI endpoint for a multi-module deployment with classes shared of several libraries and accessible
* submodules.
*
* @author Joachim Grimm
*/
@RunWith(Arquillian.class)
@RunAsClient
public class OpenAPIMultiModuleDeploymentIndexTestCase {
private static final String PARENT_DEPLOYMENT_NAME =
OpenAPIMultiModuleDeploymentIndexTestCase.class.getSimpleName() + ".ear";
@Deployment
public static Archive<?> deploy() throws Exception {
WebArchive jaxrs = ShrinkWrap.create(WebArchive.class, "rest.war")
.addAsResource(TestResource.class.getResource("beans.xml"), "WEB-INF/beans.xml")
.addClasses(TestApplication.class, TestResource.class);
JavaArchive core = ShrinkWrap.create(JavaArchive.class, "core.jar")
.addClasses(TestEjb.class, TestRequest.class)
.addAsResource(new StringAsset(
"<ejb-jar version=\"3.0\" "
+ "metadata-complete=\"true\"></ejb-jar>"),
"META-INF/ejb-jar.xml");
JavaArchive common = ShrinkWrap.create(JavaArchive.class, "common.jar").addClass(TestResponse.class);
return ShrinkWrap.create(EnterpriseArchive.class, PARENT_DEPLOYMENT_NAME)
.addAsModules(jaxrs, core)
.addAsManifestResource(
TestEjb.class.getResource("application.xml"),
"application.xml")
.addAsLibraries(common);
}
@Test
public void test(@ArquillianResource URL baseURL) throws IOException, URISyntaxException {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
try (CloseableHttpResponse response = client.execute(new HttpGet(baseURL.toURI().resolve("/openapi")))) {
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
Assert.assertEquals("application/yaml", response.getEntity().getContentType().getValue());
JsonNode node =
new ObjectMapper(new YAMLFactory()).reader().readTree(response.getEntity().getContent());
JsonNode schemas = node.get("components").get("schemas");
Assert.assertNotNull(schemas);
Assert.assertNotNull(schemas.get("TestRequest"));
Assert.assertNotNull(schemas.get("TestResponse"));
}
}
}
}
| 5,312
| 49.122642
| 117
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/OpenAPIAltPathTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.openapi;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.test.integration.microprofile.openapi.service.TestApplication;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
/**
* Validates usage of "mp.openapi.extensions.path" configuration property.
* @author Paul Ferraro
*/
@RunWith(Arquillian.class)
@RunAsClient
public class OpenAPIAltPathTestCase {
private static final String DEPLOYMENT_NAME = OpenAPIAltPathTestCase.class.getSimpleName() + ".war";
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME)
.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml")
.addPackage(TestApplication.class.getPackage())
.addAsManifestResource(new StringAsset("mp.openapi.extensions.path=/swagger"), "microprofile-config.properties")
;
}
@Test
public void test(@ArquillianResource URL baseURL) throws IOException, URISyntaxException {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
try (CloseableHttpResponse response = client.execute(new HttpGet(baseURL.toURI().resolve("/openapi")))) {
Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
}
try (CloseableHttpResponse response = client.execute(new HttpGet(baseURL.toURI().resolve("/swagger")))) {
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
List<String> urls = validateContent(response);
// Ensure relative urls are valid
for (String url : urls) {
try (CloseableHttpResponse r = client.execute(new HttpGet(baseURL.toURI().resolve(url + "/test/echo/foo")))) {
Assert.assertEquals(HttpServletResponse.SC_OK, r.getStatusLine().getStatusCode());
Assert.assertEquals("foo", EntityUtils.toString(r.getEntity()));
}
}
}
}
}
private static List<String> validateContent(HttpResponse response) throws IOException {
Assert.assertEquals("application/yaml", response.getEntity().getContentType().getValue());
JsonNode node = new ObjectMapper(new YAMLFactory()).reader().readTree(response.getEntity().getContent());
JsonNode info = node.findValue("info");
Assert.assertNotNull(info);
Assert.assertEquals(DEPLOYMENT_NAME, info.get("title").asText());
Assert.assertNull(info.findValue("description"));
JsonNode servers = node.required("servers");
List<String> result = new LinkedList<>();
for (JsonNode server : servers) {
result.add(server.required("url").asText());
}
Assert.assertFalse(result.isEmpty());
return result;
}
}
| 5,063
| 43.814159
| 130
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/OpenAPIDisabledTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.openapi;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.test.integration.microprofile.openapi.service.TestApplication;
/**
* Validates usage of "mp.openapi.extensions.disable" configuration property.
* @author Paul Ferraro
*/
@RunWith(Arquillian.class)
@RunAsClient
public class OpenAPIDisabledTestCase {
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(WebArchive.class, "openapi-disabled.war")
.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml")
.addPackage(TestApplication.class.getPackage())
.addAsManifestResource(new StringAsset("mp.openapi.extensions.enabled=false"), "microprofile-config.properties")
;
}
@Test
public void test(@ArquillianResource URL baseURL) throws IOException, URISyntaxException {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
try (CloseableHttpResponse response = client.execute(new HttpGet(baseURL.toURI().resolve("/openapi")))) {
Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
}
}
}
}
| 3,109
| 40.466667
| 128
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/OpenAPIAbsoluteServersTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.openapi;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import javax.net.ssl.SSLHandshakeException;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.test.integration.microprofile.openapi.service.TestApplication;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
/**
* Validates usage of "mp.openapi.extensions.servers.relative" configuration property.
* @author Paul Ferraro
*/
@RunWith(Arquillian.class)
@RunAsClient
public class OpenAPIAbsoluteServersTestCase {
private static final String DEPLOYMENT_NAME = OpenAPIAbsoluteServersTestCase.class.getSimpleName() + ".war";
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME)
.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml")
.addPackage(TestApplication.class.getPackage())
.addAsManifestResource(new StringAsset("mp.openapi.extensions.servers.relative=false"), "microprofile-config.properties")
;
}
@Test
public void test(@ArquillianResource URL baseURL) throws IOException, URISyntaxException {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
try (CloseableHttpResponse response = client.execute(new HttpGet(baseURL.toURI().resolve("/openapi")))) {
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
List<String> urls = validateContent(response);
// Ensure absolute urls are valid
for (String url : urls) {
try (CloseableHttpResponse r = client.execute(new HttpGet(url + "/test/echo/foo"))) {
Assert.assertEquals(HttpServletResponse.SC_OK, r.getStatusLine().getStatusCode());
Assert.assertEquals("foo", EntityUtils.toString(r.getEntity()));
} catch (SSLHandshakeException ignored) {
// Ignore exception due to auto-generated self-signed certificate
// javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
}
}
}
}
}
private static List<String> validateContent(HttpResponse response) throws IOException {
Assert.assertEquals("application/yaml", response.getEntity().getContentType().getValue());
JsonNode node = new ObjectMapper(new YAMLFactory()).reader().readTree(response.getEntity().getContent());
JsonNode info = node.required("info");
Assert.assertNotNull(info);
Assert.assertEquals(DEPLOYMENT_NAME, info.required("title").asText());
Assert.assertNull(info.get("description"));
JsonNode servers = node.required("servers");
List<String> result = new LinkedList<>();
for (JsonNode server : servers) {
result.add(server.required("url").asText());
}
Assert.assertFalse(result.isEmpty());
return result;
}
}
| 5,279
| 44.913043
| 253
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/service/TestApplication.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.openapi.service;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
/**
* @author Paul Ferraro
*/
@ApplicationPath("/test")
public class TestApplication extends Application {
}
| 1,282
| 35.657143
| 70
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/service/EchoResource.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.openapi.service;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
/**
* @author Paul Ferraro
*/
@Path("/echo")
@Produces(MediaType.TEXT_PLAIN)
public class EchoResource {
@GET
@Path("{value}")
public String echo(@PathParam("value") String value) {
return value;
}
}
| 1,473
| 32.5
| 70
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/service/multimodule/TestRequest.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.openapi.service.multimodule;
/**
* @author Joachim Grimm
*/
public class TestRequest {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
| 1,328
| 32.225
| 78
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/service/multimodule/TestResource.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.openapi.service.multimodule;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
/**
* @author Joachim Grimm
*/
@Path("/echo")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class TestResource {
@Inject
private TestEjb testEjb;
@POST
@Operation(summary = "Test the indexing of multi module deployments")
@APIResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = TestResponse.class)),
description = "Indexes found")
public TestResponse echo(TestRequest request) {
return testEjb.hello(request);
}
}
| 2,095
| 36.428571
| 113
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/service/multimodule/TestResponse.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.openapi.service.multimodule;
/**
* @author Joachim Grimm
*/
public class TestResponse {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
| 1,321
| 32.05
| 78
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/openapi/service/multimodule/TestEjb.java
|
/*
* Copyright 2020 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.test.integration.microprofile.openapi.service.multimodule;
import jakarta.ejb.Stateless;
/**
* @author Joachim Grimm
*/
@Stateless
public class TestEjb {
public TestResponse hello(TestRequest request) {
TestResponse testResponse = new TestResponse();
testResponse.setValue(request.getValue() + "1");
return testResponse;
}
}
| 978
| 28.666667
| 78
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/faulttolerance/context/asynchronous/RequestFoo.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.faulttolerance.context.asynchronous;
import java.util.concurrent.atomic.AtomicBoolean;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.enterprise.context.RequestScoped;
/**
* Adapted from Thorntail.
*
* @author Radoslav Husar
*/
@RequestScoped
public class RequestFoo {
static final AtomicBoolean DESTROYED = new AtomicBoolean(false);
private String foo;
@PostConstruct
void init() {
foo = "ok";
}
public String getFoo() {
return foo;
}
@PreDestroy
void destroy() {
DESTROYED.set(true);
}
}
| 1,686
| 29.125
| 86
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/faulttolerance/context/asynchronous/AsyncService.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.faulttolerance.context.asynchronous;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.eclipse.microprofile.faulttolerance.Asynchronous;
/**
* Adapted from Thorntail.
*
* @author Radoslav Husar
*/
@ApplicationScoped
public class AsyncService {
@Inject
RequestFoo foo;
@Asynchronous
public Future<String> perform() {
return CompletableFuture.completedFuture(foo.getFoo());
}
}
| 1,613
| 33.340426
| 86
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/faulttolerance/context/asynchronous/AsynchronousRequestContextTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.faulttolerance.context.asynchronous;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.ExecutionException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Adapted from Thorntail/SmallRye.
*
* @author Martin Kouba
* @author Radoslav Husar
*/
@RunWith(Arquillian.class)
public class AsynchronousRequestContextTestCase {
@Deployment
public static WebArchive createTestArchive() {
return ShrinkWrap.create(WebArchive.class, AsynchronousRequestContextTestCase.class.getSimpleName() + ".war")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addPackage(AsynchronousRequestContextTestCase.class.getPackage())
;
}
@Test
public void testRequestContextActive(AsyncService asyncService) throws InterruptedException, ExecutionException {
RequestFoo.DESTROYED.set(false);
assertEquals("ok", asyncService.perform().get());
assertTrue(RequestFoo.DESTROYED.get());
}
}
| 2,377
| 37.354839
| 117
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/faulttolerance/context/timeout/TimeoutContextTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.faulttolerance.context.timeout;
import static org.junit.Assert.assertEquals;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test case for https://issues.redhat.com/browse/WFLY-12982 which used to fail on legacy SR FT with:
* <p>
* UT005023: Exception handling request to /: org.jboss.weld.context.ContextNotActiveException:
* WELD-001303: No active contexts for scope type jakarta.enterprise.context.RequestScoped
*
* @author Radoslav Husar
*/
@RunWith(Arquillian.class)
public class TimeoutContextTestCase {
@Deployment
public static WebArchive createTestArchive() {
return ShrinkWrap.create(WebArchive.class, TimeoutContextTestCase.class.getSimpleName() + ".war")
.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml")
.addPackage(TimeoutContextTestCase.class.getPackage())
;
}
@Test
public void testRequestContextActive(TimeoutBean timeoutBean) throws Exception {
assertEquals("Hello bar", timeoutBean.greet());
}
}
| 2,401
| 39.033333
| 113
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/faulttolerance/context/timeout/RequestScopedService.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.faulttolerance.context.timeout;
import jakarta.enterprise.context.RequestScoped;
/**
* @author Radoslav Husar
*/
@RequestScoped
public class RequestScopedService {
public String call() {
return "bar";
}
}
| 1,300
| 34.162162
| 81
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/faulttolerance/context/timeout/TimeoutBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.faulttolerance.context.timeout;
import jakarta.inject.Inject;
import org.eclipse.microprofile.faulttolerance.Timeout;
/**
* @author Radoslav Husar
*/
public class TimeoutBean {
@Inject
RequestScopedService service;
@Timeout
public String greet() throws InterruptedException {
return "Hello " + service.call();
}
}
| 1,423
| 32.904762
| 81
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/faulttolerance/micrometer/FaultToleranceMicrometerIntegrationTestCase.java
|
/*
* Copyright 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.test.integration.microprofile.faulttolerance.micrometer;
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import jakarta.inject.Inject;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.test.integration.common.HttpRequest;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.test.integration.microprofile.faulttolerance.micrometer.deployment.FaultTolerantApplication;
import org.wildfly.test.integration.observability.micrometer.MicrometerSetupTask;
/**
* Test case to verify SmallRye Fault Tolerance integration with Micrometer. This invokes a REST application which always
* times out and Eclipse MP FT @Timeout kicks in, then we verify the counter in the injected Micrometer's MeterRegistry.
*
* @author Radoslav Husar
*/
@RunWith(Arquillian.class)
@ServerSetup(MicrometerSetupTask.class)
public class FaultToleranceMicrometerIntegrationTestCase {
// Let's use a slightly higher number of invocations, so we can at times differentiate between stale read and or other problems
private static final int INVOCATION_COUNT = 10;
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(WebArchive.class, FaultToleranceMicrometerIntegrationTestCase.class.getSimpleName() + ".war")
.addClasses(ServerSetupTask.class)
.addPackage(FaultTolerantApplication.class.getPackage())
.addAsWebInfResource(FaultToleranceMicrometerIntegrationTestCase.class.getPackage(), "web.xml", "web.xml")
.addAsWebInfResource(FaultToleranceMicrometerIntegrationTestCase.class.getPackage(), "beans.xml", "beans.xml");
}
@ArquillianResource
private URL url;
@Inject
private MeterRegistry meterRegistry;
@Test
@InSequence(1)
public void testClearInjectedRegistry() {
Assert.assertNotNull(meterRegistry);
meterRegistry.clear();
}
@Test
@RunAsClient
@InSequence(2)
public void makeRequests() throws IOException, ExecutionException, TimeoutException {
for (int i = 0; i < INVOCATION_COUNT; i++) {
HttpRequest.get(url.toString() + "app/timeout", 10, TimeUnit.SECONDS);
}
}
@Test
@InSequence(3)
public void checkCounter() {
Counter counterInvocations = meterRegistry.get("ft.invocations.total").counter();
Assert.assertEquals(0, counterInvocations.count(), 0);
Counter counterTimeouts = meterRegistry.get("ft.timeout.calls.total").counter();
Assert.assertEquals(INVOCATION_COUNT, counterTimeouts.count(), 0);
}
}
| 3,913
| 37.752475
| 131
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/faulttolerance/micrometer/deployment/TimeoutService.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.faulttolerance.micrometer.deployment;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import org.eclipse.microprofile.faulttolerance.Fallback;
import org.eclipse.microprofile.faulttolerance.Timeout;
/**
* A service that always times out!
*
* @author Radoslav Husar
*/
@Path("/timeout")
@ApplicationScoped
public class TimeoutService {
@Fallback(fallbackMethod = "fallback")
@Timeout(100)
@GET
public String alwaysTimeout() {
try {
// Note that sleep duration is longer than the timeout above.
// Also note that this needs to be more than slightly higher than the timeout on slow/overloaded systems.
Thread.sleep(5_000);
} catch (InterruptedException e) {
// Ignore.
}
return "standard method processing";
}
public String fallback() {
return "fallback method called";
}
}
| 2,027
| 33.965517
| 117
|
java
|
null |
wildfly-main/testsuite/integration/microprofile/src/test/java/org/wildfly/test/integration/microprofile/faulttolerance/micrometer/deployment/FaultTolerantApplication.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.test.integration.microprofile.faulttolerance.micrometer.deployment;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
/**
* @author Radoslav Husar
*/
@ApplicationPath("/app")
public class FaultTolerantApplication extends Application {
}
| 1,312
| 37.617647
| 87
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/security/IIOPSecurityStatelessBean.java
|
package org.jboss.as.test.iiop.security;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* @author Stuart Douglas
*/
@RemoteHome(IIOPSecurityStatelessHome.class)
@Stateless
@SecurityDomain("other")
public class IIOPSecurityStatelessBean {
@RolesAllowed("Role1")
public String role1() {
return "role1";
}
@RolesAllowed("Role2")
public String role2() {
return "role2";
}
public void ejbCreate() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void ejbRemove() {
}
public void setSessionContext(SessionContext context) {
}
}
| 793
| 15.541667
| 59
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/security/IIOPSecurityInvocationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.security;
import java.rmi.RemoteException;
import java.util.Properties;
import java.util.concurrent.Callable;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.network.NetworkUtils;
import org.jboss.as.test.shared.FileUtils;
import org.jboss.as.test.shared.PropertiesValueResolver;
import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils;
import org.jboss.as.test.shared.integration.ejb.security.Util;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.security.permission.ElytronPermission;
/**
* A simple IIOP invocation for one AS7 server to another
*/
@RunWith(Arquillian.class)
public class IIOPSecurityInvocationTestCase {
@Deployment(name = "server", testable = false)
@TargetsContainer("iiop-server")
public static Archive<?> deployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "server.jar");
jar.addClasses(IIOPSecurityStatelessBean.class, IIOPSecurityStatelessHome.class, IIOPSecurityStatelessRemote.class)
.addAsManifestResource(IIOPSecurityInvocationTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
return jar;
}
@Deployment(name = "client", testable = true)
@TargetsContainer("iiop-client")
public static Archive<?> clientDeployment() {
/*
* The @EJB annotation doesn't allow to specify the address dynamically. So, istead of
* @EJB(lookup = "corbaname:iiop:localhost:3628#IIOPTransactionalStatelessBean")
* private IIOPTransactionalHome home;
* we need to do this trick to get the ${node0} sys prop into ejb-jar.xml
* and have it injected that way.
*/
String ejbJar = FileUtils.readFile(IIOPSecurityInvocationTestCase.class, "ejb-jar.xml");
final Properties properties = new Properties();
properties.putAll(System.getProperties());
if (properties.containsKey("node1")) {
properties.put("node1", NetworkUtils.formatPossibleIpv6Address((String) properties.get("node1")));
}
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "client.jar");
jar.addClasses(ClientEjb.class, IIOPSecurityStatelessHome.class, IIOPSecurityStatelessRemote.class, IIOPSecurityInvocationTestCase.class, Util.class)
.addAsManifestResource(IIOPSecurityInvocationTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml")
.addAsManifestResource(new StringAsset(PropertiesValueResolver.replaceProperties(ejbJar, properties)), "ejb-jar.xml")
// the following permission is needed because of usage of LoginContext in the test
.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(new ElytronPermission("authenticate"),
new ElytronPermission("getSecurityDomain"), new ElytronPermission("getPrivateCredentials")), "permissions.xml");
return jar;
}
@Test
@OperateOnDeployment("client")
public void testSuccessfulInvocation() throws Exception {
Callable<Void> callable = () -> {
final ClientEjb ejb = client();
Assert.assertEquals("role1", ejb.testSuccess());
return null;
};
Util.switchIdentity("user1", "password1", callable);
}
@Test
@OperateOnDeployment("client")
public void testFailedInvocation() throws Exception {
Callable<Void> callable = () -> {
final ClientEjb ejb = client();
ejb.testFailure();
return null;
};
try {
Util.switchIdentity("user1", "password1", callable);
Assert.fail("Invocation should have failed");
} catch (RemoteException expected) {
}
}
private ClientEjb client() throws NamingException {
final InitialContext context = new InitialContext();
return (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
}
}
| 5,538
| 42.614173
| 157
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/security/IIOPSecurityStatelessRemote.java
|
package org.jboss.as.test.iiop.security;
import jakarta.ejb.EJBObject;
import java.rmi.RemoteException;
/**
* @author Stuart Douglas
*/
public interface IIOPSecurityStatelessRemote extends EJBObject {
String role1() throws RemoteException;
String role2() throws RemoteException;
}
| 296
| 17.5625
| 64
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/security/IIOPSecurityStatelessHome.java
|
package org.jboss.as.test.iiop.security;
import jakarta.ejb.EJBHome;
import java.rmi.RemoteException;
/**
* @author Stuart Douglas
*/
public interface IIOPSecurityStatelessHome extends EJBHome {
IIOPSecurityStatelessRemote create() throws RemoteException;
}
| 268
| 18.214286
| 64
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/security/ClientEjb.java
|
package org.jboss.as.test.iiop.security;
import java.rmi.RemoteException;
import jakarta.ejb.Stateless;
/**
* @author Stuart Douglas
*/
@Stateless
public class ClientEjb {
private IIOPSecurityStatelessHome statelessHome;
public String testSuccess() throws RemoteException {
IIOPSecurityStatelessRemote ejb = statelessHome.create();
return ejb.role1();
}
public String testFailure() throws RemoteException {
IIOPSecurityStatelessRemote ejb = statelessHome.create();
return ejb.role2();
}
}
| 549
| 21
| 65
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/client/IIOPTestBeanHome.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.client;
import java.rmi.RemoteException;
import jakarta.ejb.EJBHome;
public interface IIOPTestBeanHome extends EJBHome {
IIOPTestRemote create() throws RemoteException;
}
| 1,222
| 37.21875
| 69
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/client/IIOPTestBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.client;
import java.rmi.RemoteException;
import jakarta.annotation.Resource;
import jakarta.ejb.Remote;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionAttribute;
import jakarta.ejb.TransactionAttributeType;
import jakarta.transaction.TransactionSynchronizationRegistry;
@Remote(IIOPTestRemote.class)
@RemoteHome(IIOPTestBeanHome.class)
@Stateless
public class IIOPTestBean {
@Resource
private SessionContext sessionContext;
@Resource
private TransactionSynchronizationRegistry transactionSynchronizationRegistry;
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public String callMandatory() throws RemoteException {
return "transaction-attribute-mandatory";
}
@TransactionAttribute(TransactionAttributeType.NEVER)
public String callNever() throws RemoteException {
return "transaction-attributte-never";
}
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public String callRollbackOnly() throws RemoteException {
sessionContext.setRollbackOnly();
return "transaction-rollback-only";
}
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public int transactionStatus() throws RemoteException {
return transactionSynchronizationRegistry.getTransactionStatus();
}
}
| 2,424
| 34.144928
| 82
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/client/IIOPTestRemote.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.client;
import java.rmi.RemoteException;
import jakarta.ejb.EJBObject;
public interface IIOPTestRemote extends EJBObject {
String callMandatory() throws RemoteException;
String callNever() throws RemoteException;
String callRollbackOnly() throws RemoteException;
int transactionStatus() throws RemoteException;
}
| 1,376
| 38.342857
| 69
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/client/IIOPTransactionPropagationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.client;
import java.io.IOException;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import jakarta.transaction.Status;
import org.jboss.arquillian.container.test.api.ContainerController;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.management.ManagementOperations;
import org.jboss.as.test.integration.management.util.MgmtOperationException;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CORBA.SystemException;
/**
* @author Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
@RunAsClient
public class IIOPTransactionPropagationTestCase {
@ArquillianResource
private static ContainerController container;
@ArquillianResource
private Deployer deployer;
public static final String DEFAULT_JBOSSAS = "iiop-server";
private static final String ARCHIVE_NAME = "iiop-jts-ctx-propag-test";
private static InitialContext context;
@Deployment(name = ARCHIVE_NAME, managed = true)
@TargetsContainer(DEFAULT_JBOSSAS)
public static Archive<?> deploy() throws InvalidName, SystemException {
JavaArchive jar = ShrinkWrap
.create(JavaArchive.class, ARCHIVE_NAME + ".jar")
.addClass(IIOPTestBean.class)
.addClass(IIOPTestBeanHome.class)
.addClass(IIOPTestRemote.class)
.addAsManifestResource(IIOPTransactionPropagationTestCase.class.getPackage(), "jboss-ejb3.xml",
"jboss-ejb3.xml");
// File testPackage = new File("/tmp", ARCHIVE_NAME + ".jar");
// jar.as(ZipExporter.class).exportTo(testPackage, true);
return jar;
}
@BeforeClass
public static void beforeClass() throws InvalidName, SystemException, NamingException {
// // Orb presseting has to be done before the ORB is started to be used
Util.presetOrb();
context = Util.getContext();
}
@AfterClass
public static void afterClass() throws NamingException {
Util.tearDownOrb();
}
@Test
public void testIIOPInvocation() throws Throwable {
final Object iiopObj = context.lookup(IIOPTestBean.class.getSimpleName());
final IIOPTestBeanHome beanHome = (IIOPTestBeanHome) PortableRemoteObject.narrow(iiopObj, IIOPTestBeanHome.class);
final IIOPTestRemote bean = beanHome.create();
try {
Util.startCorbaTx();
Assert.assertEquals(Status.STATUS_ACTIVE, bean.transactionStatus());
Assert.assertEquals("transaction-attribute-mandatory", bean.callMandatory());
Util.commitCorbaTx();
} catch (Throwable e) {
// Util.rollbackCorbaTx();
throw e;
}
}
@Test
public void testIIOPNeverCallInvocation() throws Throwable {
final Object iiopObj = context.lookup(IIOPTestBean.class.getSimpleName());
final IIOPTestBeanHome beanHome = (IIOPTestBeanHome) PortableRemoteObject.narrow(iiopObj, IIOPTestBeanHome.class);
final IIOPTestRemote bean = beanHome.create();
try {
Util.startCorbaTx();
Assert.assertEquals(Status.STATUS_ACTIVE, bean.transactionStatus());
bean.callNever();
Assert.fail("Exception is supposed to be here thrown from TransactionAttribute.NEVER method");
} catch (Exception e) {
// this is OK - is expected never throwing that TS exists
Assert.assertEquals(Status.STATUS_ACTIVE, bean.transactionStatus());
} finally {
Util.rollbackCorbaTx();
}
}
@Test
public void testIIOPInvocationWithRollbackOnly() throws Throwable {
final Object iiopObj = context.lookup(IIOPTestBean.class.getSimpleName());
final IIOPTestBeanHome beanHome = (IIOPTestBeanHome) PortableRemoteObject.narrow(iiopObj, IIOPTestBeanHome.class);
final IIOPTestRemote bean = beanHome.create();
try {
Util.startCorbaTx();
Assert.assertEquals(Status.STATUS_ACTIVE, bean.transactionStatus());
bean.callRollbackOnly();
Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, bean.transactionStatus());
} finally {
Util.rollbackCorbaTx();
}
}
/**
* The setup tasks are bound to deploy/undeploy actions.
*/
static class JTSSetup implements ServerSetupTask {
public static final String IIOP_TRANSACTIONS_JTA = "spec";
public static final String IIOP_TRANSACTIONS_JTS = "on";
private static final Logger log = Logger.getLogger(JTSSetup.class);
private boolean isTransactionJTS = true;
private String iiopTransaction = IIOP_TRANSACTIONS_JTA;
ManagementClient managementClient = null;
/**
* The setup method is prepared here just for sure. The jts switching on is done by xslt transformation before the test
* is launched.
*/
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
log.trace("JTSSetup.setup");
this.managementClient = managementClient;
boolean isNeedReload = false;
// check what is defined before
isTransactionJTS = checkJTSOnTransactions();
iiopTransaction = checkTransactionsOnJacorb();
if (!isTransactionJTS) {
setTransactionJTS(true);
isNeedReload = true;
}
if (IIOP_TRANSACTIONS_JTA.equalsIgnoreCase(iiopTransaction)) {
setJTS(true);
isNeedReload = true;
}
if (isNeedReload) {
ServerReload.executeReloadAndWaitForCompletion(managementClient, 40000);
}
}
@Override
public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception {
log.trace("JTSSetup.tearDown");
this.managementClient = managementClient;
boolean isNeedReload = false;
// get it back what was defined before
// if it was not JTS, set it back to JTA (was set to JTS setup())
// if it was JTA, set it back to JTA (was set to JTS in setup())
if (IIOP_TRANSACTIONS_JTA.equalsIgnoreCase(iiopTransaction)) {
setJTS(false);
isNeedReload = true;
}
if (!isTransactionJTS) {
setTransactionJTS(false);
}
if (isNeedReload) {
ServerReload.executeReloadAndWaitForCompletion(managementClient, 40000);
}
}
public boolean checkJTSOnTransactions() throws IOException, MgmtOperationException {
/* /subsystem=transactions:read-attribute(name=jts) */
final ModelNode address = new ModelNode();
address.add("subsystem", "transactions");
final ModelNode operation = new ModelNode();
operation.get(OP).set(READ_ATTRIBUTE_OPERATION);
operation.get(OP_ADDR).set(address);
operation.get("name").set("jts");
return executeOperation(operation).asBoolean();
}
public String checkTransactionsOnJacorb() throws IOException, MgmtOperationException {
/* /subsystem=iiop-openjdk:read-attribute(name=transactions) */
final ModelNode address = new ModelNode();
address.add("subsystem", "iiop-openjdk");
final ModelNode operation = new ModelNode();
operation.get(OP).set(READ_ATTRIBUTE_OPERATION);
operation.get(OP_ADDR).set(address);
operation.get("name").set("transactions");
return executeOperation(operation).asString();
}
public void setTransactionJTS(boolean enabled) throws IOException, MgmtOperationException {
/* /subsystem=transactions:write-attribute(name=jts,value=false|true) */
ModelNode address = new ModelNode();
address.add("subsystem", "transactions");
ModelNode operation = new ModelNode();
operation.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
operation.get(OP_ADDR).set(address);
operation.get("name").set("jts");
operation.get("value").set(enabled);
log.trace("operation=" + operation);
executeOperation(operation);
}
public void setJTS(boolean enabled) throws IOException, MgmtOperationException {
String transactionsOnIIOP = (enabled) ? IIOP_TRANSACTIONS_JTS : IIOP_TRANSACTIONS_JTA;
ModelNode address = new ModelNode();
address.add("subsystem", "iiop-openjdk");
ModelNode operation = new ModelNode();
operation.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
operation.get(OP_ADDR).set(address);
operation.get("name").set("transactions");
operation.get("value").set(transactionsOnIIOP);
log.trace("operation=" + operation);
executeOperation(operation);
}
private ModelNode executeOperation(final ModelNode op) throws IOException, MgmtOperationException {
return ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
}
}
}
| 11,609
| 41.065217
| 127
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/client/Util.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.client;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.as.arquillian.container.NetworkUtils;
import org.omg.CORBA.SystemException;
import org.omg.CORBA.ORBPackage.InvalidName;
import com.arjuna.ats.arjuna.recovery.RecoveryManager;
import com.arjuna.ats.internal.jts.ORBManager;
import com.arjuna.ats.internal.jts.context.ContextPropagationManager;
import com.arjuna.ats.jts.OTSManager;
import com.arjuna.orbportability.OA;
import com.arjuna.orbportability.ORB;
import com.sun.corba.se.impl.orbutil.ORBConstants;
public class Util {
public static final String HOST = NetworkUtils.formatPossibleIpv6Address(System.getProperty("node1", "localhost"));
private static org.omg.CORBA.ORB orb = null;
private static ORB arjunaORB = null;
// Recovery manager is needed till the end of orb usage
private static ExecutorService recoveryManagerPool;
public static void presetOrb() throws InvalidName, SystemException {
Properties properties = new Properties();
properties.setProperty(ORBConstants.PERSISTENT_SERVER_PORT_PROPERTY, "15151");
properties.setProperty(ORBConstants.ORB_SERVER_ID_PROPERTY, "1");
new ContextPropagationManager();
orb = org.omg.CORBA.ORB.init(new String[0], properties);
arjunaORB = com.arjuna.orbportability.ORB.getInstance("ClientSide");
arjunaORB.setOrb(orb);
OA oa = OA.getRootOA(arjunaORB);
org.omg.PortableServer.POA rootPOA = org.omg.PortableServer.POAHelper.narrow(orb
.resolve_initial_references("RootPOA"));
oa.setPOA(rootPOA);
oa.initOA();
ORBManager.setORB(arjunaORB);
ORBManager.setPOA(oa);
// Recovery manager has to be started on client when we want recovery
// and we start the transaction on client
recoveryManagerPool = Executors.newFixedThreadPool(1);
recoveryManagerPool.submit(new Callable<String>() {
@Override
public String call() throws Exception {
RecoveryManager.main(new String[] { "-test" });
return "Running recovery manager";
}
});
}
public static void tearDownOrb() {
ORBManager.reset();
if (recoveryManagerPool != null) {
recoveryManagerPool.shutdown();
}
}
public static void startCorbaTx() throws Throwable {
OTSManager.get_current().begin();
}
public static void commitCorbaTx() throws Throwable {
OTSManager.get_current().commit(true);
}
public static void rollbackCorbaTx() throws Throwable {
OTSManager.get_current().rollback();
}
public static InitialContext getContext() throws NamingException {
// this is needed to get the iiop call successful
System.setProperty("com.sun.CORBA.ORBUseDynamicStub", "true");
final Properties prope = new Properties();
prope.put(Context.PROVIDER_URL, "corbaloc::" + HOST + ":3628/JBoss/Naming/root");
prope.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
prope.put("java.naming.corba.orb", orb);
return new InitialContext(prope);
}
}
| 4,470
| 36.258333
| 119
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/basic/BasicIIOPInvocationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.basic;
import java.io.IOException;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.junit.Assert;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.network.NetworkUtils;
import org.jboss.as.test.shared.FileUtils;
import org.jboss.as.test.shared.PropertiesValueResolver;
import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.security.permission.ElytronPermission;
/**
* A simple IIOP invocation for one AS7 server to another
*/
@RunWith(Arquillian.class)
public class BasicIIOPInvocationTestCase {
@Deployment(name = "server", testable = false)
@TargetsContainer("iiop-server")
public static Archive<?> deployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "server.jar");
jar.addClasses(IIOPBasicBean.class, IIOPBasicHome.class, IIOPBasicRemote.class,
IIOPBasicStatefulBean.class, IIOPBasicStatefulHome.class, IIOPBasicStatefulRemote.class,
HandleWrapper.class)
.addAsManifestResource(BasicIIOPInvocationTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
return jar;
}
@Deployment(name = "client", testable = true)
@TargetsContainer("iiop-client")
public static Archive<?> clientDeployment() {
/*
* The @EJB annotation doesn't allow to specify the address dynamically. So, istead of
* @EJB(lookup = "corbaname:iiop:localhost:3628#IIOPTransactionalStatelessBean")
* private IIOPTransactionalHome home;
* we need to do this trick to get the ${node0} sys prop into ejb-jar.xml
* and have it injected that way.
*/
String ejbJar = FileUtils.readFile(BasicIIOPInvocationTestCase.class, "ejb-jar.xml");
final Properties properties = new Properties();
properties.putAll(System.getProperties());
if(properties.containsKey("node1")) {
properties.put("node1", NetworkUtils.formatPossibleIpv6Address((String) properties.get("node1")));
}
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "client.jar");
jar.addClasses(ClientEjb.class, IIOPBasicHome.class, IIOPBasicRemote.class,
BasicIIOPInvocationTestCase.class, IIOPBasicStatefulHome.class,
IIOPBasicStatefulRemote.class, HandleWrapper.class)
.addAsManifestResource(BasicIIOPInvocationTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml")
.addAsManifestResource(new StringAsset(PropertiesValueResolver.replaceProperties(ejbJar, properties)), "ejb-jar.xml")
.addAsManifestResource(
PermissionUtils.createPermissionsXmlAsset(new ElytronPermission("getPrivateCredentials")),
"permissions.xml");
return jar;
}
@Test
@OperateOnDeployment("client")
public void testRemoteIIOPInvocation() throws IOException, NamingException {
final ClientEjb ejb = client();
Assert.assertEquals("hello", ejb.getRemoteMessage());
}
@Test
@OperateOnDeployment("client")
public void testHomeHandle() throws IOException, NamingException {
final ClientEjb ejb = client();
Assert.assertEquals("hello", ejb.getRemoteViaHomeHandleMessage());
}
@Test
@OperateOnDeployment("client")
public void testHandle() throws IOException, NamingException, ClassNotFoundException {
final ClientEjb ejb = client();
Assert.assertEquals("hello", ejb.getRemoteViaHandleMessage());
}
/**
* Tests that even if a handle is returned embedded in another object the substitution service will
* replace it with a correct IIOP version of a handle.
*/
@Test
@OperateOnDeployment("client")
public void testWrappedHandle() throws IOException, NamingException, ClassNotFoundException {
final ClientEjb ejb = client();
Assert.assertEquals("hello", ejb.getRemoteViaWrappedHandle());
}
@Test
@OperateOnDeployment("client")
public void testEjbMetadata() throws IOException, NamingException {
final ClientEjb ejb = client();
Assert.assertEquals("hello", ejb.getRemoteMessageViaEjbMetadata());
}
@Test
@OperateOnDeployment("client")
public void testIsIdentical() throws IOException, NamingException {
final ClientEjb ejb = client();
ejb.testIsIdentical();
}
private ClientEjb client() throws NamingException {
final InitialContext context = new InitialContext();
return (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
}
}
| 6,228
| 40.805369
| 133
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/basic/HandleWrapper.java
|
package org.jboss.as.test.iiop.basic;
import java.io.Serializable;
import jakarta.ejb.Handle;
/**
* @author Stuart Douglas
*/
public class HandleWrapper implements Serializable{
private static final long serialVersionUID = 1L;
private final Handle handle;
public HandleWrapper(Handle handle) {
this.handle = handle;
}
public Handle getHandle() {
return handle;
}
}
| 413
| 17
| 52
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/basic/IIOPBasicHome.java
|
package org.jboss.as.test.iiop.basic;
import java.rmi.RemoteException;
import jakarta.ejb.EJBHome;
/**
* @author Stuart Douglas
*/
public interface IIOPBasicHome extends EJBHome {
IIOPBasicRemote create() throws RemoteException;
}
| 242
| 15.2
| 52
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/basic/IIOPBasicStatefulRemote.java
|
package org.jboss.as.test.iiop.basic;
import jakarta.ejb.EJBObject;
import java.rmi.RemoteException;
/**
* @author Stuart Douglas
*/
public interface IIOPBasicStatefulRemote extends EJBObject {
int state() throws RemoteException;
}
| 241
| 17.615385
| 60
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/basic/IIOPBasicRemote.java
|
package org.jboss.as.test.iiop.basic;
import java.rmi.RemoteException;
import jakarta.ejb.EJBObject;
/**
* @author Stuart Douglas
*/
public interface IIOPBasicRemote extends EJBObject {
String hello() throws RemoteException;
HandleWrapper wrappedHandle() throws RemoteException;
}
| 296
| 17.5625
| 57
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/basic/IIOPBasicBean.java
|
package org.jboss.as.test.iiop.basic;
import jakarta.annotation.Resource;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import java.rmi.RemoteException;
/**
* @author Stuart Douglas
*/
@RemoteHome(IIOPBasicHome.class)
@Stateless
public class IIOPBasicBean {
@Resource
private SessionContext sessionContext;
public String hello() {
return "hello";
}
public HandleWrapper wrappedHandle() {
try {
return new HandleWrapper(sessionContext.getEJBObject().getHandle());
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}
| 669
| 19.30303
| 80
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/basic/IIOPBasicStatefulHome.java
|
package org.jboss.as.test.iiop.basic;
import jakarta.ejb.EJBHome;
import java.rmi.RemoteException;
/**
* @author Stuart Douglas
*/
public interface IIOPBasicStatefulHome extends EJBHome {
IIOPBasicStatefulRemote create(int state) throws RemoteException;
}
| 266
| 18.071429
| 69
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/basic/IIOPBasicStatefulBean.java
|
package org.jboss.as.test.iiop.basic;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.Stateful;
/**
* @author Stuart Douglas
*/
@RemoteHome(IIOPBasicStatefulHome.class)
@Stateful
public class IIOPBasicStatefulBean {
private int state;
public void ejbCreate( int state) {
this.state = state;
}
public int state() {
return state;
}
}
| 378
| 14.791667
| 40
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/basic/ClientEjb.java
|
package org.jboss.as.test.iiop.basic;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.rmi.RemoteException;
import jakarta.ejb.EJBMetaData;
import jakarta.ejb.Handle;
import jakarta.ejb.HomeHandle;
import jakarta.ejb.Stateless;
import javax.rmi.PortableRemoteObject;
import org.junit.Assert;
import org.jboss.ejb.iiop.HandleImplIIOP;
/**
* @author Stuart Douglas
*/
@Stateless
public class ClientEjb {
private IIOPBasicHome home;
private IIOPBasicStatefulHome statefulHome;
public String getRemoteMessage() throws RemoteException {
return home.create().hello();
}
public String getRemoteViaHomeHandleMessage() throws RemoteException {
final HomeHandle handle = home.getHomeHandle();
final IIOPBasicHome newHome = (IIOPBasicHome) PortableRemoteObject.narrow(handle.getEJBHome(), IIOPBasicHome.class);
final IIOPBasicRemote object = newHome.create();
return object.hello();
}
public String getRemoteViaHandleMessage() throws RemoteException, IOException, ClassNotFoundException {
final IIOPBasicRemote object = home.create();
final Handle handle = serializeAndDeserialize(object.getHandle());
final IIOPBasicRemote newObject = (IIOPBasicRemote) PortableRemoteObject.narrow(handle.getEJBObject(), IIOPBasicRemote.class);
return newObject.hello();
}
public String getRemoteViaWrappedHandle() throws RemoteException, IOException, ClassNotFoundException {
final IIOPBasicRemote object = home.create();
final Handle handle = serializeAndDeserialize(object.wrappedHandle().getHandle());
Assert.assertEquals(HandleImplIIOP.class, handle.getClass());
final IIOPBasicRemote newObject = (IIOPBasicRemote) PortableRemoteObject.narrow(handle.getEJBObject(), IIOPBasicRemote.class);
return newObject.hello();
}
public String getRemoteMessageViaEjbMetadata() throws RemoteException {
final EJBMetaData metadata = home.getEJBMetaData();
final IIOPBasicHome newHome = (IIOPBasicHome) PortableRemoteObject.narrow(metadata.getEJBHome(), IIOPBasicHome.class);
final IIOPBasicRemote object = newHome.create();
Assert.assertEquals(IIOPBasicHome.class, metadata.getHomeInterfaceClass());
Assert.assertEquals(IIOPBasicRemote.class, metadata.getRemoteInterfaceClass());
return object.hello();
}
public void testIsIdentical() throws RemoteException {
final IIOPBasicStatefulRemote b1 = statefulHome.create(10);
final IIOPBasicStatefulRemote b2 = statefulHome.create(20);
Assert.assertTrue(b1.isIdentical(b1));
Assert.assertFalse(b1.isIdentical(b2));
final IIOPBasicRemote s1 = home.create();
final IIOPBasicRemote s2 = home.create();
Assert.assertTrue(s1.isIdentical(s1));
Assert.assertTrue(s1.isIdentical(s2));
}
private static <T extends Serializable> T serializeAndDeserialize(T o) throws IOException, ClassNotFoundException {
//serialize
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(o);
oos.close();
//.. and deserialize hande
ByteArrayInputStream fileInputStream
= new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream objectInputStream
= new ObjectInputStream(fileInputStream);
T result = (T) objectInputStream.readObject();
objectInputStream.close();
return result;
}
}
| 3,737
| 37.142857
| 134
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/IIOPTransactionalStatefulHome.java
|
package org.jboss.as.test.iiop.transaction;
import java.rmi.RemoteException;
import jakarta.ejb.EJBHome;
/**
* @author Stuart Douglas
*/
public interface IIOPTransactionalStatefulHome extends EJBHome {
IIOPTransactionalStatefulRemote create() throws RemoteException;
}
| 280
| 17.733333
| 68
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/IIOPTransactionalStatefulRemote.java
|
package org.jboss.as.test.iiop.transaction;
import java.rmi.RemoteException;
import jakarta.ejb.EJBObject;
/**
* @author Stuart Douglas
*/
public interface IIOPTransactionalStatefulRemote extends EJBObject {
int transactionStatus() throws RemoteException;
Boolean getCommitSucceeded() throws RemoteException;
boolean isBeforeCompletion() throws RemoteException;
void resetStatus() throws RemoteException;
void sameTransaction(boolean first) throws RemoteException;
void rollbackOnly() throws RemoteException;
void setRollbackOnlyBeforeCompletion(boolean rollbackOnlyInBeforeCompletion) throws RemoteException;
}
| 653
| 23.222222
| 104
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/IIOPTransactionalRemote.java
|
package org.jboss.as.test.iiop.transaction;
import java.rmi.RemoteException;
import jakarta.ejb.EJBObject;
/**
* @author Stuart Douglas
*/
public interface IIOPTransactionalRemote extends EJBObject {
int transactionStatus() throws RemoteException;
}
| 260
| 17.642857
| 60
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/IIOPTransactionalStatelessBean.java
|
package org.jboss.as.test.iiop.transaction;
import jakarta.annotation.Resource;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionAttribute;
import jakarta.ejb.TransactionAttributeType;
import jakarta.transaction.TransactionSynchronizationRegistry;
/**
* @author Stuart Douglas
*/
@RemoteHome(IIOPTransactionalHome.class)
@Stateless
public class IIOPTransactionalStatelessBean {
@Resource
private TransactionSynchronizationRegistry transactionSynchronizationRegistry;
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public int transactionStatus() {
return transactionSynchronizationRegistry.getTransactionStatus();
}
}
| 704
| 26.115385
| 82
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/IIOPTransactionalStatefulBean.java
|
package org.jboss.as.test.iiop.transaction;
import java.rmi.RemoteException;
import jakarta.annotation.Resource;
import jakarta.ejb.EJBException;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.SessionContext;
import jakarta.ejb.SessionSynchronization;
import jakarta.ejb.Stateful;
import jakarta.ejb.TransactionAttribute;
import jakarta.ejb.TransactionAttributeType;
import jakarta.transaction.TransactionSynchronizationRegistry;
/**
* @author Stuart Douglas
*/
@RemoteHome(IIOPTransactionalStatefulHome.class)
@Stateful
public class IIOPTransactionalStatefulBean implements SessionSynchronization {
private Boolean commitSucceeded;
private boolean beforeCompletion = false;
private Object transactionKey = null;
private boolean rollbackOnlyBeforeCompletion = false;
@Resource
private SessionContext sessionContext;
@Resource
private TransactionSynchronizationRegistry transactionSynchronizationRegistry;
public void ejbCreate() {
}
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public int transactionStatus() {
return transactionSynchronizationRegistry.getTransactionStatus();
}
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void resetStatus() {
commitSucceeded = null;
beforeCompletion = false;
transactionKey = null;
}
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public void setRollbackOnlyBeforeCompletion(boolean rollbackOnlyBeforeCompletion) throws RemoteException {
this.rollbackOnlyBeforeCompletion = rollbackOnlyBeforeCompletion;
}
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void sameTransaction(boolean first) throws RemoteException {
if (first) {
transactionKey = transactionSynchronizationRegistry.getTransactionKey();
} else {
if (!transactionKey.equals(transactionSynchronizationRegistry.getTransactionKey())) {
throw new RemoteException("Transaction on second call was not the same as on first call");
}
}
}
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void rollbackOnly() throws RemoteException {
sessionContext.setRollbackOnly();
}
@Override
public void afterBegin() throws EJBException, RemoteException {
}
@Override
public void beforeCompletion() throws EJBException, RemoteException {
beforeCompletion = true;
if (rollbackOnlyBeforeCompletion) {
sessionContext.setRollbackOnly();
}
}
@Override
public void afterCompletion(final boolean committed) throws EJBException, RemoteException {
commitSucceeded = committed;
}
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public Boolean getCommitSucceeded() {
return commitSucceeded;
}
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public boolean isBeforeCompletion() {
return beforeCompletion;
}
}
| 3,050
| 29.818182
| 110
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/IIOPTransactionalHome.java
|
package org.jboss.as.test.iiop.transaction;
import java.rmi.RemoteException;
import jakarta.ejb.EJBHome;
/**
* @author Stuart Douglas
*/
public interface IIOPTransactionalHome extends EJBHome {
IIOPTransactionalRemote create() throws RemoteException;
}
| 264
| 16.666667
| 60
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/TransactionIIOPInvocationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.transaction;
import java.io.IOException;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import jakarta.transaction.HeuristicMixedException;
import jakarta.transaction.HeuristicRollbackException;
import jakarta.transaction.NotSupportedException;
import jakarta.transaction.RollbackException;
import jakarta.transaction.SystemException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.network.NetworkUtils;
import org.jboss.as.test.shared.FileUtils;
import org.jboss.as.test.shared.PropertiesValueResolver;
import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.security.permission.ElytronPermission;
/**
* A simple IIOP invocation for one AS7 server to another
*/
@RunWith(Arquillian.class)
public class TransactionIIOPInvocationTestCase {
@Deployment(name = "server", testable = false)
@TargetsContainer("iiop-server")
public static Archive<?> deployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "server.jar");
jar.addClasses(IIOPTransactionalStatelessBean.class, IIOPTransactionalHome.class,
IIOPTransactionalRemote.class, IIOPTransactionalStatefulHome.class,
IIOPTransactionalStatefulRemote.class, IIOPTransactionalStatefulBean.class)
.addAsManifestResource(TransactionIIOPInvocationTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
return jar;
}
@Deployment(name = "client", testable = true)
@TargetsContainer("iiop-client")
public static Archive<?> clientDeployment() {
String ejbJar = FileUtils.readFile(TransactionIIOPInvocationTestCase.class, "ejb-jar.xml");
final Properties properties = new Properties();
properties.putAll(System.getProperties());
if(properties.containsKey("node1")) {
properties.put("node1", NetworkUtils.formatPossibleIpv6Address((String) properties.get("node1")));
}
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "client.jar");
jar.addClasses(ClientEjb.class, IIOPTransactionalHome.class,
IIOPTransactionalRemote.class, TransactionIIOPInvocationTestCase.class
, IIOPTransactionalStatefulHome.class, IIOPTransactionalStatefulRemote.class)
.addAsManifestResource(TransactionIIOPInvocationTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml")
.addAsManifestResource(new StringAsset(PropertiesValueResolver.replaceProperties(ejbJar, properties)), "ejb-jar.xml")
.addAsManifestResource(
PermissionUtils.createPermissionsXmlAsset(new ElytronPermission("getPrivateCredentials")),
"permissions.xml");
return jar;
}
@Test
@OperateOnDeployment("client")
public void testRemoteIIOPInvocation() throws IOException, NamingException, NotSupportedException, SystemException {
final InitialContext context = new InitialContext();
final ClientEjb ejb = (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
ejb.basicTransactionPropagationTest();
}
@Test
@OperateOnDeployment("client")
public void testRollbackOnly() throws IOException, NamingException, NotSupportedException, SystemException {
final InitialContext context = new InitialContext();
final ClientEjb ejb = (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
ejb.testRollbackOnly();
}
@Test
@OperateOnDeployment("client")
public void testRollbackOnlyBeforeCompletion() throws IOException, NamingException, NotSupportedException, SystemException, HeuristicMixedException, HeuristicRollbackException {
final InitialContext context = new InitialContext();
final ClientEjb ejb = (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
ejb.testRollbackOnlyBeforeCompletion();
}
@Test
@OperateOnDeployment("client")
public void testSameTransactionEachCall() throws IOException, NamingException, NotSupportedException, SystemException {
final InitialContext context = new InitialContext();
final ClientEjb ejb = (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
ejb.testSameTransactionEachCall();
}
@Test
@OperateOnDeployment("client")
public void testSynchronizationSucceeded() throws IOException, NamingException, NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
final InitialContext context = new InitialContext();
final ClientEjb ejb = (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
ejb.testSynchronization(true);
}
@Test
@OperateOnDeployment("client")
public void testSynchronizationFailed() throws IOException, NamingException, NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
final InitialContext context = new InitialContext();
final ClientEjb ejb = (ClientEjb) context.lookup("java:module/" + ClientEjb.class.getSimpleName());
ejb.testSynchronization(false);
}
}
| 6,828
| 46.423611
| 196
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/ClientEjb.java
|
package org.jboss.as.test.iiop.transaction;
import java.rmi.RemoteException;
import jakarta.annotation.Resource;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
import jakarta.transaction.HeuristicMixedException;
import jakarta.transaction.HeuristicRollbackException;
import jakarta.transaction.NotSupportedException;
import jakarta.transaction.RollbackException;
import jakarta.transaction.Status;
import jakarta.transaction.SystemException;
import jakarta.transaction.UserTransaction;
import org.junit.Assert;
/**
* @author Stuart Douglas
*/
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class ClientEjb {
@Resource
private UserTransaction userTransaction;
private IIOPTransactionalHome home;
private IIOPTransactionalStatefulHome statefulHome;
public void basicTransactionPropagationTest() throws RemoteException, SystemException, NotSupportedException {
final IIOPTransactionalRemote remote = home.create();
Assert.assertEquals(Status.STATUS_NO_TRANSACTION, remote.transactionStatus());
userTransaction.begin();
try {
Assert.assertEquals(Status.STATUS_ACTIVE, remote.transactionStatus());
} finally {
userTransaction.rollback();
}
}
public void testSameTransactionEachCall() throws RemoteException, SystemException, NotSupportedException {
final IIOPTransactionalStatefulRemote remote = statefulHome.create();
userTransaction.begin();
try {
remote.sameTransaction(true);
remote.sameTransaction(false);
} finally {
userTransaction.rollback();
}
}
public void testSynchronization(final boolean succeeded) throws RemoteException, SystemException, NotSupportedException, RollbackException, HeuristicRollbackException, HeuristicMixedException {
final IIOPTransactionalStatefulRemote remote = statefulHome.create();
userTransaction.begin();
try {
remote.sameTransaction(true);
remote.sameTransaction(false);
} finally {
if (succeeded) {
userTransaction.commit();
} else {
userTransaction.rollback();
}
}
Assert.assertEquals(succeeded, remote.isBeforeCompletion());
Assert.assertEquals((Boolean) succeeded, remote.getCommitSucceeded());
}
public void testRollbackOnly() throws RemoteException, SystemException, NotSupportedException {
final IIOPTransactionalStatefulRemote remote = statefulHome.create();
userTransaction.begin();
try {
Assert.assertEquals(Status.STATUS_ACTIVE, remote.transactionStatus());
remote.rollbackOnly();
Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, remote.transactionStatus());
} finally {
userTransaction.rollback();
}
Assert.assertFalse(remote.isBeforeCompletion());
Assert.assertFalse(remote.getCommitSucceeded());
}
public void testRollbackOnlyBeforeCompletion() throws RemoteException, SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException {
final IIOPTransactionalStatefulRemote remote = statefulHome.create();
userTransaction.begin();
try {
Assert.assertEquals(Status.STATUS_ACTIVE, remote.transactionStatus());
remote.setRollbackOnlyBeforeCompletion(true);
userTransaction.commit();
} catch (RollbackException expected) {
}
Assert.assertFalse(remote.getCommitSucceeded());
Assert.assertEquals(Status.STATUS_NO_TRANSACTION, remote.transactionStatus());
}
}
| 3,793
| 36.196078
| 197
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/timeout/IIOPTimeoutTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.transaction.timeout;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.transactions.TransactionCheckerSingleton;
import org.jboss.as.test.integration.transactions.TransactionCheckerSingletonRemote;
import org.jboss.as.test.integration.transactions.RemoteLookups;
import org.jboss.as.test.integration.transactions.TxTestUtil;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.naming.NamingException;
import jakarta.transaction.TransactionRolledbackException;
import java.net.URISyntaxException;
import java.rmi.RemoteException;
import java.rmi.ServerException;
import java.util.PropertyPermission;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
/**
* Tests on transaction timeout behavior with SLSB beans
* that is contacted via IIOP.
*/
@RunAsClient
@RunWith(Arquillian.class)
public class IIOPTimeoutTestCase {
private static final int DEFAULT_IIOP_PORT = 3528;
private static final String DEPLOYMENT_NAME = "stateless-iiop-txn-timeout";
@ContainerResource("iiop-client")
private ManagementClient mgmtClient;
private TransactionCheckerSingletonRemote checker;
@Deployment(name = DEPLOYMENT_NAME)
@TargetsContainer("iiop-client")
public static Archive<?> deploy() {
System.setProperty("com.sun.CORBA.ORBUseDynamicStub", "true");
return ShrinkWrap.create(JavaArchive.class, DEPLOYMENT_NAME + ".jar")
.addPackage(IIOPTimeoutTestCase.class.getPackage())
.addPackage(TxTestUtil.class.getPackage())
.addClasses(TimeoutUtil.class)
.addAsManifestResource(IIOPTimeoutTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml")
.addAsManifestResource(new StringAsset("<beans></beans>"), "beans.xml")
// grant necessary permissions for -Dsecurity.manager
.addAsResource(createPermissionsXmlAsset(
new PropertyPermission("ts.timeout.factor", "read")), "META-INF/jboss-permissions.xml");
}
@Before
public void startUp() throws NamingException, URISyntaxException {
if(checker == null) {
checker = RemoteLookups.lookupEjbStateless(mgmtClient, DEPLOYMENT_NAME,
TransactionCheckerSingleton.class, TransactionCheckerSingletonRemote.class);
}
checker.resetAll();
}
@Test
public void noTimeoutStateless() throws Exception {
TestBeanRemote bean = lookupStateless();
bean.testTransaction();
// synchronization is not called as we use stateless bean
Assert.assertEquals("Expecting two XA resources for each commit happened", 2, checker.getCommitted());
Assert.assertEquals("Expecting no rollback happened", 0, checker.getRolledback());
}
/**
* <p>
* Remote ejb iiop call to SLSB where timeout happens which leads to transaction rollback.
* There is subsequent call afterwards which starts different transaction which is committed.
* <p>
* We can see multiple exception in server log. See
* <a href="https://access.redhat.com/solutions/645963">https://access.redhat.com/solutions/645963</a>
*/
@Test
public void timeoutStateless() throws Exception {
TestBeanRemote bean = lookupStateless();
try {
bean.testTimeout();
Assert.fail("Expected rollback exception being thrown");
} catch (Exception e) {
// expected: enlistment of the resource to a timed out transaction should fail
// the SystemException from wildfly transaction client is transfered to ServerException
Assert.assertTrue("Timeout failure expects one of the exception "
+ ServerException.class.getName() + " or " + TransactionRolledbackException.class.getName(),
ServerException.class.equals(e.getClass()) || TransactionRolledbackException.class.equals(e.getClass()));
}
Assert.assertEquals("Expecting no commit happened on any XA resource", 0, checker.getCommitted());
Assert.assertEquals("Expecting transaction after synchronization finished with rollback", 1, checker.countSynchronizedAfterRolledBack());
// for stateless bean this should be ok
bean.touch();
// let's lookup the bean again and do a transaction work
bean = lookupStateless();
bean.testTransaction();
Assert.assertEquals("Expecting two commits happened on XA resources", 2, checker.getCommitted());
Assert.assertEquals("Expecting transaction after synchronization finished with commit", 1, checker.countSynchronizedAfterCommitted());
}
/**
* EJB iiop call to SFSB where transaction is started and successfully committed.
*/
@Test
public void noTimeoutStateful() throws Exception {
TestBeanRemote bean = lookupStateful();
bean.testTransaction();
Assert.assertTrue("Synchronization after begin should be called", checker.isSynchronizedBegin());
Assert.assertTrue("Synchronization before completion should be called", checker.isSynchronizedBefore());
Assert.assertTrue("Synchronization after completion should be called", checker.isSynchronizedAfter());
Assert.assertEquals("Expecting two XA resources for each commit happened", 2, checker.getCommitted());
Assert.assertEquals("Expecting no rollback happened", 0, checker.getRolledback());
}
/**
* EJB iiop call to SFSB where transaction is started but txn timeout happens
* and resources are rolled back.
*/
@Test
public void timeoutStateful() throws Exception {
TestBeanRemote bean = lookupStateful();
try {
bean.testTimeout();
Assert.fail("Excpected rollback exception being thrown");
} catch (Exception e) {
Assert.assertTrue("Timeout failure expects one of the exception "
+ ServerException.class.getName() + " or " + TransactionRolledbackException.class.getName(),
ServerException.class.equals(e.getClass()) || TransactionRolledbackException.class.equals(e.getClass()));
}
Assert.assertEquals("Synchronization after begin should be called", 1, checker.countSynchronizedBegin());
Assert.assertEquals("Synchronization before completion should not be called", 0, checker.countSynchronizedBefore());
Assert.assertEquals("Synchronization after completion should be called", 1, checker.countSynchronizedAfter());
Assert.assertEquals("Expecting no commit happened on any XA resource", 0, checker.getCommitted());
Assert.assertEquals("Expecting transaction after synchronization finished with rollback", 1, checker.countSynchronizedAfterRolledBack());
// the second call on the same stateful bean
bean.testTransaction();
Assert.assertEquals("Synchronization after begin should be called again", 2, checker.countSynchronizedBegin());
Assert.assertEquals("Synchronization before completion should be called", 1, checker.countSynchronizedBefore());
Assert.assertEquals("Synchronization after completion should be called again", 2, checker.countSynchronizedAfter());
Assert.assertEquals("Expecting two commits happened on XA resources", 2, checker.getCommitted());
Assert.assertEquals("Expecting transaction after synchronization finished with commit", 1, checker.countSynchronizedAfterCommitted());
}
private TestBeanRemote lookupStateless() throws NamingException, RemoteException {
TestBeanHome beanHome = RemoteLookups.lookupIIOP(mgmtClient.getMgmtAddress(), DEFAULT_IIOP_PORT,
TestBeanHome.class, StatelessBean.class);
return beanHome.create();
}
private TestBeanRemote lookupStateful() throws NamingException, RemoteException {
TestBeanHome beanHome = RemoteLookups.lookupIIOP(mgmtClient.getMgmtAddress(), DEFAULT_IIOP_PORT,
TestBeanHome.class, StatefulBean.class);
return beanHome.create();
}
}
| 9,792
| 47.241379
| 145
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/timeout/TestBeanHome.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.transaction.timeout;
import jakarta.ejb.EJBHome;
import java.rmi.RemoteException;
public interface TestBeanHome extends EJBHome {
TestBeanRemote create() throws RemoteException;
}
| 1,245
| 39.193548
| 70
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/timeout/StatefulBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2016, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.transaction.timeout;
import java.rmi.RemoteException;
import jakarta.annotation.Resource;
import jakarta.ejb.CreateException;
import jakarta.ejb.EJBException;
import jakarta.ejb.Remote;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.SessionSynchronization;
import jakarta.ejb.Stateful;
import jakarta.inject.Inject;
import jakarta.transaction.SystemException;
import jakarta.transaction.Transaction;
import jakarta.transaction.TransactionManager;
import org.jboss.as.test.integration.transactions.TransactionCheckerSingleton;
import org.jboss.as.test.integration.transactions.TxTestUtil;
import org.jboss.ejb3.annotation.TransactionTimeout;
import org.jboss.logging.Logger;
@Stateful
@Remote(TestBeanRemote.class)
@RemoteHome(TestBeanHome.class)
public class StatefulBean implements SessionSynchronization {
private static final Logger log = Logger.getLogger(StatefulBean.class);
@Resource(name = "java:jboss/TransactionManager")
private TransactionManager tm;
@Inject
private TransactionCheckerSingleton checker;
public void afterBegin() throws EJBException, RemoteException {
log.trace("afterBegin called");
checker.setSynchronizedBegin();
}
public void beforeCompletion() throws EJBException, RemoteException {
log.trace("beforeCompletion called");
checker.setSynchronizedBefore();
}
public void afterCompletion(boolean committed) throws EJBException, RemoteException {
log.tracef("afterCompletion: transaction was%s committed", committed ? "" : " not");
checker.setSynchronizedAfter(committed);
}
public void ejbCreate() throws RemoteException, CreateException {
log.debugf("Creating method for home interface '%s' was invoked", this.getClass());
}
public void testTransaction() throws RemoteException, SystemException {
log.trace("Method stateful #testTransaction called");
Transaction txn;
txn = tm.getTransaction();
TxTestUtil.enlistTestXAResource(txn, checker);
TxTestUtil.enlistTestXAResource(txn, checker);
}
@TransactionTimeout(value = 1)
public void testTimeout() throws SystemException, RemoteException {
log.trace("Method stateful #testTimeout called");
Transaction txn = tm.getTransaction();
TxTestUtil.enlistTestXAResource(txn, checker);
TxTestUtil.enlistTestXAResource(txn, checker);
try {
TxTestUtil.waitForTimeout(tm);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new RemoteException("Interupted during waiting for transaction timeout", ie);
}
}
public void touch() {
log.trace("Stateful bean instance has been touched");
}
}
| 3,820
| 36.097087
| 95
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/timeout/StatelessBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2016, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.transaction.timeout;
import java.rmi.RemoteException;
import jakarta.annotation.Resource;
import jakarta.ejb.EJBException;
import jakarta.ejb.Remote;
import jakarta.ejb.RemoteHome;
import jakarta.ejb.Stateless;
import jakarta.inject.Inject;
import jakarta.transaction.SystemException;
import jakarta.transaction.Transaction;
import jakarta.transaction.TransactionManager;
import org.jboss.as.test.integration.transactions.TransactionCheckerSingleton;
import org.jboss.as.test.integration.transactions.TxTestUtil;
import org.jboss.ejb3.annotation.TransactionTimeout;
import org.jboss.logging.Logger;
@Stateless
@Remote(TestBeanRemote.class)
@RemoteHome(TestBeanHome.class)
public class StatelessBean {
private static final Logger log = Logger.getLogger(StatelessBean.class);
@Resource(name = "java:jboss/TransactionManager")
private TransactionManager tm;
@Inject
private TransactionCheckerSingleton checker;
public void afterBegin() throws EJBException, RemoteException {
log.trace("afterBegin called");
checker.setSynchronizedBegin();
}
public void beforeCompletion() throws EJBException, RemoteException {
log.trace("beforeCompletion called");
checker.setSynchronizedBefore();
}
public void afterCompletion(boolean committed) throws EJBException, RemoteException {
log.tracef("afterCompletion: transaction was%s committed", committed ? "" : " not");
checker.setSynchronizedAfter(committed);
}
public void testTransaction() throws RemoteException, SystemException {
log.trace("Method stateless #testTransaction called");
Transaction txn;
txn = tm.getTransaction();
TxTestUtil.addSynchronization(txn, checker);
TxTestUtil.enlistTestXAResource(txn, checker);
TxTestUtil.enlistTestXAResource(txn, checker);
}
@TransactionTimeout(value = 1)
public void testTimeout() throws SystemException, RemoteException {
log.trace("Method stateless #testTimeout called");
Transaction txn;
txn = tm.getTransaction();
TxTestUtil.addSynchronization(txn, checker);
TxTestUtil.enlistTestXAResource(txn, checker);
try {
TxTestUtil.waitForTimeout(tm);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new RemoteException("Interupted during waiting for transaction timeout", ie);
}
TxTestUtil.enlistTestXAResource(txn, checker);
}
public void touch() {
log.trace("Stateless bean instance has been touched");
}
}
| 3,667
| 34.61165
| 95
|
java
|
null |
wildfly-main/testsuite/integration/iiop/src/test/java/org/jboss/as/test/iiop/transaction/timeout/TestBeanRemote.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.iiop.transaction.timeout;
import java.rmi.RemoteException;
import jakarta.ejb.EJBObject;
public interface TestBeanRemote extends EJBObject {
void testTransaction() throws RemoteException;
void testTimeout() throws RemoteException;
void touch() throws RemoteException;
}
| 1,339
| 38.411765
| 70
|
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.