Search in sources :

Example 1 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class GetCallerPrincipalTestCase method testMDBLifecycle.

/**
     * Run this one in the container so it can lookup the queue
     * @throws Exception
     */
@OperateOnDeployment("test")
@Test
public void testMDBLifecycle() throws Exception {
    deployer.deploy("mdb");
    SecurityClient client = this.login();
    ITestResultsSingleton results = this.getResultsSingleton();
    MessageProducer producer = null;
    MessageConsumer consumer = null;
    QueueConnection conn = null;
    Session session = null;
    try {
        QueueConnectionFactory qcf = (QueueConnectionFactory) new InitialContext().lookup("java:/ConnectionFactory");
        Queue queue = (Queue) new InitialContext().lookup("java:jboss/" + QUEUE_NAME);
        conn = qcf.createQueueConnection("guest", "guest");
        conn.start();
        session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        TemporaryQueue replyQueue = session.createTemporaryQueue();
        TextMessage msg = session.createTextMessage("Hello world");
        msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
        msg.setJMSReplyTo(replyQueue);
        producer = session.createProducer(queue);
        producer.send(msg);
        consumer = session.createConsumer(replyQueue);
        Message replyMsg = consumer.receive(5000);
        Object obj = ((ObjectMessage) replyMsg).getObject();
        log.trace("MDB message get: " + obj);
        Assert.assertEquals(OK + "start", results.getMdb("postconstruct"));
        deployer.undeploy("mdb");
        Assert.assertEquals(OK + "stop", results.getMdb("predestroy"));
    } finally {
        if (consumer != null) {
            consumer.close();
        }
        if (producer != null) {
            producer.close();
        }
        if (session != null) {
            session.close();
        }
        if (conn != null) {
            conn.close();
        }
        client.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueConnectionFactory(javax.jms.QueueConnectionFactory) InitialContext(javax.naming.InitialContext) QueueConnection(javax.jms.QueueConnection) ObjectMessage(javax.jms.ObjectMessage) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 2 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class IIOPNamingInContainerDDNameTestCase method testIIOPNamingInvocationWithDDOverride.

/**
     * <p>
     * Tests the lookup of a bean that used the jboss-ejb3.xml deployment descriptor to override the COSNaming binding.
     * So, insteand of looking for the standard test2/IIOPNamingBean context we will look for the configured
     * bean/custom/name/IIOPNamingBean context.
     * </p>
     *
     * @throws NamingException if an error occurs while looking up the bean.
     * @throws RemoteException if an error occurs while invoking the remote bean.
     */
@Test
@OperateOnDeployment("test")
public void testIIOPNamingInvocationWithDDOverride() throws NamingException, RemoteException {
    final Properties prope = new Properties();
    final InitialContext context = new InitialContext(prope);
    final Object iiopObj = context.lookup("corbaname:iiop:" + managementClient.getMgmtAddress() + ":3528#bean/custom/name/IIOPNamingBean");
    final IIOPNamingHome object = (IIOPNamingHome) PortableRemoteObject.narrow(iiopObj, IIOPNamingHome.class);
    final IIOPRemote result = object.create();
    Assert.assertEquals("hello", result.hello());
}
Also used : PortableRemoteObject(javax.rmi.PortableRemoteObject) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 3 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class IIOPNamingInContainerTestCase method testStatefulIIOPNamingInvocation.

@Test
@OperateOnDeployment("test")
public void testStatefulIIOPNamingInvocation() throws NamingException, RemoteException, RemoveException {
    final Properties prope = new Properties();
    final InitialContext context = new InitialContext(prope);
    final Object iiopObj = context.lookup("corbaname:iiop:" + managementClient.getMgmtAddress() + ":3528#IIOPStatefulNamingBean");
    final IIOPStatefulNamingHome object = (IIOPStatefulNamingHome) PortableRemoteObject.narrow(iiopObj, IIOPStatefulNamingHome.class);
    final IIOPStatefulRemote result = object.create(10);
    Assert.assertEquals(11, result.increment());
    Assert.assertEquals(12, result.increment());
    result.remove();
    try {
        result.increment();
        Assert.fail("Expected NoSuchObjectException");
    } catch (NoSuchObjectException expected) {
    }
}
Also used : PortableRemoteObject(javax.rmi.PortableRemoteObject) NoSuchObjectException(java.rmi.NoSuchObjectException) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 4 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class JAXBUsageTestCase method testJAXBServlet.

@OperateOnDeployment("app")
@Test
public void testJAXBServlet() throws Exception {
    final HttpClient httpClient = new DefaultHttpClient();
    final String xml = "dummy.xml";
    final String requestURL = url.toExternalForm() + JAXBUsageServlet.URL_PATTERN;
    final HttpGet request = new HttpGet(requestURL);
    final HttpResponse response = httpClient.execute(request);
    int statusCode = response.getStatusLine().getStatusCode();
    Assert.assertEquals("Unexpected status code", 200, statusCode);
    final HttpEntity entity = response.getEntity();
    Assert.assertNotNull("Response message from servlet was null", entity);
    final String responseMessage = EntityUtils.toString(entity);
    Assert.assertEquals("Wrong return value", "Mill Valley", responseMessage.trim());
}
Also used : HttpEntity(org.apache.http.HttpEntity) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 5 with OperateOnDeployment

use of org.jboss.arquillian.container.test.api.OperateOnDeployment in project wildfly by wildfly.

the class LoggingDeploymentResourceTestCase method testEarDeploymentConfigurationResource.

@OperateOnDeployment(EAR_DEPLOYMENT_NAME)
@Test
public void testEarDeploymentConfigurationResource() throws Exception {
    ModelNode loggingConfiguration = readDeploymentResource(EAR_DEPLOYMENT_NAME, EAR_DEPLOYMENT_NAME + "/META-INF/logging.properties");
    // The address should have logging.properties
    Deque<Property> resultAddress = new ArrayDeque<>(Operations.getOperationAddress(loggingConfiguration).asPropertyList());
    Assert.assertTrue("The configuration path did not include logging.properties", resultAddress.getLast().getValue().asString().contains("logging.properties"));
    ModelNode handler = loggingConfiguration.get("handler", "FILE");
    Assert.assertTrue("The FILE handler was not found effective configuration", handler.isDefined());
    Assert.assertTrue(handler.hasDefined("properties"));
    String fileName = null;
    // Find the fileName property
    for (Property property : handler.get("properties").asPropertyList()) {
        if ("fileName".equals(property.getName())) {
            fileName = property.getValue().asString();
            break;
        }
    }
    Assert.assertNotNull("fileName property not found", fileName);
    Assert.assertTrue(fileName.endsWith("test-logging-ear.log"));
    // Check the WAR which should inherit the EAR's logging.properties
    loggingConfiguration = readSubDeploymentResource(EAR_DEPLOYMENT_NAME, EAR_WAR_DEPLOYMENT_NAME, EAR_DEPLOYMENT_NAME + "/META-INF/logging.properties");
    // The address should have logging.properties
    resultAddress = new ArrayDeque<>(Operations.getOperationAddress(loggingConfiguration).asPropertyList());
    Assert.assertTrue("The configuration path did not include logging.properties", resultAddress.getLast().getValue().asString().contains("logging.properties"));
    handler = loggingConfiguration.get("handler", "FILE");
    Assert.assertTrue("The FILE handler was not found effective configuration", handler.isDefined());
    Assert.assertTrue(handler.hasDefined("properties"));
    fileName = null;
    // Find the fileName property
    for (Property property : handler.get("properties").asPropertyList()) {
        if ("fileName".equals(property.getName())) {
            fileName = property.getValue().asString();
            break;
        }
    }
    Assert.assertNotNull("fileName property not found", fileName);
    Assert.assertTrue(fileName.endsWith("test-logging-ear.log"));
}
Also used : ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property) ArrayDeque(java.util.ArrayDeque) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Aggregations

OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)94 Test (org.junit.Test)93 URL (java.net.URL)31 URI (java.net.URI)22 HttpGet (org.apache.http.client.methods.HttpGet)20 HttpResponse (org.apache.http.HttpResponse)17 InitialContext (javax.naming.InitialContext)15 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)13 QName (javax.xml.namespace.QName)11 Service (javax.xml.ws.Service)11 HttpEntity (org.apache.http.HttpEntity)10 Bus (org.apache.cxf.Bus)9 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)9 WrapThreadContextClassLoader (org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)9 ActAsServiceIface (org.jboss.as.test.integration.ws.wsse.trust.actas.ActAsServiceIface)6 OnBehalfOfServiceIface (org.jboss.as.test.integration.ws.wsse.trust.onbehalfof.OnBehalfOfServiceIface)6 GetMethodWebRequest (com.meterware.httpunit.GetMethodWebRequest)5 WebConversation (com.meterware.httpunit.WebConversation)5 WebForm (com.meterware.httpunit.WebForm)5 WebRequest (com.meterware.httpunit.WebRequest)5