Java Code Examples for org.wso2.carbon.automation.engine.context.beans.User#getUserNameWithoutDomain()

The following examples show how to use org.wso2.carbon.automation.engine.context.beans.User#getUserNameWithoutDomain() . 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: TopicPermissionTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a topic by giving topic creation rights to the user.
 * 1. User is in a role with no permissions.
 * 2. Admin gives permissions to the role to create topics and for logging in.
 * 3. User creates a topic.
 * 4. Validates whether topic is created.
 *
 * @throws XPathExpressionException
 * @throws IOException
 * @throws UserAdminUserAdminException
 */
@Test(groups = {"wso2.mb", "topic"})
public void createTopicPermissionTestCase() throws XPathExpressionException, IOException, UserAdminUserAdminException {
    String topicName = "topicCreationPermission";

    AutomationContext authAutomationContext =
            new AutomationContext("MB", "mb001", FrameworkConstants.SUPER_TENANT_KEY,
                                                                                "topicAuthUser");
    User contextUser = authAutomationContext.getContextTenant().getContextUser();

    String[] createPermissionUser = new String[]{contextUser.getUserNameWithoutDomain()};

    // Logging into user management as admin
    UserManagementClient userManagementClient =
            new UserManagementClient(super.backendURL, "admin", "admin");

    // Removing admin permission for user
    userManagementClient.updateUserListOfRole(FrameworkConstants.ADMIN_ROLE, null, createPermissionUser);

    // Adding roles along with users
    userManagementClient
            .addRole(CREATE_TOPIC_PERMISSION_ROLE, createPermissionUser, new String[]{ADD_TOPIC_PERMISSION, LOGIN_PERMISSION});

    driver.get(getLoginURL());
    LoginPage loginPage = new LoginPage(driver);
    // Logging in to the the management console
    HomePage homePage = loginPage.loginAs(contextUser.getUserNameWithoutDomain(), contextUser.getPassword());

    TopicAddPage topicAddPage =
            homePage.getTopicAddPage("home.mb.topics.add.without.queue.xpath");

    // Creating a topic by the user and check whether valid dialog pop up is shown
    Assert.assertEquals(topicAddPage.addTopic(topicName), true);

    TopicsBrowsePage topicsBrowsePage = homePage.getTopicsBrowsePage("home.mb.topics.browse.without.queue.xpath");

    // Checks whether topic is created in the browsing page
    Assert.assertEquals(topicsBrowsePage.isTopicPresent(topicName), true);
}
 
Example 2
Source File: QueuePermissionTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a queue by giving queue creation rights to the user.
 * 1. User is in a role with no permissions.
 * 2. Admin gives permissions to the role to create queues and for logging in.
 * 3. User creates a queue.
 * 4. Validates whether queue is created.
 *
 * @throws IOException
 * @throws UserAdminUserAdminException
 * @throws XPathExpressionException
 */
@Test(groups = {"wso2.mb", "queue"})
public void createQueuePermissionTestCase() throws IOException, UserAdminUserAdminException,
        XPathExpressionException {
    String queueName = "queueCreationPermission";

    AutomationContext authAutomationContext =
            new AutomationContext("MB", "mb001", FrameworkConstants.SUPER_TENANT_KEY,
                                                                            "queueAuthUser");
    User contextUser = authAutomationContext.getContextTenant().getContextUser();

    String[] createPermissionUsers = new String[]{contextUser.getUserNameWithoutDomain()};

    // Logging into user management as admin
    UserManagementClient userManagementClient =
            new UserManagementClient(backendURL, "admin", "admin");

    // Removing admin permission for user
    userManagementClient
            .updateUserListOfRole(FrameworkConstants.ADMIN_ROLE, null, createPermissionUsers);

    // Adding roles along with user
    userManagementClient.addRole(CREATE_QUEUE_PERMISSION_ROLE, createPermissionUsers,
                                                            new String[]{ADD_QUEUE_PERMISSION, LOGIN_PERMISSION});

    driver.get(getLoginURL());
    LoginPage loginPage = new LoginPage(driver);

    // Logging in to the the management console
    HomePage homePage = loginPage.loginAs(contextUser.getUserNameWithoutDomain(), contextUser.getPassword());

    QueueAddPage queueAddPage = homePage.getQueueAddPage();

    // Creating a queue by the user and check whether valid dialog pop up is shown
    Assert.assertEquals(queueAddPage.addQueue(queueName), true);
    QueuesBrowsePage queuesBrowsePage = homePage.getQueuesBrowsePage();

    // Checks whether queue is created in the browsing page
    Assert.assertEquals(queuesBrowsePage.isQueuePresent(queueName), true);

}
 
Example 3
Source File: TopicUserAuthorizationTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Runs a test case where a consumer and publisher is created and published with a given user
 * key from the automation.xml.
 *
 * @param userKey         The user key mentioned in the automation.xml for a specific user.
 * @param destinationName The destination name of the topic.
 * @throws XPathExpressionException
 * @throws org.wso2.mb.integration.common.clients.exceptions.AndesClientConfigurationException
 * @throws IOException
 * @throws javax.jms.JMSException
 * @throws org.wso2.mb.integration.common.clients.exceptions.AndesClientException
 * @throws javax.naming.NamingException
 */
