Java Code Examples for org.wso2.carbon.integration.common.utils.LoginLogoutClient#logout()

The following examples show how to use org.wso2.carbon.integration.common.utils.LoginLogoutClient#logout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PurgeMessagesTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Revert changed configuration, purge and delete the queue.
 *
 * @throws XPathExpressionException
 * @throws IOException
 */
@AfterClass()
public void cleanup() throws Exception {
    LoginLogoutClient loginLogoutClientForAdmin = new LoginLogoutClient(super.automationContext);
    String sessionCookie = loginLogoutClientForAdmin.login();
    AndesAdminClient andesAdminClient =
            new AndesAdminClient(super.backendURL, sessionCookie);

    andesAdminClient.deleteQueue(TEST_QUEUE_PURGE);
    andesAdminClient.deleteQueue(DLCQueueUtils.identifyTenantInformationAndGenerateDLCString(TEST_QUEUE_PURGE));

    loginLogoutClientForAdmin.logout();
    //Revert back to original configuration.
    super.serverManager.restoreToLastConfiguration(true);

}
 
Example 2
Source File: PerMessageAcknowledgementsTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * This method will restore all the configurations back. Following configurations will be restored. 1.
 * AndesAckWaitTimeOut system property. 2. Delete all destination created in the test case. 3. Restore default
 * broker.xml and restart server.
 *
 * @throws IOException
 * @throws AutomationUtilException
 * @throws AndesAdminServiceBrokerManagerAdminException
 * @throws LogoutAuthenticationExceptionException
 */
@AfterClass()
public void tearDown() throws IOException, AutomationUtilException, AndesAdminServiceBrokerManagerAdminException,
        LogoutAuthenticationExceptionException {
    if (StringUtils.isBlank(defaultAndesAckWaitTimeOut)) {
        System.clearProperty(AndesClientConstants.ANDES_ACK_WAIT_TIMEOUT_PROPERTY);
    } else {
        System.setProperty(AndesClientConstants.ANDES_ACK_WAIT_TIMEOUT_PROPERTY, defaultAndesAckWaitTimeOut);
    }

    LoginLogoutClient loginLogoutClientForAdmin = new LoginLogoutClient(super.automationContext);
    String sessionCookie = loginLogoutClientForAdmin.login();
    AndesAdminClient andesAdminClient = new AndesAdminClient(super.backendURL, sessionCookie);

    andesAdminClient.deleteQueue("firstMessageInvalidOnlyPerAckQueue");
    andesAdminClient.deleteQueue("allUnacknowledgePerAckQueue");
    andesAdminClient.deleteQueue("oneByOneUnacknowledgePerAckQueue");
    andesAdminClient.deleteQueue("firstFewUnacknowledgePerAckQueue");
    andesAdminClient.deleteQueue("unacknowledgeMiddleMessagePerAckQueue");
    andesAdminClient.deleteQueue("oneByOneUnacknowledgeQueuePerAckMultiple");
    andesAdminClient.deleteQueue("allAcknowledgeMultiplePerAckQueue");
    loginLogoutClientForAdmin.logout();

    //Revert back to original configuration.
    super.serverManager.restoreToLastConfiguration(true);
}
 
Example 3
Source File: TopicUserAuthorizationTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Deleting the topics that were created.
 *
 * @throws XPathExpressionException
 * @throws LoginAuthenticationExceptionException
 * @throws IOException
 * @throws XMLStreamException
 * @throws URISyntaxException
 * @throws SAXException
 * @throws AndesEventAdminServiceEventAdminException
 * @throws LogoutAuthenticationExceptionException
 */
@AfterClass()
public void cleanUpTopics()
        throws XPathExpressionException, LoginAuthenticationExceptionException, IOException,
        XMLStreamException, URISyntaxException, SAXException,
        AndesEventAdminServiceEventAdminException,
        LogoutAuthenticationExceptionException, AutomationUtilException {
    LoginLogoutClient loginLogoutClientForUser = new LoginLogoutClient(this.automationContext);
    String sessionCookie = loginLogoutClientForUser.login();
    TopicAdminClient topicAdminClient =
            new TopicAdminClient(this.backendURL, sessionCookie);
    topicAdminClient.removeTopic("authTopic1");
    topicAdminClient.removeTopic("authTopic2");
    topicAdminClient.removeTopic("authTopic3");
    topicAdminClient.removeTopic("authTopic4");
    topicAdminClient.removeTopic("authTopic5");
    topicAdminClient.removeTopic("authTopic6");
    topicAdminClient.removeTopic("authTopic7");
    topicAdminClient.removeTopic("authTopic8");
    topicAdminClient.removeTopic("authTopic9");

    loginLogoutClientForUser.logout();

}
 
