类org.testng.annotations.Parameters源码实例Demo

下面列出了怎么用org.testng.annotations.Parameters的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: presto   文件: TestHiveAlluxioMetastore.java
@Parameters({
        "hive.hadoop2.alluxio.host",
        "hive.hadoop2.alluxio.port",
        "hive.hadoop2.hiveVersionMajor",
        "hive.hadoop2.timeZone",
})
@BeforeClass
public void setup(String host, String port, int hiveVersionMajor, String timeZone)
{
    checkArgument(hiveVersionMajor > 0, "Invalid hiveVersionMajor: %s", hiveVersionMajor);

    this.alluxioAddress = host + ":" + port;
    this.hiveVersionMajor = hiveVersionMajor;

    System.setProperty(PropertyKey.Name.SECURITY_LOGIN_USERNAME, "presto");
    System.setProperty(PropertyKey.Name.MASTER_HOSTNAME, host);
    HiveConfig hiveConfig = new HiveConfig();
    hiveConfig.setTimeZone(timeZone);

    AlluxioHiveMetastoreConfig alluxioConfig = new AlluxioHiveMetastoreConfig();
    alluxioConfig.setMasterAddress(this.alluxioAddress);
    TableMasterClient client = AlluxioMetastoreModule.createCatalogMasterClient(alluxioConfig);
    hdfsEnvironment = new HdfsEnvironment(createTestHdfsConfiguration(), new HdfsConfig(), new NoHdfsAuthentication());
    setup(SCHEMA, hiveConfig, new AlluxioHiveMetastore(client), hdfsEnvironment);
}
 
源代码2 项目: presto   文件: TestHiveFileSystemAbfs.java
@Parameters({
        "hive.hadoop2.metastoreHost",
        "hive.hadoop2.metastorePort",
        "hive.hadoop2.databaseName",
        "hive.hadoop2.wasb-container",
        "hive.hadoop2.wasb-account",
        "hive.hadoop2.wasb-access-key"
})
@BeforeClass
public void setup(String host, int port, String databaseName, String container, String account, String accessKey)
{
    checkArgument(!isNullOrEmpty(host), "expected non empty host");
    checkArgument(!isNullOrEmpty(databaseName), "Expected non empty databaseName");
    checkArgument(!isNullOrEmpty(container), "expected non empty container");
    checkArgument(!isNullOrEmpty(account), "expected non empty account");
    checkArgument(!isNullOrEmpty(accessKey), "expected non empty accessKey");

    this.container = container;
    this.account = account;
    this.accessKey = accessKey;

    super.setup(host, port, databaseName, false, createHdfsConfiguration());
}
 
@Parameters({"admin-username", "admin-password", "test-username", "test-password", "user1-username"})
@Test(priority = 2,
        description = "grant permission to test user and test user grant permission to user1")
public void testGrantPermissionExchangesByTestUser(String adminUsername, String adminPassword, String testUsername,
                                                   String testPassword, String user1Username) throws IOException {
    String exchangeName = "DacExchange";
    addUserGroupToExchange("grantPermission", exchangeName, testUsername, adminUsername, adminPassword);

    UserGroupList userGroupList = new UserGroupList();
    userGroupList.getUserGroups().add(user1Username);

    HttpPost httpPost = new HttpPost(apiBasePath + ExchangesApiDelegate.EXCHANGES_API_PATH
            + "/" + exchangeName + "/permissions/actions/publish/groups");
    ClientHelper.setAuthHeader(httpPost, testUsername, testPassword);
    String value = objectMapper.writeValueAsString(userGroupList);
    StringEntity stringEntity = new StringEntity(value, ContentType.APPLICATION_JSON);
    httpPost.setEntity(stringEntity);

    CloseableHttpResponse response = client.execute(httpPost);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK,
            "Incorrect status code.");
}
 
@Parameters({"admin-username", "admin-password", "test-username", "test-password", "broker-hostname",
             "broker-port"})
