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/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/ManagedExecutorServiceMetricsTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.concurrent;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.ee.subsystem.EESubsystemModel;
import org.jboss.as.ee.subsystem.EeExtension;
import org.jboss.as.ee.subsystem.ManagedExecutorServiceMetricsAttributes;
import org.jboss.as.ee.subsystem.ManagedExecutorServiceResourceDefinition;
import org.jboss.as.ee.subsystem.ManagedScheduledExecutorServiceResourceDefinition;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.jboss.remoting3.security.RemotingPermission;
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.extension.requestcontroller.RequestControllerExtension;
import jakarta.enterprise.concurrent.ManagedExecutorService;
import javax.naming.InitialContext;
import java.io.FilePermission;
import java.io.IOException;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
/**
* Test case for managed executor runtime stats
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class ManagedExecutorServiceMetricsTestCase {
private static final Logger logger = Logger.getLogger(ManagedExecutorServiceMetricsTestCase.class);
private static final PathAddress REQUEST_CONTROLLER_PATH_ADDRESS = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, RequestControllerExtension.SUBSYSTEM_NAME));
private static final PathAddress EE_SUBSYSTEM_PATH_ADDRESS = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, EeExtension.SUBSYSTEM_NAME));
private static final String RESOURCE_NAME = ManagedExecutorServiceMetricsTestCase.class.getSimpleName();
private static final String ACTIVE_REQUEST_ATTRIBUTE_NAME = "active-requests";
private static final String MAX_REQUEST_ATTRIBUTE_NAME = "max-requests";
@ArquillianResource
private ManagementClient managementClient;
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(JavaArchive.class, ManagedExecutorServiceMetricsTestCase.class.getSimpleName() + ".jar")
.addClasses(ManagedExecutorServiceMetricsTestCase.class)
.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller, org.jboss.as.ee, org.jboss.remoting\n"), "MANIFEST.MF")
.addAsManifestResource(createPermissionsXmlAsset(
new RemotingPermission("createEndpoint"),
new RemotingPermission("connect"),
new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read")
), "permissions.xml");
}
@Test
public void testManagedExecutorServiceManagement() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/executor/" + RESOURCE_NAME;
addOperation.get(ManagedExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
// note: threads will increase till CORE_THREADS config value, then reuses if has idle thread
addOperation.get(ManagedExecutorServiceResourceDefinition.CORE_THREADS).set(2);
// task will be considered hung if duration > 1s
addOperation.get(ManagedExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD).set(1000);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
Assert.assertNotNull(executorService);
testRuntimeStats(pathAddress, executorService);
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION)
.isDefined());
}
}
@Test
public void testManagedScheduledExecutorServiceManagement() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/scheduledexecutor/" + RESOURCE_NAME;
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
// note: threads will increase till CORE_THREADS config value, then reuses if has idle thread
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.CORE_THREADS).set(2);
// task will be considered hung if duration > 1s
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD).set(1000);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
// lookup the executor
final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
Assert.assertNotNull(executorService);
testRuntimeStats(pathAddress, executorService);
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION)
.isDefined());
}
}
/**
* WFLY-13177 - this tests an edge-case when executor threads are all busy and even queue is at its maximum. In that case
* the executor will reject any other tasks which should not increase active request counter in RequestController.
*
* @throws Exception
*/
@Test
public void testActiveRequests() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/activerequests/" + RESOURCE_NAME;
addOperation.get(ManagedExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
// note: threads will increase till CORE_THREADS config value, then reuses if has idle thread
addOperation.get(ManagedExecutorServiceResourceDefinition.CORE_THREADS).set(2);
addOperation.get(ManagedExecutorServiceResourceDefinition.QUEUE_LENGTH).set(1);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
Assert.assertNotNull(executorService);
testActiveRequestStats(pathAddress, executorService);
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION)
.isDefined());
}
}
/**
* WFLY-13177 - this tests another edge-case when executor is busy, but a new task is rejected due to a max-requests counter achieved.
* In that case RequestController will reject any other tasks which should not decrease/increase active request counter in RequestController.
*
* @throws Exception
*/
@Test
public void testMaxRequests() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/maxrequests/" + RESOURCE_NAME;
addOperation.get(ManagedExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
// note: threads will increase till CORE_THREADS config value, then reuses if has idle thread
addOperation.get(ManagedExecutorServiceResourceDefinition.CORE_THREADS).set(2);
addOperation.get(ManagedExecutorServiceResourceDefinition.QUEUE_LENGTH).set(1);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
writeAttribute(REQUEST_CONTROLLER_PATH_ADDRESS, MAX_REQUEST_ATTRIBUTE_NAME, 3, true);
try {
final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
Assert.assertNotNull(executorService);
testActiveRequestStats(pathAddress, executorService);
} finally {
try {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION)
.isDefined());
} finally {
undefineAttribute(REQUEST_CONTROLLER_PATH_ADDRESS, MAX_REQUEST_ATTRIBUTE_NAME, true);
}
}
}
private void testActiveRequestStats(PathAddress pathAddress, ManagedExecutorService executorService) throws IOException, ExecutionException, InterruptedException, BrokenBarrierException {
// assert stats initial values
Assert.assertEquals(0, readStatsAttribute(REQUEST_CONTROLLER_PATH_ADDRESS, ACTIVE_REQUEST_ATTRIBUTE_NAME));
Assert.assertEquals(0, readStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.ACTIVE_THREAD_COUNT));
Assert.assertEquals(0, readStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.COMPLETED_TASK_COUNT));
Assert.assertEquals(0, readStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.CURRENT_QUEUE_SIZE));
Assert.assertEquals(0, readStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.TASK_COUNT));
// exclusive testing of queue size stat
final CyclicBarrier barrier1 = new CyclicBarrier(3);
final CyclicBarrier barrier2 = new CyclicBarrier(3);
final Future f1 = executorService.submit(() -> {
logger.info("Executing task #4.1");
try {
barrier1.await();
barrier2.await();
} catch (Exception e) {
Assert.fail();
}
});
Assert.assertEquals(1, readStatsAttribute(REQUEST_CONTROLLER_PATH_ADDRESS, ACTIVE_REQUEST_ATTRIBUTE_NAME));
final Future f2 = executorService.submit(() -> {
logger.info("Executing task #4.2");
try {
barrier1.await();
barrier2.await();
} catch (Exception e) {
Assert.fail();
}
});
Assert.assertEquals(2, readStatsAttribute(REQUEST_CONTROLLER_PATH_ADDRESS, ACTIVE_REQUEST_ATTRIBUTE_NAME));
barrier1.await();
// 2 tasks running, executing a 3rd should place it in queue,
// cause when core threads is reached executor always prefers queueing than creating a new thread
final Future f3 = executorService.submit(() -> {
logger.info("Executing task #4.3");
});
Assert.assertEquals(3, readStatsAttribute(REQUEST_CONTROLLER_PATH_ADDRESS, ACTIVE_REQUEST_ATTRIBUTE_NAME));
Assert.assertEquals(1, readStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.CURRENT_QUEUE_SIZE));
// executor is full, the following task will be rejected which should not increase the active request counter
try {
final Future f4 = executorService.submit(() -> {
logger.info("Executing task #4.4");
});
Assert.fail();
} catch (RejectedExecutionException e) {
// expected exception
}
Assert.assertEquals(3, readStatsAttribute(REQUEST_CONTROLLER_PATH_ADDRESS, ACTIVE_REQUEST_ATTRIBUTE_NAME));
// resume tasks running, ensure all complete and then confirm expected idle stats
barrier2.await();
f1.get();
f2.get();
f3.get();
Assert.assertEquals(0, readStatsAttribute(REQUEST_CONTROLLER_PATH_ADDRESS, ACTIVE_REQUEST_ATTRIBUTE_NAME));
Assert.assertEquals(0, readStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.ACTIVE_THREAD_COUNT));
Assert.assertEquals(3, readStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.COMPLETED_TASK_COUNT));
Assert.assertEquals(0, readStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.CURRENT_QUEUE_SIZE));
Assert.assertEquals(3, readStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.TASK_COUNT));
}
private void testRuntimeStats(PathAddress pathAddress, ManagedExecutorService executorService) throws IOException, ExecutionException, InterruptedException, BrokenBarrierException {
// assert stats initial values
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.ACTIVE_THREAD_COUNT, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.COMPLETED_TASK_COUNT, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.CURRENT_QUEUE_SIZE, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.HUNG_THREAD_COUNT, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.MAX_THREAD_COUNT, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.TASK_COUNT, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.THREAD_COUNT, 0);
// execute task #1 and assert stats values
executorService.submit(() -> {
logger.info("Executing task #1");
try {
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.ACTIVE_THREAD_COUNT, 1);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.COMPLETED_TASK_COUNT, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.CURRENT_QUEUE_SIZE, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.MAX_THREAD_COUNT, 1);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.TASK_COUNT, 1);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.THREAD_COUNT, 1);
} catch (IOException | InterruptedException e) {
Assert.fail();
}
}).get();
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.ACTIVE_THREAD_COUNT, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.COMPLETED_TASK_COUNT, 1);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.CURRENT_QUEUE_SIZE, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.HUNG_THREAD_COUNT, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.MAX_THREAD_COUNT, 1);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.TASK_COUNT, 1);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.THREAD_COUNT, 1);
// execute task #2 and assert stats values
executorService.submit(() -> {
logger.info("Executing task #2");
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// after sleeping for over hung threshold time the thread executing this should be considered hung...
try {
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.HUNG_THREAD_COUNT, 1);
} catch (IOException | InterruptedException e) {
Assert.fail();
}
}).get();
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.ACTIVE_THREAD_COUNT, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.COMPLETED_TASK_COUNT, 2);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.CURRENT_QUEUE_SIZE, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.HUNG_THREAD_COUNT, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.MAX_THREAD_COUNT, 2);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.TASK_COUNT, 2);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.THREAD_COUNT, 2);
// exclusive testing of queue size stat
final CyclicBarrier barrier1 = new CyclicBarrier(3);
final CyclicBarrier barrier2 = new CyclicBarrier(3);
final Future f1 = executorService.submit(() -> {
logger.info("Executing task #3.1");
try {
barrier1.await();
barrier2.await();
} catch (Exception e) {
Assert.fail();
}
});
final Future f2 = executorService.submit(() -> {
logger.info("Executing task #3.2");
try {
barrier1.await();
barrier2.await();
} catch (Exception e) {
Assert.fail();
}
});
barrier1.await();
// 2 tasks running, executing a 3rd should place it in queue,
// cause when core threads is reached executor always prefers queueing than creating a new thread
final Future f3 = executorService.submit(() -> {
logger.info("Executing task #3.3");
});
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.CURRENT_QUEUE_SIZE, 1);
// resume tasks running, ensure all complete and then confirm expected idle stats
barrier2.await();
f1.get();
f2.get();
f3.get();
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.ACTIVE_THREAD_COUNT, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.COMPLETED_TASK_COUNT, 5);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.CURRENT_QUEUE_SIZE, 0);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.MAX_THREAD_COUNT, 2);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.TASK_COUNT, 5);
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.THREAD_COUNT, 2);
}
private int readStatsAttribute(PathAddress resourceAddress, String attrName) throws IOException {
ModelNode op = Util.getReadAttributeOperation(resourceAddress, attrName);
final ModelNode result = managementClient.getControllerClient().execute(op);
Assert.assertFalse(result.get(FAILURE_DESCRIPTION).toString(), result.get(FAILURE_DESCRIPTION).isDefined());
return result.get(RESULT).asInt();
}
private void assertStatsAttribute(PathAddress resourceAddress, String attrName, int expectedAttrValue) throws IOException, InterruptedException {
int actualAttrValue = readStatsAttribute(resourceAddress, attrName);
int retries = 3;
while (actualAttrValue != expectedAttrValue && retries > 0) {
Thread.sleep(500);
actualAttrValue = readStatsAttribute(resourceAddress, attrName);
retries--;
}
Assert.assertEquals(attrName, expectedAttrValue, actualAttrValue);
}
private void undefineAttribute(PathAddress resourceAddress, String attrName, boolean allowResourseServiceRestart) throws IOException {
ModelNode op = Util.getUndefineAttributeOperation(resourceAddress, attrName);
execute(op, allowResourseServiceRestart);
}
private void writeAttribute(PathAddress resourceAddress, String attrName, int value, boolean allowResourseServiceRestart) throws IOException {
ModelNode op = Util.getWriteAttributeOperation(resourceAddress, attrName, value);
execute(op, allowResourseServiceRestart);
}
private void execute(ModelNode op, boolean allowResourseServiceRestart) throws IOException {
if (allowResourseServiceRestart) {
op.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
}
final ModelNode result = managementClient.getControllerClient().execute(op);
Assert.assertFalse(result.get(FAILURE_DESCRIPTION).toString(), result.get(FAILURE_DESCRIPTION).isDefined());
}
}
| 24,493 | 57.598086 | 191 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/EEConcurrentManagementTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.concurrent;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import java.io.FilePermission;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.ee.subsystem.ContextServiceResourceDefinition;
import org.jboss.as.ee.subsystem.EESubsystemModel;
import org.jboss.as.ee.subsystem.EeExtension;
import org.jboss.as.ee.subsystem.ManagedExecutorServiceResourceDefinition;
import org.jboss.as.ee.subsystem.ManagedScheduledExecutorServiceResourceDefinition;
import org.jboss.as.ee.subsystem.ManagedThreadFactoryResourceDefinition;
import org.jboss.dmr.ModelNode;
import org.jboss.remoting3.security.RemotingPermission;
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;
/**
* Test case for adding and removing EE concurrent resources.
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class EEConcurrentManagementTestCase {
private static final PathAddress EE_SUBSYSTEM_PATH_ADDRESS = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, EeExtension.SUBSYSTEM_NAME));
private static final String RESOURCE_NAME = EEConcurrentManagementTestCase.class.getSimpleName();
@ArquillianResource
private ManagementClient managementClient;
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(JavaArchive.class, EEConcurrentManagementTestCase.class.getSimpleName() + ".jar")
.addClasses(EEConcurrentManagementTestCase.class)
.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller, org.jboss.as.ee, org.jboss.remoting\n"), "MANIFEST.MF")
.addAsManifestResource(createPermissionsXmlAsset(
new RemotingPermission("createEndpoint"),
new RemotingPermission("connect"),
new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read")
), "permissions.xml");
}
@Test
public void testContextServiceManagement() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.CONTEXT_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/contextservice/" + RESOURCE_NAME;
addOperation.get(ContextServiceResourceDefinition.JNDI_NAME).set(jndiName);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
// lookup
Assert.assertNotNull(new InitialContext().lookup(jndiName));
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION)
.isDefined());
try {
new InitialContext().lookup(jndiName);
Assert.fail();
} catch (NameNotFoundException e) {
// expected
}
}
}
@Test
public void testManagedThreadFactoryManagement() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_THREAD_FACTORY, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/threadfactory/" + RESOURCE_NAME;
addOperation.get(ManagedThreadFactoryResourceDefinition.JNDI_NAME).set(jndiName);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
// lookup
Assert.assertNotNull(new InitialContext().lookup(jndiName));
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION)
.isDefined());
try {
new InitialContext().lookup(jndiName);
Assert.fail();
} catch (NameNotFoundException e) {
// expected
}
}
}
@Test
public void testManagedExecutorServiceManagement() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/executor/" + RESOURCE_NAME;
addOperation.get(ManagedExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
addOperation.get(ManagedExecutorServiceResourceDefinition.CORE_THREADS).set(2);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
// lookup
Assert.assertNotNull(new InitialContext().lookup(jndiName));
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION)
.isDefined());
try {
new InitialContext().lookup(jndiName);
Assert.fail();
} catch (NameNotFoundException e) {
// expected
}
}
}
@Test
public void testManagedScheduledExecutorServiceManagement() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/scheduledexecutor/" + RESOURCE_NAME;
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.CORE_THREADS).set(2);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
// lookup
Assert.assertNotNull(new InitialContext().lookup(jndiName));
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION)
.isDefined());
try {
new InitialContext().lookup(jndiName);
Assert.fail();
} catch (NameNotFoundException e) {
// expected
}
}
}
}
| 10,302 | 50.258706 | 153 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/DefaultContextServiceTestEJB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.concurrent;
import java.security.Principal;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import jakarta.annotation.Resource;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.EJBContext;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
import jakarta.enterprise.concurrent.ContextService;
import javax.naming.NamingException;
import org.jboss.logging.Logger;
/**
* @author Eduardo Martins
*/
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
@LocalBean
@RolesAllowed("guest")
public class DefaultContextServiceTestEJB {
private static final Logger logger = Logger.getLogger(DefaultContextServiceTestEJB.class);
@Resource
private ContextService contextService;
@Resource
private EJBContext ejbContext;
/**
* @param task
* @return
* @throws javax.naming.NamingException
*/
public Future<?> submit(TestEJBRunnable task) throws NamingException {
final Principal principal = ejbContext.getCallerPrincipal();
logger.debugf("Principal: %s", principal);
task.setExpectedPrincipal(principal);
final ExecutorService executorService = Executors.newSingleThreadExecutor();
try {
return executorService.submit(contextService.createContextualProxy(task,Runnable.class));
} finally {
executorService.shutdown();
}
}
}
| 2,618 | 33.460526 | 101 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/DefaultContextServiceTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.concurrent;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import java.util.concurrent.Callable;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
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.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.security.permission.ElytronPermission;
/**
* Test for EE's default context service
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class DefaultContextServiceTestCase {
@Deployment
public static Archive<?> getDeployment() {
return ShrinkWrap.create(JavaArchive.class, DefaultContextServiceTestCase.class.getSimpleName() + ".jar")
.addClasses(DefaultContextServiceTestCase.class, DefaultContextServiceTestEJB.class, TestEJBRunnable.class, Util.class)
.addAsManifestResource(createPermissionsXmlAsset(
new RuntimePermission("modifyThread"),
new ElytronPermission("getSecurityDomain"),
new ElytronPermission("authenticate")
), "permissions.xml");
}
@Test
public void testTaskSubmit() throws Exception {
final Callable<Void> callable = () -> {
final DefaultContextServiceTestEJB testEJB = (DefaultContextServiceTestEJB) new InitialContext().lookup("java:module/" + DefaultContextServiceTestEJB.class.getSimpleName());
testEJB.submit(new TestEJBRunnable()).get();
return null;
};
Util.switchIdentitySCF("guest", "guest", callable);
}
}
| 2,916 | 40.084507 | 185 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/HungTasksTerminationTestCase.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.jboss.as.test.integration.ee.concurrent;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.ee.subsystem.EESubsystemModel;
import org.jboss.as.ee.subsystem.EeExtension;
import org.jboss.as.ee.subsystem.ManagedExecutorServiceMetricsAttributes;
import org.jboss.as.ee.subsystem.ManagedExecutorServiceResourceDefinition;
import org.jboss.as.ee.subsystem.ManagedScheduledExecutorServiceResourceDefinition;
import org.jboss.as.ee.subsystem.ManagedExecutorTerminateHungTasksOperation;
import org.jboss.dmr.ModelNode;
import org.jboss.remoting3.security.RemotingPermission;
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 jakarta.enterprise.concurrent.ManagedExecutorService;
import javax.naming.InitialContext;
import java.io.FilePermission;
import java.io.IOException;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutionException;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
/**
* Test case for managed executor's hung tasks termination feature.
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class HungTasksTerminationTestCase {
private static final PathAddress EE_SUBSYSTEM_PATH_ADDRESS = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, EeExtension.SUBSYSTEM_NAME));
private static final String RESOURCE_NAME = HungTasksTerminationTestCase.class.getSimpleName();
// a task is considered hung when is running over 0.5s
private static final long HUNG_TASK_THRESHOLD_TEST_VALUE = 500;
// hung tasks periodic cancellation should be done every 5s
private static final long HUNG_TASK_CANCELLATION_PERIOD_TEST_VALUE = 5000;
@ArquillianResource
private ManagementClient managementClient;
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(JavaArchive.class, HungTasksTerminationTestCase.class.getSimpleName() + ".jar")
.addClasses(HungTasksTerminationTestCase.class)
.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller, org.jboss.as.ee, org.jboss.remoting\n"), "MANIFEST.MF")
.addAsManifestResource(createPermissionsXmlAsset(
new RemotingPermission("createEndpoint"),
new RemotingPermission("connect"),
new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read")
), "permissions.xml");
}
/**
* Tests the 'on demand' hung task termination, through a management operation, works on a ManagedExecutorService.
* @throws Exception
*/
@Test
public void testManagedExecutorServiceHungTasksCancellationOperation() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/executor/" + RESOURCE_NAME;
addOperation.get(ManagedExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
addOperation.get(ManagedExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD).set(HUNG_TASK_THRESHOLD_TEST_VALUE);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
Assert.assertNotNull(executorService);
testHungTasksCancellationOperation(pathAddress, executorService);
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION)
.isDefined());
}
}
/**
* Tests the 'on demand' hung task termination, through a management operation, works on a ManagedScheduledExecutorService.
* @throws Exception
*/
@Test
public void testManagedScheduledExecutorServiceHungTasksCancellationOperation() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/scheduledexecutor/" + RESOURCE_NAME;
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD).set(HUNG_TASK_THRESHOLD_TEST_VALUE);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
// lookup the executor
final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
Assert.assertNotNull(executorService);
testHungTasksCancellationOperation(pathAddress, executorService);
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION)
.isDefined());
}
}
/**
* Tests the 'periodic' hung task termination works on a ManagedExecutorService.
* @throws Exception
*/
@Test
public void testManagedExecutorServiceHungTasksCancellationPeriodic() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/executor/" + RESOURCE_NAME;
addOperation.get(ManagedExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
addOperation.get(ManagedExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD).set(HUNG_TASK_THRESHOLD_TEST_VALUE);
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_TERMINATION_PERIOD).set(HUNG_TASK_CANCELLATION_PERIOD_TEST_VALUE);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
Assert.assertNotNull(executorService);
testHungTasksCancellationPeriodic(pathAddress, executorService);
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION)
.isDefined());
}
}
/**
* Tests the 'periodic' hung task termination works on a ManagedScheduledExecutorService.
* @throws Exception
*/
@Test
public void testManagedScheduledExecutorServiceHungTasksCancellationPeriodic() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/scheduledexecutor/" + RESOURCE_NAME;
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD).set(HUNG_TASK_THRESHOLD_TEST_VALUE);
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_TERMINATION_PERIOD).set(HUNG_TASK_CANCELLATION_PERIOD_TEST_VALUE);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
// lookup the executor
final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
Assert.assertNotNull(executorService);
testHungTasksCancellationPeriodic(pathAddress, executorService);
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION)
.isDefined());
}
}
private void testHungTasksCancellationOperation(PathAddress pathAddress, ManagedExecutorService executorService) throws IOException, ExecutionException, InterruptedException, BrokenBarrierException {
// assert no hung tasks exists at start
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.HUNG_THREAD_COUNT, 0);
final CyclicBarrier barrier1 = new CyclicBarrier(2);
final CyclicBarrier barrier2 = new CyclicBarrier(2);
final Runnable runnable = () -> {
try {
// signal task is running
barrier1.await();
// sleep till hung
Thread.sleep(HUNG_TASK_THRESHOLD_TEST_VALUE + 1);
// signal task is hung
barrier2.await();
} catch (Exception e) {
// unexpected, thus fail
Assert.fail();
}
// sleep 1 min, expecting cancellation
try {
Thread.sleep(60000);
} catch (Exception e) {
// expected, was cancelled
throw new RuntimeException(e);
}
// not expected, was not cancelled
Assert.fail();
};
executorService.submit(runnable);
barrier1.await();
// all crossed the 1st barrier, task is running
barrier2.await();
// all crossed the 2nd barrier, task should be considered hung
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.HUNG_THREAD_COUNT, 1);
// let's invoke the op to cancel the hung tasks
executeHungTasksCancellationOperation(pathAddress);
// and assert now no hung tasks exists
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.HUNG_THREAD_COUNT, 0);
}
private void testHungTasksCancellationPeriodic(PathAddress pathAddress, ManagedExecutorService executorService) throws IOException, ExecutionException, InterruptedException, BrokenBarrierException {
// assert no hung tasks exists at start
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.HUNG_THREAD_COUNT, 0);
final CyclicBarrier barrier1 = new CyclicBarrier(2);
final CyclicBarrier barrier2 = new CyclicBarrier(2);
final Runnable runnable = () -> {
try {
// signal task is running
barrier1.await();
// sleep till hung
Thread.sleep(HUNG_TASK_THRESHOLD_TEST_VALUE + 1);
// signal task is hung
barrier2.await();
} catch (Exception e) {
// unexpected, thus fail
Assert.fail();
}
// sleep 1 min, expecting cancellation
try {
Thread.sleep(60000);
} catch (Exception e) {
// expected, was cancelled
throw new RuntimeException(e);
}
// not expected, was not cancelled
Assert.fail();
};
executorService.submit(runnable);
barrier1.await();
// all crossed the 1st barrier, task is running
barrier2.await();
// all crossed the 2nd barrier, task should be considered hung
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.HUNG_THREAD_COUNT, 1);
// sleep periodic cancellation
try {
Thread.sleep(HUNG_TASK_CANCELLATION_PERIOD_TEST_VALUE);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// assert no hung tasks exists
assertStatsAttribute(pathAddress, ManagedExecutorServiceMetricsAttributes.HUNG_THREAD_COUNT, 0);
}
private int readStatsAttribute(PathAddress resourceAddress, String attrName) throws IOException {
ModelNode op = Util.getReadAttributeOperation(resourceAddress, attrName);
final ModelNode result = managementClient.getControllerClient().execute(op);
Assert.assertFalse(result.get(FAILURE_DESCRIPTION).toString(), result.get(FAILURE_DESCRIPTION).isDefined());
return result.get(RESULT).asInt();
}
private void assertStatsAttribute(PathAddress resourceAddress, String attrName, int expectedAttrValue) throws IOException, InterruptedException {
int actualAttrValue = readStatsAttribute(resourceAddress, attrName);
int retries = 5;
while (actualAttrValue != expectedAttrValue && retries > 0) {
Thread.sleep(500);
actualAttrValue = readStatsAttribute(resourceAddress, attrName);
retries--;
}
Assert.assertEquals(attrName, expectedAttrValue, actualAttrValue);
}
private void executeHungTasksCancellationOperation(PathAddress resourceAddress) throws IOException {
ModelNode op = Util.createOperation(ManagedExecutorTerminateHungTasksOperation.NAME, resourceAddress);
final ModelNode result = managementClient.getControllerClient().execute(op);
Assert.assertFalse(result.get(FAILURE_DESCRIPTION).toString(), result.get(FAILURE_DESCRIPTION).isDefined());
}
}
| 17,198 | 53.6 | 203 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/DefaultManagedScheduledExecutorServiceTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.concurrent;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
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.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.security.permission.ElytronPermission;
/**
* Test for EE's default ManagedScheduledExecutorService
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class DefaultManagedScheduledExecutorServiceTestCase {
@Deployment
public static Archive<?> getDeployment() {
return ShrinkWrap.create(JavaArchive.class, DefaultManagedScheduledExecutorServiceTestCase.class.getSimpleName() + ".jar")
.addClasses(DefaultManagedScheduledExecutorServiceTestCase.class, DefaultManagedScheduledExecutorServiceTestEJB.class, TestEJBRunnable.class, Util.class)
.addAsManifestResource(createPermissionsXmlAsset(new ElytronPermission("getSecurityDomain"),
new ElytronPermission("authenticate")), "permissions.xml");
}
@Test
public void testTaskSubmit() throws Exception {
final Callable<Void> callable = () -> {
final DefaultManagedScheduledExecutorServiceTestEJB testEJB = (DefaultManagedScheduledExecutorServiceTestEJB) new InitialContext().lookup("java:module/" + DefaultManagedScheduledExecutorServiceTestEJB.class.getSimpleName());
testEJB.schedule(new TestEJBRunnable(), 10L, TimeUnit.MILLISECONDS).get();
return null;
};
Util.switchIdentitySCF("guest", "guest", callable);
}
}
| 3,046 | 43.808824 | 236 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/DefaultManagedThreadFactoryTestEJB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.concurrent;
import java.security.Principal;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.EJBContext;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
import jakarta.enterprise.concurrent.ManagedThreadFactory;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.logging.Logger;
import org.junit.Assert;
/**
* @author Eduardo Martins
*/
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
@LocalBean
@RolesAllowed("guest")
public class DefaultManagedThreadFactoryTestEJB {
private static final Logger logger = Logger.getLogger(DefaultManagedThreadFactoryTestEJB.class);
@Resource
private ManagedThreadFactory managedThreadFactory;
@Resource
private EJBContext ejbContext;
/**
*
* @param task
* @throws Exception
*/
public void run(final TestEJBRunnable task) throws Exception {
final Principal principal = ejbContext.getCallerPrincipal();
logger.debugf("Principal: %s", principal);
task.setExpectedPrincipal(principal);
final CountDownLatch latch = new CountDownLatch(1);
final Runnable r = new Runnable() {
@Override
public void run() {
task.run();
latch.countDown();
}
};
managedThreadFactory.newThread(r).start();
if (! latch.await(TimeoutUtil.adjust(5000), TimeUnit.MILLISECONDS)) {
Assert.fail("Thread not finished correctly");
}
}
}
| 2,780 | 32.914634 | 100 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/DefaultManagedThreadFactoryTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.concurrent;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import java.util.PropertyPermission;
import java.util.concurrent.Callable;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.test.shared.TimeoutUtil;
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.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.security.permission.ElytronPermission;
/**
* Test for EE's default managed thread factory
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class DefaultManagedThreadFactoryTestCase {
@Deployment
public static Archive<?> getDeployment() {
return ShrinkWrap.create(JavaArchive.class, DefaultManagedThreadFactoryTestCase.class.getSimpleName() + ".jar")
.addClasses(DefaultManagedThreadFactoryTestCase.class, DefaultManagedThreadFactoryTestEJB.class, TestEJBRunnable.class, Util.class, TimeoutUtil.class)
.addAsManifestResource(createPermissionsXmlAsset(
new ElytronPermission("getSecurityDomain"),
new ElytronPermission("authenticate"),
new PropertyPermission("ts.timeout.factor", "read")
), "permissions.xml");
}
@Test
public void testTaskSubmit() throws Exception {
final Callable<Void> callable = () -> {
final DefaultManagedThreadFactoryTestEJB testEJB = (DefaultManagedThreadFactoryTestEJB) new InitialContext().lookup("java:module/" + DefaultManagedThreadFactoryTestEJB.class.getSimpleName());
testEJB.run(new TestEJBRunnable());
return null;
};
Util.switchIdentitySCF("guest", "guest", callable);
}
}
| 3,070 | 41.652778 | 203 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/TestEJBRunnable.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.concurrent;
import java.security.Principal;
import jakarta.ejb.EJBContext;
import jakarta.ejb.SessionContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import jakarta.transaction.NotSupportedException;
import jakarta.transaction.SystemException;
import jakarta.transaction.UserTransaction;
/**
* @author Eduardo Martins
*/
public class TestEJBRunnable implements Runnable {
private Principal expectedPrincipal;
public void setExpectedPrincipal(Principal expectedPrincipal) {
this.expectedPrincipal = expectedPrincipal;
}
@Override
public void run() {
// asserts correct class loader is set
try {
Thread.currentThread().getContextClassLoader().loadClass(this.getClass().getName());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
// asserts correct naming context is set
final InitialContext initialContext;
try {
initialContext = new InitialContext();
} catch (NamingException e) {
throw new RuntimeException(e);
}
final EJBContext ejbContext;
try {
ejbContext = (SessionContext) initialContext.lookup("java:comp/EJBContext");
} catch (NamingException e) {
throw new RuntimeException(e);
}
// asserts correct security context is set
final Principal callerPrincipal = ejbContext.getCallerPrincipal();
if (expectedPrincipal != null) {
if (!expectedPrincipal.equals(callerPrincipal)) {
throw new IllegalStateException("the caller principal " + callerPrincipal + " is not the expected " + expectedPrincipal);
}
} else {
if (callerPrincipal != null) {
throw new IllegalStateException("the caller principal " + callerPrincipal + " is not the expected " + expectedPrincipal);
}
}
// assert tx context is set
try {
final UserTransaction userTransaction = (UserTransaction) initialContext.lookup("java:comp/UserTransaction");
userTransaction.begin();
userTransaction.rollback();
} catch (NamingException | SystemException | NotSupportedException e) {
throw new RuntimeException(e);
}
}
}
| 3,412 | 38.229885 | 137 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/DefaultManagedScheduledExecutorServiceTestEJB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.concurrent;
import java.security.Principal;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.EJBContext;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
import jakarta.enterprise.concurrent.ManagedScheduledExecutorService;
import javax.naming.NamingException;
import org.jboss.logging.Logger;
/**
* @author Eduardo Martins
*/
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
@LocalBean
@RolesAllowed("guest")
public class DefaultManagedScheduledExecutorServiceTestEJB {
private static final Logger logger = Logger.getLogger(DefaultManagedScheduledExecutorServiceTestEJB.class);
// keep the name, it's part of the test. If only the name is set then injection source should be the default managed scheduled executor service
@Resource(name = "blabla")
private ManagedScheduledExecutorService executorService;
@Resource
private EJBContext ejbContext;
/**
* @param task
* @param delay
* @param timeUnit
* @return
* @throws NamingException
*/
public Future<?> schedule(TestEJBRunnable task, long delay, TimeUnit timeUnit) throws NamingException {
final Principal principal = ejbContext.getCallerPrincipal();
logger.debugf("Principal: %s", principal);
task.setExpectedPrincipal(principal);
return executorService.schedule(task, delay, timeUnit);
}
}
| 2,662 | 35.479452 | 147 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/ManagedScheduledExecutorExceptionTestCase.java
|
/*
*
* * JBoss, Home of Professional Open Source.
* * Copyright $year 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.jboss.as.test.integration.ee.concurrent;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.enterprise.concurrent.ManagedScheduledExecutorService;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
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)
public class ManagedScheduledExecutorExceptionTestCase {
@Deployment
public static Archive<?> getDeployment() {
return ShrinkWrap.create(JavaArchive.class, ManagedScheduledExecutorExceptionTestCase.class.getSimpleName() + ".jar")
.addClasses(ManagedScheduledExecutorExceptionTestCase.class);
}
private static final String loggerMessage = "WFLYEE0136";
private static final String message = "WFLY-17186";
private static void badMethod() {
throw new RuntimeException(message);
}
@Resource(lookup = "java:comp/DefaultManagedScheduledExecutorService")
private ManagedScheduledExecutorService executorService;
@Test
public void testScheduledRunnable() {
assert executorService != null;
Runnable r = ManagedScheduledExecutorExceptionTestCase::badMethod;
ScheduledFuture<?> future = executorService.schedule(r, 1, TimeUnit.MILLISECONDS);
checkFuture(future);
}
@Test
public void testScheduledCallable() {
assert executorService != null;
Callable<Void> callable = () -> { badMethod(); return null;};
ScheduledFuture<?> future = executorService.schedule(callable, 1, TimeUnit.MILLISECONDS);
checkFuture(future);
}
private void checkFuture(ScheduledFuture<?> future) {
try {
future.get();
fail("Exception did not propagate");
} catch (ExecutionException e) {
assertTrue(e.toString(), e.getCause().getMessage().contains(loggerMessage));
assertTrue(e.toString(), e.getCause().getCause().getMessage().contains(message));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
fail("Caught " + e);
}
}
}
| 3,276 | 35.820225 | 125 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/DefaultManagedExecutorServiceTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.concurrent;
import java.util.concurrent.Callable;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
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.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.security.permission.ElytronPermission;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
/**
* Test for EE's default ManagedExecutorService
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class DefaultManagedExecutorServiceTestCase {
@Deployment
public static Archive<?> getDeployment() {
return ShrinkWrap.create(JavaArchive.class, DefaultManagedExecutorServiceTestCase.class.getSimpleName() + ".jar")
.addClasses(DefaultManagedExecutorServiceTestCase.class, DefaultManagedExecutorServiceTestEJB.class, TestEJBRunnable.class, Util.class)
.addAsManifestResource(createPermissionsXmlAsset(new ElytronPermission("getSecurityDomain"),
new ElytronPermission("authenticate")), "permissions.xml");
}
@Test
public void testTaskSubmit() throws Exception {
final Callable<Void> callable = () -> {
final DefaultManagedExecutorServiceTestEJB testEJB = (DefaultManagedExecutorServiceTestEJB) new InitialContext().lookup("java:module/" + DefaultManagedExecutorServiceTestEJB.class.getSimpleName());
testEJB.submit(new TestEJBRunnable()).get();
return null;
};
Util.switchIdentitySCF("guest", "guest", callable);
}
}
| 2,907 | 41.764706 | 209 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/DefaultManagedExecutorServiceTestEJB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.concurrent;
import java.security.Principal;
import java.util.concurrent.Future;
import jakarta.annotation.Resource;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.EJBContext;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
import jakarta.enterprise.concurrent.ManagedExecutorService;
import javax.naming.NamingException;
import org.jboss.logging.Logger;
/**
* @author Eduardo Martins
*/
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
@LocalBean
@RolesAllowed("guest")
public class DefaultManagedExecutorServiceTestEJB {
private static final Logger logger = Logger.getLogger(DefaultManagedExecutorServiceTestEJB.class);
// keep the lookup, it's part of the test. It is not needed for injection of the default managed executor service, but the jndi name used when lookup is missing is the original one in java:jboss/ee/concurrent
//@Resource(lookup = "java:comp/DefaultManagedExecutorService")
@Resource
private ManagedExecutorService executorService;
@Resource
private EJBContext ejbContext;
/**
* @param task
* @return
* @throws NamingException
*/
public Future<?> submit(TestEJBRunnable task) throws NamingException {
final Principal principal = ejbContext.getCallerPrincipal();
logger.debugf("Principal: %s", principal);
task.setExpectedPrincipal(principal);
return executorService.submit(task);
}
}
| 2,609 | 35.760563 | 212 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/scheduled/ExceptionInScheduleTestCase.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.jboss.as.test.integration.ee.concurrent.scheduled;
import jakarta.ejb.EJB;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test case for managed executor's hung tasks termination feature.
*
* @author baranowb
*/
@RunWith(Arquillian.class)
public class ExceptionInScheduleTestCase {
@EJB(lookup = "java:module/ExecFlawedTaskBean!org.jboss.as.test.integration.ee.concurrent.scheduled.ExecNumber")
private ExecNumber execNumber;
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(JavaArchive.class, ExceptionInScheduleTestCase.class.getSimpleName() + ".jar")
.addClasses(ExecFlawedTaskBean.class, ExecNumber.class);
}
@Test
public void testExecutionCount() throws Exception {
execNumber.start();
Thread.currentThread().sleep(2000);
execNumber.cease();
Assert.assertEquals(execNumber.expected(), execNumber.actual());
}
}
| 2,254 | 35.370968 | 116 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/scheduled/ExecNumber.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.jboss.as.test.integration.ee.concurrent.scheduled;
public interface ExecNumber {
void cease();
void start();
int actual();
int expected();
}
| 1,197 | 34.235294 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/scheduled/ExecFlawedTaskBean.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.jboss.as.test.integration.ee.concurrent.scheduled;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.PreDestroy;
import jakarta.annotation.Resource;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
import jakarta.enterprise.concurrent.ManagedScheduledExecutorService;
@Singleton
@Startup
public class ExecFlawedTaskBean implements ExecNumber {
@Resource
private ManagedScheduledExecutorService managedScheduledExecutorService;
private ScheduledFuture future;
private int count;
private final int expected = 3;
@Override
public void cease() {
if (this.future != null) {
this.future.cancel(false);
}
}
public void start() {
future = managedScheduledExecutorService.scheduleWithFixedDelay(myTask, 0, 100, TimeUnit.MILLISECONDS);
}
@Override
public int actual() {
return this.count;
}
@Override
public int expected() {
return this.expected;
}
@PreDestroy
private void preDestroy() {
if (this.future != null) {
this.future.cancel(true);
}
}
private Runnable myTask = () -> {
count++;
if (count == this.expected) {
throw new RuntimeException("Throwing exception to suppress subsequent executions.");
}
};
}
| 2,417 | 28.851852 | 111 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/concurrency/DefaultConcurrencyCDITestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.integration.ee.naming.defaultbindings.concurrency;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.test.shared.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 jakarta.inject.Inject;
/**
*
* Test for EE's default data source on a Jakarta Contexts and Dependency Injection Bean
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class DefaultConcurrencyCDITestCase {
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class);
jar.addClasses(DefaultConcurrencyCDITestCase.class, DefaultConcurrencyTestCDIBean.class);
jar.addAsManifestResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml");
jar.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(new RuntimePermission("getClassLoader")), "permissions.xml");
return jar;
}
@Inject
private DefaultConcurrencyTestCDIBean defaultConcurrencyTestCDIBean;
@Test
public void testCDI() throws Throwable {
defaultConcurrencyTestCDIBean.test();
}
}
| 2,416 | 37.365079 | 137 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/concurrency/DefaultConcurrencyEJBTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.naming.defaultbindings.concurrency;
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.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.naming.InitialContext;
/**
* Test for EE's default data source on an EJB
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class DefaultConcurrencyEJBTestCase {
@Deployment
public static EnterpriseArchive getDeployment() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, DefaultConcurrencyEJBTestCase.class.getSimpleName() + ".ear");
JavaArchive module = ShrinkWrap.create(JavaArchive.class, "module.jar");
module.addClasses(DefaultConcurrencyEJBTestCase.class, DefaultConcurrencyTestEJB.class);
ear.addAsModule(module);
return ear;
}
@Test
public void testEJB() throws Throwable {
final DefaultConcurrencyTestEJB testEJB = (DefaultConcurrencyTestEJB) new InitialContext().lookup("java:module/" + DefaultConcurrencyTestEJB.class.getSimpleName());
testEJB.test();
}
}
| 2,321 | 39.034483 | 172 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/concurrency/DefaultConcurrencyTestCDIBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.integration.ee.naming.defaultbindings.concurrency;
import org.wildfly.security.manager.WildFlySecurityManager;
import jakarta.annotation.Resource;
import jakarta.enterprise.concurrent.ContextService;
import jakarta.enterprise.concurrent.ManagedExecutorService;
import jakarta.enterprise.concurrent.ManagedScheduledExecutorService;
import jakarta.enterprise.concurrent.ManagedThreadFactory;
/**
* @author Eduardo Martins
*/
public class DefaultConcurrencyTestCDIBean {
@Resource
private ContextService contextService;
@Resource
private ManagedExecutorService managedExecutorService;
@Resource
private ManagedScheduledExecutorService managedScheduledExecutorService;
@Resource
private ManagedThreadFactory managedThreadFactory;
/**
*
* @throws Throwable
*/
public void test() throws Throwable {
// check injected resources
if(contextService == null) {
throw new NullPointerException("contextService");
}
if(managedExecutorService == null) {
throw new NullPointerException("managedExecutorService");
}
if(managedScheduledExecutorService == null) {
throw new NullPointerException("managedScheduledExecutorService");
}
if(managedThreadFactory == null) {
throw new NullPointerException("managedThreadFactory");
}
// WFLY-12039 regression check
managedExecutorService.submit((Runnable) () -> {
if (WildFlySecurityManager.getCurrentContextClassLoaderPrivileged() == null) {
throw new IllegalStateException("WFLY-12039 regression, no TCCL found in task executed by non EE component");
}
}).get();
}
}
| 2,787 | 36.173333 | 125 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/concurrency/DefaultConcurrencyTestEJB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.naming.defaultbindings.concurrency;
import jakarta.annotation.Resource;
import jakarta.ejb.Stateless;
import jakarta.enterprise.concurrent.ContextService;
import jakarta.enterprise.concurrent.ManagedExecutorService;
import jakarta.enterprise.concurrent.ManagedScheduledExecutorService;
import jakarta.enterprise.concurrent.ManagedThreadFactory;
import javax.naming.InitialContext;
/**
* @author Eduardo Martins
*/
@Stateless
public class DefaultConcurrencyTestEJB {
@Resource
private ContextService contextService;
@Resource
private ManagedExecutorService managedExecutorService;
@Resource
private ManagedScheduledExecutorService managedScheduledExecutorService;
@Resource
private ManagedThreadFactory managedThreadFactory;
/**
*
* @throws Throwable
*/
public void test() throws Throwable {
// check injected resources
if(contextService == null) {
throw new NullPointerException("contextService");
}
if(managedExecutorService == null) {
throw new NullPointerException("managedExecutorService");
}
if(managedScheduledExecutorService == null) {
throw new NullPointerException("managedScheduledExecutorService");
}
if(managedThreadFactory == null) {
throw new NullPointerException("managedThreadFactory");
}
// checked jndi lookup
new InitialContext().lookup("java:comp/DefaultContextService");
new InitialContext().lookup("java:comp/DefaultManagedExecutorService");
new InitialContext().lookup("java:comp/DefaultManagedScheduledExecutorService");
new InitialContext().lookup("java:comp/DefaultManagedThreadFactory");
}
}
| 2,813 | 35.545455 | 88 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/datasource/DefaultDataSourceEJBTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.naming.defaultbindings.datasource;
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.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.naming.InitialContext;
/**
* Test for EE's default data source on an EJB
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class DefaultDataSourceEJBTestCase {
@Deployment
public static EnterpriseArchive getDeployment() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, DefaultDataSourceEJBTestCase.class.getSimpleName() + ".ear");
JavaArchive module = ShrinkWrap.create(JavaArchive.class, "module.jar");
module.addClasses(DefaultDataSourceEJBTestCase.class, DefaultDataSourceTestEJB.class);
ear.addAsModule(module);
return ear;
}
@Test
public void testEJB() throws Throwable {
final DefaultDataSourceTestEJB testEJB = (DefaultDataSourceTestEJB) new InitialContext().lookup("java:module/" + DefaultDataSourceTestEJB.class.getSimpleName());
testEJB.test();
}
}
| 2,313 | 38.896552 | 169 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/datasource/DefaultDSWithCtxListenerServlet.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2020, 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.integration.ee.naming.defaultbindings.datasource;
import org.junit.Assert;
import jakarta.annotation.Resource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebListener;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.PrintWriter;
/**
* This can be used only in tests which remove default datasource binding from ee subsystem.
*
* @author <a href="mailto:[email protected]">Lin Gao</a>
*/
@WebServlet(name = "DefaultDSWithCtxListenerServlet", urlPatterns = {"/defaultDSWithCtxListener"}, loadOnStartup = 1)
public class DefaultDSWithCtxListenerServlet extends HttpServlet {
@Resource(name = "ds")
private DataSource dataSource;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter out = resp.getWriter();
// this is expected to be null because default datasource binding was removed from ee subsystem
Assert.assertNull(dataSource);
// the ds injection can be done in a ServeltContextListener just like what spring does
Assert.assertNotNull(getServletContext().getAttribute("lookupDS"));
// but it looks like java:comp/env/ds does not work
try {
new InitialContext().lookup("java:comp/env/ds");
Assert.fail("java:comp/env/ds should not be available ??");
} catch (NamingException e) {
Assert.assertTrue(e.getMessage().contains("env/ds"));
}
out.print("OK");
out.flush();
}
// this simulates spring context which does resource injection.
@WebListener
public static class CtxListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
try {
Object obj = new InitialContext().lookup("java:jboss/datasources/ExampleDS");
sce.getServletContext().setAttribute("lookupDS", obj);
} catch (NamingException e) {
Assert.fail(e.getMessage());
}
}
}
}
| 3,491 | 39.604651 | 117 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/datasource/DefaultDataSourceCDITestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.integration.ee.naming.defaultbindings.datasource;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
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 jakarta.inject.Inject;
/**
*
* Test for EE's default data source on a Jakarta Contexts and Dependency Injection Bean
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class DefaultDataSourceCDITestCase {
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class);
jar.addClasses(DefaultDataSourceCDITestCase.class, DefaultDataSourceTestCDIBean.class);
jar.addAsManifestResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml");
return jar;
}
@Inject
private DefaultDataSourceTestCDIBean defaultDataSourceTestCDIBean;
@Test
public void testCDI() throws Throwable {
defaultDataSourceTestCDIBean.test();
}
}
| 2,222 | 35.442623 | 111 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/datasource/DefaultDSWithNameServlet.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2020, 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.integration.ee.naming.defaultbindings.datasource;
import org.junit.Assert;
import jakarta.annotation.Resource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.PrintWriter;
/**
* This can be used only in tests which remove default datasource binding from ee subsystem.
*
* @author <a href="mailto:[email protected]">Lin Gao</a>
*/
public class DefaultDSWithNameServlet extends HttpServlet {
private boolean hasLookup;
@Resource(name = "ds")
private DataSource dataSource;
@Override
public void init() throws ServletException {
try {
hasLookup = Boolean.parseBoolean(getServletConfig().getInitParameter("hasLookup"));
} catch (Exception e) {
hasLookup = false;
}
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter out = resp.getWriter();
if (hasLookup) {
if (dataSource == null) {
throw new ServletException("dataSource is null when lookup is defined in jboss-web.xml");
}
} else {
if (dataSource != null) {
throw new ServletException("No lookup is defined, dataSource should be null");
}
}
if (hasLookup) {
try {
Assert.assertNotNull(new InitialContext().lookup("java:comp/env/ds"));
} catch (NamingException e) {
throw new IOException("Cannot lookup java:comp/env/ds when has lookup specified", e);
}
} else {
try {
new InitialContext().lookup("java:comp/env/ds");
Assert.fail("lookup should fail when no lookup specified for 'java:comp/env/ds'");
} catch (NamingException e) {
Assert.assertTrue(e.getMessage().contains("env/ds"));
}
}
out.print("OK");
out.flush();
}
}
| 3,270 | 35.344444 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/datasource/DefaultDSServlet.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2020, 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.integration.ee.naming.defaultbindings.datasource;
import org.junit.Assert;
import jakarta.annotation.Resource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.PrintWriter;
/**
* This can be used only in tests which remove default datasource binding from ee subsystem.
*
* @author <a href="mailto:[email protected]">Lin Gao</a>
*/
@WebServlet(name = "DefaultDSServlet", urlPatterns = {"/defaultDS"}, loadOnStartup = 1)
public class DefaultDSServlet extends HttpServlet {
@Resource()
private DataSource dataSource;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter out = resp.getWriter();
// this is expected to be null because default datasource binding was removed from ee subsystem
Assert.assertNull(dataSource);
try {
new InitialContext().lookup("java:comp/env/dataSource");
Assert.fail("Lookup should fail!");
} catch (Exception e) {
Assert.assertTrue(e instanceof NamingException);
}
out.print("OK");
out.flush();
}
}
| 2,496 | 37.415385 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/datasource/DefaultDataSourceRemovedTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2020, 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.integration.ee.naming.defaultbindings.datasource;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.ee.subsystem.DefaultBindingsResourceDefinition;
import org.jboss.as.ee.subsystem.EESubsystemModel;
import org.jboss.as.ee.subsystem.EeExtension;
import org.jboss.as.test.integration.common.HttpRequest;
import org.jboss.as.test.shared.TestSuiteEnvironment;
import org.jboss.as.test.integration.jaxrs.packaging.war.WebXml;
import org.jboss.as.test.shared.SnapshotRestoreSetupTask;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.ShrinkWrap;
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 java.net.URL;
import java.util.concurrent.TimeUnit;
import java.net.SocketPermission;
/**
* @author <a href="mailto:[email protected]">Lin Gao</a>
*/
@RunWith(Arquillian.class)
@ServerSetup(DefaultDataSourceRemovedTestCase.RemoveDefaultDSBindingSetupTask.class)
public class DefaultDataSourceRemovedTestCase {
static class RemoveDefaultDSBindingSetupTask extends SnapshotRestoreSetupTask {
@Override
protected void doSetup(ManagementClient client, String containerId) throws Exception {
ModelNode undefineDatasourceFromDefaultBindings = new ModelNode();
undefineDatasourceFromDefaultBindings.get(ModelDescriptionConstants.ADDRESS)
.set(PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM,EeExtension.SUBSYSTEM_NAME), EESubsystemModel.DEFAULT_BINDINGS_PATH).toModelNode());
undefineDatasourceFromDefaultBindings.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION);
undefineDatasourceFromDefaultBindings.get(ModelDescriptionConstants.NAME).set(DefaultBindingsResourceDefinition.DATASOURCE);
ModelNode response = client.getControllerClient().execute(undefineDatasourceFromDefaultBindings);
Assert.assertEquals(SUCCESS, response.get(OUTCOME).asString());
}
}
@Deployment(name = "with-default-ds")
public static WebArchive defaultDS() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "with-default-ds.war");
war.addClasses(DefaultDSServlet.class);
war.addPackage(HttpRequest.class.getPackage());
war.addAsManifestResource(createPermissionsXmlAsset(
new RuntimePermission("modifyThread"),
new SocketPermission(TestSuiteEnvironment.getHttpAddress() + ":" + TestSuiteEnvironment.getHttpPort(), "connect,resolve")), "permissions.xml");
return war;
}
@Deployment(name = "with-default-ds-with-name")
public static WebArchive defaultDSWithName() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "with-default-ds-with-name.war");
war.addPackage(HttpRequest.class.getPackage());
war.addClasses(DefaultDSWithNameServlet.class);
war.addAsWebInfResource(WebXml.get("<servlet>\n" +
" <servlet-name>DefaultDSWithNameServlet</servlet-name>\n" +
" <servlet-class>org.jboss.as.test.integration.ee.naming.defaultbindings.datasource.DefaultDSWithNameServlet</servlet-class>" +
" <load-on-startup>1</load-on-startup>\n" +
"</servlet>\n" +
"<servlet-mapping>\n" +
" <servlet-name>DefaultDSWithNameServlet</servlet-name>\n" +
" <url-pattern>/defaultDSWithName</url-pattern>\n" +
"</servlet-mapping>"), "web.xml");
war.addAsManifestResource(createPermissionsXmlAsset(
new RuntimePermission("modifyThread"),
new SocketPermission(TestSuiteEnvironment.getHttpAddress() + ":" + TestSuiteEnvironment.getHttpPort(), "connect,resolve")), "permissions.xml");
return war;
}
@Deployment(name = "with-default-ds-with-name-and-lookup")
public static WebArchive defaultDSWithNameAndLookup() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "with-default-ds-with-name-and-lookup.war");
war.addClasses(DefaultDSWithNameServlet.class);
war.addPackage(HttpRequest.class.getPackage());
war.addAsManifestResource(createPermissionsXmlAsset(
new RuntimePermission("modifyThread"),
new SocketPermission(TestSuiteEnvironment.getHttpAddress() + ":" + TestSuiteEnvironment.getHttpPort(), "connect,resolve")), "permissions.xml");
war.addAsWebInfResource(WebXml.get("<servlet>\n" +
" <servlet-name>DefaultDSWithNameServlet</servlet-name>\n" +
" <servlet-class>org.jboss.as.test.integration.ee.naming.defaultbindings.datasource.DefaultDSWithNameServlet</servlet-class>\n" +
" <load-on-startup>1</load-on-startup>\n" +
" <init-param>\n" +
" <param-name>hasLookup</param-name>\n" +
" <param-value>true</param-value>\n" +
" </init-param>\n" +
"</servlet>\n" +
"<servlet-mapping>\n" +
" <servlet-name>DefaultDSWithNameServlet</servlet-name>\n" +
" <url-pattern>/defaultDSWithName</url-pattern>\n" +
"</servlet-mapping>"), "web.xml");
war.addAsWebInfResource(new StringAsset("<jboss-web>\n" +
" <resource-ref>\n" +
" <res-ref-name>ds</res-ref-name>\n" +
" <res-type>javax.sql.DataSource</res-type>\n" +
" <lookup-name>java:jboss/datasources/ExampleDS</lookup-name>\n" +
" </resource-ref>\n" +
"</jboss-web>"), "jboss-web.xml");
return war;
}
@Deployment(name = "with-default-ds-with-name-and-ctx")
public static WebArchive defaultDSWithNameAndCtx() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "with-default-ds-with-name-and-ctx.war");
war.addClasses(DefaultDSWithCtxListenerServlet.class);
war.addPackage(HttpRequest.class.getPackage());
war.addAsManifestResource(createPermissionsXmlAsset(
new RuntimePermission("modifyThread"),
new SocketPermission(TestSuiteEnvironment.getHttpAddress() + ":" + TestSuiteEnvironment.getHttpPort(), "connect,resolve")), "permissions.xml");
return war;
}
@Test
@OperateOnDeployment("with-default-ds")
public void testDeployDefaultDS(@ArquillianResource URL webURL) throws Exception {
String response = HttpRequest.get(webURL + "/defaultDS", 10, TimeUnit.SECONDS);
Assert.assertEquals("OK", response);
}
@Test
@OperateOnDeployment("with-default-ds-with-name")
public void testDeployDefaultDSWithName(@ArquillianResource URL webURL) throws Exception {
String response = HttpRequest.get(webURL + "/defaultDSWithName", 10, TimeUnit.SECONDS);
Assert.assertEquals("OK", response);
}
@Test
@OperateOnDeployment("with-default-ds-with-name-and-lookup")
public void testDeployDefaultDSWithNameAndLookup(@ArquillianResource URL webURL) throws Exception {
String response = HttpRequest.get(webURL + "/defaultDSWithName", 10, TimeUnit.SECONDS);
Assert.assertEquals("OK", response);
}
@Test
@OperateOnDeployment("with-default-ds-with-name-and-ctx")
public void testDeployDefaultDSWithNameAndCtx(@ArquillianResource URL webURL) throws Exception {
String response = HttpRequest.get(webURL + "/defaultDSWithCtxListener", 10, TimeUnit.SECONDS);
Assert.assertEquals("OK", response);
}
}
| 9,446 | 51.483333 | 193 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/datasource/DefaultDataSourceTestCDIBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.integration.ee.naming.defaultbindings.datasource;
import jakarta.annotation.Resource;
import javax.sql.DataSource;
/**
* @author Eduardo Martins
*/
public class DefaultDataSourceTestCDIBean {
@Resource
private DataSource injectedResource;
/**
*
* @throws Throwable
*/
public void test() throws Throwable {
// check injected resource
if(injectedResource == null) {
throw new NullPointerException("injected resource");
}
}
}
| 1,542 | 32.543478 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/datasource/DefaultDataSourceTestServlet.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2013, 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.integration.ee.naming.defaultbindings.datasource;
import jakarta.annotation.Resource;
import javax.naming.InitialContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.IOException;
/**
* @author Eduardo Martins
*/
@WebServlet(name = "SimpleServlet", urlPatterns = { "/simple" })
public class DefaultDataSourceTestServlet extends HttpServlet {
@Resource
private DataSource injectedResource;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
// check injected resource
if(injectedResource == null) {
throw new NullPointerException("injected resource");
}
// checked jndi lookup
new InitialContext().lookup("java:comp/DefaultDataSource");
} catch (Throwable e) {
throw new ServletException(e);
}
}
}
| 2,188 | 36.741379 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/datasource/DefaultDataSourceServletTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2013, 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.integration.ee.naming.defaultbindings.datasource;
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.integration.common.HttpRequest;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.net.URL;
import static java.util.concurrent.TimeUnit.SECONDS;
/**
* Test for EE's default data source on a Servlet
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
@RunAsClient
public class DefaultDataSourceServletTestCase {
@ArquillianResource
private URL url;
@Deployment
public static WebArchive deployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class, DefaultDataSourceServletTestCase.class.getSimpleName()+".war");
war.addClasses(HttpRequest.class, DefaultDataSourceTestServlet.class);
return war;
}
@Test
public void testServlet() throws Exception {
HttpRequest.get(url.toExternalForm() + "simple", 10, SECONDS);
}
}
| 2,263 | 34.936508 | 124 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/datasource/DefaultDataSourceTestEJB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.naming.defaultbindings.datasource;
import jakarta.annotation.Resource;
import jakarta.ejb.Stateless;
import javax.naming.InitialContext;
import javax.sql.DataSource;
/**
* @author Eduardo Martins
*/
@Stateless
public class DefaultDataSourceTestEJB {
@Resource
private DataSource injectedResource;
/**
*
* @throws Throwable
*/
public void test() throws Throwable {
// check injected resource
if(injectedResource == null) {
throw new NullPointerException("injected resource");
}
// checked jndi lookup
new InitialContext().lookup("java:comp/DefaultDataSource");
}
}
| 1,723 | 31.528302 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/jmsconnectionfactory/DefaultJMSConnectionFactoryCDITestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.integration.ee.naming.defaultbindings.jmsconnectionfactory;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
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 jakarta.inject.Inject;
/**
*
* Test for EE's default data source on a Jakarta Contexts and Dependency Injection Bean
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class DefaultJMSConnectionFactoryCDITestCase {
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class);
jar.addClasses(DefaultJMSConnectionFactoryCDITestCase.class, DefaultJMSConnectionFactoryTestCDIBean.class);
jar.addAsManifestResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml");
return jar;
}
@Inject
private DefaultJMSConnectionFactoryTestCDIBean defaultJMSConnectionFactoryTestCDIBean;
@Test
public void testCDI() throws Throwable {
defaultJMSConnectionFactoryTestCDIBean.test();
}
}
| 2,292 | 36.590164 | 115 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/jmsconnectionfactory/DefaultJMSConnectionFactoryTestEJB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.naming.defaultbindings.jmsconnectionfactory;
import jakarta.annotation.Resource;
import jakarta.ejb.Stateless;
import jakarta.jms.ConnectionFactory;
import javax.naming.InitialContext;
/**
* @author Eduardo Martins
*/
@Stateless
public class DefaultJMSConnectionFactoryTestEJB {
@Resource
private ConnectionFactory injectedResource;
/**
*
* @throws Throwable
*/
public void test() throws Throwable {
// check injected resource
if(injectedResource == null) {
throw new NullPointerException("injected resource");
}
// checked jndi lookup
new InitialContext().lookup("java:comp/DefaultJMSConnectionFactory");
}
}
| 1,769 | 32.396226 | 85 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/jmsconnectionfactory/DefaultJMSConnectionFactoryTestServlet.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2013, 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.integration.ee.naming.defaultbindings.jmsconnectionfactory;
import jakarta.annotation.Resource;
import jakarta.jms.ConnectionFactory;
import javax.naming.InitialContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author Eduardo Martins
*/
@WebServlet(name = "SimpleServlet", urlPatterns = { "/simple" })
public class DefaultJMSConnectionFactoryTestServlet extends HttpServlet {
@Resource
private ConnectionFactory injectedResource;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
// check injected resource
if(injectedResource == null) {
throw new NullPointerException("injected resource");
}
// checked jndi lookup
new InitialContext().lookup("java:comp/DefaultJMSConnectionFactory");
} catch (Throwable e) {
throw new ServletException(e);
}
}
}
| 2,234 | 37.534483 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/jmsconnectionfactory/DefaultJMSConnectionFactoryTestCDIBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, 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.integration.ee.naming.defaultbindings.jmsconnectionfactory;
import jakarta.annotation.Resource;
import jakarta.jms.ConnectionFactory;
/**
* @author Eduardo Martins
*/
public class DefaultJMSConnectionFactoryTestCDIBean {
@Resource
private ConnectionFactory injectedResource;
/**
*
* @throws Throwable
*/
public void test() throws Throwable {
// check injected resource
if(injectedResource == null) {
throw new NullPointerException("injected resource");
}
}
}
| 1,578 | 33.326087 | 85 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/jmsconnectionfactory/DefaultJMSConnectionFactoryEJBTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.naming.defaultbindings.jmsconnectionfactory;
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.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.naming.InitialContext;
/**
* Test for EE's default data source on an EJB
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
public class DefaultJMSConnectionFactoryEJBTestCase {
@Deployment
public static EnterpriseArchive getDeployment() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, DefaultJMSConnectionFactoryEJBTestCase.class.getSimpleName() + ".ear");
JavaArchive module = ShrinkWrap.create(JavaArchive.class, "module.jar");
module.addClasses(DefaultJMSConnectionFactoryEJBTestCase.class, DefaultJMSConnectionFactoryTestEJB.class);
ear.addAsModule(module);
return ear;
}
@Test
public void testEJB() throws Throwable {
final DefaultJMSConnectionFactoryTestEJB testEJB = (DefaultJMSConnectionFactoryTestEJB) new InitialContext().lookup("java:module/" + DefaultJMSConnectionFactoryTestEJB.class.getSimpleName());
testEJB.test();
}
}
| 2,393 | 40.275862 | 199 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/naming/defaultbindings/jmsconnectionfactory/DefaultJMSConnectionFactoryServletTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2013, 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.integration.ee.naming.defaultbindings.jmsconnectionfactory;
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.integration.common.HttpRequest;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.net.URL;
import static java.util.concurrent.TimeUnit.SECONDS;
/**
* Test for EE's default data source on a Servlet
*
* @author Eduardo Martins
*/
@RunWith(Arquillian.class)
@RunAsClient
public class DefaultJMSConnectionFactoryServletTestCase {
@ArquillianResource
private URL url;
@Deployment
public static WebArchive deployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class, DefaultJMSConnectionFactoryServletTestCase.class.getSimpleName()+".war");
war.addClasses(HttpRequest.class, DefaultJMSConnectionFactoryTestServlet.class);
return war;
}
@Test
public void testServlet() throws Exception {
HttpRequest.get(url.toExternalForm() + "simple", 10, SECONDS);
}
}
| 2,303 | 35.571429 | 134 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/appclient/util/AppClientWrapper.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.integration.ee.appclient.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Vector;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.jboss.as.test.shared.TestSuiteEnvironment;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
/**
* @author Dominik Pospisil <[email protected]>
* @author Stuart Douglas
*/
public class AppClientWrapper implements Runnable {
private static final Logger LOGGER = Logger.getLogger(AppClientWrapper.class);
private String appClientCommand = null;
private static final String outThreadHame = "APPCLIENT-out";
private static final String errThreadHame = "APPCLIENT-err";
private Process appClientProcess;
private BufferedReader outputReader;
private BufferedReader errorReader;
private BlockingQueue<String> outputQueue = new LinkedBlockingQueue<String>();
private Thread shutdownThread;
private final Archive<?> archive;
private final String clientArchiveName;
private final String appClientArgs;
private File archiveOnDisk;
private final String args;
/**
* Creates new CLI wrapper. If the connect parameter is set to true the CLI
* will connect to the server using <code>connect</code> command.
*
*
* @param archive
* @param clientArchiveName
* @param args
* @throws Exception
*/
public AppClientWrapper(final Archive<?> archive,final String appClientArgs, final String clientArchiveName, final String args) throws Exception {
this.archive = archive;
this.clientArchiveName = clientArchiveName;
this.args = args;
this.appClientArgs = appClientArgs;
init();
}
/**
* Consumes all available output from App Client.
*
* @param timeout number of milliseconds to wait for each subsequent line
* @return array of App Client output lines
*/
public String[] readAll(final long timeout) {
Vector<String> lines = new Vector<String>();
String line = null;
do {
try {
line = outputQueue.poll(timeout, TimeUnit.MILLISECONDS);
if (line != null) lines.add(line);
} catch (InterruptedException ioe) {
}
} while (line != null);
return lines.toArray(new String[]{});
}
/**
* Consumes all available output from CLI.
*
* @param timeout number of milliseconds to wait for each subsequent line
* @return array of CLI output lines
*/
public String readAllUnformated(long timeout) {
String[] lines = readAll(timeout);
StringBuilder buf = new StringBuilder();
for (String line : lines) buf.append(line + "\n");
return buf.toString();
}
/**
* Kills the app client
*
* @throws Exception
*/
public synchronized void quit() throws Exception {
appClientProcess.destroy();
try {
appClientProcess.waitFor();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Runtime.getRuntime().removeShutdownHook(shutdownThread);
if (archiveOnDisk != null) {
archiveOnDisk.delete();
}
}
private void init() throws Exception {
shutdownThread = new Thread(new Runnable() {
@Override
public void run() {
if (appClientProcess != null) {
appClientProcess.destroy();
if (archiveOnDisk != null) {
archiveOnDisk.delete();
}
try {
appClientProcess.waitFor();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
});
Runtime.getRuntime().addShutdownHook(shutdownThread);
appClientProcess = Runtime.getRuntime().exec(getAppClientCommand());
new PrintWriter(appClientProcess.getOutputStream());
outputReader = new BufferedReader(new InputStreamReader(appClientProcess.getInputStream(), StandardCharsets.UTF_8));
errorReader = new BufferedReader(new InputStreamReader(appClientProcess.getErrorStream(), StandardCharsets.UTF_8));
final Thread readOutputThread = new Thread(this, outThreadHame);
readOutputThread.start();
final Thread readErrorThread = new Thread(this, errThreadHame);
readErrorThread.start();
}
private String getAppClientCommand() throws Exception {
if (appClientCommand != null) return appClientCommand;
final String tempDir = System.getProperty("java.io.tmpdir");
archiveOnDisk = new File(tempDir + File.separator + archive.getName());
if(archiveOnDisk.exists()) {
archiveOnDisk.delete();
}
final ZipExporter exporter = archive.as(ZipExporter.class);
exporter.exportTo(archiveOnDisk);
final String archivePath = archiveOnDisk.getAbsolutePath();
// We don't directly pass the archive file and deployment name to appclient's main
// Instead we prove expressions work by passing an expression
final String archiveArg;
if(clientArchiveName == null) {
archiveArg = "${test.expr.appclient.file: " + archivePath + "}";
} else {
archiveArg = "${test.expr.appclient.file:" + archivePath + "}#${test.expr.appclient.deployment:" + clientArchiveName + "}";
}
// TODO: Move to a shared testsuite lib.
String asDist = System.getProperty("jboss.dist");
if( asDist == null ) throw new Exception("'jboss.dist' property is not set.");
if( ! new File(asDist).exists() ) throw new Exception("AS dir from 'jboss.dist' doesn't exist: " + asDist + " user.dir: " + System.getProperty("user.dir"));
String instDir = System.getProperty("jboss.install.dir");
if( instDir == null ) throw new Exception("'jboss.install.dir' property is not set.");
if( ! new File(instDir).exists() ) throw new Exception("AS dir from 'jboss.install.dir' doesn't exist: " + instDir + " user.dir: " + System.getProperty("user.dir"));
String java = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
appClientCommand = java +
" -Djboss.modules.dir="+ asDist + "/modules" +
" -Djline.WindowsTerminal.directConsole=false" +
TestSuiteEnvironment.getIpv6Args() +
"-Djboss.bind.address=" + TestSuiteEnvironment.getServerAddress() +
" "+System.getProperty("server.jvm.args") +
" -jar "+ instDir + "/jboss-modules.jar" +
" -mp "+ asDist + "/modules" +
" org.jboss.as.appclient" +
" -Djboss.server.base.dir="+ instDir + "/appclient" +
" -Djboss.home.dir="+ instDir +
" " + this.appClientArgs + " " + archiveArg + " " + args;
System.out.println(appClientCommand);
return appClientCommand;
}
/**
*
*/
public void run() {
final String threadName = Thread.currentThread().getName();
final BufferedReader reader = threadName.equals(outThreadHame) ? outputReader : errorReader;
try {
String line = reader.readLine();
while (line != null) {
if (threadName.equals(outThreadHame))
outputLineReceived(line);
else
errorLineReceived(line);
line = reader.readLine();
}
} catch (Exception e) {
} finally {
synchronized (this) {
if (threadName.equals(outThreadHame))
outputReader = null;
else
errorReader = null;
}
}
}
private synchronized void outputLineReceived(String line) {
LOGGER.info("[" + outThreadHame + "] " + line);
outputQueue.add(line);
}
private synchronized void errorLineReceived(String line) {
LOGGER.info("[" + outThreadHame + "] " + line);
}
}
| 9,525 | 37.257028 | 173 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/appclient/basic/AppClientMain.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.integration.ee.appclient.basic;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import org.jboss.logging.Logger;
/**
* @author Stuart Douglas
*/
public class AppClientMain {
private static final Logger logger = Logger.getLogger("org.jboss.as.test.appclient");
@Resource(lookup = "java:comp/InAppClientContainer")
private static boolean appclient;
@EJB
private static AppClientSingletonRemote appClientSingletonRemote;
public static void main(final String[] params) {
logger.trace("Main method invoked");
if(!appclient) {
logger.error("InAppClientContainer was not true");
throw new RuntimeException("InAppClientContainer was not true");
}
try {
appClientSingletonRemote.makeAppClientCall(params[0]);
logger.trace("Main method invocation completed with success");
} catch (Exception e) {
logger.error("Main method failed", e);
}
}
}
| 2,041 | 33.610169 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/appclient/basic/AppClientStateSingleton.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.integration.ee.appclient.basic;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.ConcurrencyManagement;
import jakarta.ejb.ConcurrencyManagementType;
import jakarta.ejb.Singleton;
import org.jboss.logging.Logger;
/**
* @author Stuart Douglas
*/
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class AppClientStateSingleton implements AppClientSingletonRemote {
private static final Logger logger = Logger.getLogger("org.jboss.as.test.appclient");
private volatile CountDownLatch latch = new CountDownLatch(1);
private volatile String value;
@Override
public void reset() {
logger.trace("Reset called!");
value = null;
//if we have a thread blocked on the latch release it
latch.countDown();
latch = new CountDownLatch(1);
}
@Override
public void makeAppClientCall(final String value) {
logger.trace("AppClient Call called!");
this.value = value;
latch.countDown();
}
@Override
public String awaitAppClientCall() {
try {
boolean b = latch.await(30, TimeUnit.SECONDS);
logger.trace("Await returned: " + b + " : " + value);
if (!b) {
ThreadInfo[] threadInfos = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
for (ThreadInfo info : threadInfos) {
logger.trace(info);
}
}
return value;
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
| 2,770 | 33.6375 | 106 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/appclient/basic/DescriptorClientMain.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.integration.ee.appclient.basic;
import org.jboss.logging.Logger;
/**
* @author Stuart Douglas
*/
public class DescriptorClientMain {
private static final Logger logger = Logger.getLogger("org.jboss.as.test.appclient");
private static AppClientSingletonRemote appClientSingletonRemote;
private static String envEntry;
public static void main(final String[] params) {
appClientSingletonRemote.makeAppClientCall(envEntry);
}
}
| 1,510 | 34.97619 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/appclient/basic/AbstractSimpleApplicationClientTestCase.java
|
package org.jboss.as.test.integration.ee.appclient.basic;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.net.URL;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.ee.appclient.util.AppClientWrapper;
import org.jboss.ejb.client.EJBClient;
import org.jboss.ejb.client.StatelessEJBLocator;
import org.jboss.shrinkwrap.api.Archive;
public abstract class AbstractSimpleApplicationClientTestCase {
protected static final String APP_NAME = "simple-app-client-test";
protected static final String MODULE_NAME = "ejb";
@ArquillianResource
protected ManagementClient managementClient;
public abstract Archive<?> getArchive();
/**
* Tests a simple app client that calls an ejb with its command line parameters
*/
public void simpleAppClientTest() throws Exception {
final StatelessEJBLocator<AppClientSingletonRemote> locator = new StatelessEJBLocator(AppClientSingletonRemote.class,
APP_NAME, MODULE_NAME, AppClientStateSingleton.class.getSimpleName(), "");
final AppClientSingletonRemote remote = EJBClient.createProxy(locator);
remote.reset();
final AppClientWrapper wrapper = new AppClientWrapper(getArchive(), getHostArgument(),
"client-annotation.jar", "${test.expr.applcient.param:cmdLineParam}");
try {
final String result = remote.awaitAppClientCall();
assertTrue("App client call failed. App client output: " + wrapper.readAllUnformated(1000), result != null);
assertEquals("cmdLineParam", result);
} finally {
wrapper.quit();
}
}
/**
* Tests an app client with a deployment descriptor, that injects an env-entry and an EJB.
*
* @throws Exception
*/
public void descriptorBasedAppClientTest() throws Exception {
final StatelessEJBLocator<AppClientSingletonRemote> locator = new StatelessEJBLocator(AppClientSingletonRemote.class,
APP_NAME, MODULE_NAME, AppClientStateSingleton.class.getSimpleName(), "");
final AppClientSingletonRemote remote = EJBClient.createProxy(locator);
remote.reset();
final AppClientWrapper wrapper = new AppClientWrapper(getArchive(), getHostArgument(),
"client-dd.jar", "");
try {
final String result = remote.awaitAppClientCall();
assertTrue("App client call failed. App client output: " + wrapper.readAllUnformated(1000), result != null);
assertEquals("EnvEntry", result);
} finally {
wrapper.quit();
}
}
/**
* Tests an app client with a deployment descriptor, that injects an env-entry and an EJB.
*
* @throws Exception
*/
public void testAppClientJBossDescriptor() throws Exception {
final StatelessEJBLocator<AppClientSingletonRemote> locator = new StatelessEJBLocator(AppClientSingletonRemote.class,
APP_NAME, MODULE_NAME, AppClientStateSingleton.class.getSimpleName(), "");
final AppClientSingletonRemote remote = EJBClient.createProxy(locator);
remote.reset();
URL props = getClass().getClassLoader().getResource("jboss-ejb-client.properties");
final AppClientWrapper wrapper = new AppClientWrapper(getArchive(),
" -Dnode0=" + managementClient.getMgmtAddress() + getEjbClientPropertiesArgument(props),
"client-override.jar",
"");
try {
final String result = remote.awaitAppClientCall();
assertTrue("App client call failed. App client output: " + wrapper.readAllUnformated(1000), result != null);
assertEquals("OverridenEnvEntry", result);
} finally {
wrapper.quit();
}
}
private String getHostArgument() {
// Use an expression for the host arg value to validate that works
return "--host=${test.expr.appclient.host:" + managementClient.getRemoteEjbURL() + "}";
}
private String getEjbClientPropertiesArgument(URL props) {
// Use an expression for the arg value to validate that works
return " --ejb-client-properties=${test.expr.appclient.properties:" + props + "}";
}
}
| 4,378 | 42.79 | 125 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/appclient/basic/AppClientSingletonRemote.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.integration.ee.appclient.basic;
import jakarta.ejb.Remote;
/**
* @author Stuart Douglas
*/
@Remote
public interface AppClientSingletonRemote {
void reset();
void makeAppClientCall(final String value);
String awaitAppClientCall();
}
| 1,301 | 32.384615 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/appclient/basic/ClientInterceptor.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2018, 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.integration.ee.appclient.basic;
import org.jboss.ejb.client.EJBClientInterceptor;
import org.jboss.ejb.client.EJBClientInvocationContext;
public class ClientInterceptor implements EJBClientInterceptor {
@Override
public void handleInvocation(EJBClientInvocationContext context) throws Exception {
context.sendRequest();
}
@Override
public Object handleInvocationResult(EJBClientInvocationContext context) throws Exception {
return context.getResult();
}
}
| 1,540 | 39.552632 | 95 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/appclient/basic/SimpleApplicationClientTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.integration.ee.appclient.basic;
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.test.integration.ee.appclient.util.AppClientWrapper;
import org.jboss.as.test.shared.integration.ejb.security.CallbackHandler;
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.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that an application client can launch and conntect to a remote EJB
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
@RunAsClient
public class SimpleApplicationClientTestCase extends AbstractSimpleApplicationClientTestCase {
private static Archive archive;
@Override
public Archive<?> getArchive() {
return SimpleApplicationClientTestCase.archive;
}
@Deployment(testable = false)
public static Archive<?> deploy() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear");
final JavaArchive lib = ShrinkWrap.create(JavaArchive.class, "lib.jar");
lib.addClasses(AppClientSingletonRemote.class, AppClientWrapper.class, CallbackHandler.class);
ear.addAsLibrary(lib);
final JavaArchive ejb = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
ejb.addClasses(SimpleApplicationClientTestCase.class, AppClientStateSingleton.class);
ear.addAsModule(ejb);
final JavaArchive appClient = ShrinkWrap.create(JavaArchive.class, "client-annotation.jar");
appClient.addClasses(org.junit.Assert.class, org.junit.ComparisonFailure.class);
appClient.addClasses(AppClientMain.class);
appClient.addAsManifestResource(new StringAsset("Main-Class: " + AppClientMain.class.getName() + "\n"), "MANIFEST.MF");
ear.addAsModule(appClient);
final JavaArchive clientDD = ShrinkWrap.create(JavaArchive.class, "client-dd.jar");
clientDD.addClasses(DescriptorClientMain.class, org.junit.ComparisonFailure.class);
clientDD.addClasses(org.junit.Assert.class);
clientDD.addAsManifestResource(new StringAsset("Main-Class: " + DescriptorClientMain.class.getName() + "\n"), "MANIFEST.MF");
clientDD.addAsManifestResource(SimpleApplicationClientTestCase.class.getPackage(), "application-client.xml", "application-client.xml");
ear.addAsModule(clientDD);
final JavaArchive clientOverride = ShrinkWrap.create(JavaArchive.class, "client-override.jar");
clientOverride.addClasses(DescriptorClientMain.class, org.junit.ComparisonFailure.class);
clientOverride.addClasses(org.junit.Assert.class);
clientOverride.addAsManifestResource(new StringAsset("Main-Class: " + DescriptorClientMain.class.getName() + "\n"), "MANIFEST.MF");
clientOverride.addAsManifestResource(SimpleApplicationClientTestCase.class.getPackage(), "application-client.xml", "application-client.xml");
clientOverride.addAsManifestResource(SimpleApplicationClientTestCase.class.getPackage(), "jboss-client.xml", "jboss-client.xml");
ear.addAsModule(clientOverride);
archive = ear;
return ear;
}
@Test
public void simpleAppClientTest() throws Exception {
super.simpleAppClientTest();
}
@Test
public void descriptorBasedAppClientTest() throws Exception {
super.descriptorBasedAppClientTest();
}
@Test
public void testAppClientJBossDescriptor() throws Exception {
super.testAppClientJBossDescriptor();
}
}
| 4,809 | 45.25 | 149 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/appclient/basic/SimpleApplicationClientTestCase2.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, 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.integration.ee.appclient.basic;
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.test.integration.ee.appclient.util.AppClientWrapper;
import org.jboss.as.test.shared.integration.ejb.security.CallbackHandler;
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.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that an application client can launch and conntect to a remote EJB
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
@RunAsClient
public class SimpleApplicationClientTestCase2 extends AbstractSimpleApplicationClientTestCase {
private static Archive archive;
@Override
public Archive<?> getArchive() {
return SimpleApplicationClientTestCase2.archive;
}
@Deployment(testable = false)
public static Archive<?> deploy() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear");
final JavaArchive lib = ShrinkWrap.create(JavaArchive.class, "lib.jar");
lib.addClasses(AppClientSingletonRemote.class, AppClientWrapper.class, CallbackHandler.class, ClientInterceptor.class);
ear.addAsLibrary(lib);
final JavaArchive ejb = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
ejb.addClasses(SimpleApplicationClientTestCase2.class, AppClientStateSingleton.class);
ear.addAsModule(ejb);
final JavaArchive appClient = ShrinkWrap.create(JavaArchive.class, "client-annotation.jar");
appClient.addClasses(AppClientMain.class);
appClient.addClasses(org.junit.Assert.class, org.junit.ComparisonFailure.class);
appClient.addAsManifestResource(new StringAsset("Main-Class: " + AppClientMain.class.getName() + "\n"), "MANIFEST.MF");
ear.addAsModule(appClient);
final JavaArchive clientOverride = ShrinkWrap.create(JavaArchive.class, "client-override.jar");
clientOverride.addClasses(org.junit.Assert.class, org.junit.ComparisonFailure.class);
clientOverride.addClasses(DescriptorClientMain.class);
clientOverride.addAsManifestResource(new StringAsset("Main-Class: " + DescriptorClientMain.class.getName() + "\n"),
"MANIFEST.MF");
clientOverride.addAsManifestResource(SimpleApplicationClientTestCase2.class.getPackage(), "application-client.xml",
"application-client.xml");
clientOverride.addAsManifestResource(SimpleApplicationClientTestCase2.class.getPackage(), "jboss-client.xml",
"jboss-client.xml");
clientOverride.addAsResource(new StringAsset(ClientInterceptor.class.getCanonicalName()),
"META-INF/services/org.jboss.ejb.client.EJBClientInterceptor");
ear.addAsModule(clientOverride);
archive = ear;
return ear;
}
@Test
public void simpleAppClientTest() throws Exception {
super.simpleAppClientTest();
}
}
| 4,250 | 44.709677 | 127 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/jmx/property/JMXPropertyEditorsTestCase.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.integration.ee.jmx.property;
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.container.ManagementClient;
import org.jboss.as.test.integration.common.DefaultConfiguration;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.xnio.IoUtils;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.URI;
import java.net.URL;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsNull.notNullValue;
/**
* @author baranowb
*/
@RunWith(Arquillian.class)
@RunAsClient
public class JMXPropertyEditorsTestCase {
private static final String SAR_DEPLOMENT_NAME = "property-editors-beans";
private static final String SAR_DEPLOMENT_FILE = SAR_DEPLOMENT_NAME + ".sar";
@ContainerResource
private ManagementClient managementClient;
private MBeanServerConnection connection;
private JMXConnector connector;
@Before
public void initialize() throws Exception {
connection = getMBeanServerConnection();
Assert.assertNotNull(connection);
}
@After
public void closeConnection() throws Exception {
connection = null;
IoUtils.safeClose(connector);
}
private MBeanServerConnection getMBeanServerConnection() throws IOException {
final String address = managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort();
connector = JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:remote+http://" + address), DefaultConfiguration.credentials());
return connector.getMBeanServerConnection();
}
private static class AssetTestBuilder {
private StringBuilder xml;
public AssetTestBuilder begin() {
xml = new StringBuilder(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<server xmlns=\"urn:jboss:service:7.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ "xsi:schemaLocation=\"urn:jboss:service:7.0 jboss-service_7_0.xsd\">"
+ "<mbean code=\"org.jboss.as.test.integration.ee.jmx.property.WithProperties\" name=\"test:service=WithProperties\">");
return this;
}
AssetTestBuilder addAttribute(String attributeName, String attributeValue) {
xml.append("<attribute name=\"")
.append(attributeName)
.append("\">")
.append(attributeValue)
.append("</attribute>");
return this;
}
Asset end() {
return new StringAsset(xml.append("</mbean>")
.append("</server>")
.toString());
}
}
@Deployment
public static Archive<?> deployment() {
final JavaArchive jmxSAR = ShrinkWrap.create(JavaArchive.class, SAR_DEPLOMENT_FILE);
jmxSAR.addClass(WithPropertiesMBean.class);
jmxSAR.addClass(WithProperties.class);
//JBossServiceXmlDescriptorParser does not support XML as attribs, so tests for
//saving and restoring a xml document / element are not added
Asset asset = new AssetTestBuilder().begin()
.addAttribute("AtomicBoolean", "true")
.addAttribute("AtomicInteger", "3")
.addAttribute("AtomicLong", "2")
.addAttribute("BigDecimal", "100000000")
.addAttribute("BigInteger", "100000000")
.addAttribute("Boolean", "true")
.addAttribute("BooleanArray", "true,false")
.addAttribute("Byte", "1")
.addAttribute("ByteArray", "1,2,3")
.addAttribute("Char", "R")
.addAttribute("CharacterArray", "R,R,X")
.addAttribute("Clazz", "java.lang.String")
.addAttribute("ClassArray", "java.lang.String,java.util.List")
.addAttribute("Double", "4")
.addAttribute("File", "/I_DONT_EXIST/DUNNO")
.addAttribute("Float", "1.5")
.addAttribute("FloatArray", "1.5,2.5")
.addAttribute("InetAddress", "10.10.10.1")
.addAttribute("InetAddressArray", "10.10.10.1,localhost")
.addAttribute("Integer", "1")
.addAttribute("IntegerArray", "1,5,4")
.addAttribute("Locale", Locale.ENGLISH.toString())
.addAttribute("Long", "14")
.addAttribute("LongArray", "14,15")
.addAttribute("ObjectBoolean", "true")
.addAttribute("ObjectByte", "10")
.addAttribute("ObjectChar", "Z")
.addAttribute("ObjectDouble", "10")
.addAttribute("ObjectFloat", "10")
.addAttribute("ObjectInteger", "10")
.addAttribute("ObjectLong", "10")
.addAttribute("ObjectShort", "10")
.addAttribute("Properties", "prop1=ugabuga\nprop2=HAHA\nenv=${env.TEST_PROP}")
.addAttribute("Short", "1")
.addAttribute("ShortArray", "1,20")
.addAttribute("StringArray", "1,20")
.addAttribute("URI", "http://nowhere.com")
.addAttribute("URL", "http://nowhere.com")
.end();
jmxSAR.addAsManifestResource(asset, "jboss-service.xml");
return jmxSAR;
}
@Test
public void testAtomicBoolean() throws Exception {
performTest("AtomicBoolean", new AtomicBoolean(true), Comparator.comparing(AtomicBoolean::get));
}
@Test
public void testAtomicInteger() throws Exception {
performTest("AtomicInteger", new AtomicInteger(3), Comparator.comparing(AtomicInteger::get));
}
@Test
public void testAtomicLong() throws Exception {
performTest("AtomicLong", new AtomicLong(2), Comparator.comparing(AtomicLong::get));
}
@Test
public void testBigDecimal() throws Exception {
performTest("BigDecimal", new BigDecimal(100000000));
}
@Test
public void testBigInteger() throws Exception {
performTest("BigInteger", new BigInteger("100000000"));
}
@Test
public void testBoolean() throws Exception {
performTest("Boolean", new Boolean(true));
}
@Test
public void testBooleanArray() throws Exception {
performTest("BooleanArray", new boolean[]{true, false});
}
@Test
public void testByte() throws Exception {
performTest("Byte", new Byte((byte) 1));
}
@Test
public void testByteArray() throws Exception {
performTest("ByteArray", new byte[]{1, 2, 3});
}
@Test
public void testChar() throws Exception {
performTest("Char", new Character('R'));
}
@Test
public void testCharacterArray() throws Exception {
performTest("CharacterArray", new char[]{'R', 'R', 'X'});
}
@Test
public void testClazz() throws Exception {
performTest("Clazz", String.class);
}
@Test
public void testClassArray() throws Exception {
performTest("ClassArray", new Class[]{String.class, List.class});
}
@Test
public void testDouble() throws Exception {
performTest("Double", new Double(4));
}
@Test
public void testFile() throws Exception {
performTest("File", new File("/I_DONT_EXIST/DUNNO").getAbsoluteFile());
}
@Test
public void testFloat() throws Exception {
performTest("Float", new Float("1.5"));
}
@Test
public void testFloatArray() throws Exception {
performTest("FloatArray", new float[]{1.5f, 2.5f});
}
@Test
public void testInetAddress() throws Exception {
performTest("InetAddress", InetAddress.getByAddress(new byte[]{10, 10, 10, 1}));
}
@Test
public void testInetAddressArray() throws Exception {
performTest("InetAddressArray", new InetAddress[]{InetAddress.getByAddress(new byte[]{10, 10, 10, 1}),
InetAddress.getByName("localhost")});
}
@Test
public void testInteger() throws Exception {
performTest("Integer", new Integer("1"));
}
@Test
public void testIntegerArray() throws Exception {
performTest("IntegerArray", new int[]{1, 5, 4});
}
@Test
public void testLocale() throws Exception {
performTest("Locale", Locale.ENGLISH);
}
@Test
public void testLong() throws Exception {
performTest("Long", new Long(14));
}
@Test
public void testLongArray() throws Exception {
performTest("LongArray", new long[]{14, 15});
}
@Test
public void testObjectBoolean() throws Exception {
performTest("ObjectBoolean", new Boolean(true));
}
@Test
public void testObjectByte() throws Exception {
performTest("ObjectByte", new Byte((byte) 10));
}
@Test
public void testObjectCharacter() throws Exception {
performTest("ObjectChar", new Character('Z'));
}
@Test
public void testObjectDouble() throws Exception {
performTest("ObjectDouble", new Double(10));
}
@Test
public void testObjectFloat() throws Exception {
performTest("ObjectFloat", new Float(10));
}
@Test
public void testObjectInteger() throws Exception {
performTest("ObjectInteger", new Integer(10));
}
@Test
public void testObjectLong() throws Exception {
performTest("ObjectLong", new Long(10));
}
@Test
public void testObjectShort() throws Exception {
performTest("ObjectShort", new Short((short) 10));
}
@Test
public void testProperties() throws Exception {
Properties props = new Properties();
props.put("prop1", "ugabuga");
props.put("prop2", "HAHA");
props.put("env", System.getenv("TEST_PROP"));
performTest("Properties", props, (o1, o2) -> {
Properties p1 = (Properties) o1;
Properties p2 = (Properties) o2;
if (p1.size() != p2.size()) {
return 1;
}
if (!p1.keySet().containsAll(p2.keySet())) {
return 1;
}
Set<Object> keys1 = p1.keySet();
for (Object key : keys1) {
Object v1 = p1.get(key);
Object v2 = p2.get(key);
if (!v1.equals(v2)) {
return 1;
}
}
return 0;
});
}
@Test
public void testShort() throws Exception {
performTest("Short", new Short((short) 1));
}
@Test
public void testShortArray() throws Exception {
performTest("ShortArray", new short[]{1, 20});
}
@Test
public void testStringArray() throws Exception {
performTest("StringArray", new String[]{"1", "20"});
}
@Test
public void testURI() throws Exception {
performTest("URI", new URI("http://nowhere.com"));
}
@Test
public void testURL() throws Exception {
performTest("URL", new URL("http://nowhere.com"));
}
private void performTest(String attributeName, Object expectedValue) throws Exception {
this.performTest(attributeName, expectedValue, null);
}
private void performTest(String attributeName, Object expectedValue, Comparator comparator) throws Exception {
ObjectName oname = new ObjectName("test:service=WithProperties");
Object attributeValue = connection.getAttribute(oname, attributeName);
assertThat("Found null attribute value for '" + attributeName + "'", attributeValue, is(notNullValue()));
if (comparator == null) {
assertThat("Found wrong attribute value for '" + attributeName + "', value: '" + attributeValue + "' expected: '" + expectedValue + "'", expectedValue, equalTo(attributeValue));
} else {
boolean equal = comparator.compare(expectedValue, attributeValue) == 0;
assertThat("Found wrong attribute value for '" + attributeName + "', value: '" + attributeValue + "' expected: '" + expectedValue + "'", equal, equalTo(true));
}
}
}
| 14,410 | 33.476077 | 189 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/jmx/property/WithProperties.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.integration.ee.jmx.property;
import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.URI;
import java.net.URL;
import java.util.Locale;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* @author baranowb
*
*/
public class WithProperties implements WithPropertiesMBean {
// those will have default values on get op, so test must set it to non def.
private boolean _boolean;
private byte _byte;
private char _char;
private double _double;
private float _float;
private int _integer;
private long _long;
private short _short;
private AtomicBoolean atomicBoolean;
private AtomicInteger atomicInteger;
private AtomicLong atomicLong;
private BigDecimal bigDecimal;
private BigInteger bigInteger;
private boolean[] booleanArray;
private byte[] byteArray;
private char[] characterArray;
private Class[] classArray;
private Class clazz;
private Document document;
private Element element;
private File file;
private float[] floatArray;
private InetAddress inetAddress;
private InetAddress[] inetAddressArray;
private int[] integerArray;
private Locale locale;
private long[] longArray;
private Boolean objectBoolean;
private Byte objectByte;
private Character objectChar;
private Double objectDouble;
private Float objectFloat;
private Integer objectInteger;
private Long objectLong;
private Short objectShort;
private Properties properties;
private short[] shortArray;
private String[] stringArray;
private URI uri;
private URL url;
public WithProperties() {
}
@Override
public AtomicBoolean getAtomicBoolean() {
return atomicBoolean;
}
@Override
public AtomicInteger getAtomicInteger() {
return atomicInteger;
}
@Override
public AtomicLong getAtomicLong() {
return atomicLong;
}
@Override
public BigDecimal getBigDecimal() {
return this.bigDecimal;
}
@Override
public BigInteger getBigInteger() {
return bigInteger;
}
@Override
public boolean getBoolean() {
return this._boolean;
}
@Override
public boolean[] getBooleanArray() {
return booleanArray;
}
@Override
public byte getByte() {
return _byte;
}
@Override
public byte[] getByteArray() {
return this.byteArray;
}
@Override
public char getChar() {
return _char;
}
@Override
public char[] getCharacterArray() {
return this.characterArray;
}
@Override
public Class[] getClassArray() {
return this.classArray;
}
@Override
public Class getClazz() {
return this.clazz;
}
@Override
public Document getDocument() {
return this.document;
}
@Override
public double getDouble() {
return _double;
}
@Override
public Element getElement() {
return this.element;
}
@Override
public File getFile() {
return this.file;
}
@Override
public float getFloat() {
return _float;
}
@Override
public float[] getFloatArray() {
return this.floatArray;
}
@Override
public InetAddress getInetAddress() {
return this.inetAddress;
}
@Override
public InetAddress[] getInetAddressArray() {
return this.inetAddressArray;
}
@Override
public int getInteger() {
return _integer;
}
@Override
public int[] getIntegerArray() {
return this.integerArray;
}
@Override
public Locale getLocale() {
return this.locale;
}
@Override
public long getLong() {
return _long;
}
@Override
public long[] getLongArray() {
return this.longArray;
}
@Override
public Boolean getObjectBoolean() {
return objectBoolean;
}
@Override
public Byte getObjectByte() {
return objectByte;
}
@Override
public Character getObjectChar() {
return objectChar;
}
@Override
public Double getObjectDouble() {
return objectDouble;
}
@Override
public Float getObjectFloat() {
return objectFloat;
}
@Override
public Integer getObjectInteger() {
return objectInteger;
}
@Override
public Long getObjectLong() {
return objectLong;
}
@Override
public Short getObjectShort() {
return objectShort;
}
@Override
public Properties getProperties() {
return this.properties;
}
@Override
public short getShort() {
return _short;
}
@Override
public short[] getShortArray() {
return this.shortArray;
}
@Override
public String[] getStringArray() {
return this.stringArray;
}
@Override
public URI getURI() {
return this.uri;
}
@Override
public URL getURL() {
return this.url;
}
@Override
public void setAtomicBoolean(AtomicBoolean atomicBoolean) {
this.atomicBoolean = atomicBoolean;
}
@Override
public void setAtomicInteger(AtomicInteger atomicInteger) {
this.atomicInteger = atomicInteger;
}
@Override
public void setAtomicLong(AtomicLong atomicLong) {
this.atomicLong = atomicLong;
}
@Override
public void setBigDecimal(BigDecimal bd) {
this.bigDecimal = bd;
}
@Override
public void setBigInteger(BigInteger bigInteger) {
this.bigInteger = bigInteger;
}
@Override
public void setBoolean(boolean b) {
this._boolean = b;
}
@Override
public void setBooleanArray(boolean[] b) {
this.booleanArray = b;
}
@Override
public void setByte(byte _byte) {
this._byte = _byte;
}
@Override
public void setByteArray(byte[] b) {
this.byteArray = b;
}
@Override
public void setChar(char _char) {
this._char = _char;
}
@Override
public void setCharacterArray(char[] b) {
this.characterArray = b;
}
@Override
public void setClassArray(Class[] b) {
this.classArray = b;
}
@Override
public void setClazz(Class b) {
this.clazz = b;
}
@Override
public void setDocument(Document b) {
this.document = b;
}
@Override
public void setDouble(double _double) {
this._double = _double;
}
@Override
public void setElement(Element b) {
this.element = b;
}
@Override
public void setFile(File b) {
this.file = b;
}
@Override
public void setFloat(float _float) {
this._float = _float;
}
@Override
public void setFloatArray(float[] b) {
this.floatArray = b;
}
@Override
public void setInetAddress(InetAddress b) {
this.inetAddress =b;
}
@Override
public void setInetAddressArray(InetAddress[] b) {
this.inetAddressArray = b;
}
@Override
public void setInteger(int _integer) {
this._integer = _integer;
}
@Override
public void setIntegerArray(int[] b) {
this.integerArray = b;
}
@Override
public void setLocale(Locale b) {
this.locale =b;
}
@Override
public void setLong(long _long) {
this._long = _long;
}
@Override
public void setLongArray(long[] b) {
this.longArray = b;
}
@Override
public void setObjectBoolean(Boolean objectBoolean) {
this.objectBoolean = objectBoolean;
}
@Override
public void setObjectByte(Byte objectByte) {
this.objectByte = objectByte;
}
@Override
public void setObjectChar(Character objectChar) {
this.objectChar = objectChar;
}
@Override
public void setObjectDouble(Double objectDouble) {
this.objectDouble = objectDouble;
}
@Override
public void setObjectFloat(Float objectFloat) {
this.objectFloat = objectFloat;
}
@Override
public void setObjectInteger(Integer objectInteger) {
this.objectInteger = objectInteger;
}
@Override
public void setObjectLong(Long objectLong) {
this.objectLong = objectLong;
}
@Override
public void setObjectShort(Short objectShort) {
this.objectShort = objectShort;
}
@Override
public void setProperties(Properties b) {
this.properties = b;
}
@Override
public void setShort(short _short) {
this._short = _short;
}
@Override
public void setShortArray(short[] b) {
this.shortArray = b;
}
@Override
public void setStringArray(String[] b) {
this.stringArray = b;
}
@Override
public void setURI(URI b) {
this.uri = b;
}
@Override
public void setURL(URL b) {
this.url = b;
}
@Override
public void start() throws Exception {
}
@Override
public void stop() throws Exception {
}
}
| 10,454 | 19.300971 | 80 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/jmx/property/WithPropertiesMBean.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 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 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.integration.ee.jmx.property;
import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.URI;
import java.net.URL;
import java.util.Locale;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* @author baranowb
*
*/
public interface WithPropertiesMBean {
AtomicBoolean getAtomicBoolean();
AtomicInteger getAtomicInteger();
AtomicLong getAtomicLong();
BigDecimal getBigDecimal();
BigInteger getBigInteger();
boolean getBoolean();
boolean[] getBooleanArray();
byte getByte();
byte[] getByteArray();
char getChar();
char[] getCharacterArray();
Class[] getClassArray();
Class getClazz();
Document getDocument();
double getDouble();
Element getElement();
File getFile();
float getFloat();
float[] getFloatArray();
InetAddress getInetAddress();
InetAddress[] getInetAddressArray();
int getInteger();
int[] getIntegerArray();
Locale getLocale();
long getLong();
long[] getLongArray();
Boolean getObjectBoolean();
Byte getObjectByte();
Character getObjectChar();
Double getObjectDouble();
Float getObjectFloat();
Integer getObjectInteger();
Long getObjectLong();
Short getObjectShort();
Properties getProperties();
short getShort();
short[] getShortArray();
String[] getStringArray();
URI getURI();
URL getURL();
void setAtomicBoolean(AtomicBoolean b);
void setAtomicInteger(AtomicInteger b);
void setAtomicLong(AtomicLong b);
void setBigDecimal(BigDecimal bd);
void setBigInteger(BigInteger bigInteger);
void setBoolean(boolean b);
void setBooleanArray(boolean[] b);
void setByte(byte _byte);
void setByteArray(byte[] b);
void setChar(char _char);
void setCharacterArray(char[] b);
void setClassArray(Class[] b);
// cant override final method from Object :)
void setClazz(Class b);
void setDocument(Document b);
void setDouble(double _double);
void setElement(Element b);
void setFile(File b);
void setFloat(float _float);
void setFloatArray(float[] b);
void setInetAddress(InetAddress b);
void setInetAddressArray(InetAddress[] b);
void setInteger(int _integer);
void setIntegerArray(int[] b);
void setLocale(Locale b);
void setLong(long _long);
void setLongArray(long[] b);
void setObjectBoolean(Boolean objectBoolean);
void setObjectByte(Byte objectByte);
void setObjectChar(Character objectChar);
void setObjectDouble(Double objectDouble);
void setObjectFloat(Float objectFloat);
void setObjectInteger(Integer objectInteger);
void setObjectLong(Long objectLong);
void setObjectShort(Short objectShort);
void setProperties(Properties b);
void setShort(short _short);
void setShortArray(short[] b);
void setStringArray(String[] b);
void setURI(URI b);
void setURL(URL b);
void start() throws Exception;
void stop() throws Exception;
}
| 4,336 | 19.457547 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/invokedintf/InvokedBusinessInterfaceBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2007, Red Hat Middleware LLC, 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.integration.ee.injection.invokedintf;
import jakarta.annotation.Resource;
import jakarta.ejb.Remote;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@Stateless
@Remote({ Remote1.class, Remote2.class })
public class InvokedBusinessInterfaceBean implements CommonRemote {
@Resource
private SessionContext ctx;
public Class<?> getInvokedBusinessInterface() {
return ctx.getInvokedBusinessInterface();
}
}
| 1,575 | 36.52381 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/invokedintf/TestFailedException.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2007, Red Hat Middleware LLC, 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.integration.ee.injection.invokedintf;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public class TestFailedException extends Exception {
private static final long serialVersionUID = 1L;
public TestFailedException(String message) {
super(message);
}
}
| 1,356 | 38.911765 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/invokedintf/Remote1.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2007, Red Hat Middleware LLC, 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.integration.ee.injection.invokedintf;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public interface Remote1 extends CommonRemote {
}
| 1,219 | 39.666667 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/invokedintf/Remote2.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2007, Red Hat Middleware LLC, 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.integration.ee.injection.invokedintf;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public interface Remote2 extends CommonRemote {
}
| 1,219 | 39.666667 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/invokedintf/Tester.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2007, Red Hat Middleware LLC, 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.integration.ee.injection.invokedintf;
import jakarta.ejb.Remote;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@Remote
public interface Tester {
void testAnnotated1() throws TestFailedException;
void testAnnotated2() throws TestFailedException;
void testXml1() throws TestFailedException;
void testXml2() throws TestFailedException;
}
| 1,439 | 35.923077 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/invokedintf/TesterBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2007, Red Hat Middleware LLC, 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.integration.ee.injection.invokedintf;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
import org.jboss.logging.Logger;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@Stateless
public class TesterBean implements Tester {
private static final Logger log = Logger.getLogger(TesterBean.class);
@EJB
private Remote1 annotated1;
@EJB
private Remote2 annotated2;
private Remote1 xml1;
private Remote2 xml2;
private void check(String name, CommonRemote bean, Class<?> expectedInvokedBusinessInterface) throws TestFailedException {
if (bean == null)
throw new TestFailedException(name + " was not injected");
Class<?> invokedBusinessInterface = bean.getInvokedBusinessInterface();
log.trace("invokedBusinessInterface = " + invokedBusinessInterface);
if (!invokedBusinessInterface.equals(expectedInvokedBusinessInterface))
throw new TestFailedException("InvokedBusinessInterface was " + invokedBusinessInterface + " instead of "
+ expectedInvokedBusinessInterface);
}
public void testAnnotated1() throws TestFailedException {
check("annotated1", annotated1, Remote1.class);
}
public void testAnnotated2() throws TestFailedException {
check("annotated2", annotated2, Remote2.class);
}
public void testXml1() throws TestFailedException {
check("xml1", xml1, Remote1.class);
}
public void testXml2() throws TestFailedException {
check("xml2", xml2, Remote2.class);
}
}
| 2,633 | 35.583333 | 126 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/invokedintf/InvokedBusinessInterfaceUnitTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2007, Red Hat Middleware LLC, 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.integration.ee.injection.invokedintf;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
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.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test to see if the proper invoked business interface is returned. Part of migration tests from EJB Testsuite (ejbthree-1060)
* to AS7 [JIRA JBQA-5483].
*
* @author Carlo de Wolf, Ondrej Chaloupka
*/
@RunWith(Arquillian.class)
public class InvokedBusinessInterfaceUnitTestCase {
private static final String ARCHIVE_NAME = "business-interface-test";
private static final Logger log = Logger.getLogger(InvokedBusinessInterfaceUnitTestCase.class);
@ArquillianResource
InitialContext ctx;
@Deployment
public static Archive<?> deployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar").addPackage(
InvokedBusinessInterfaceUnitTestCase.class.getPackage());
jar.addAsManifestResource(InvokedBusinessInterfaceUnitTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
return jar;
}
protected <Q, T> Q lookupInterface(Class<T> bean, Class<Q> intf) throws NamingException {
log.trace("initctx: " + ctx);
return intf.cast(ctx.lookup("java:global/" + ARCHIVE_NAME + "/" + bean.getSimpleName() + "!" + intf.getName()));
}
@Test
public void testAnnotated1() throws Exception {
Tester tester = lookupInterface(TesterBean.class, Tester.class);
try {
tester.testAnnotated1();
} catch (TestFailedException e) {
Assert.fail(e.getMessage());
}
}
@Test
public void testAnnotated2() throws Exception {
Tester tester = lookupInterface(TesterBean.class, Tester.class);
try {
tester.testAnnotated2();
} catch (TestFailedException e) {
Assert.fail(e.getMessage());
}
}
@Test
public void testXml1() throws Exception {
Tester tester = lookupInterface(TesterBean.class, Tester.class);
try {
tester.testXml1();
} catch (TestFailedException e) {
Assert.fail(e.getMessage());
}
}
@Test
public void testXml2() throws Exception {
Tester tester = lookupInterface(TesterBean.class, Tester.class);
try {
tester.testXml2();
} catch (TestFailedException e) {
Assert.fail(e.getMessage());
}
}
}
| 3,858 | 35.752381 | 127 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/invokedintf/CommonRemote.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2007, Red Hat Middleware LLC, 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.integration.ee.injection.invokedintf;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
public interface CommonRemote {
Class<?> getInvokedBusinessInterface();
}
| 1,246 | 40.566667 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/mappedname/MappedNameInjectionTestCase.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.integration.ee.injection.mappedname;
import javax.naming.InitialContext;
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.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that the mappedName attribute of {@link jakarta.ejb.EJB @EJB} and {@link jakarta.annotation.Resource @Resource} is
* processed correctly.
* <p/>
*
* @see https://issues.jboss.org/browse/AS7-900
* <p/>
* User: Jaikiran Pai
*/
@RunWith(Arquillian.class)
public class MappedNameInjectionTestCase {
@Deployment
public static WebArchive createSecondDeployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class);
war.addClasses(MappedNameInjectionTestCase.class, MappedNameBean.class);
war.addAsWebInfResource(MappedNameInjectionTestCase.class.getPackage(), "/web.xml","/web.xml");
return war;
}
/**
* Test that resources are injected when <code>mappedName</code> attribute is used with @Resource and @EJB annotations
*
* @throws Exception
*/
@Test
public void testResourceInjectionWithMappedName() throws Exception {
final String jndiName = "java:module/" + MappedNameBean.class.getSimpleName() + "!" + MappedNameBean.class.getName();
final MappedNameBean bean = (MappedNameBean) new InitialContext().lookup(jndiName);
Assert.assertTrue("@Resource with mappedName wasn't injected", bean.isResourceWithMappedNameInjected());
Assert.assertTrue("@Resource with lookup attribute wasn't injected", bean.isResourceWithLookupNameInjected());
Assert.assertTrue("@EJB with mappedName wasn't injected", bean.isEJBWithMappedNameInjected());
Assert.assertTrue("@EJB with lookup attribute wasn't injected", bean.isEJBWithLookupNameInjected());
}
}
| 3,004 | 40.164384 | 125 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/mappedname/MappedNameBean.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.integration.ee.injection.mappedname;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
/**
* User: jpai
*/
@Stateless
public class MappedNameBean {
@Resource(mappedName = "java:comp/env/ResourceFromWebXml")
private Object resourceByMappedName;
@Resource(lookup = "java:comp/env/ResourceFromWebXml")
private Object resourceByLookupName;
@EJB(lookup = "java:module/MappedNameBean")
private MappedNameBean selfByLookupName;
@EJB(mappedName = "java:module/MappedNameBean")
private MappedNameBean selfByMappedName;
public boolean isResourceWithMappedNameInjected() {
return this.resourceByMappedName != null;
}
public boolean isResourceWithLookupNameInjected() {
return this.resourceByLookupName != null;
}
public boolean isEJBWithLookupNameInjected() {
return this.selfByLookupName != null;
}
public boolean isEJBWithMappedNameInjected() {
return this.selfByMappedName != null;
}
}
| 2,076 | 31.968254 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/Bravo.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
@RequestScoped
public class Bravo {
@Inject
Alpha alpha;
public String getAlphaId() {
return alpha.getId();
}
}
| 1,303 | 33.315789 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/ComponentInterceptorBinding.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import jakarta.interceptor.InterceptorBinding;
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
@Documented
@InterceptorBinding
public @interface ComponentInterceptorBinding {
}
| 1,546 | 36.731707 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/AroundConstructInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, 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.integration.ee.injection.support;
import jakarta.annotation.Priority;
import jakarta.interceptor.AroundConstruct;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;
@Interceptor
@AroundConstructBinding
@Priority(Interceptor.Priority.APPLICATION + 5)
public class AroundConstructInterceptor {
public static boolean aroundConstructCalled = false;
private static String prefix = "AroundConstructInterceptor#";
@AroundConstruct
public Object intercept(InvocationContext ctx) throws Exception {
aroundConstructCalled = true;
Object[] params = ctx.getParameters();
if (params.length > 0) {
params[0] = prefix + params[0];
}
return ctx.proceed();
}
public static void reset() {
aroundConstructCalled = false;
}
}
| 1,885 | 34.584906 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/ProducedString.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.jboss.as.test.integration.ee.injection.support;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import jakarta.inject.Qualifier;
@Qualifier
@Target({ TYPE, METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Documented
public @interface ProducedString {
}
| 1,392 | 36.648649 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/StringProducer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, 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.integration.ee.injection.support;
import jakarta.enterprise.inject.Produces;
public class StringProducer {
@Produces
@ProducedString
public String name() {
return "Joe";
}
}
| 1,250 | 35.794118 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/Alpha.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support;
import java.util.UUID;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class Alpha {
private String id;
@PostConstruct
public void init() {
this.id = UUID.randomUUID().toString();
}
public String getId() {
return this.id;
}
}
| 1,429 | 30.777778 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/Charlie.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support;
import jakarta.inject.Inject;
public class Charlie {
@Inject
Alpha alpha;
public String getAlphaId() {
return alpha.getId();
}
}
| 1,241 | 33.5 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/ComponentInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import jakarta.annotation.Priority;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;
@Priority(Interceptor.Priority.APPLICATION + 10)
@Interceptor
@ComponentInterceptorBinding
public class ComponentInterceptor {
private static final List<Interception> interceptions = Collections.synchronizedList(new ArrayList<Interception>());
@AroundInvoke
public Object alwaysReturnThis(InvocationContext ctx) throws Exception {
interceptions.add(new Interception(ctx.getMethod().getName(), ctx.getTarget().getClass().getName()));
return ctx.proceed();
}
public static void resetInterceptions() {
interceptions.clear();
}
public static List<Interception> getInterceptions() {
return interceptions;
}
public static class Interception {
private final String methodName;
private final String targetClassName;
public Interception(String methodName, String targetClassName) {
super();
this.methodName = methodName;
this.targetClassName = targetClassName;
}
public String getMethodName() {
return methodName;
}
public String getTargetClassName() {
return targetClassName;
}
}
}
| 2,512 | 31.636364 | 120 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/InjectionSupportTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support;
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.test.integration.common.HttpRequest;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
/**
*
* @author Martin Kouba
*/
public abstract class InjectionSupportTestCase {
protected static WebArchive createTestArchiveBase() {
return ShrinkWrap.create(WebArchive.class)
.addClasses(Alpha.class, Bravo.class, Charlie.class, ComponentInterceptorBinding.class, ComponentInterceptor.class, InjectionSupportTestCase.class)
.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml");
}
public static final Class<?>[] constructTestsHelperClasses = new Class<?>[] { AroundConstructInterceptor.class,
AroundConstructBinding.class, StringProducer.class, ProducedString.class };
@ArquillianResource
protected URL contextPath;
protected String doGetRequest(String path) throws IOException, ExecutionException, TimeoutException {
return HttpRequest.get(contextPath + path, 10, TimeUnit.SECONDS);
}
}
| 2,455 | 40.627119 | 163 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/AroundConstructBinding.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.jboss.as.test.integration.ee.injection.support;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import jakarta.interceptor.InterceptorBinding;
@Target({ TYPE })
@Retention(RUNTIME)
@Documented
@InterceptorBinding
public @interface AroundConstructBinding {
}
| 1,230 | 35.205882 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jaxrs/JaxRsCdiInterceptionTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.jaxrs;
import static org.junit.Assert.assertEquals;
import java.net.URL;
import java.util.concurrent.TimeUnit;
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.integration.common.HttpRequest;
import org.jboss.as.test.integration.ee.injection.support.Alpha;
import org.jboss.as.test.integration.ee.injection.support.Bravo;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptor;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptorBinding;
import org.jboss.as.test.integration.jaxrs.packaging.war.WebXml;
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;
@RunWith(Arquillian.class)
@RunAsClient
public class JaxRsCdiInterceptionTestCase {
@Deployment(testable = false)
public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "jaxrscdi.war");
war.addPackage(HttpRequest.class.getPackage());
war.addClass(JaxRsCdiInterceptionTestCase.class);
war.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
war.addClasses(JaxRsResource.class, ResourceInterceptor.class, ComponentInterceptorBinding.class,
ComponentInterceptor.class, Bravo.class, Alpha.class);
war.addAsWebInfResource(WebXml.get("<servlet-mapping>\n" + " <servlet-name>jakarta.ws.rs.core.Application</servlet-name>\n"
+ " <url-pattern>/rest/*</url-pattern>\n" + " </servlet-mapping>\n" + "\n"), "web.xml");
return war;
}
@ArquillianResource
private URL url;
private String performCall(String urlPattern) throws Exception {
return HttpRequest.get(url + urlPattern, 10, TimeUnit.SECONDS);
}
@Test
public void testJaxRsMethodInterception() throws Exception {
ComponentInterceptor.resetInterceptions();
String result = performCall("rest/interception/resource");
assertEquals("Hello World", result);
String firstInterceptedMethod = performCall("rest/interception/resource/componentInterceptor/firstInterception");
Assert.assertEquals("getMessage", firstInterceptedMethod);
Boolean injectionBool = Boolean.valueOf(performCall("rest/interception/resource/injectionOk"));
Assert.assertTrue("Jax Rs field injection not correct.", injectionBool);
Integer intercepts = Integer.valueOf(performCall("rest/interception/resource/componentInterceptor/numberOfInterceptions"));
Assert.assertEquals(Integer.valueOf(4), intercepts);
}
}
| 3,984 | 43.277778 | 138 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jaxrs/JaxRsResource.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.jaxrs;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import org.jboss.as.test.integration.ee.injection.support.Alpha;
import org.jboss.as.test.integration.ee.injection.support.Bravo;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptor;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptorBinding;
@Path("interception/resource")
@ComponentInterceptorBinding
public class JaxRsResource {
public static boolean injectionOK = false;
@Inject
private Alpha alpha;
@Inject
public void setBravo(Bravo bravo) {
injectionOK = (alpha != null) && (bravo != null);
}
@GET
@Produces({ "text/plain" })
public String getMessage() {
return "Hello";
}
@GET
@Path("/componentInterceptor/numberOfInterceptions")
@Produces({ "text/plain" })
public Integer getComponentInterceptorIntercepts() {
return ComponentInterceptor.getInterceptions().size();
}
@GET
@Path("componentInterceptor/firstInterception")
@Produces({ "text/plain" })
public String getFirstInterceptionMethodName() {
return ComponentInterceptor.getInterceptions().get(0).getMethodName();
}
@GET
@Path("/injectionOk")
@Produces({ "text/plain" })
public Boolean getResourceInjectionBool() {
return injectionOK;
}
}
| 2,511 | 31.623377 | 86 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jaxrs/ResourceInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.jaxrs;
import jakarta.annotation.Priority;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptorBinding;
@Interceptor
@Priority(900)
@ComponentInterceptorBinding
public class ResourceInterceptor {
@AroundInvoke
public Object intercept(final InvocationContext invocationContext) throws Exception {
if (invocationContext.getMethod().getName().equals("getMessage")) {
return invocationContext.proceed() + " World";
}
return invocationContext.proceed();
}
}
| 1,741 | 37.711111 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/managedbean/ManagedBeanWithInject.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, 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.integration.ee.injection.support.managedbean;
import jakarta.annotation.ManagedBean;
import jakarta.inject.Inject;
import org.jboss.as.test.integration.ee.injection.support.ProducedString;
@ManagedBean("ManagedBeanWithInject")
public class ManagedBeanWithInject {
private final String name;
public ManagedBeanWithInject() {
this.name = null;
}
@Inject
public ManagedBeanWithInject(@ProducedString String name) {
this.name = name;
}
public String getName() {
return name;
}
}
| 1,587 | 32.787234 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/managedbean/ComplicatedManagedBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, 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.integration.ee.injection.support.managedbean;
import jakarta.annotation.ManagedBean;
import jakarta.inject.Inject;
import org.jboss.as.test.integration.ee.injection.support.AroundConstructBinding;
import org.jboss.as.test.integration.ee.injection.support.ProducedString;
@AroundConstructBinding
@ManagedBean("ComplicatedManagedBean")
public class ComplicatedManagedBean {
private final String name;
public ComplicatedManagedBean() {
this.name = null;
}
@Inject
public ComplicatedManagedBean(@ProducedString String name) {
this.name = name + "#ComplicatedManagedBean";
}
public String getName() {
return name;
}
}
| 1,725 | 34.22449 | 81 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/managedbean/InterceptedManagedBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, 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.integration.ee.injection.support.managedbean;
import jakarta.annotation.ManagedBean;
import org.jboss.as.test.integration.ee.injection.support.AroundConstructBinding;
@AroundConstructBinding
@ManagedBean("InterceptedManagedBean")
public class InterceptedManagedBean {
}
| 1,322 | 40.34375 | 81 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/managedbean/ManagedBeanConstructTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, 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.integration.ee.injection.support.managedbean;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.test.integration.ee.injection.support.AroundConstructInterceptor;
import org.jboss.as.test.integration.ee.injection.support.InjectionSupportTestCase;
import org.jboss.shrinkwrap.api.ShrinkWrap;
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 Matus Abaffy
*/
@RunWith(Arquillian.class)
public class ManagedBeanConstructTestCase {
@ArquillianResource
private InitialContext context;
@Deployment
public static WebArchive createDeployment() throws Exception {
WebArchive war = ShrinkWrap.create(WebArchive.class, "managedbean.war");
war.addPackage(ManagedBeanConstructTestCase.class.getPackage());
war.addClasses(InjectionSupportTestCase.constructTestsHelperClasses);
war.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml");
return war;
}
@Test
public void testManagedBeanAroundConstructInterception() throws Exception {
AroundConstructInterceptor.reset();
InterceptedManagedBean bean = (InterceptedManagedBean) context.lookup("java:module/"
+ InterceptedManagedBean.class.getSimpleName());
Assert.assertTrue("AroundConstruct interceptor method not invoked.", AroundConstructInterceptor.aroundConstructCalled);
}
@Test
public void testManagedBeanConstructorInjection() throws Exception {
ManagedBeanWithInject bean = (ManagedBeanWithInject) context.lookup("java:module/"
+ ManagedBeanWithInject.class.getSimpleName());
Assert.assertEquals("Constructor injection failed.", "Joe", bean.getName());
}
@Test
public void testManagedBeanConstructorInjectionAndInterception() throws Exception {
AroundConstructInterceptor.reset();
ComplicatedManagedBean bean = (ComplicatedManagedBean) context.lookup("java:module/"
+ ComplicatedManagedBean.class.getSimpleName());
Assert.assertTrue(AroundConstructInterceptor.aroundConstructCalled);
Assert.assertEquals("AroundConstructInterceptor#Joe#ComplicatedManagedBean", bean.getName());
}
}
| 3,552 | 43.4125 | 127 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jpa/EntityListenerInjectionSupportTestCase.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.integration.ee.injection.support.jpa;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.test.integration.ee.injection.support.Alpha;
import org.jboss.as.test.integration.ee.injection.support.Bravo;
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.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @author Matus Abaffy
*/
@RunWith(Arquillian.class)
public class EntityListenerInjectionSupportTestCase {
private static final String ARCHIVE_NAME = "test";
@Deployment
public static Archive<?> deploy() {
EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, ARCHIVE_NAME + ".ear");
WebArchive war = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME + ".war");
war.addPackage(EntityListenerInjectionSupportTestCase.class.getPackage());
war.addClasses(Alpha.class, Bravo.class);
war.addAsWebInfResource(EntityListenerInjectionSupportTestCase.class.getPackage(), "persistence.xml",
"classes/META-INF/persistence.xml");
war.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml");
ear.addAsModule(war);
return ear;
}
@ArquillianResource
private static InitialContext iniCtx;
protected <T> T lookup(String beanName, Class<T> interfaceType) throws NamingException {
return interfaceType
.cast(iniCtx.lookup("java:app/" + ARCHIVE_NAME + "/" + beanName + "!" + interfaceType.getName()));
}
@Test
public void testCDIInjectionPerformed() throws Exception {
MyBean cmt = lookup("MyBean", MyBean.class);
cmt.createEmployee("Joe Black", "Brno 2", 0);
assertTrue(MyListener.isIjectionPerformed());
}
@Test
public void testInterceptorCalled() throws Exception {
MyListener.setInvocationCount(0);
int id = 1;
MyBean bean = lookup("MyBean", MyBean.class);
bean.createEmployee("Joe Black", "Brno 2", id);
assertEquals("EntityListener was not called.", 1, MyListener.getInvocationCount());
assertTrue("Interceptor was not called.", MyListenerInterceptor.wasCalled);
// ID should be increased by 1 in MyListenerInterceptor
// id++;
Employee emp = bean.getEmployeeById(id);
assertNotNull("Could not load added employee.", emp);
}
}
| 3,932 | 39.546392 | 114 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jpa/Employee.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.integration.ee.injection.support.jpa;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.Id;
/**
* Employee entity class
*
* @author Scott Marlow
*/
@Entity
@EntityListeners({ MyListener.class })
public class Employee {
@Id
private int id;
private String name;
private String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String toString() {
return "employee " + name +", " + address + ", #" + id;
}
}
| 1,909 | 25.164384 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jpa/MyListener.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.integration.ee.injection.support.jpa;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Inject;
import jakarta.interceptor.Interceptors;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.PrePersist;
import org.jboss.as.test.integration.ee.injection.support.Alpha;
import org.jboss.as.test.integration.ee.injection.support.Bravo;
public class MyListener {
private static boolean injectionPerformed = false;
private static volatile int invocationCount = 0;
@PersistenceContext(unitName = "mypc")
EntityManager em;
@PersistenceContext(unitName = "onephasePU")
EntityManager onephaseEm;
@Inject
private Alpha alpha;
private Bravo bravo;
public static int getInvocationCount() {
return invocationCount;
}
public static void setInvocationCount(int invocationCount) {
MyListener.invocationCount = invocationCount;
}
@Inject
public void setBravo(Bravo bravo) {
this.bravo = bravo;
}
@PostConstruct
public void checkInjectionPerformed() {
injectionPerformed = alpha != null && bravo != null && em != null && onephaseEm!=null;
}
public static boolean isIjectionPerformed() {
return injectionPerformed;
}
@PrePersist
@Interceptors(MyListenerInterceptor.class)
public void onEntityCallback(Object entity) {
invocationCount++;
}
}
| 2,510 | 30.3875 | 94 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jpa/MyBean.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.integration.ee.injection.support.jpa;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
import jakarta.persistence.EntityManager;
import jakarta.persistence.LockModeType;
import jakarta.persistence.PersistenceContext;
@Stateless
@LocalBean
@TransactionManagement(TransactionManagementType.CONTAINER)
public class MyBean {
@PersistenceContext(unitName = "mypc")
EntityManager em;
@PersistenceContext(unitName = "onephasePU")
EntityManager onephaseEm;
public void createEmployee(String name, String address, int id) {
Employee emp = new Employee();
emp.setId(id);
emp.setAddress(address);
emp.setName(name);
em.joinTransaction();
em.persist(emp);
}
public Employee getEmployeeById(int id) {
return onephaseEm.find(Employee.class, id, LockModeType.NONE);
}
}
| 1,997 | 34.678571 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jpa/MyListenerInterceptor.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.jboss.as.test.integration.ee.injection.support.jpa;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
public class MyListenerInterceptor {
public static boolean wasCalled = false;
@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception {
wasCalled = true;
// change entity's ID to 2 before persisting
// Employee emp = (Employee) ctx.getParameters()[0];
// emp.setId(emp.getId() + 1);
return ctx.proceed();
}
}
| 1,320 | 34.702703 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jpa/beanmanager/Employee.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.integration.ee.injection.support.jpa.beanmanager;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.Id;
/**
* Employee entity class
*
* @author Scott Marlow
*/
@Entity
@EntityListeners({ TestEntityListener.class })
public class Employee {
@Id
private int id;
private String name;
private String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String toString() {
return "employee " + name +", " + address + ", #" + id;
}
}
| 1,929 | 25.438356 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jpa/beanmanager/EntityListenerBeanManagerInjectionTestCase.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.integration.ee.injection.support.jpa.beanmanager;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
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;
@RunWith(Arquillian.class)
public class EntityListenerBeanManagerInjectionTestCase {
private static final String ARCHIVE_NAME = "test";
@Deployment
public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME + ".war");
war.addPackage(EntityListenerBeanManagerInjectionTestCase.class.getPackage());
war.addAsWebInfResource(EntityListenerBeanManagerInjectionTestCase.class.getPackage(), "persistence.xml",
"classes/META-INF/persistence.xml");
war.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return war;
}
@ArquillianResource
private static InitialContext iniCtx;
protected <T> T lookup(String beanName, Class<T> interfaceType) throws NamingException {
return interfaceType
.cast(iniCtx.lookup("java:global/" + ARCHIVE_NAME + "/" + beanName + "!" + interfaceType.getName()));
}
@Test
public void testBeanManagerInEntityListenerCallbacks(Foo foo, Bar bar) throws NamingException {
TestBean bean = lookup("TestBean", TestBean.class);
bean.createEmployee("Joe Black", "Brno 2", 20);
bean.updateEmployee(20);
bean.removeEmployee(20);
// PostLoad call back is called twice
Assert.assertEquals(8, foo.getCounter().get());
Assert.assertEquals(8, bar.getCounter().get());
}
}
| 3,006 | 40.191781 | 117 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jpa/beanmanager/Bar.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.integration.ee.injection.support.jpa.beanmanager;
import java.util.concurrent.atomic.AtomicInteger;
import jakarta.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class Bar {
public AtomicInteger getCounter() {
return counter;
}
AtomicInteger counter = new AtomicInteger();
public void ping(){
counter.incrementAndGet();
}
}
| 1,433 | 33.142857 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jpa/beanmanager/Foo.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.integration.ee.injection.support.jpa.beanmanager;
import java.util.concurrent.atomic.AtomicInteger;
import jakarta.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class Foo {
public AtomicInteger getCounter() {
return counter;
}
AtomicInteger counter = new AtomicInteger();
public void ping(){
counter.incrementAndGet();
}
}
| 1,433 | 33.142857 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jpa/beanmanager/TestEntityListener.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.integration.ee.injection.support.jpa.beanmanager;
import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.inject.spi.Bean;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.CDI;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import jakarta.persistence.PostLoad;
import jakarta.persistence.PostPersist;
import jakarta.persistence.PostRemove;
import jakarta.persistence.PostUpdate;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreRemove;
import jakarta.persistence.PreUpdate;
public class TestEntityListener {
@PrePersist
public void prePersist(Object obj) throws NamingException {
Foo foo = obtainFooViaCdiCurrent();
Bar bar = obtainBarViaBMFromJNDI();
foo.ping();
bar.ping();
}
@PreUpdate
public void preUpdate(Object obj) throws NamingException {
Foo foo = obtainFooViaCdiCurrent();
Bar bar = obtainBarViaBMFromJNDI();
foo.ping();
bar.ping();
}
@PreRemove
public void preRemove(Object obj) throws NamingException {
Foo foo = obtainFooViaCdiCurrent();
Bar bar = obtainBarViaBMFromJNDI();
foo.ping();
bar.ping();
}
@PostLoad
public void postLoad(Object obj) throws NamingException {
Foo foo = obtainFooViaCdiCurrent();
Bar bar = obtainBarViaBMFromJNDI();
foo.ping();
bar.ping();
}
@PostUpdate
public void postUpdate(Object obj) throws NamingException {
Foo foo = obtainFooViaCdiCurrent();
Bar bar = obtainBarViaBMFromJNDI();
foo.ping();
bar.ping();
}
@PostPersist
public void postPersist(Object obj) throws NamingException {
Foo foo = obtainFooViaCdiCurrent();
Bar bar = obtainBarViaBMFromJNDI();
foo.ping();
bar.ping();
}
@PostRemove
public void postRemove(Object obj) throws NamingException {
Foo foo = obtainFooViaCdiCurrent();
Bar bar = obtainBarViaBMFromJNDI();
foo.ping();
bar.ping();
}
private Foo obtainFooViaCdiCurrent() {
BeanManager cdiCurrentBeanManager = CDI.current().getBeanManager();
Bean<Foo> bean = (Bean<Foo>) cdiCurrentBeanManager.getBeans(Foo.class).stream().findFirst().get();
CreationalContext<Foo> creationalContext = cdiCurrentBeanManager.createCreationalContext(bean);
Foo fooBean = (Foo) cdiCurrentBeanManager.getReference(bean, Foo.class, creationalContext);
return fooBean;
}
private Bar obtainBarViaBMFromJNDI() throws NamingException {
BeanManager bm = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
Bean<Bar> bean = (Bean<Bar>) bm.getBeans(Bar.class).stream().findFirst().get();
CreationalContext<Bar> creationalContext = bm.createCreationalContext(bean);
Bar bar = (Bar) bm.getReference(bean, Bar.class, creationalContext);
return bar;
}
}
| 4,069 | 35.017699 | 106 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/jpa/beanmanager/TestBean.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.integration.ee.injection.support.jpa.beanmanager;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
@Stateless
@LocalBean
public class TestBean {
@PersistenceContext(unitName = "mypc")
EntityManager em;
public void createEmployee(String name, String address, int id) {
Employee emp = new Employee();
emp.setId(id);
emp.setAddress(address);
emp.setName(name);
em.joinTransaction();
em.persist(emp);
}
public void updateEmployee(int id) {
Employee employee = em.find(Employee.class, id);
employee.setName("Johny");
em.merge(employee);
}
public void removeEmployee(int id) {
Employee employee = em.find(Employee.class, id);
em.remove(employee);
}
}
| 1,925 | 30.57377 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/websocket/AnnotatedEndpoint.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.websocket;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Inject;
import jakarta.websocket.OnMessage;
import jakarta.websocket.server.PathParam;
import jakarta.websocket.server.ServerEndpoint;
import org.jboss.as.test.integration.ee.injection.support.Alpha;
import org.jboss.as.test.integration.ee.injection.support.AroundConstructBinding;
import org.jboss.as.test.integration.ee.injection.support.Bravo;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptorBinding;
import org.jboss.as.test.integration.ee.injection.support.ProducedString;
@AroundConstructBinding
@ServerEndpoint("/websocket/{name}")
public class AnnotatedEndpoint {
public static boolean postConstructCalled = false;
public static boolean injectionOK = false;
private static String name;
@Inject
private Alpha alpha;
@Inject
public AnnotatedEndpoint(@ProducedString String name) {
AnnotatedEndpoint.name = name + "#AnnotatedEndpoint";
}
@Inject
public void setBravo(Bravo bravo) {
injectionOK = (alpha != null) && (bravo != null) && (name != null);
}
@PostConstruct
private void init() {
postConstructCalled = true;
}
@OnMessage
@ComponentInterceptorBinding
public String message(String message, @PathParam("name") String name) {
return message + " " + name;
}
public static String getName() {
return name;
}
public static void reset() {
postConstructCalled = false;
injectionOK = false;
AnnotatedEndpoint.name = null;
}
}
| 2,680 | 32.5125 | 86 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/websocket/WebSocketInjectionSupportTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.websocket;
import java.net.SocketPermission;
import java.net.URI;
import java.util.PropertyPermission;
import jakarta.websocket.ContainerProvider;
import jakarta.websocket.WebSocketContainer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.test.integration.ee.injection.support.Alpha;
import org.jboss.as.test.integration.ee.injection.support.Bravo;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptor;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptorBinding;
import org.jboss.as.test.integration.ee.injection.support.InjectionSupportTestCase;
import org.jboss.as.test.shared.AssumeTestGroupUtil;
import org.jboss.as.test.shared.TestSuiteEnvironment;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
/**
* @author Matus Abaffy
*/
@RunWith(Arquillian.class)
public class WebSocketInjectionSupportTestCase {
@BeforeClass
public static void beforeClass() {
// TODO WFLY-16551
AssumeTestGroupUtil.assumeSecurityManagerDisabled();
}
@Deployment
public static WebArchive deploy() {
return ShrinkWrap
.create(WebArchive.class, "websocket.war")
.addPackage(WebSocketInjectionSupportTestCase.class.getPackage())
.addClasses(TestSuiteEnvironment.class, Alpha.class, Bravo.class, ComponentInterceptorBinding.class,
ComponentInterceptor.class).addClasses(InjectionSupportTestCase.constructTestsHelperClasses)
.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml")
.addAsManifestResource(new StringAsset("io.undertow.websockets.jsr.UndertowContainerProvider"),
"services/jakarta.websocket.ContainerProvider")
.addAsManifestResource(createPermissionsXmlAsset(
// Needed for the TestSuiteEnvironment.getServerAddress() and TestSuiteEnvironment.getHttpPort()
new PropertyPermission("management.address", "read"),
new PropertyPermission("node0", "read"),
new PropertyPermission("jboss.http.port", "read"),
// Needed for the serverContainer.connectToServer()
new SocketPermission("*:" + TestSuiteEnvironment.getHttpPort(), "connect,resolve"),
// Needed for xnio's WorkerThread which binds to Xnio.ANY_INET_ADDRESS, see WFLY-7538
new SocketPermission("*:0", "listen,resolve")),
"permissions.xml");
}
@Test
public void testWebSocketInjectionAndInterception() throws Exception {
AnnotatedClient.reset();
AnnotatedEndpoint.reset();
ComponentInterceptor.resetInterceptions();
final WebSocketContainer serverContainer = ContainerProvider.getWebSocketContainer();
serverContainer.connectToServer(AnnotatedClient.class, new URI("ws", "", TestSuiteEnvironment.getServerAddress(), TestSuiteEnvironment.getHttpPort(), "/websocket/websocket/cruel", "", ""));
Assert.assertEquals("Hello cruel World", AnnotatedClient.getMessage());
Assert.assertTrue("Client endpoint's injection not correct.", AnnotatedClient.injectionOK);
Assert.assertTrue("Server endpoint's injection not correct.", AnnotatedEndpoint.injectionOK);
Assert.assertTrue("PostConstruct method on client endpoint instance not called.", AnnotatedClient.postConstructCalled);
Assert.assertTrue("PostConstruct method on server endpoint instance not called.", AnnotatedEndpoint.postConstructCalled);
Assert.assertEquals("AroundConstruct interceptor method not invoked for client endpoint.",
"AroundConstructInterceptor#Joe#AnnotatedClient", AnnotatedClient.getName());
Assert.assertEquals("AroundConstruct interceptor method not invoked for server endpoint.",
"AroundConstructInterceptor#Joe#AnnotatedEndpoint", AnnotatedEndpoint.getName());
Assert.assertEquals(2, ComponentInterceptor.getInterceptions().size());
Assert.assertEquals("open", ComponentInterceptor.getInterceptions().get(0).getMethodName());
Assert.assertEquals("message", ComponentInterceptor.getInterceptions().get(1).getMethodName());
}
}
| 5,796 | 51.225225 | 197 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/websocket/OnMessageClientInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.websocket;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
public class OnMessageClientInterceptor {
@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception {
String s = (String) ctx.getParameters()[0];
ctx.setParameters(new String[] { s + " World" });
return ctx.proceed();
}
}
| 1,461 | 39.611111 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/websocket/AnnotatedClient.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.websocket;
import java.io.IOException;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Inject;
import jakarta.interceptor.Interceptors;
import jakarta.websocket.ClientEndpoint;
import jakarta.websocket.OnMessage;
import jakarta.websocket.OnOpen;
import jakarta.websocket.Session;
import org.jboss.as.test.integration.ee.injection.support.Alpha;
import org.jboss.as.test.integration.ee.injection.support.AroundConstructBinding;
import org.jboss.as.test.integration.ee.injection.support.Bravo;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptorBinding;
import org.jboss.as.test.integration.ee.injection.support.ProducedString;
@AroundConstructBinding
@ClientEndpoint
public class AnnotatedClient {
public static boolean postConstructCalled = false;
public static boolean injectionOK = false;
private static String name;
private static final BlockingDeque<String> queue = new LinkedBlockingDeque<>();
@Inject
private Alpha alpha;
@Inject
public AnnotatedClient(@ProducedString String name) {
AnnotatedClient.name = name + "#AnnotatedClient";
}
@Inject
public void setBravo(Bravo bravo) {
injectionOK = (alpha != null) && (bravo != null) && (name != null);
}
@PostConstruct
private void init() {
postConstructCalled = true;
}
@OnOpen
@ComponentInterceptorBinding
public void open(final Session session) throws IOException {
session.getBasicRemote().sendText("Hello");
}
@OnMessage
@Interceptors(OnMessageClientInterceptor.class)
public void message(final String message) {
queue.add(message);
}
public static String getMessage() throws InterruptedException {
return queue.poll(5, TimeUnit.SECONDS);
}
public static String getName() {
return name;
}
public static void reset() {
queue.clear();
postConstructCalled = false;
injectionOK = false;
AnnotatedClient.name = null;
}
}
| 3,248 | 31.49 | 86 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/servlet/HttpUpgradeHandlerInjectionSupportTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.servlet;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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.test.integration.ee.injection.support.InjectionSupportTestCase;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* The code of this test is largely based on the <a
* href="https://weblogs.java.net/blog/swchan2/archive/2013/05/07/protocol-upgrade-servlet-31-example">example</a> by Servlet 3.1 spec lead Shing Wai Chan.
*
* @author Martin Kouba
*/
@RunAsClient
@RunWith(Arquillian.class)
public class HttpUpgradeHandlerInjectionSupportTestCase extends InjectionSupportTestCase {
private static final String CRLF = "\r\n";
@Deployment
public static WebArchive createTestArchive() {
return createTestArchiveBase().addClasses(TestHttpUpgradeHandler.class, TestReadListener.class, TestUpgradeServlet.class);
}
@Test
public void testInjectionSupport() throws IOException, ExecutionException, TimeoutException {
String host;
String contextRoot;
int port;
Socket socket = null;
BufferedReader in = null;
BufferedWriter out = null;
String response;
Matcher matcher = Pattern.compile("http://(.*):(\\d{1,5})/(.*)").matcher(contextPath.toString());
if (matcher.find()) {
host = matcher.group(1);
port = Integer.valueOf(matcher.group(2));
contextRoot = matcher.group(3);
} else {
throw new AssertionError("Cannot parse the test archive URL");
}
try {
socket = new Socket(host, port);
out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8));
// Initial HTTP upgrade request
out.write("GET /" + contextRoot + "TestUpgradeServlet HTTP/1.1" + CRLF);
out.write("Host: " + host + ":" + port + CRLF);
out.write("Upgrade: foo" + CRLF);
out.write("Connection: Upgrade" + CRLF);
out.write(CRLF);
out.flush();
// Receive the protocol upgrade response
in = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
String line = null;
while ((line = in.readLine()) != null) {
if ("".equals(line)) {
break;
}
}
// Send dummy request
out.write("dummy request#");
out.flush();
// Receive the dummy response
StringBuilder buffer = new StringBuilder();
while (!(line = in.readLine()).equals("END")) {
buffer.append(line);
}
response = buffer.toString();
} finally {
if (out != null) {
try {
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (in != null) {
try {
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (socket != null) {
try {
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
assertTrue(response.contains("isPostConstructCallbackInvoked: true"));
assertTrue(response.contains("isInterceptorInvoked: true"));
assertTrue(response.contains("isInjectionOk: true"));
}
}
| 5,243 | 35.165517 | 155 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/servlet/ServletInjectionSupportTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.servlet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
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.test.integration.ee.injection.support.InjectionSupportTestCase;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
*
* @author Martin Kouba
* @author Matus Abaffy
*/
@RunAsClient
@RunWith(Arquillian.class)
public class ServletInjectionSupportTestCase extends InjectionSupportTestCase {
@Deployment
public static WebArchive createTestArchive() {
return createTestArchiveBase().addClass(TestServlet.class).addClasses(constructTestsHelperClasses);
}
@Test
public void testFieldInjection() throws IOException, ExecutionException, TimeoutException {
assertNotNull(doGetRequest("/TestServlet?mode=field"));
}
@Test
public void testSetterInjection() throws IOException, ExecutionException, TimeoutException {
assertNotNull(doGetRequest("/TestServlet?mode=method"));
}
@Test
public void testConstructorInjection() throws IOException, ExecutionException, TimeoutException {
doGetRequest("/TestServlet?mode=constructor");
}
@Test
public void testAroundInvokeInterceptor() throws IOException, ExecutionException, TimeoutException {
// Servlet.service(ServletRequest, ServletResponse) must be intercepted
assertEquals("0", doGetRequest("/TestServlet?mode=interceptorReset"));
assertEquals("1", doGetRequest("/TestServlet?mode=aroundInvokeVerify"));
}
@Test
public void testAroundConstructInterceptor() throws IOException, ExecutionException, TimeoutException {
assertEquals("AroundConstructInterceptor#Joe#TestServlet", doGetRequest("/TestServlet?mode=aroundConstructVerify"));
}
}
| 3,167 | 38.6 | 124 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/servlet/TestReadListener.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.servlet;
import static org.wildfly.common.Assert.checkNotNullParam;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.List;
import jakarta.servlet.ReadListener;
import jakarta.servlet.ServletInputStream;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptor;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptor.Interception;
public class TestReadListener implements ReadListener {
private final TestHttpUpgradeHandler handler;
public TestReadListener(TestHttpUpgradeHandler handler) {
this.handler = checkNotNullParam("handler", handler);
}
@Override
public void onDataAvailable() throws IOException {
ServletInputStream input = handler.getWebConnection().getInputStream();
int len = -1;
byte[] b = new byte[1024];
if (input.isReady()) {
// Expected data is "dummy request#"
len = input.read(b);
if (len > 0) {
String data = new String(b, 0, len, StandardCharsets.UTF_8);
if (data.endsWith("#")) {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(handler.getWebConnection().getOutputStream(), StandardCharsets.UTF_8));
writeLine(writer, "isPostConstructCallbackInvoked: " + handler.isPostConstructCallbackInvoked());
writeLine(writer, "isInjectionOk: " + handler.isInjectionOk());
writeLine(writer, "isInterceptorInvoked: " + isInterceptorInvoked());
writeLine(writer, "END");
writer.flush();
}
}
}
}
private boolean isInterceptorInvoked() {
List<Interception> interceptions = ComponentInterceptor.getInterceptions();
return interceptions != null && (interceptions.size() == 1) && interceptions.get(0).getMethodName().equals("init");
}
private void writeLine(BufferedWriter writer, String text) throws IOException {
writer.write(text);
writer.newLine();
}
@Override
public void onAllDataRead() throws IOException {
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
}
| 3,426 | 36.25 | 157 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/servlet/TestUpgradeServlet.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.servlet;
import java.io.IOException;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptor;
@SuppressWarnings("serial")
@WebServlet("/TestUpgradeServlet")
public class TestUpgradeServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/plain");
if ("foo".equals(req.getHeader("Upgrade"))) {
ComponentInterceptor.resetInterceptions();
req.upgrade(TestHttpUpgradeHandler.class);
resp.setStatus(HttpServletResponse.SC_SWITCHING_PROTOCOLS);
resp.setHeader("Upgrade", "foo");
resp.setHeader("Connection", "Upgrade");
} else {
resp.setStatus(500);
}
}
}
| 2,123 | 37.618182 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/servlet/ListenerInjectionSupportTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.servlet;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
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.test.integration.ee.injection.support.InjectionSupportTestCase;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
*
* @author Martin Kouba
* @author Matus Abaffy
*/
@RunAsClient
@RunWith(Arquillian.class)
public class ListenerInjectionSupportTestCase extends InjectionSupportTestCase {
@Deployment
public static WebArchive createTestArchive() {
return createTestArchiveBase().addClasses(TestListener.class, TestListenerServlet.class).addClasses(
constructTestsHelperClasses);
}
@Test
public void testFieldInjection() throws IOException, ExecutionException, TimeoutException {
doGetRequest("/TestListenerServlet?mode=field");
}
@Test
public void testSetterInjection() throws IOException, ExecutionException, TimeoutException {
doGetRequest("/TestListenerServlet?mode=method");
}
@Test
public void testConstructorInjection() throws IOException, ExecutionException, TimeoutException {
doGetRequest("/TestListenerServlet?mode=constructor");
}
@Test
public void testAroundInvokeInterceptor() throws IOException, ExecutionException, TimeoutException {
// ServletRequestListener.requestInitialized(ServletRequestEvent) and ServletRequestListener.requestDestroyed(ServletRequestEvent) must be intercepted
assertEquals("0", doGetRequest("/TestListenerServlet?mode=interceptorReset"));
assertEquals("2", doGetRequest("/TestListenerServlet?mode=aroundInvokeVerify"));
}
@Test
public void testAroundConstructInterceptor() throws IOException, ExecutionException, TimeoutException {
assertEquals("AroundConstructInterceptor#Joe#TestListener", doGetRequest("/TestListenerServlet?mode=aroundConstructVerify"));
}
}
| 3,267 | 39.85 | 158 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/servlet/TestListener.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.servlet;
import jakarta.inject.Inject;
import jakarta.servlet.ServletRequestEvent;
import jakarta.servlet.ServletRequestListener;
import jakarta.servlet.annotation.WebListener;
import jakarta.servlet.http.HttpServletRequest;
import org.jboss.as.test.integration.ee.injection.support.Alpha;
import org.jboss.as.test.integration.ee.injection.support.AroundConstructBinding;
import org.jboss.as.test.integration.ee.injection.support.Bravo;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptorBinding;
import org.jboss.as.test.integration.ee.injection.support.ProducedString;
@AroundConstructBinding
@ComponentInterceptorBinding
@WebListener
public class TestListener implements ServletRequestListener {
@Inject
private Alpha alpha;
private Bravo bravo;
private String name;
@Inject
public TestListener(@ProducedString String name) {
this.name = name + "#TestListener";
}
@Inject
public void setBravo(Bravo bravo) {
this.bravo = bravo;
}
@Override
public void requestDestroyed(ServletRequestEvent sre) {
}
@Override
public void requestInitialized(ServletRequestEvent sre) {
HttpServletRequest req = (HttpServletRequest) sre.getServletRequest();
req.setAttribute("field.injected", alpha != null);
req.setAttribute("setter.injected", bravo != null);
req.setAttribute("name", name);
}
}
| 2,511 | 34.380282 | 86 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/servlet/FilterInjectionSupportTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.servlet;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
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.test.integration.ee.injection.support.InjectionSupportTestCase;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
*
* @author Martin Kouba
* @author Matus Abaffy
*/
@RunAsClient
@RunWith(Arquillian.class)
public class FilterInjectionSupportTestCase extends InjectionSupportTestCase {
@Deployment
public static WebArchive createTestArchive() {
return createTestArchiveBase().addClass(TestFilter.class).addClasses(constructTestsHelperClasses);
}
@Test
public void testFieldInjection() throws IOException, ExecutionException, TimeoutException {
doGetRequest("/TestFilter?mode=field");
}
@Test
public void testSetterInjection() throws IOException, ExecutionException, TimeoutException {
doGetRequest("/TestFilter?mode=method");
}
@Test
public void testConstructorInjection() throws IOException, ExecutionException, TimeoutException {
doGetRequest("/TestFilter?mode=constructor");
}
@Test
public void testAroundInvokeInterceptor() throws IOException, ExecutionException, TimeoutException {
// Filter.doFilter(ServletRequest, ServletResponse, FilterChain) must be intercepted
assertEquals("0", doGetRequest("/TestFilter?mode=interceptorReset"));
assertEquals("1", doGetRequest("/TestFilter?mode=aroundInvokeVerify"));
}
@Test
public void testAroundConstructInterceptor() throws IOException, ExecutionException, TimeoutException {
assertEquals("AroundConstructInterceptor#Joe#TestFilter", doGetRequest("/TestFilter?mode=aroundConstructVerify"));
}
}
| 3,095 | 38.189873 | 122 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/servlet/TestServlet.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.servlet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import jakarta.inject.Inject;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jboss.as.test.integration.ee.injection.support.Alpha;
import org.jboss.as.test.integration.ee.injection.support.AroundConstructBinding;
import org.jboss.as.test.integration.ee.injection.support.AroundConstructInterceptor;
import org.jboss.as.test.integration.ee.injection.support.Bravo;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptor;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptorBinding;
import org.jboss.as.test.integration.ee.injection.support.ProducedString;
@SuppressWarnings("serial")
@AroundConstructBinding
@ComponentInterceptorBinding
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
@Inject
private Alpha alpha;
private Bravo bravo;
private String name;
@Inject
public void setBravo(Bravo bravo) {
this.bravo = bravo;
}
@Inject
public TestServlet(@ProducedString String name) {
this.name = name + "#TestServlet";
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String mode = req.getParameter("mode");
resp.setContentType("text/plain");
if ("field".equals(mode)) {
assertNotNull(alpha);
resp.getWriter().append(alpha.getId());
} else if ("method".equals(mode)) {
assertNotNull(bravo);
resp.getWriter().append(bravo.getAlphaId());
} else if ("constructor".equals(mode)) {
assertNotNull(name);
assertTrue(name.contains("Joe"));
resp.getWriter().append(name);
} else if ("interceptorReset".equals(mode)) {
// Reset the interceptions - it will be incremented at the end of the service() method invocation
ComponentInterceptor.resetInterceptions();
assertEquals(0, ComponentInterceptor.getInterceptions().size());
resp.getWriter().append(""+ComponentInterceptor.getInterceptions().size());
} else if ("aroundInvokeVerify".equals(mode)) {
assertEquals("Servlet invocation not intercepted", 1, ComponentInterceptor.getInterceptions().size());
assertEquals("service", ComponentInterceptor.getInterceptions().get(0).getMethodName());
resp.getWriter().append(""+ComponentInterceptor.getInterceptions().size());
} else if ("aroundConstructVerify".equals(mode)) {
assertTrue("AroundConstruct interceptor method not invoked", AroundConstructInterceptor.aroundConstructCalled);
assertNotNull(name);
assertTrue(name.contains("AroundConstructInterceptor#"));
resp.getWriter().append(name);
} else {
resp.setStatus(404);
}
}
}
| 4,293 | 40.288462 | 123 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/servlet/TestFilter.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.servlet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import jakarta.inject.Inject;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jboss.as.test.integration.ee.injection.support.Alpha;
import org.jboss.as.test.integration.ee.injection.support.AroundConstructBinding;
import org.jboss.as.test.integration.ee.injection.support.AroundConstructInterceptor;
import org.jboss.as.test.integration.ee.injection.support.Bravo;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptor;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptorBinding;
import org.jboss.as.test.integration.ee.injection.support.ProducedString;
@ComponentInterceptorBinding
@AroundConstructBinding
@WebFilter("/TestFilter")
public class TestFilter implements Filter {
@Inject
private Alpha alpha;
private Bravo bravo;
private String name;
@Inject
public TestFilter(@ProducedString String name) {
this.name = name + "#TestFilter";
}
@Inject
public void setBravo(Bravo bravo) {
this.bravo = bravo;
}
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
String mode = req.getParameter("mode");
resp.setContentType("text/plain");
if ("field".equals(mode)) {
assertNotNull(alpha);
resp.getWriter().append(alpha.getId());
} else if ("method".equals(mode)) {
assertNotNull(bravo);
resp.getWriter().append(bravo.getAlphaId());
} else if ("constructor".equals(mode)) {
assertNotNull(name);
assertTrue(name.contains("Joe"));
resp.getWriter().append(name);
} else if ("interceptorReset".equals(mode)) {
// Reset the interceptions - it will be incremented at the end of the service() method invocation
ComponentInterceptor.resetInterceptions();
assertEquals(0, ComponentInterceptor.getInterceptions().size());
resp.getWriter().append("" + ComponentInterceptor.getInterceptions().size());
} else if ("aroundInvokeVerify".equals(mode)) {
assertEquals("Filter invocation not intercepted", 1, ComponentInterceptor.getInterceptions().size());
assertEquals("doFilter", ComponentInterceptor.getInterceptions().get(0).getMethodName());
resp.getWriter().append("" + ComponentInterceptor.getInterceptions().size());
} else if ("aroundConstructVerify".equals(mode)) {
assertTrue("AroundConstruct interceptor method not invoked", AroundConstructInterceptor.aroundConstructCalled);
assertNotNull(name);
assertTrue(name.contains("AroundConstructInterceptor#"));
resp.getWriter().append(name);
} else {
resp.setStatus(404);
}
}
public void init(FilterConfig filterConfig) throws ServletException {
}
}
| 4,653 | 40.185841 | 132 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/injection/support/servlet/TestHttpUpgradeHandler.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.integration.ee.injection.support.servlet;
import java.io.IOException;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Inject;
import jakarta.servlet.http.HttpUpgradeHandler;
import jakarta.servlet.http.WebConnection;
import org.jboss.as.test.integration.ee.injection.support.Alpha;
import org.jboss.as.test.integration.ee.injection.support.Charlie;
import org.jboss.as.test.integration.ee.injection.support.ComponentInterceptorBinding;
/**
* {@link #init(WebConnection)} method should be intercepted.
*
* @author Martin Kouba
*/
public class TestHttpUpgradeHandler implements HttpUpgradeHandler {
@Inject
private Alpha alpha;
private Charlie charlie;
private boolean postConstructCallbackInvoked = false;
private boolean injectionOk = false;
private WebConnection webConnection;
@PostConstruct
public void initialize() {
postConstructCallbackInvoked = true;
}
@Inject
public void setBravo(Charlie charlie) {
this.charlie = charlie;
}
@ComponentInterceptorBinding
@Override
public void init(WebConnection wc) {
try {
injectionOk = (alpha != null && charlie != null && alpha.getId().equals(charlie.getAlphaId()));
} catch (Exception e) {
// e.printStackTrace();
}
try {
this.webConnection = wc;
this.webConnection.getInputStream().setReadListener(new TestReadListener(this));
this.webConnection.getOutputStream().flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void destroy() {
}
WebConnection getWebConnection() {
return webConnection;
}
boolean isPostConstructCallbackInvoked() {
return postConstructCallbackInvoked;
}
boolean isInjectionOk() {
return injectionOk;
}
}
| 2,955 | 28.858586 | 107 |
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.