Example 4
Source File: TopicUserAuthorizationTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Assigning consuming publishing permissions of a topic to a role.
 *
 * @param topicName   The topic name
 * @param permissions New permissions for the role. can be publish, consume.
 * @throws XPathExpressionException
 * @throws IOException
 * @throws URISyntaxException
 * @throws SAXException
 * @throws XMLStreamException
 * @throws LoginAuthenticationExceptionException
 * @throws AndesAdminServiceBrokerManagerAdminException
 * @throws LogoutAuthenticationExceptionException
 * @throws UserAdminUserAdminException
 */
public void updateTopicRoleConsumePublishPermission(String topicName,
                                                    TopicRolePermission permissions)
        throws XPathExpressionException, IOException, URISyntaxException, SAXException,
        XMLStreamException, LoginAuthenticationExceptionException,
        AndesAdminServiceBrokerManagerAdminException,
        LogoutAuthenticationExceptionException,
        UserAdminUserAdminException,
        AndesEventAdminServiceEventAdminException, AutomationUtilException {

    LoginLogoutClient loginLogoutClientForUser = new LoginLogoutClient(automationContext);
    String sessionCookie = loginLogoutClientForUser.login();
    TopicAdminClient topicAdminClient =
            new TopicAdminClient(backendURL, sessionCookie);
    topicAdminClient.updatePermissionForTopic(topicName, permissions);
    loginLogoutClientForUser.logout();
}
 
Example 5
Source File: SubTopicUserAuthorizationTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Deleting the topics that were created.
 *
 * @throws XPathExpressionException
 * @throws LoginAuthenticationExceptionException
 * @throws IOException
 * @throws XMLStreamException
 * @throws URISyntaxException
 * @throws SAXException
 * @throws AndesEventAdminServiceEventAdminException
 * @throws LogoutAuthenticationExceptionException
 */
@AfterClass()
public void cleanUpTopics()
        throws XPathExpressionException, LoginAuthenticationExceptionException, IOException,
        XMLStreamException, URISyntaxException, SAXException,
        AndesEventAdminServiceEventAdminException,
        LogoutAuthenticationExceptionException, AutomationUtilException {
    LoginLogoutClient loginLogoutClientForUser = new LoginLogoutClient(this.automationContext);
    String sessionCookie = loginLogoutClientForUser.login();
    TopicAdminClient topicAdminClient =
            new TopicAdminClient(this.backendURL, sessionCookie);
    topicAdminClient.removeTopic("authTopic1");
    topicAdminClient.removeTopic("authTopic2");
    topicAdminClient.removeTopic("authTopic3");

    loginLogoutClientForUser.logout();

}
 
Example 6
Source File: QueueUserAuthorizationTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Deleting the queues that were created.
 *
 * @throws IOException
 * @throws XPathExpressionException
 * @throws LogoutAuthenticationExceptionException
 * @throws URISyntaxException
 * @throws SAXException
 * @throws XMLStreamException
 * @throws LoginAuthenticationExceptionException
 * @throws AndesAdminServiceBrokerManagerAdminException
 */
@AfterClass()
public void cleanUpQueues()
        throws IOException, XPathExpressionException,
        LogoutAuthenticationExceptionException, URISyntaxException, SAXException,
        XMLStreamException, LoginAuthenticationExceptionException,
        AndesAdminServiceBrokerManagerAdminException, AutomationUtilException {
    LoginLogoutClient loginLogoutClientForAdmin = new LoginLogoutClient(super.automationContext);
    String sessionCookie = loginLogoutClientForAdmin.login();
    AndesAdminClient andesAdminClient =
            new AndesAdminClient(super.backendURL, sessionCookie);

    andesAdminClient.deleteQueue("authQueue1");
    andesAdminClient.deleteQueue("authQueue2");
    andesAdminClient.deleteQueue("authQueue3");
    andesAdminClient.deleteQueue("authQueue4");
    andesAdminClient.deleteQueue("authQueue5");
    andesAdminClient.deleteQueue("authQueue6");
    andesAdminClient.deleteQueue("authQueue7");
    andesAdminClient.deleteQueue("authQueue8");
    andesAdminClient.deleteQueue("authQueue9");

    loginLogoutClientForAdmin.logout();
}
 