@Test
public void testCloseConnectionWithUnAuthorizedUSer(String adminUserName, String adminPassword, String
        testUsername, String testPassword, String hostName, String port) throws Exception {

    connections.add(createConnection(2, adminUserName, adminPassword, hostName, port));
    ConnectionMetadata[] connectionMetadataBeforeClosing = getConnections(adminUserName, adminPassword);
    Assert.assertEquals(connectionMetadataBeforeClosing.length, 1,
                        "Incorrect connection count before closing connection.");

    //Send delete request with invalid connection identifier
    HttpDelete httpDelete = new HttpDelete(apiBasePath + CONNECTIONS_API_PATH + "/"
                                           + connectionMetadataBeforeClosing[0].getId());
    ClientHelper.setAuthHeader(httpDelete, testUsername, testPassword);
    CloseableHttpResponse connectionCloseResponse = client.execute(httpDelete);
    Assert.assertEquals(connectionCloseResponse.getStatusLine().getStatusCode(), HttpStatus.SC_FORBIDDEN,
                        "Incorrect status code while closing connections");
}
 
@Parameters({"admin-username", "admin-password", "test-username", "test-password", "broker-hostname",
        "broker-port"})
@Test
public void testCloseChannelWithUnAuthorizedUSer(String adminUserName, String adminPassword,
                                                 String testUsername, String testPassword, String hostName,
                                                 String port) throws Exception {

    connections.add(createConnection(2, adminUserName, adminPassword, hostName, port));
    ConnectionMetadata[] connectionMetadataBeforeClosing = getConnections(adminUserName, adminPassword);

    //Send delete request with invalid connection identifier
    HttpDelete httpDelete = new HttpDelete(apiBasePath + CONNECTIONS_API_PATH + "/"
                                           + connectionMetadataBeforeClosing[0].getId() + "/channels/1");
    ClientHelper.setAuthHeader(httpDelete, testUsername, testPassword);
    CloseableHttpResponse connectionCloseResponse = client.execute(httpDelete);
    Assert.assertEquals(connectionCloseResponse.getStatusLine().getStatusCode(), HttpStatus.SC_FORBIDDEN,
                        "Incorrect status code while closing channels with unauthorized user");
}
 
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testCloseChannelsIfUsedFalse(String username, String password, String hostName, String port) throws
        Exception {

    int channelCount = 3;
    connections.add(createConnection(channelCount, username, password, hostName, port));

    ConnectionMetadata[] connectionMetadataBeforeClosing = getConnections(username, password);
    Assert.assertEquals(connectionMetadataBeforeClosing.length, 1,
                        "Incorrect connection count before closing channel.");
    Assert.assertEquals(connectionMetadataBeforeClosing[0].getChannelCount().intValue(), channelCount,
                        "Incorrect channel count before closing channel.");

    //Send delete request
    HttpDelete httpDelete = new HttpDelete(apiBasePath + CONNECTIONS_API_PATH + "/"
                                           + connectionMetadataBeforeClosing[0].getId() + "/" + "channels" + "/2");
    ClientHelper.setAuthHeader(httpDelete, username, password);
    CloseableHttpResponse channelCloseResponse = client.execute(httpDelete);
    Assert.assertEquals(channelCloseResponse.getStatusLine().getStatusCode(), HttpStatus.SC_BAD_REQUEST,
                        "Incorrect status code while closing connections");
}
 
源代码7 项目: ballerina-message-broker   文件: QueueCmdTest.java
@Test(groups = "StreamReading", description = "test command 'transfer queue'")
@Parameters({ "test-username"})
public void testChangeOwnerQueue(String testUser) {
    String queueName = "testChangeOwnerQueue";
    String[] createCmd = { CLI_ROOT_COMMAND, Constants.CMD_CREATE, Constants.CMD_QUEUE, queueName, "-d" };

    String[] changeOwnerCmd = { CLI_ROOT_COMMAND, Constants.CMD_TRANSFER, Constants.CMD_QUEUE, queueName, "-n",
                          testUser };

    String[] checkCmd = { CLI_ROOT_COMMAND, Constants.CMD_LIST, Constants.CMD_QUEUE, queueName };

    Main.main(createCmd);
    Main.main(changeOwnerCmd);
    Main.main(checkCmd);

    evalStreamContent(PrintStreamHandler.readOutStream(), "owner         : " + testUser, changeOwnerCmd);
}
 
