org.testng.annotations.Parameters Java Examples

The following examples show how to use org.testng.annotations.Parameters. 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: ConnectionsRestApiTest.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #2
Source File: TestHiveFileSystemAbfs.java    From presto with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #3
Source File: RdbmsDiscretionaryAccessControlForExchangesTest.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
@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.");
}
 
Example #4
Source File: TestHiveAlluxioMetastore.java    From presto with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: ConnectionsRestApiTest.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #6
Source File: InboundMethodLevelInvalidOperationTestIT.java    From apimanager-swagger-promote with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #7
Source File: ConnectionsRestApiTest.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #8
Source File: ConnectionsRestApiTest.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #9
Source File: QueueCmdTest.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #10
Source File: MethodLevelInvalidProfileTestIT.java    From apimanager-swagger-promote with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #11
Source File: RdbmsMandatoryAccessControlGrantTest.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #12
Source File: RdbmsDiscretionaryAccessControlForQueuesTest.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #13
Source File: InvalidQuotaConfigTestIT.java    From apimanager-swagger-promote with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #14
Source File: LoggersRestApiTest.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
@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");

}
 
Example #15
Source File: RdbmsMandatoryAccessControlForExchangesTest.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
@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");

}
 
Example #16
Source File: CommandHttpTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example #17
Source File: CommandHttpTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example #18
Source File: TestHiveFileSystemS3.java    From presto with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #19
Source File: CloseCmdTest.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #20
Source File: NoChangeAPITestIT.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
	swaggerImport = new ImportTestAction();
	description("Import an API and re-import it without any change. It must be detected, that no change happened.");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/my-no-change-${apiNumber}");
	variable("apiName", "No-Change-${apiNumber}");

	echo("####### Importing API: '${apiName}' on path: '${apiPath}' for the first time #######");
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/basic/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/basic/1_no-change-config.json");
	createVariable("expectedReturnCode", "0");
	swaggerImport.doExecute(context);

	echo("####### Validate API: '${apiName}' on path: '${apiPath}' has been imported #######");
	http(builder -> builder.client("apiManager").send().get("/proxies").header("Content-Type", "application/json"));

	http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId"));

	echo("####### RE-Importing same API: '${apiName}' on path: '${apiPath}' without changes. Expecting failure with RC 99. #######");
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/basic/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/basic/1_no-change-config.json");
	createVariable("expectedReturnCode", "10");
	swaggerImport.doExecute(context);
	
	echo("####### Make sure, the API-ID hasn't changed #######");
	http(builder -> builder.client("apiManager").send().get("/proxies/${apiId}").header("Content-Type", "application/json"));

	// Check the API is still exposed on the same path
	http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.validate("$.[?(@.path=='${apiPath}')].id", "${apiId}")); // Must be the same API-ID as before!
}
 
Example #21
Source File: ConnectionsRestApiTest.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testGetConnectionsWithInvalidPassword(String username, String password, String hostName, String port)
        throws Exception {
    connections.add(createConnection(1, username, password, hostName, port));
    CloseableHttpResponse response = sendGetConnections(username, "invalidPassword");

    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_UNAUTHORIZED,
            "Incorrect status code while retrieving connection");
}
 
Example #22
Source File: RdbmsMandatoryAccessControlForExchangesTest.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
@Parameters({"test-username", "test-password"})
@Test(priority = 2, description = "delete an exchange by a user who does not have exchanges:delete scope")
public void testDeleteExchangeByTestUser(String username, String password) throws Exception {

    HttpDelete httpDelete = new HttpDelete(apiBasePath + "/exchanges/" + "adminUserExchange");
    ClientHelper.setAuthHeader(httpDelete, username, password);
    CloseableHttpResponse response = client.execute(httpDelete);

    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_FORBIDDEN);

}
 
Example #23
Source File: SwaggerFromURLRefFileInConfigurationTestIT.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
	swaggerImport = new ImportTestAction();
	description("Validates a Swagger-File can be taken from a URL using a REF-File described in API json configuration");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/ref-file-swagger-in-configuration-${apiNumber}");
	variable("apiName", "Ref-File-Swagger in configuration from URL-${apiNumber}");
	

	
	echo("####### Importing API: '${apiName}' on path: '${apiPath}' for the first time from URL #######");
	createVariable(ImportTestAction.API_DEFINITION,  "");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/basic/minimal-config-with-api-definition.json");
	createVariable("testAPIDefinition","./src/test/resources/com/axway/apim/test/files/basic/swagger-file-with-username.url");
	createVariable("status", "unpublished");
	createVariable("expectedReturnCode", "0");
	swaggerImport.doExecute(context);
	
	echo("####### Validate API: '${apiName}' on path: '${apiPath}' has been imported #######");
	http(builder -> builder.client("apiManager").send().get("/proxies").header("Content-Type", "application/json"));

	http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.validate("$.[?(@.path=='${apiPath}')].state", "unpublished")
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId"));
	
	echo("####### Re-Import API from URL without a change #######");
	createVariable(ImportTestAction.API_DEFINITION,  "");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/basic/minimal-config-with-api-definition.json");
	createVariable("testAPIDefinition","./src/test/resources/com/axway/apim/test/files/basic/swagger-file-with-username.url");
	createVariable("status", "unpublished");
	createVariable("expectedReturnCode", "10");
	swaggerImport.doExecute(context);
}
 