Example 7
Source File: QueueUserAuthorizationTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Assigning consuming publishing permissions of a queue to a role.
 *
 * @param queueName   The queue name
 * @param permissions New permissions for the role. can be publish, consume.
 * @throws XPathExpressionException
 * @throws IOException
 * @throws URISyntaxException
 * @throws SAXException
 * @throws XMLStreamException
 * @throws LoginAuthenticationExceptionException
 * @throws AndesAdminServiceBrokerManagerAdminException
 * @throws LogoutAuthenticationExceptionException
 * @throws UserAdminUserAdminException
 */
public void updateQueueRoleConsumePublishPermission(String queueName,
                                                    QueueRolePermission permissions)
        throws XPathExpressionException, IOException, URISyntaxException, SAXException,
        XMLStreamException, LoginAuthenticationExceptionException,
        AndesAdminServiceBrokerManagerAdminException,
        LogoutAuthenticationExceptionException,
        UserAdminUserAdminException, AutomationUtilException {

    LoginLogoutClient loginLogoutClientForAdmin = new LoginLogoutClient(super.automationContext);
    String sessionCookie = loginLogoutClientForAdmin.login();
    AndesAdminClient andesAdminClient =
            new AndesAdminClient(super.backendURL, sessionCookie);
    andesAdminClient.updatePermissionForQueue(queueName, permissions);
    loginLogoutClientForAdmin.logout();
}
 
Example 8
Source File: AMQPSessionRecoverTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Revert changed configuration, purge and delete the queue.
 *
 * @throws XPathExpressionException on an issue reading XPATH elements in config
 * @throws IOException on an file issue reading with config files
 */
@AfterClass()
public void cleanup() throws Exception {
    LoginLogoutClient loginLogoutClientForAdmin = new LoginLogoutClient(super.automationContext);
    String sessionCookie = loginLogoutClientForAdmin.login();
    AndesAdminClient andesAdminClient =
            new AndesAdminClient(super.backendURL, sessionCookie);

    andesAdminClient.deleteQueue(TEST_SESSION_RECOVER_WITHOUT_ACK);
    andesAdminClient.deleteQueue(TEST_SESSION_RECOVER_WITH_ACK);
    andesAdminClient.deleteQueue(TEST_SESSION_RECOVER_AND_DLC);

    loginLogoutClientForAdmin.logout();
    //Revert back to original configuration.
    super.serverManager.restoreToLastConfiguration(true);

}
 
Example 9
Source File: DLCQueueTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the number of messages in the DLC queue.
 *
 * @return The number of messages.
 * @throws AutomationUtilException
 * @throws RemoteException
 * @throws LogoutAuthenticationExceptionException
 * @throws AndesAdminServiceBrokerManagerAdminException
 */
private long getDLCMessageCount() throws AutomationUtilException, RemoteException,
        LogoutAuthenticationExceptionException, AndesAdminServiceBrokerManagerAdminException {
    LoginLogoutClient loginLogoutClientForAdmin = new LoginLogoutClient(mbServer);
    String sessionCookie = loginLogoutClientForAdmin.login();
    AndesAdminClient andesAdminClient = new AndesAdminClient(backendURL, sessionCookie);
    long messageCount = andesAdminClient.getDlcQueue().getMessageCount();
    loginLogoutClientForAdmin.logout();

    return messageCount;
}
 
Example 10
Source File: RedeliveryDelayTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * This method will restore all the configurations back.
 * Following configurations will be restored.
 * 1. AndesAckWaitTimeOut system property.
 * 2. AndesRedeliveryDelay system property.
 * 3. Deleted all destination created in this test class.
 * 4. Restore default broker.xml and restart server.
 *
 * @throws IOException
 * @throws AutomationUtilException
 */