@CitrusTest
@Test @Parameters("context")
public void runOutboundProfileValidation(@Optional @CitrusResource TestContext context) throws IOException, AppException {
	swaggerImport = new ImportTestAction();
	description("Make sure only valid profile names are referenced");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/invalid-authn-profile-api-${apiNumber}");
	variable("apiName", "Invalid AuthN-Profile-API-${apiNumber}");
	
	echo("####### Try to replicate an API having invalid profiles referenced #######");		
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/basic/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/methodLevel/method-level-outboundbound-invalidProfileReference.json");
	createVariable("state", "unpublished");
	createVariable("expectedReturnCode", "73");
	createVariable("authenticationProfileName1", "HTTP Basic");
	createVariable("authenticationProfileName2", "SomethingWrong");
	swaggerImport.doExecute(context);
}
 
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
	swaggerImport = new ImportTestAction();
	description("Make sure, the error that an invalid operationId is given is properly handled.");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/basic-method-level-api-${apiNumber}");
	variable("apiName", "Basic Method-Level-API-${apiNumber}");
	
	echo("####### Try to replicate an API having Method-Level settings declared #######");		
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/basic/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/methodLevel/method-level-inbound-invalidOperation.json");
	createVariable("state", "unpublished");
	createVariable("expectedReturnCode", "72");
	createVariable("securityProfileName", "APIKeyBased${apiNumber}");
	swaggerImport.doExecute(context);
}
 
@Parameters({"broker-hostname", "broker-rest-port", "admin-username", "admin-password",
        "test-username", "test-password", "user1-username"})
@BeforeClass
public void setUp(String brokerHost, String port, String adminUsername, String adminPassword,
                  String testUsername, String testPassword, String user1Username)
        throws Exception {
    this.adminUsername = adminUsername;
    this.adminPassword = adminPassword;
    this.testUsername = testUsername;
    this.testPassword = testPassword;
    this.user1Username = user1Username;
    apiBasePath = HttpClientHelper.getRestApiBasePath(brokerHost, port);
    objectMapper = new ObjectMapper();
    brokerRestApiClient = new BrokerRestApiClient(adminUsername, adminPassword, port, brokerHost);
    brokerRestApiClient.createExchange(exchangeName, exchangeType, true);
    brokerRestApiClient.createQueue(queueName, true, false);
}
 
@Parameters({"admin-username", "admin-password", "test-username", "test-password"})
@Test(priority = 2, description = "grant get permission to test user and retrieve queue details")
public void testGetQueuesByTestUser(String adminUsername, String adminPassword, String testUsername,
                                    String testPassword) throws IOException {
    String queueName = "AdminUserDacQueue";

    addUserGroupToQueue("get", queueName, testUsername, adminUsername, adminPassword);

    HttpGet httpGet = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH + "/" + queueName);
    ClientHelper.setAuthHeader(httpGet, testUsername, testPassword);
    CloseableHttpResponse response = client.execute(httpGet);

    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK, "Incorrect status code.");

    String body = EntityUtils.toString(response.getEntity());
    QueueMetadata queueMetadata = objectMapper.readValue(body, QueueMetadata.class);

    Assert.assertEquals(queueMetadata.getName(), queueName, "Incorrect queue name.");
    Assert.assertEquals(queueMetadata.getConsumerCount().intValue(), 0, "JMS consumer should be present.");
    Assert.assertTrue(queueMetadata.isDurable());
    Assert.assertEquals(queueMetadata.getSize().intValue(), 0, "Queue should be empty.");
    Assert.assertFalse(queueMetadata.isAutoDelete());
}
 
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
	swaggerImport = new ImportTestAction();
	description("Try to import an API with invalid quota configuration.");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/invalid-quota-api-${apiNumber}");
	variable("apiName", "Invalid Quota-API-${apiNumber}");

	echo("####### Trying to import API: '${apiName}' on path: '${apiPath}' with invalid quota config #######");		
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/basic/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/quota/issue-109-invalid-quota-config-1.json");
	createVariable("state", "unpublished");
	createVariable("expectedReturnCode", "71");
	swaggerImport.doExecute(context);
	
	echo("####### Trying to import API: '${apiName}' on path: '${apiPath}' with invalid quota config #######");		
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/basic/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/quota/issue-109-invalid-quota-config-2.json");
	createVariable("state", "unpublished");
	createVariable("expectedReturnCode", "71");
	swaggerImport.doExecute(context);
}
 
@Parameters({"admin-username", "admin-password"})
@Test
public void testUpdatingInvalidLogger(String username, String password) throws IOException {
    String loggerName = "fake.BrokerImpl";
    String loggerLevel = "WARN";
    LoggerMetadata loggerMetadata = new LoggerMetadata().name(loggerName).level(loggerLevel);

    HttpPut httpPut = new HttpPut(apiBasePath + LOGGERS_API_PATH);
    ClientHelper.setAuthHeader(httpPut, username, password);
    String value = objectMapper.writeValueAsString(loggerMetadata);
    StringEntity stringEntity = new StringEntity(value, ContentType.APPLICATION_JSON);
    httpPut.setEntity(stringEntity);

    CloseableHttpResponse response = client.execute(httpPut);

    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_NOT_FOUND, "Incorrect status code");

}
 