private void createPublishAndSubscribeFromUser(String userKey, String destinationName)
        throws XPathExpressionException, AndesClientConfigurationException, IOException,
               JMSException, AndesClientException, NamingException {
    long sendCount = 10L;
    long expectedCount = 10L;

    AutomationContext userAutomationContext =
            new AutomationContext("MB", "mb001", FrameworkConstants.SUPER_TENANT_KEY, userKey);
    User contextUser = userAutomationContext.getContextTenant().getContextUser();

    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration
            consumerConfig =
            new AndesJMSConsumerClientConfiguration( getAMQPPort(),
                            contextUser.getUserNameWithoutDomain(), contextUser.getPassword(),
                            ExchangeType.TOPIC, destinationName);
    consumerConfig.setMaximumMessagesToReceived(expectedCount);
    consumerConfig.setAsync(false);

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration publisherConfig =
            new AndesJMSPublisherClientConfiguration( getAMQPPort(),
                    contextUser.getUserNameWithoutDomain(), contextUser.getPassword(),
                    ExchangeType.TOPIC, destinationName);
    publisherConfig.setNumberOfMessagesToSend(sendCount);

    // Creating clients
    AndesClient consumerClient = new AndesClient(consumerConfig, true);
    consumerClient.startClient();

    AndesClient publisherClient = new AndesClient(publisherConfig, true);
    publisherClient.startClient();

    AndesClientUtils
            .waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME);

    // Evaluating
    Assert.assertEquals(publisherClient.getSentMessageCount(), sendCount, "Message sending " +
                                  "failed for user : " + contextUser.getUserNameWithoutDomain());
    Assert.assertEquals(consumerClient.getReceivedMessageCount(), expectedCount, "Message " +
                        "receiving failed for user : " + contextUser.getUserNameWithoutDomain());
}
 
Example 4
Source File: TopicUserAuthorizationTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Runs a test case where a consumer and publisher is created and published with a given user
 * key from the automation.xml. Subscriber get unsubscribe after receiving expected message count.
 *
 * @param userKey         The user key mentioned in the automation.xml for a specific user.
 * @param destinationName The destination name of the topic.
 * @throws XPathExpressionException
 * @throws org.wso2.mb.integration.common.clients.exceptions.AndesClientConfigurationException
 * @throws IOException
 * @throws javax.jms.JMSException
 * @throws org.wso2.mb.integration.common.clients.exceptions.AndesClientException
 * @throws javax.naming.NamingException
 */
private void createPublishSubscribeAndUnsubscribeFromUser(String userKey, String destinationName)
        throws XPathExpressionException, AndesClientConfigurationException, IOException,
        JMSException, AndesClientException, NamingException {
    long sendCount = 10L;
    long expectedCount = 10L;

    AutomationContext userAutomationContext =
            new AutomationContext("MB", "mb001", FrameworkConstants.SUPER_TENANT_KEY, userKey);
    User contextUser = userAutomationContext.getContextTenant().getContextUser();

    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration
            consumerConfig =
            new AndesJMSConsumerClientConfiguration( getAMQPPort(),
                    contextUser.getUserNameWithoutDomain(), contextUser.getPassword(),
                    ExchangeType.TOPIC, destinationName);
    consumerConfig.setMaximumMessagesToReceived(expectedCount);
    consumerConfig.setUnSubscribeAfterEachMessageCount(expectedCount);
    consumerConfig.setAsync(false);

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration publisherConfig =
            new AndesJMSPublisherClientConfiguration( getAMQPPort(),
                    contextUser.getUserNameWithoutDomain(), contextUser.getPassword(),
                    ExchangeType.TOPIC, destinationName);
    publisherConfig.setNumberOfMessagesToSend(sendCount);

    // Creating clients
    AndesClient consumerClient = new AndesClient(consumerConfig, true);
    consumerClient.startClient();

    AndesClient publisherClient = new AndesClient(publisherConfig, true);
    publisherClient.startClient();

    AndesClientUtils
            .waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME);

    // Evaluating
    Assert.assertEquals(publisherClient.getSentMessageCount(), sendCount, "Message sending " +
            "failed for user : " + contextUser.getUserNameWithoutDomain());
    Assert.assertEquals(consumerClient.getReceivedMessageCount(), expectedCount, "Message " +
            "receiving failed for user : " + contextUser.getUserNameWithoutDomain());
}
 
Example 5
Source File: SubTopicUserAuthorizationTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Runs a test case where a consumer and publisher is created and published with a given user
 * key from the automation.xml.
 *
 * @param topicConsumeUser user defined in automation.xml for consume from a topic.
 * @param topicPublishUser user defined in automation.xml for publish to a topic.
 * @param destinationName topic destination.
 * @throws XPathExpressionException
 * @throws AndesClientConfigurationException
 * @throws IOException
 * @throws JMSException
 * @throws AndesClientException
 * @throws NamingException
 */
