Search in sources :

Example 6 with QueueDeployment

use of org.apache.activemq.artemis.rest.queue.QueueDeployment in project activemq-artemis by apache.

the class JMSTest method testJmsProducer.

@Test
public void testJmsProducer() throws Exception {
    String queueName = "testQueue";
    String prefixedQueueName = ActiveMQDestination.createQueueAddressFromName(queueName).toString();
    System.out.println("Queue name: " + prefixedQueueName);
    QueueDeployment deployment = new QueueDeployment();
    deployment.setDuplicatesAllowed(true);
    deployment.setDurableSend(false);
    deployment.setName(queueName);
    manager.getQueueManager().deploy(deployment);
    ClientRequest request = new ClientRequest(generateURL(Util.getUrlPath(queueName)));
    ClientResponse<?> response = request.head();
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
    System.out.println("create: " + sender);
    Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
    System.out.println("pull: " + consumers);
    response = Util.setAutoAck(consumers, true);
    Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
    System.out.println("consume-next: " + consumeNext);
    // test that Accept header is used to set content-type
    {
        Order order = new Order();
        order.setName("1");
        order.setAmount("$5.00");
        publish(prefixedQueueName, order, null);
        ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/xml").post(String.class);
        Assert.assertEquals(200, res.getStatus());
        Assert.assertEquals("application/xml", res.getHeaders().getFirst("Content-Type").toString().toLowerCase());
        Order order2 = res.getEntity(Order.class);
        res.releaseConnection();
        Assert.assertEquals(order, order2);
        consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
        Assert.assertNotNull(consumeNext);
    }
    // test that Accept header is used to set content-type
    {
        Order order = new Order();
        order.setName("1");
        order.setAmount("$5.00");
        publish(prefixedQueueName, order, null);
        ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").accept("application/json").post(String.class);
        Assert.assertEquals(200, res.getStatus());
        Assert.assertEquals("application/json", res.getHeaders().getFirst("Content-Type").toString().toLowerCase());
        Order order2 = res.getEntity(Order.class);
        res.releaseConnection();
        Assert.assertEquals(order, order2);
        consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
        Assert.assertNotNull(consumeNext);
    }
    // test that message property is used to set content type
    {
        Order order = new Order();
        order.setName("2");
        order.setAmount("$15.00");
        publish(prefixedQueueName, order, "application/xml");
        ClientResponse<?> res = consumeNext.request().header("Accept-Wait", "2").post(String.class);
        Assert.assertEquals(200, res.getStatus());
        Assert.assertEquals("application/xml", res.getHeaders().getFirst("Content-Type").toString().toLowerCase());
        Order order2 = res.getEntity(Order.class);
        res.releaseConnection();
        Assert.assertEquals(order, order2);
        consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
        Assert.assertNotNull(consumeNext);
    }
}
Also used : ClientResponse(org.jboss.resteasy.client.ClientResponse) QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) ClientRequest(org.jboss.resteasy.client.ClientRequest) Link(org.jboss.resteasy.spi.Link) Test(org.junit.Test)

Example 7 with QueueDeployment

use of org.apache.activemq.artemis.rest.queue.QueueDeployment in project activemq-artemis by apache.

the class DupQueueTest method testDupWithId.

@Test
public void testDupWithId() throws Exception {
    String testName = "testDupWithId";
    QueueDeployment deployment = new QueueDeployment();
    deployment.setDuplicatesAllowed(false);
    deployment.setDurableSend(false);
    deployment.setName(testName);
    manager.getQueueManager().deploy(deployment);
    ClientRequest request = new ClientRequest(generateURL("/queues/" + testName));
    ClientResponse<?> response = request.head();
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create-with-id");
    System.out.println("create: " + sender);
    Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
    System.out.println("pull: " + consumers);
    response = Util.setAutoAck(consumers, true);
    Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
    System.out.println("poller: " + consumeNext);
    ClientResponse<?> res = sender.request().pathParameter("id", "1").body("text/plain", Integer.toString(1)).post();
    res.releaseConnection();
    Assert.assertEquals(201, res.getStatus());
    res = sender.request().body("text/plain", Integer.toString(1)).pathParameter("id", "1").post();
    res.releaseConnection();
    Assert.assertEquals(201, res.getStatus());
    sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "create-next");
    res = sender.request().body("text/plain", Integer.toString(2)).post();
    res.releaseConnection();
    Assert.assertEquals(201, res.getStatus());
    res = consumeNext.request().post(String.class);
    Assert.assertEquals(200, res.getStatus());
    Assert.assertEquals("1", res.getEntity(String.class));
    res.releaseConnection();
    Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
    System.out.println("session: " + session);
    consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
    System.out.println("consumeNext: " + consumeNext);
    res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
    Assert.assertEquals(200, res.getStatus());
    Assert.assertEquals("2", res.getEntity(String.class));
    res.releaseConnection();
    session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
    System.out.println("session: " + session);
    consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
    System.out.println("consumeNext: " + consumeNext);
    res = consumeNext.request().post(String.class);
    res.releaseConnection();
    Assert.assertEquals(503, res.getStatus());
    res = session.request().delete();
    res.releaseConnection();
    Assert.assertEquals(204, res.getStatus());
}
Also used : QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) ClientRequest(org.jboss.resteasy.client.ClientRequest) Link(org.jboss.resteasy.spi.Link) Test(org.junit.Test)