@Parameters({"admin-username", "admin-password"})
@Test(priority = 1, description = "create an exchange by a user who has exchanges:create scope")
public void testCreateExchangeByAdminUser(String username, String password) throws Exception {

    ExchangeCreateRequest request = new ExchangeCreateRequest()
            .name("adminUserExchange").durable(true).type("direct");

    HttpPost httpPost = new HttpPost(apiBasePath + "/exchanges");
    ClientHelper.setAuthHeader(httpPost, username, password);
    String value = objectMapper.writeValueAsString(request);
    StringEntity stringEntity = new StringEntity(value, ContentType.APPLICATION_JSON);
    httpPost.setEntity(stringEntity);

    CloseableHttpResponse response = client.execute(httpPost);

    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_CREATED);
    Assert.assertTrue(response.getFirstHeader(HttpHeaders.LOCATION)
                    .getValue().contains("/exchanges/" + "adminUserExchange"), "Incorrect location header");

}
 
源代码15 项目: netbeans   文件: CommandHttpTest.java
/**
 * Get Payara test server properties.
 * <p>
 * @return Payara test server properties.
 */
@BeforeSuite
@Parameters({ "http-properties" })
public static Properties payaraProperties(String propertyFile) {
    if (payaraProperties != null) {
        return payaraProperties;
    }
    else {
        synchronized(CommandHttpTest.class) {
            if (payaraProperties == null) {
                payaraProperties = readProperties(propertyFile);
            }
        }
        return payaraProperties;
    }
}
 
源代码16 项目: netbeans   文件: CommandHttpTest.java
/**
 * Get GlassFish test server properties.
 * <p>
 * @return GlassFish test server properties.
 */
@BeforeSuite
@Parameters({ "http-properties" })
public static Properties glassfishProperties(String propertyFile) {
    if (glassfishProperties != null) {
        return glassfishProperties;
    }
    else {
        synchronized(CommandHttpTest.class) {
            if (glassfishProperties == null) {
                glassfishProperties = readProperties(propertyFile);
            }
        }
        return glassfishProperties;
    }
}
 
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testCloseConnectionsIfUsedFalse(String username, String password, String hostName, String port) throws
        Exception {

    int connectionCount = 3;
    //Create 3 connections each having 0, 1 and 2 channels respectively
    for (int i = 0; i < connectionCount; i++) {
        connections.add(createConnection(i, username, password, hostName, port));
    }

    ConnectionMetadata[] connectionMetadataBeforeClosing = getConnections(username, password);
    Assert.assertEquals(connectionMetadataBeforeClosing.length, connectionCount,
                        "Incorrect connection count before closing connection.");

    //Send delete request
    HttpDelete httpDelete = new HttpDelete(apiBasePath + CONNECTIONS_API_PATH + "/"
                                           + connectionMetadataBeforeClosing[1].getId());
    ClientHelper.setAuthHeader(httpDelete, username, password);
    CloseableHttpResponse connectionCloseResponse = client.execute(httpDelete);
    Assert.assertEquals(connectionCloseResponse.getStatusLine().getStatusCode(), HttpStatus.SC_BAD_REQUEST,
                        "Incorrect status code while closing connections");
}
 
@Parameters({ "broker-port"})
@Test
public void testSubscriberPublisher(String port) throws Exception {
    String topicName = "MyTopic1";
    int numberOfMessages = 100;

    InitialContext initialContext = ClientHelper
            .getInitialContextBuilder("admin", "admin", "localhost", port)
            .withTopic(topicName)
            .build();

    TopicConnectionFactory connectionFactory
            = (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY);
    TopicConnection connection = connectionFactory.createTopicConnection();
    connection.start();

    // Initialize subscriber
    TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic subscriberDestination = (Topic) initialContext.lookup(topicName);
    TopicSubscriber subscriber = subscriberSession.createSubscriber(subscriberDestination);

    // publish 100 messages
    TopicSession producerSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicPublisher producer = producerSession.createPublisher(subscriberDestination);

    for (int i = 0; i < numberOfMessages; i++) {
        producer.publish(producerSession.createTextMessage("Test message " + i));
    }

    producerSession.close();

    for (int i = 0; i < numberOfMessages; i++) {
        Message message = subscriber.receive(1000);
        Assert.assertNotNull(message, "Message #" + i + " was not received");
    }

    connection.close();
}
 