@AfterClass()
public void tearDown()
        throws IOException, AutomationUtilException, LogoutAuthenticationExceptionException,
        AndesAdminServiceBrokerManagerAdminException {
    if (StringUtils.isBlank(defaultAndesAckWaitTimeOut)) {
        System.clearProperty(AndesClientConstants.ANDES_ACK_WAIT_TIMEOUT_PROPERTY);
    } else {
        System.setProperty(AndesClientConstants.ANDES_ACK_WAIT_TIMEOUT_PROPERTY, defaultAndesAckWaitTimeOut);
    }

    if (StringUtils.isBlank(defaultAndesRedeliveryDelay)) {
        System.clearProperty(AndesClientConstants.ANDES_REDELIVERY_DELAY_PROPERTY);
    } else {
        System.setProperty(AndesClientConstants.ANDES_REDELIVERY_DELAY_PROPERTY, defaultAndesRedeliveryDelay);
    }

    LoginLogoutClient loginLogoutClientForAdmin = new LoginLogoutClient(super.automationContext);
    String sessionCookie = loginLogoutClientForAdmin.login();
    AndesAdminClient andesAdminClient = new AndesAdminClient(super.backendURL, sessionCookie);

    andesAdminClient.deleteQueue("firstMessageInvalidOnlyQueue");
    andesAdminClient.deleteQueue("firstMessageInvalidOnlyReceiverQueue");
    andesAdminClient.deleteQueue("multipleUnacknowledgeQueue");
    andesAdminClient.deleteQueue("multipleUnacknowledgeReceiverQueue");
    andesAdminClient.deleteQueue("oneByOneUnacknowledgeQueue");
    andesAdminClient.deleteQueue("oneByOneUnacknowledgeReceiverQueue");
    andesAdminClient.deleteQueue("firstFewUnacknowledgeQueue");
    andesAdminClient.deleteQueue("firstFewUnacknowledgeReceiverQueue");
    andesAdminClient.deleteQueue("unacknowledgeMiddleMessageQueue");
    andesAdminClient.deleteQueue("unacknowledgeMiddleMessageReceiverQueue");
    andesAdminClient.deleteQueue("oneByOneUnacknowledgeMessageListenerForMultiple");
    andesAdminClient.deleteQueue("oneByOneUnacknowledgeMessageReceiverForMultipleQueue");
    loginLogoutClientForAdmin.logout();

    //Revert back to original configuration.
    super.serverManager.restoreToLastConfiguration(true);
}
 
Example 11
Source File: MultiTenantQueueTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Test case 1
 * 1. Start a client in a tenant(Normal tenant) which listens to a queue
 * 2. Send 200 messages to the queue
 * 3. Client should receive all 200 messages
 *
 * @throws JMSException
 * @throws IOException
 * @throws NamingException
 * @throws AndesClientConfigurationException
 * @throws AndesClientException
 */
@Test(groups = "wso2.mb", description = "Single Tenant Test")
public void performSingleTenantMultipleUserQueueTestCase()
        throws JMSException, IOException, NamingException, AndesClientConfigurationException,
        AndesClientException, LoginAuthenticationExceptionException, XPathExpressionException,
        AndesAdminServiceBrokerManagerAdminException, URISyntaxException, SAXException,
        LogoutAuthenticationExceptionException, XMLStreamException, AutomationUtilException {
    int sendMessageCount = 200;
    int expectedMessageCount = 200;

    String destinationName = "topictenant1.com/tenantQueue";

    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration adminConsumerConfig =
            new AndesJMSConsumerClientConfiguration(getAMQPPort(), "admin!topictenant1.com", "admin",
                                        ExchangeType.QUEUE, destinationName);
    adminConsumerConfig.setMaximumMessagesToReceived(expectedMessageCount);
    adminConsumerConfig.setPrintsPerMessageCount(expectedMessageCount / 10L);
    adminConsumerConfig.setAsync(false);

    // Creating clients
    AndesClient adminConsumerClient = new AndesClient(adminConsumerConfig, true);
    adminConsumerClient.startClient();


    // Add permission to be able to publish
    QueueRolePermission queueRolePermission = new QueueRolePermission();
    queueRolePermission.setRoleName(PUBLISHER_ROLE);
    queueRolePermission.setAllowedToConsume(true);
    queueRolePermission.setAllowedToPublish(true);

    // Get the automation context for the tenant
    AutomationContext tenantContext = new AutomationContext("MB", "mb001", "topictenant1", "topictenantuser1");


    LoginLogoutClient loginLogoutClient = new LoginLogoutClient(tenantContext);
    String sessionCookie = loginLogoutClient.login();
    AndesAdminClient andesAdminClient =
            new AndesAdminClient(super.backendURL, sessionCookie);

    // Update permissions for the destination queue to be able to publish/subscribe from topictenantuser1
    andesAdminClient.updatePermissionForQueue(destinationName, queueRolePermission);
    loginLogoutClient.logout();

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration tenantPublisherConfig =
            new AndesJMSPublisherClientConfiguration(getAMQPPort(), "topictenantuser1!topictenant1.com",
                         "topictenantuser1", ExchangeType.QUEUE, destinationName);
    tenantPublisherConfig.setNumberOfMessagesToSend(sendMessageCount);
    tenantPublisherConfig.setPrintsPerMessageCount(sendMessageCount / 10L);


    AndesClient tenantPublisherClient = new AndesClient(tenantPublisherConfig, true);
    tenantPublisherClient.startClient();

    AndesClientUtils.waitForMessagesAndShutdown(adminConsumerClient,
                                                        AndesClientConstants.DEFAULT_RUN_TIME);

    // Evaluating
    Assert.assertEquals(tenantPublisherClient.getSentMessageCount(), sendMessageCount,
                                                        "Sending failed for tenant 1 user 1.");
    Assert.assertEquals(adminConsumerClient.getReceivedMessageCount(), expectedMessageCount,
                                            "Message receiving failed for admin of tenant 1.");
}
 
