下面列出了怎么用org.testng.annotations.Optional的API类实例代码及写法,或者点击链接到github查看源代码。
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, InterruptedException {
description("Import an API, export it afterwards and validate it equals to the imported API");
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
variable("apiPath", "/api/test/"+this.getClass().getSimpleName()+"-${apiNumber}");
variable("apiName", this.getClass().getSimpleName()+"-${apiNumber}");
variable("state", "published");
echo("####### Importing the API, which should exported in the second step #######");
createVariable(ImportTestAction.API_DEFINITION, "/test/export/files/basic/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/test/export/files/basic/complete-config.json");
createVariable("image", "/com/axway/apim/test/files/basic/API-Logo.jpg");
createVariable("expectedReturnCode", "0");
swaggerImport.doExecute(context);
if(APIManagerAdapter.hasAPIManagerVersion("7.7.20200130")) {
Thread.sleep(1000); // Starting with this version, we need to wait a few milliseconds, otherwise the REST-API doesn't return the complete set of quotas
}
exportAPI(context, false);
exportAPI(context, true);
}
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException {
description("Import an API to export it afterwards");
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
variable("apiPath", "/api/test/"+this.getClass().getSimpleName()+"-${apiNumber}");
variable("apiName", this.getClass().getSimpleName()+"-${apiNumber}");
variable("state", "published");
echo("####### Importing the API, which should exported in the second step #######");
createVariable(ImportTestAction.API_DEFINITION, "/test/export/files/basic/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/test/export/files/customPolicies/custom-policies-issue-156.json");
createVariable("requestPolicy", "Request policy 1");
createVariable("responsePolicy", "Response policy 1");
createVariable("tokenInfoPolicy", "Tokeninfo policy 1");
createVariable("expectedReturnCode", "0");
swaggerImport.doExecute(context);
exportAPI(context, false);
exportAPI(context, true);
}
@CitrusTest
@Test @Parameters("context")
public void runInboundProfileValidation(@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-sec-profile-api-${apiNumber}");
variable("apiName", "Invalid-SecProfile-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-inbound-invalidProfileRefercence.json");
createVariable("state", "unpublished");
createVariable("expectedReturnCode", "73");
createVariable("securityProfileName1", "APIKeyBased${apiNumber}");
createVariable("securityProfileName2", "SomethingWrong${apiNumber}");
swaggerImport.doExecute(context);
}
@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 runInboundCorsProfileValidation(@Optional @CitrusResource TestContext context) throws IOException, AppException {
swaggerImport = new ImportTestAction();
description("Is the CORS-Profile not know - Error must be 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 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-inbound-invalidCorsProfileRefercence.json");
createVariable("state", "unpublished");
createVariable("expectedReturnCode", "73");
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);
}
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
swaggerImport = new ImportTestAction();
description("But OrgAdmins should not being allowed to register published APIs.");
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
variable("apiPath", "/org-admin-published-${apiNumber}");
variable("apiName", "OrgAdmin-Published-${apiNumber}");
variable("ignoreAdminAccount", "true"); // This tests simulate to use only an Org-Admin-Account
variable("allowOrgAdminsToPublish", "false"); // Disable OrgAdmins to publish APIs
echo("####### Calling the tool with a Non-Admin-User. #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/2_initially_published.json");
createVariable("expectedReturnCode", "17");
createVariable("apiManagerUser", "${oadminUsername1}"); // This is an org-admin user
createVariable("apiManagerPass", "${oadminPassword1}");
swaggerImport.doExecute(context);
}
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
swaggerImport = new ImportTestAction();
description("If no api-definition is passed as argument and no apiDefinition attribute is found in configuration file, the tool must fail with a dedicated return code.");
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
variable("apiPath", "/my-no-api-def-${apiNumber}");
variable("apiName", "No-API-DEF-CONFIGURED-${apiNumber}");
echo("####### Calling the tool with a Non-Admin-User. #######");
createVariable(ImportTestAction.API_DEFINITION, "");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
createVariable("status", "unpublished");
createVariable("expectedReturnCode", String.valueOf(ErrorCode.NO_API_DEFINITION_CONFIGURED.getCode()));
swaggerImport.doExecute(context);
}
@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);
}
/**
* Get Payara test server properties.
* <p>
* @return Payara test server properties.
*/
@BeforeSuite
@Parameters({ "rest-properties" })
public static Properties payaraProperties(@Optional String propertyFile) {
if (payaraProperties != null) {
return payaraProperties;
}
else {
synchronized(CommandRestTest.class) {
if (payaraProperties == null) {
if (propertyFile == null)
propertyFile = PAYARA_PROPERTES;
payaraProperties = readProperties(propertyFile);
}
}
return payaraProperties;
}
}
/**
* Get GlassFish test server properties.
* <p>
* @return GlassFish test server properties.
*/
@BeforeSuite
@Parameters({ "rest-properties" })
public static Properties glassfishProperties(@Optional String propertyFile) {
if (glassfishProperties != null) {
return glassfishProperties;
}
else {
synchronized(CommandRestTest.class) {
if (glassfishProperties == null) {
if (propertyFile == null)
propertyFile = GLASSFISH_PROPERTES;
glassfishProperties = readProperties(propertyFile);
}
}
return glassfishProperties;
}
}
@Test
@Parameters({"opDiscoveryPath"})
public void testWithNoOP(@Optional String opDiscoveryPath) throws Exception {
final DevelopersApi client = api();
final GetJwksParams params = new GetJwksParams();
params.setOpDiscoveryPath(opDiscoveryPath);
try {
client.getJsonWebKeySetWithHttpInfo(params, Tester.getAuthorization(), null);
} catch (ApiException ex) {
assertEquals(ex.getCode(), 400);
}
}
@Test(groups = "perfHash")
@Parameters({"readRatio", "threadMin", "threadMax", "threadIncrement",
"hashTableSize", "hashTableImpl"})
public static void benchmark(String readRatio, String threadMin, String threadMax,
String threadIncrement, String hashTableSize, @Optional("0") String hashTableImpl)
throws Exception {
String[] args = {
readRatio,
threadMin,
threadMax,
threadIncrement,
hashTableSize,
hashTableImpl
};
main(args);
}
@RunAsClient
@Parameters({ "gluuConfigurationPath", "webTarget" })
@Consumes(MediaType.APPLICATION_JSON)
@Test
public void getConfigurationTest(String gluuConfigurationPath,
@Optional @ArquillianResteasyResource("") final WebTarget webTarget) throws Exception {
Response response = webTarget.path(gluuConfigurationPath).request().get();
String entity = response.readEntity(String.class);
BaseTest.showResponse("UMA : TConfiguration.configuration", response, entity);
assertEquals(response.getStatus(), 200, "Unexpected response code.");
try {
GluuConfiguration appConfiguration = ServerUtil.createJsonMapper().readValue(entity,
GluuConfiguration.class);
System.err.println(appConfiguration.getIdGenerationEndpoint());
assertNotNull(appConfiguration, "Meta data configuration is null");
assertNotNull(appConfiguration.getIdGenerationEndpoint());
assertNotNull(appConfiguration.getIntrospectionEndpoint());
assertNotNull(appConfiguration.getAuthLevelMapping());
assertNotNull(appConfiguration.getScopeToClaimsMapping());
} catch (IOException e) {
e.printStackTrace();
fail();
}
}
@Test
@Parameters({"opHost", "opDiscoveryPath"})
public void test(String opHost, @Optional String opDiscoveryPath) throws Exception {
final DevelopersApi client = api();
final GetJwksParams params = new GetJwksParams();
params.setOpHost(opHost);
params.setOpDiscoveryPath(opDiscoveryPath);
final GetJwksResponse response = client.getJsonWebKeySet(params, Tester.getAuthorization(), null);
assertNotNull(response);
assertNotNull(response.getKeys());
assertFalse(response.getKeys().isEmpty());
}
@BeforeMethod(alwaysRun = true)
@Parameters("browser")
public void preCondition(@Optional("chrome") String browser) {
Configuration configuration = ConfigurationManager.getConfiguration();
WebDriver driver = DriverFactory.createInstance(browser);
DriverManager.setDriver(driver);
DriverManager.getDriver().get(configuration.url());
}
/**
* @param browserName Browser name
* @param configFile
* @author wasiqb
* @since Sep 13, 2018 9:55:41 PM
*/
@Parameters ({ BROWSER, CONFIG })
@BeforeTest (alwaysRun = true)
public void setupTest (@Optional final String browserName, @Optional final String configFile) {
if (isNotEmpty (configFile)) {
setProperty (COTEAFS_CONFIG_KEY, configFile);
}
this.browser = new Browser ();
this.browser.setBrowserUnderTest (browserName);
this.browser.start ();
}
/**
* suiteSetup method
*
* @param environment
* @param context
* @throws Exception
*/
@Parameters({"environment"})
@BeforeSuite(alwaysRun = true, enabled = true)
protected void suiteSetup(@Optional(Global_VARS.ENVIRONMENT) String environment,
ITestContext context)
throws Exception {
Global_VARS.DEF_ENVIRONMENT = System.getProperty("environment", environment);
Global_VARS.SUITE_NAME = context.getSuite().getXmlSuite().getName();
}
/**
* testSetup method
*
* @param browser
* @param platform
* @param includePattern
* @param excludePattern
* @param ctxt
* @throws Exception
*/
@Parameters({"browser", "platform", "includePattern", "excludePattern"})
@BeforeTest(alwaysRun = true, enabled = true)
protected void testSetup(@Optional(Global_VARS.BROWSER) String browser,
@Optional(Global_VARS.PLATFORM) String platform,
@Optional String includePattern,
@Optional String excludePattern,
ITestContext ctxt)
throws Exception {
// data provider filters
if ( includePattern != null ) {
System.setProperty("includePattern", includePattern);
}
if ( excludePattern != null ) {
System.setProperty("excludePattern", excludePattern);
}
// global variables
Global_VARS.DEF_BROWSER = System.getProperty("browser", browser);
Global_VARS.DEF_PLATFORM = System.getProperty("platform", platform);
// create driver
CreateDriver.getInstance().setDriver(Global_VARS.DEF_BROWSER,
Global_VARS.DEF_PLATFORM,
Global_VARS.DEF_ENVIRONMENT);
}
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
swaggerImport = new ImportTestAction();
description("Test to validate behavior if OutboundProfiles are set, but no AuthN-Profile. It should result into no AuthN.");
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
variable("apiPath", "/issue-133-noauth-${apiNumber}");
variable("apiName", "Issue 133 No-Auth ${apiNumber}");
echo("####### Importing API: '${apiName}' on path: '${apiPath}' Outbound-Profiles (for policies) not containing a AuthN-Profile. #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/security/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/security/issue-133-outbound-profile-no-auth.json");
createVariable("state", "unpublished");
createVariable("expectedReturnCode", "0");
swaggerImport.doExecute(context);
echo("####### Validate API: '${apiName}' on path: '${apiPath}' with outbound security set to No-AuthN as this should be the default. #######");
http(builder -> builder.client("apiManager").send().get("/proxies").name("api").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")
.validate("$.[?(@.path=='${apiPath}')].authenticationProfiles[0].name", "_default")
.validate("$.[?(@.path=='${apiPath}')].authenticationProfiles[0].type", "none")
.validate("$.[?(@.path=='${apiPath}')].authenticationProfiles[0].isDefault", "true")
.validate("$.[?(@.path=='${apiPath}')].outboundProfiles._default.authenticationProfile", "_default")
.validate("$.[?(@.path=='${apiPath}')].outboundProfiles._default.routeType", "policy")
.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId"));
echo("####### No-Change test for '${apiName}' on path: '${apiPath}' #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/security/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/security/issue-133-outbound-profile-no-auth.json");
createVariable("state", "unpublished");
createVariable("expectedReturnCode", "10");
swaggerImport.doExecute(context);
}
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
swaggerImport = new ImportTestAction();
description("Making sure, organization are not conisdered as changes if desired state is Unpublished");
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
variable("apiPath", "/no-change-org-unpublished-${apiNumber}");
variable("apiName", "No-Change-Org-Unpublished-${apiNumber}");
// Replication must fail, is Query-String option is enabled, but API-Manager hasn't configured it
echo("####### API-Config without queryString option - Must fail #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/organizations/1_api-with-client-orgs.json");
createVariable("state", "unpublished");
createVariable("orgName", "${orgName}");
createVariable("orgName2", "${orgName2}");
createVariable("expectedReturnCode", "0");
swaggerImport.doExecute(context);
echo("####### Re-Import the same - Must lead to a No-Change! #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/organizations/1_api-with-client-orgs.json");
createVariable("state", "unpublished");
createVariable("orgName", "${orgName}");
createVariable("orgName2", "${orgName2}");
createVariable("expectedReturnCode", "10"); // No-Change is expected!
swaggerImport.doExecute(context);
}
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
swaggerImport = new ImportTestAction();
description("Issue #156 - Cant deploy an API with response policy only");
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
variable("apiPath", "/response-policy-empty-string-${apiNumber}");
variable("apiName", "Response Policy Empty String ${apiNumber}");
variable("status", "unpublished");
echo("####### Trying to import API: '${apiName}' on path: '${apiPath}' with following settings: #######");
createVariable("responsePolicy", "Response policy 1");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/security/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/policies/1_response-policy.json");
createVariable("expectedReturnCode", "0");
swaggerImport.doExecute(context);
echo("####### Validate API: '${apiName}' on path: '${apiPath}' has correct settings #######");
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")
.validate("$.[?(@.path=='${apiPath}')].outboundProfiles._default.responsePolicy", "@assertThat(containsString(Response policy 1))@")
.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId"));
}
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
swaggerImport = new ImportTestAction();
description("Test a Routing-Policy");
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
variable("apiPath", "/routing-policy-test-${apiNumber}");
variable("apiName", "Routing Policy Test ${apiNumber}");
variable("status", "unpublished");
echo("####### Importing API: '${apiName}' on path: '${apiPath}' with following settings: #######");
createVariable("routePolicy", "Routing policy 1");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/security/petstore.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/policies/1_routing-policy.json");
createVariable("expectedReturnCode", "0");
swaggerImport.doExecute(context);
echo("####### Validate API: '${apiName}' on path: '${apiPath}' has correct settings #######");
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")
.validate("$.[?(@.path=='${apiPath}')].outboundProfiles._default.routePolicy", "@assertThat(containsString(Routing policy 1))@")
.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId"));
}
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
swaggerImport = new ImportTestAction();
description("Import an API which initially has the status published.");
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
variable("apiPath", "/initially-published-${apiNumber}");
variable("apiName", "Initially-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/2_initially_published.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}")
.validate("$.[?(@.path=='${apiPath}')].state", "published")
.validate("$.[?(@.path=='${apiPath}')].securityProfiles[0].devices[0].type", "apiKey")
.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId"));
}
@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}"));
}
@CitrusTest
@Test @Parameters("context")
public void run(@Optional @CitrusResource TestContext context) throws IOException, AppException {
swaggerImport = new ImportTestAction();
description("Import an API having some special characters in the Swagger & API-Config-File.");
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
variable("apiPath", "/special-chars-${apiNumber}");
variable("apiName", "Special-Chars-${apiNumber}");
echo("####### Importing Special-Chars API: '${apiName}' on path: '${apiPath}' #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/petstore-special-chars.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/special-chars-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}")
// TODO: Find a way to validate unicode characters as well
//.validate("$.[?(@.path=='${apiPath}')].summary", "�дпат или умри.")
.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-special-chars.json");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/special-chars-config.json");
createVariable("expectedReturnCode", "10");
swaggerImport.doExecute(context);
}
@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);
}
@BeforeSuite(dependsOnMethods = "initContext")
@Parameters({"cloudbreakServer", "cloudProvider", "credentialName", "instanceGroups", "hostGroups", "blueprintName",
"stackName", "networkName", "securityGroupName"})
public void initCloudbreakSuite(@Optional("") String cloudbreakServer, @Optional("") String cloudProvider, @Optional("") String credentialName,
@Optional("") String instanceGroups, @Optional("") String hostGroups, @Optional("") String blueprintName,
@Optional("") String stackName, @Optional("") String networkName, @Optional("") String securityGroupName) {
cloudbreakServer = StringUtils.hasLength(cloudbreakServer) ? cloudbreakServer : defaultCloudbreakServer;
String cbServerRoot = cloudbreakServer + cbRootContextPath;
itContext.putContextParam(CloudbreakITContextConstants.SKIP_REMAINING_SUITETEST_AFTER_ONE_FAILED, skipRemainingSuiteTestsAfterOneFailed);
itContext.putContextParam(CloudbreakITContextConstants.CLOUDBREAK_SERVER, cloudbreakServer);
itContext.putContextParam(CloudbreakITContextConstants.CLOUDBREAK_SERVER_ROOT, cbServerRoot);
itContext.putContextParam(CloudbreakITContextConstants.CLOUDPROVIDER, cloudProvider);
CloudbreakServiceUserCrnClient cloudbreakClient = new CloudbreakUserCrnClientBuilder(cbServerRoot)
.withCertificateValidation(false)
.withIgnorePreValidation(true)
.withDebug(true)
.build();
itContext.putContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, cloudbreakClient);
Long workspaceId = itContext.getContextParam(CloudbreakITContextConstants.WORKSPACE_ID, Long.class);
if (cleanUpBeforeStart) {
cleanUpService.deleteTestStacksAndResources(cloudbreakClient.withCrn(userCrn), workspaceId);
}
putBlueprintToContextIfExist(itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class)
.blueprintV4Endpoint(), blueprintName, workspaceId);
putStackToContextIfExist(itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class)
.stackV4Endpoint(), workspaceId, stackName);
if (StringUtils.hasLength(instanceGroups)) {
List<String[]> instanceGroupStrings = templateAdditionHelper.parseCommaSeparatedRows(instanceGroups);
}
if (StringUtils.hasLength(hostGroups)) {
List<String[]> hostGroupStrings = templateAdditionHelper.parseCommaSeparatedRows(hostGroups);
itContext.putContextParam(CloudbreakITContextConstants.HOSTGROUP_ID, createHostGroups(hostGroupStrings));
}
}
@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 file path described in json configuration file");
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
variable("apiPath", "/file-swagger-in-configuration-${apiNumber}");
variable("apiName", "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/petstore.json");
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/petstore.json");
createVariable("status", "unpublished");
createVariable("expectedReturnCode", "10");
swaggerImport.doExecute(context);
}
@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.");
variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
variable("apiPath", "/ref-file-swagger-${apiNumber}");
variable("apiName", "Ref-File-Swagger from URL-${apiNumber}");
echo("####### Importing API: '${apiName}' on path: '${apiPath}' for the first time from URL #######");
createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/basic/swagger-file-with-username.url");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
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, "/com/axway/apim/test/files/basic/swagger-file-with-username.url");
createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/basic/minimal-config.json");
createVariable("status", "unpublished");
createVariable("expectedReturnCode", "10");
swaggerImport.doExecute(context);
}