private void createPublishAndSubscribeFromUsers(String topicConsumeUser, String topicPublishUser,
                                                String destinationName)
        throws XPathExpressionException, AndesClientConfigurationException, IOException,
        JMSException, AndesClientException, NamingException {

    long sendCount = 100L;
    long expectedCount = 100L;

    // get context for topic consume user
    AutomationContext topicConsumeUserAutomationContext =
            new AutomationContext("MB", "mb001", FrameworkConstants.SUPER_TENANT_KEY, topicConsumeUser);
    User consumeUser = topicConsumeUserAutomationContext.getContextTenant().getContextUser();

    // get context for topic publisher user
    AutomationContext topicPublishUserAutomationContext =
            new AutomationContext("MB", "mb001", FrameworkConstants.SUPER_TENANT_KEY, topicPublishUser);
    User publishUser = topicPublishUserAutomationContext.getContextTenant().getContextUser();


    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration
            consumerConfig =
            new AndesJMSConsumerClientConfiguration( getAMQPPort(),
                    consumeUser.getUserNameWithoutDomain(), consumeUser.getPassword(),
                    ExchangeType.TOPIC, destinationName);
    consumerConfig.setMaximumMessagesToReceived(expectedCount);
    consumerConfig.setAsync(false);

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration publisherConfig =
            new AndesJMSPublisherClientConfiguration( getAMQPPort(),
                    publishUser.getUserNameWithoutDomain(), publishUser.getPassword(),
                    ExchangeType.TOPIC, destinationName);
    publisherConfig.setNumberOfMessagesToSend(sendCount);

    // Creating clients
    AndesClient consumerClient = new AndesClient(consumerConfig, true);
    consumerClient.startClient();

    AndesClient publisherClient = new AndesClient(publisherConfig, true);
    publisherClient.startClient();

    AndesClientUtils
            .waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME);

        // Evaluating
        Assert.assertEquals(publisherClient.getSentMessageCount(), sendCount, "Message sending " +
                "failed for user : " + consumeUser.getUserNameWithoutDomain());
        Assert.assertEquals(consumerClient.getReceivedMessageCount(), expectedCount, "Message " +
                "receiving failed for user : " + publishUser.getUserNameWithoutDomain());
}
 
Example 6
Source File: QueueUserAuthorizationTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * Runs a test case where a consumer and publisher is created and published with a given user
 * key from the automation.xml.
 *
 * @param userKey         The user key mentioned in the automation.xml for a specific user.
 * @param destinationName The destination name of the queue.
 * @throws XPathExpressionException
 * @throws AndesClientConfigurationException
 * @throws IOException
 * @throws JMSException
 * @throws AndesClientException
 * @throws NamingException
 */
private void createPublishAndSubscribeFromUser(String userKey, String destinationName)
        throws XPathExpressionException, AndesClientConfigurationException, IOException,
               JMSException, AndesClientException, NamingException {
    long sendCount = 10L;
    long expectedCount = 10L;

    AutomationContext userAutomationContext =
            new AutomationContext("MB", "mb001", FrameworkConstants.SUPER_TENANT_KEY, userKey);
    User contextUser = userAutomationContext.getContextTenant().getContextUser();

    // Creating a consumer client configuration
    AndesJMSConsumerClientConfiguration
            consumerConfig =
            new AndesJMSConsumerClientConfiguration(getAMQPPort(),
                    contextUser.getUserNameWithoutDomain(), contextUser.getPassword(),
                    ExchangeType.QUEUE, destinationName);
    consumerConfig.setMaximumMessagesToReceived(expectedCount);
    consumerConfig.setAsync(false);

    // Creating a publisher client configuration
    AndesJMSPublisherClientConfiguration publisherConfig =
            new AndesJMSPublisherClientConfiguration(getAMQPPort(),
                    contextUser.getUserNameWithoutDomain(), contextUser.getPassword(),
                    ExchangeType.QUEUE, destinationName);
    publisherConfig.setNumberOfMessagesToSend(sendCount);

    // Creating clients
    AndesClient consumerClient = new AndesClient(consumerConfig, true);
    consumerClient.startClient();

    AndesClient publisherClient = new AndesClient(publisherConfig, true);
    publisherClient.startClient();

    AndesClientUtils
            .waitForMessagesAndShutdown(consumerClient, AndesClientConstants.DEFAULT_RUN_TIME);

    // Evaluating
    Assert.assertEquals(publisherClient.getSentMessageCount(), sendCount, "Message sending " +
                                "failed for user : " + contextUser.getUserNameWithoutDomain());
    Assert.assertEquals(consumerClient.getReceivedMessageCount(), expectedCount, "Message " +
                         "receiving failed for user : " + contextUser.getUserNameWithoutDomain());
}