源代码19 项目: ballerina-message-broker   文件: CloseCmdTest.java
@Parameters({"broker-hostname", "broker-rest-port"})
@BeforeClass
public void setUp(String brokerHost, String port) throws Exception {
    apiBasePath = HttpClientHelper.getRestApiBasePath(brokerHost, port);
    objectMapper = new ObjectMapper();
    connections = new ArrayList<>();
    client = HttpClientHelper.prepareClient();
}
 
源代码20 项目: presto   文件: TestHiveFileSystemS3.java
@Parameters({
        "hive.hadoop2.metastoreHost",
        "hive.hadoop2.metastorePort",
        "hive.hadoop2.databaseName",
        "hive.hadoop2.s3.awsAccessKey",
        "hive.hadoop2.s3.awsSecretKey",
        "hive.hadoop2.s3.writableBucket",
        "hive.hadoop2.s3.testDirectory",
})
@BeforeClass
public void setup(String host, int port, String databaseName, String awsAccessKey, String awsSecretKey, String writableBucket, String testDirectory)
{
    super.setup(host, port, databaseName, awsAccessKey, awsSecretKey, writableBucket, testDirectory, false);
}
 
@Parameters({"admin-username", "admin-password"})
@Test
public void testPurgeQueue(String username, String password) throws IOException {
    String queueName = "QueuesRestApiTestTestPurgeQueue";

    // Create a queue to delete.
    QueueCreateRequest request = new QueueCreateRequest()
            .name(queueName).durable(false).autoDelete(false);

    HttpPost httpPost = new HttpPost(apiBasePath + "/queues");
    ClientHelper.setAuthHeader(httpPost, username, password);

    String value = objectMapper.writeValueAsString(request);
    StringEntity stringEntity = new StringEntity(value, ContentType.APPLICATION_JSON);
    httpPost.setEntity(stringEntity);

    CloseableHttpResponse response = client.execute(httpPost);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_CREATED);

    // Delete the queue.
    HttpDelete httpDelete = new HttpDelete(
            apiBasePath + QueuesApiDelegate.QUEUES_API_PATH + "/" + queueName + "/messages");
    ClientHelper.setAuthHeader(httpDelete, username, password);
    response = client.execute(httpDelete);

    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK);
}
 
@Parameters({"admin-username", "admin-password", "test-username", "test-password"})
@Test(priority = 3, description = "grant delete permission to test user and delete an exchange")
public void testDeleteExchangesByTestUser(String adminUsername, String adminPassword, String testUsername,
                                          String testPassword) throws IOException {
    String exchangeName = "DacExchange";
    addUserGroupToExchange("delete", exchangeName, testUsername, adminUsername, adminPassword);

    HttpDelete httpDelete = new HttpDelete(apiBasePath + "/exchanges/" + exchangeName);
    ClientHelper.setAuthHeader(httpDelete, testUsername, testPassword);
    CloseableHttpResponse response = client.execute(httpDelete);

    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK);
}
 
@Parameters({ "broker-port", "broker-ssl-port", "broker-hostname", "admin-username", "admin-password" ,
              "broker-rest-port"})
@BeforeSuite
public void beforeSuite(String port, String sslPort, String hostname, String adminUsername, String adminPassword,
        String restPort, ITestContext context)
        throws Exception {
    ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
    LOGGER.info("Starting broker on " + port + " for suite " + context.getSuite().getName());
    StartupContext startupContext = TestUtils.initStartupContext(port, sslPort, hostname, restPort);

    BrokerConfigProvider configProvider = startupContext.getService(BrokerConfigProvider.class);
    BrokerAuthConfiguration brokerAuthConfiguration
            = configProvider.getConfigurationObject(BrokerAuthConfiguration.NAMESPACE,
                                                    BrokerAuthConfiguration.class);

    brokerAuthConfiguration.getAuthorization()
                           .setEnabled(true);
    brokerAuthConfiguration.getAuthorization()
                           .getDiscretionaryAccessController()
                           .setClassName(RdbmsDacHandler.class.getCanonicalName());
    brokerAuthConfiguration.getAuthorization()
                           .getMandatoryAccessController()
                           .setClassName(DefaultMacHandler.class.getCanonicalName());

    DbUtils.setupDB();
    DataSource dataSource = DbUtils.getDataSource();
    startupContext.registerService(DataSource.class, dataSource);

    AuthManager authManager = new AuthManager(startupContext);

    authManager.start();
    restServer = new BrokerRestServer(startupContext);
    broker = new BrokerImpl(startupContext);
    broker.startMessageDelivery();
    server = new Server(startupContext);
    server.start();
    restServer.start();
}
 