Example 12
Source File: TenantDeleteQueueTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Following steps are done by the admin user
 * 1. Create a queue.
 * 2. Delete the queue.
 * 3. Recreate a queue with same name.
 * 4. Delete the queue.
 *
 * @throws IOException
 * @throws AndesClientConfigurationException
 * @throws JMSException
 * @throws NamingException
 * @throws AndesClientException
 */
@Test(groups = "wso2.mb")
public void performCreateDeleteQueueAdminTestCase() throws Exception {

    LoginLogoutClient loginLogoutClientForAdmin = new LoginLogoutClient(automationContext);
    String sessionCookie = loginLogoutClientForAdmin.login();
    String backEndUrl = automationContext.getContextUrls().getBackEndUrl();

    AndesAdminClient andesAdminClient = new AndesAdminClient(backEndUrl, sessionCookie);

    automationContext.getContextTenant().getContextUser().getUserName();

    andesAdminClient.createQueue("deleteAdminQueue");

    andesAdminClient.deleteQueue("deleteAdminQueue");

    AndesClientUtils.sleepForInterval(5000);

    andesAdminClient.createQueue("deleteAdminQueue");

    andesAdminClient.deleteQueue("deleteAdminQueue");

    loginLogoutClientForAdmin.logout();
}
 
Example 13
Source File: TenantDeleteQueueTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Following steps are done by a tenant user
 * 1. Create a queue.
 * 2. Delete the queue.
 * 3. Recreate a queue with same name.
 * 4. Delete the queue.
 *
 * @throws IOException
 * @throws AndesClientConfigurationException
 * @throws JMSException
 * @throws NamingException
 * @throws AndesClientException
 */
@Test(groups = "wso2.mb")
public void performCreateDeleteQueueTenantTestCase() throws Exception {
    AutomationContext userAutomationContext = new AutomationContext("MB", TestUserMode.TENANT_USER);

    LoginLogoutClient loginLogoutClientForAdmin = new LoginLogoutClient(userAutomationContext);
    String sessionCookie = loginLogoutClientForAdmin.login();
    String backEndUrl = userAutomationContext.getContextUrls().getBackEndUrl();

    AndesAdminClient andesAdminClient = new AndesAdminClient(backEndUrl, sessionCookie);

    userAutomationContext.getContextTenant().getContextUser().getUserName();

    andesAdminClient.createQueue("deleteTenantQueue");

    andesAdminClient.deleteQueue(userAutomationContext.getContextTenant().getDomain() + "/deleteTenantQueue");

    AndesClientUtils.sleepForInterval(5000);

    andesAdminClient.createQueue("deleteTenantQueue");

    andesAdminClient.deleteQueue(userAutomationContext.getContextTenant().getDomain() + "/deleteTenantQueue");

    loginLogoutClientForAdmin.logout();
}
 
Example 14
Source File: MultiTenantDurableTopicTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Test case 1
 * 1. Start a Durable subscriber from a normal tenant (Not super tenant)
 * (Topic - topictenant1.com/durableTenantTopic)
 * 2. Send 200 messages to the the topic
 * 3. Durable subscriber should receive all 200 messages
 *
 * @throws AndesClientConfigurationException
 * @throws JMSException
 * @throws NamingException
 * @throws IOException
 * @throws AndesClientException
 */