Example #24
Source File: ImportUnpublishedSetToPublishedAPITestIT.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
	swaggerImport = new ImportTestAction();
	echo("Import an Unpublished-API and in the second step publish it");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/change-state-to-published-api-${apiNumber}");
	variable("apiName", "Change state to Published API ${apiNumber}");

	echo("####### Importing API: '${apiName}' on path: '${apiPath}' for the first time #######");		
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/basic/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/basic/4_flexible-status-config.json");
	createVariable("state", "unpublished");
	createVariable("expectedReturnCode", "0");
	swaggerImport.doExecute(context);
	
	echo("####### Validate API: '${apiName}' on path: '${apiPath}' has been imported #######");
	http(builder -> builder.client("apiManager").send().get("/proxies")	.header("Content-Type", "application/json"));

	http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.validate("$.[?(@.path=='${apiPath}')].state", "${state}")
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId"));
	
	echo("####### Change API-State from Unpublished to Published #######");
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/basic/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/basic/4_flexible-status-config.json");
	createVariable("state", "published");
	createVariable("expectedReturnCode", "0");
	swaggerImport.doExecute(context);
	
	echo("####### Validate the API-ID hasn't changed by that change #######");
	http(builder -> builder.client("apiManager").send().get("/proxies/${apiId}").header("Content-Type", "application/json"));

	http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.validate("$.[?(@.path=='${apiPath}')].state", "${state}")
		.validate("$.[?(@.path=='${apiPath}')].id", "${apiId}"));
}
 
Example #25
Source File: TopicDtxCommitNegativeTest.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname", "broker-rest-port"})
@BeforeMethod
public void setUp(String port,
                  String adminUsername,
                  String adminPassword,
                  String brokerHostname,
                  String restPort) throws Exception {
    initialContextBuilder = ClientHelper
            .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port);
    restApiClient = new BrokerRestApiClient(adminUsername, adminPassword, restPort, brokerHostname);
    xaResource = null;
    xaSession = null;
    xaConnection = null;
}
 
Example #26
Source File: RdbmsMandatoryAccessControlForQueuesTest.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #27
Source File: LoggersRestApiTest.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
@Parameters({"admin-username", "admin-password"})
@Test
public void testLoggerRetrieval(String username, String password) throws IOException {
    HttpGet httpGet = new HttpGet(apiBasePath + LOGGERS_API_PATH);
    ClientHelper.setAuthHeader(httpGet, username, password);
    CloseableHttpResponse response = client.execute(httpGet);

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

    String body = EntityUtils.toString(response.getEntity());

    LoggerMetadata[] loggerMetadata = objectMapper.readValue(body, LoggerMetadata[].class);

    Assert.assertTrue(loggerMetadata.length > 0, "Logger metadata list shouldn't be empty.");
}
 
Example #28
Source File: ConnectionsRestApiTest.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testCloseChannels(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"
                                           + "?" + USED_TRUE_QUERY_PARAM);
    ClientHelper.setAuthHeader(httpDelete, username, password);
    CloseableHttpResponse channelCloseResponse = client.execute(httpDelete);
    Assert.assertEquals(channelCloseResponse.getStatusLine().getStatusCode(), HttpStatus.SC_ACCEPTED,
                        "Incorrect status code while closing connections");

    //Assert connection details after delete
    int expectedChannelCount = channelCount - 1;
    ConnectionMetadata[] connectionMetadataAfterClosing = waitForChannelUpdate(expectedChannelCount, username,
                                                                               password);
    Assert.assertEquals(connectionMetadataAfterClosing[0].getChannelCount().intValue(), expectedChannelCount,
                        "Incorrect connection count after closing connection.");

}
 
Example #29
Source File: QueuesRestApiTest.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
@Parameters({"admin-username", "admin-password"})
@Test
public void testQueueRetrieval(String username, String password) throws IOException {
    HttpGet httpGet = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH);
    ClientHelper.setAuthHeader(httpGet, username, password);
    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.assertTrue(queueMetadata.length > 0, "Queue metadata list shouldn't be empty.");
}
 
Example #30
Source File: BindingsRestApiTest.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@BeforeMethod
public void setup(String username, String password, String brokerHost, String brokerPort)
        throws IOException, TimeoutException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    client = HttpClientHelper.prepareClient();
    amqpConnection = ClientHelper.getAmqpConnection(username, password, brokerHost, brokerPort);
    this.username = username;
    this.password = password;
}