@Parameters({"broker-hostname", "broker-rest-port"})
@BeforeClass
public void setUp(String brokerHost, String port) throws Exception {
    apiBasePath = HttpClientHelper.getRestApiBasePath(brokerHost, port);
    objectMapper = new ObjectMapper();
    responseHandler = new BasicResponseHandler();
}
 
@Parameters({"admin-username", "admin-password", "test-username", "test-password", "broker-hostname",
             "broker-port"})
@Test
public void testGetChannelsForConnectionWithUnauthorizedUser(String adminUsername, String adminPassword,
                                                             String username, String password, String hostName,
                                                             String port) throws Exception {
    connections.add(createConnection(1, adminUsername, adminPassword, hostName, port));
    CloseableHttpResponse response = sendGetChannels(1, username, password);

    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_FORBIDDEN,
                        "Incorrect status code while retrieving connection");
}
 
@Parameters({"broker-hostname", "broker-port", "admin-username", "admin-password"})
@Test(priority = 2,
        description = "create and consume from a queue by a user who has queues:create and queues:consume scope")
public void testCreateAndConsumeByAdminUser(String brokerHostname,
                                                 String port,
                                                 String adminUsername,
                                                 String adminPassword) throws NamingException, JMSException {
    String queueName = "testCreateAndPublishScopeByAdminUser";

    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
            .withQueue(queueName)
            .build();

    ConnectionFactory connectionFactory
            = (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    Session subscriberSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
    MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);

    int numberOfMessages = 1;
    for (int i = 0; i < numberOfMessages; i++) {
        Message message = consumer.receive(5000);
        Assert.assertNotNull(message, "Message #" + i + " was not received");
    }
    subscriberSession.close();

    connection.close();
}
 
源代码27 项目: heat   文件: SingleMode.java
/**
 * Method that takes tests parameters and sets some environment properties.
 * @param inputJsonParamPath path of the json input file with input data for tests
 * @param enabledEnvironments environments enabled for the specific suite
 * @param context testNG context
 */
@BeforeTest
@Override
@Parameters({INPUT_JSON_PATH, ENABLED_ENVIRONMENTS})
public void beforeTestCase(String inputJsonParamPath,
                           String enabledEnvironments,
                           ITestContext context) {
    super.beforeTestCase(inputJsonParamPath, enabledEnvironments, context);
    this.webappName = TestSuiteHandler.getInstance().getWebappName();
    this.webappPath = TestSuiteHandler.getInstance().getEnvironmentHandler().getEnvironmentUrl(webappName);
}
 
@Parameters({"broker-hostname", "broker-rest-port", "admin-username", "admin-password"})
@BeforeMethod
public void setup(String brokerHostname,
                  String port,
                  String adminUsername,
                  String adminPassword) throws URISyntaxException, NoSuchAlgorithmException, KeyStoreException,
        KeyManagementException {
    client = HttpClientHelper.prepareClient();
    brokerRestApiClient = new BrokerRestApiClient(adminUsername, adminPassword, port, brokerHostname);
}
 
@Parameters({"broker-hostname", "broker-rest-port", "admin-username", "admin-password", "test-username"})
@BeforeClass
public void setUp(String brokerHost, String port, String userName, String password, String testUsername)
        throws Exception {
    this.userName = userName;
    this.password = password;
    this.testUsername = testUsername;
    this.port = port;
    this.brokerHost = brokerHost;
    apiBasePath = HttpClientHelper.getRestApiBasePath(brokerHost, port);
    objectMapper = new ObjectMapper();
}
 
源代码30 项目: heat   文件: SetupTestsListener.java
@Parameters("wmTests")
@Override
public void onFinish(ITestContext iTestContext) {
    if (isWiremockTest(iTestContext, "wmTests")) {
        logger.info("{} was a wiremock test.\n Wiremock server is stopping...", iTestContext.getCurrentXmlTest().getName());
        this.wmServer.stop();
        logger.info("... Wiremock server stopped");
    }
}