@Test(groups = "wso2.mb", description = "Single Tenant Test case")
public void performSingleTenantMultipleUserDurableTopicTestCase()
        throws AndesClientConfigurationException, JMSException, NamingException, IOException,
        AndesClientException, XPathExpressionException, URISyntaxException, SAXException,
        LoginAuthenticationExceptionException, XMLStreamException, LogoutAuthenticationExceptionException,
        AndesAdminServiceBrokerManagerAdminException, AndesEventAdminServiceEventAdminException, AutomationUtilException {

    String destinationName = "topictenant1.com/durableTenantTopic";

    int sendMessageCount = 200;
    int expectedMessageCount = 200;

    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration adminConsumerConfig =
            new AndesJMSConsumerClientConfiguration(getAMQPPort(), "admin!topictenant1.com", "admin",
                    ExchangeType.TOPIC, destinationName);
    adminConsumerConfig.setUnSubscribeAfterEachMessageCount(expectedMessageCount);
    adminConsumerConfig.setPrintsPerMessageCount(expectedMessageCount / 10L);
    adminConsumerConfig.setDurable(true, "topictenant1.com/multitenant1");
    adminConsumerConfig.setAsync(false);

    // Creating clients
    AndesClient adminConsumerClient = new AndesClient(adminConsumerConfig, true);
    adminConsumerClient.startClient();


    // Add permission to the created role to be able to publish/subscribe
    TopicRolePermission topicRolePermission = new TopicRolePermission();
    topicRolePermission.setRoleName(PUBLISHER_ROLE);
    topicRolePermission.setAllowedToSubscribe(true);
    topicRolePermission.setAllowedToPublish(true);

    // Get the automation context for the tenant
    AutomationContext tenantContext = new AutomationContext("MB", "mb001", "topictenant1", "topictenantuser1");


    LoginLogoutClient loginLogoutClient = new LoginLogoutClient(tenantContext);
    String sessionCookie = loginLogoutClient.login();

    TopicAdminClient topicAdminClient =
            new TopicAdminClient(super.backendURL, sessionCookie);

    // Update permissions for the destination queue to be able to publish/subscribe from topictenantuser1
    topicAdminClient.updatePermissionForTopic(destinationName, topicRolePermission);
    loginLogoutClient.logout();

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration tenantPublisherConfig =
            new AndesJMSPublisherClientConfiguration(getAMQPPort(), "topictenantuser1!topictenant1.com",
                 "topictenantuser1", ExchangeType.TOPIC, destinationName);
    tenantPublisherConfig.setNumberOfMessagesToSend(sendMessageCount);
    tenantPublisherConfig.setPrintsPerMessageCount(sendMessageCount / 10L);

    AndesClient tenantPublisherClient = new AndesClient(tenantPublisherConfig, true);
    tenantPublisherClient.startClient();

    AndesClientUtils
            .waitForMessagesAndShutdown(adminConsumerClient, AndesClientConstants.DEFAULT_RUN_TIME);

    // Evaluating
    Assert.assertEquals(tenantPublisherClient
                                .getSentMessageCount(), sendMessageCount, "Sending failed for " +
                                                          "topictenantuser1!topictenant1.com.");
    Assert.assertEquals(adminConsumerClient
                                .getReceivedMessageCount(), expectedMessageCount, "Message " +
                                              "receiving failed for admin!topictenant1.com.");
}
 
Example 15
Source File: DtxStartPositiveTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Tests if publishing messages works correctly with session joining. Steps are,
 * 1. Create two distributed transaction sessions and join one session to other.
 * 2. Publish messages using two sessions.
 * 3. Subscribe to the published queue and see if any message is received.
 * 4. Commit the session
 * 5. Subscribe to the queue and see if two messages are received
 */