Example 8 with QueueDeployment

use of org.apache.activemq.artemis.rest.queue.QueueDeployment in project activemq-artemis by apache.

the class ClientAckQueueTest method testPullX2.

@Test
public void testPullX2() throws Exception {
    String testName = "testPullX2";
    QueueDeployment queueDeployment = new QueueDeployment(testName, true);
    manager.getQueueManager().deploy(queueDeployment);
    manager.getQueueManager().setLinkStrategy(new LinkHeaderLinkStrategy());
    testPull(1, testName);
    manager.getQueueManager().setLinkStrategy(new CustomHeaderLinkStrategy());
    testPull(4, testName);
}
Also used : CustomHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy) QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) LinkHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy) Test(org.junit.Test)

Example 9 with QueueDeployment

use of org.apache.activemq.artemis.rest.queue.QueueDeployment in project activemq-artemis by apache.

the class ClientAckQueueTest method setup.

@BeforeClass
public static void setup() throws Exception {
    QueueDeployment deployment1 = new QueueDeployment("testQueue", true);
    manager.getQueueManager().deploy(deployment1);
}
Also used : QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) BeforeClass(org.junit.BeforeClass)

Example 10 with QueueDeployment

use of org.apache.activemq.artemis.rest.queue.QueueDeployment in project activemq-artemis by apache.

the class ClientAckQueueTest method testAckTimeoutX2.

@Test
public void testAckTimeoutX2() throws Exception {
    QueueDeployment deployment = new QueueDeployment();
    deployment.setConsumerSessionTimeoutSeconds(1);
    deployment.setDuplicatesAllowed(true);
    deployment.setDurableSend(false);
    deployment.setName("testAck");
    manager.getQueueManager().deploy(deployment);
    manager.getQueueManager().setLinkStrategy(new LinkHeaderLinkStrategy());
    testAckTimeout();
    manager.getQueueManager().setLinkStrategy(new CustomHeaderLinkStrategy());
    testAckTimeout();
}
Also used : CustomHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy) QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) LinkHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy) Test(org.junit.Test)

Aggregations

QueueDeployment (org.apache.activemq.artemis.rest.queue.QueueDeployment)21 Test (org.junit.Test)15 ClientRequest (org.jboss.resteasy.client.ClientRequest)11 Link (org.jboss.resteasy.spi.Link)11 XmlLink (org.apache.activemq.artemis.rest.queue.push.xml.XmlLink)4 TopicDeployment (org.apache.activemq.artemis.rest.topic.TopicDeployment)4 CustomHeaderLinkStrategy (org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy)4 LinkHeaderLinkStrategy (org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy)4 BeforeClass (org.junit.BeforeClass)4 PushTopicRegistration (org.apache.activemq.artemis.rest.topic.PushTopicRegistration)3 Connection (javax.jms.Connection)1 Destination (javax.jms.Destination)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageListener (javax.jms.MessageListener)1 Session (javax.jms.Session)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ActiveMQDestination (org.apache.activemq.artemis.jms.client.ActiveMQDestination)1 ActiveMQPushStrategy (org.apache.activemq.artemis.rest.queue.push.ActiveMQPushStrategy)1 PushRegistration (org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration)1 ClientResponse (org.jboss.resteasy.client.ClientResponse)1