@Test(groups = { "wso2.mb", "dtx" })
public void xaMultiSessionPublishTestCase()
        throws NamingException, JMSException, XAException, XPathExpressionException {
    String queueName = "DtxStartPositiveTestCaseXaMultiSessionPublishTestCase";

    InitialContext initialContext = JMSClientHelper.createInitialContextBuilder("admin", "admin", "localhost",
                                                                                getAMQPPort()).withQueue(queueName).build();

    XAConnectionFactory xaConnectionFactory = (XAConnectionFactory) initialContext
            .lookup(JMSClientHelper.QUEUE_XA_CONNECTION_FACTORY);

    // Create XA resource one
    XAConnection xaConnectionOne = xaConnectionFactory.createXAConnection();
    xaConnectionOne.start();
    XASession xaSessionOne = xaConnectionOne.createXASession();

    XAResource xaResourceOne = xaSessionOne.getXAResource();
    Session sessionOne = xaSessionOne.getSession();

    Destination xaTestQueue = (Destination) initialContext.lookup(queueName);
    sessionOne.createQueue(queueName);
    MessageProducer producerOne = sessionOne.createProducer(xaTestQueue);

    // Create XA resource two
    XASession xaSessionTwo = xaConnectionOne.createXASession();

    XAResource xaResourceTwo = xaSessionTwo.getXAResource();
    Session sessionTwo = xaSessionTwo.getSession();

    MessageProducer producerTwo = sessionTwo.createProducer(xaTestQueue);

    Xid xid = JMSClientHelper.getNewXid();

    boolean sameRM = xaResourceOne.isSameRM(xaResourceTwo);

    Assert.assertEquals(sameRM, true, "Resource one and resource two are connected to different resource "
            + "managers");

    xaResourceOne.start(xid, XAResource.TMNOFLAGS);
    xaResourceTwo.start(xid, XAResource.TMJOIN);

    producerOne.send(sessionOne.createTextMessage("Test 1"));
    producerTwo.send(sessionTwo.createTextMessage("Test 2"));

    xaResourceOne.end(xid, XAResource.TMSUCCESS);

    // subscribe and see if the message is received
    ConnectionFactory nonXaConnectionFactory = (ConnectionFactory) initialContext
            .lookup(JMSClientHelper.QUEUE_CONNECTION_FACTORY);
    Connection nonXaQueueConnection = nonXaConnectionFactory.createConnection();
    nonXaQueueConnection.start();
    Session nonXaQueueSession = nonXaQueueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer messageConsumer = nonXaQueueSession.createConsumer(xaTestQueue);

    // wait 5 seconds
    Message receive = messageConsumer.receive(5000);
    Assert.assertNull(receive, "Message received before committing");

    xaResourceOne.prepare(xid);
    xaResourceOne.commit(xid, false);

    xaConnectionOne.close();

    //This is only added to find out the reason for the intermittent failure of this test method. Should be removed
    // once the issue is identified.
    try {
        // Logging in
        LoginLogoutClient loginLogoutClientForAdmin = new LoginLogoutClient(super.automationContext);
        String sessionCookie = loginLogoutClientForAdmin.login();
        AndesAdminClient admin = new AndesAdminClient(super.backendURL, sessionCookie);

        //Check message count in queue
        org.wso2.carbon.andes.stub.admin.types.Message[] queueOneMessages
                = admin.browseQueue(queueName, 0, 10);
        Assert.assertEquals(queueOneMessages.length, 2, "Message not published to queue " + queueName);

        //Logging out
        loginLogoutClientForAdmin.logout();

    } catch (RemoteException | AutomationUtilException | AndesAdminServiceBrokerManagerAdminException
            | LogoutAuthenticationExceptionException e) {
        e.printStackTrace();
    }

    receive = messageConsumer.receive(5000);
    Assert.assertNotNull(receive, "Message not received");

    receive = messageConsumer.receive(5000);
    Assert.assertNotNull(receive, "Message not received");

    nonXaQueueConnection.close();
}
 
Example 16
Source File: AMQPSessionRecoverTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Send 40 messages to a queue. Consume message and call session.recover per each message received. All messages
 * should be received. No message should land in DLC (as application see it only once). No more messages should be
 * received. After the test message count in queue should be zero.
 *
 * @throws AndesClientConfigurationException on invalid configs passed for client config
 * @throws JMSException on an issue running underlying JMS clients
 * @throws NamingException on lookup JNDI objects
 * @throws IOException on reading config files
 * @throws AndesClientException on running Andes client wrapping up JMS clients
 * @throws AndesAdminServiceBrokerManagerAdminException on ian issue calling admin services
 * @throws AutomationUtilException on an issue performing utils on automation framework
 * @throws LogoutAuthenticationExceptionException on an issue creating managed session with broker
 * @throws XPathExpressionException on an issue reading config elements
 * @throws LoginAuthenticationExceptionException on an issue log into broker
 */
@Test(groups = "wso2.mb", description = "Let session recover call after every message is consumed")
public void performSessionRecoverWithAckTestCase()
        throws AndesClientConfigurationException, JMSException, NamingException, IOException,
        AndesClientException, AndesAdminServiceBrokerManagerAdminException, AutomationUtilException,
        LogoutAuthenticationExceptionException, XPathExpressionException,
        LoginAuthenticationExceptionException {

    //Setting values for the sent and received message counts
    long sendToRecoverQueueCount = 40L;
    long expectedMessageCount = 40;

    // Logging in
    LoginLogoutClient loginLogoutClientForAdmin = new LoginLogoutClient(super.automationContext);
    String sessionCookie = loginLogoutClientForAdmin.login();

    // Creating a consumer client configuration. Recover session after each message read. Apply a delay between
    // each read.
    AndesJMSConsumerClientConfiguration consumerConfig1 = new AndesJMSConsumerClientConfiguration(getAMQPPort(),
            ExchangeType.QUEUE, TEST_SESSION_RECOVER_WITH_ACK);
    consumerConfig1.setAcknowledgeMode(JMSAcknowledgeMode.AUTO_ACKNOWLEDGE);
    consumerConfig1.setMaximumMessagesToReceived(expectedMessageCount);
    consumerConfig1.setRecoverAfterEachMessageCount(1);
    consumerConfig1.setPrintsPerMessageCount(expectedMessageCount / 5L);
    consumerConfig1.setAsync(false);

    //Creating a consumer with above config
    AndesClient consumerClient1 = new AndesClient(consumerConfig1, true);
    consumerClient1.startClient();

    // Creating publisher configuration with destination queue = 'recoverTestQueueWithAck' and message count = 40
    AndesJMSPublisherClientConfiguration publisherConfig1 = new AndesJMSPublisherClientConfiguration(getAMQPPort(),
            ExchangeType.QUEUE, TEST_SESSION_RECOVER_WITH_ACK);
    publisherConfig1.setNumberOfMessagesToSend(sendToRecoverQueueCount);
    publisherConfig1.setPrintsPerMessageCount(sendToRecoverQueueCount / 5L);

    //Creating publishers
    AndesClient publisherClient1 = new AndesClient(publisherConfig1, true);
    publisherClient1.startClient();

    //Receiving messages until message count gets stagnant and
    //Once done, stop client
    AndesClientUtils.waitForMessagesAndShutdown(consumerClient1, AndesClientConstants.DEFAULT_RUN_TIME);

    Assert.assertEquals(consumerClient1.getReceivedMessageCount(), expectedMessageCount,
            "Failed to receive expected message count " + expectedMessageCount
                    + ". Received " + consumerClient1.getReceivedMessageCount());

    //Creating admin client
    AndesAdminClient admin = new AndesAdminClient(super.backendURL, sessionCookie);

    //testing if DLC queue is created
    Assert.assertNotNull(admin.getDlcQueue(), "DLC queue not created");

    //Testing if no messages are moved to DLC
    Message[] messagesInDLC = admin.browseQueue(DLCQueueUtils.identifyTenantInformationAndGenerateDLCString
            (TEST_SESSION_RECOVER_WITH_ACK), 0, 200);
    Assert.assertNull(messagesInDLC, "Messages have been moved to DLC.");

    //make sure no more messages are received
    consumerConfig1.setRecoverAfterEachMessageCount(Long.MAX_VALUE);
    consumerConfig1.setRunningDelay(0);
    AndesClient consumerClient2 = new AndesClient(consumerConfig1, true);
    consumerClient2.startClient();

    AndesClientUtils.waitForMessagesAndShutdown(consumerClient2, AndesClientConstants.DEFAULT_RUN_TIME);

    Assert.assertEquals(consumerClient2.getReceivedMessageCount(), 0,
            "Received more messages than expected message count " + expectedMessageCount
                    + ". Received " + (expectedMessageCount + consumerClient2.getReceivedMessageCount()));

    //make sure message count is 0
    long remainingMessageCount = admin.getQueueByName(TEST_SESSION_RECOVER_WITH_ACK).getMessageCount();
    Assert.assertEquals(remainingMessageCount, 0, "Remaining Message count is not zero");


    //Purging 'purgeTestQueue' queue
    admin.purgeQueue(TEST_SESSION_RECOVER_WITH_ACK);

    //Put a thread sleep so that we can make sure that the queue is deleted before testing its existence
    AndesClientUtils.sleepForInterval(1000);

    //Logging out
    loginLogoutClientForAdmin.logout();
}