com.consol.citrus.message.MessageType Java Examples

The following examples show how to use com.consol.citrus.message.MessageType. 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: SimulatorRestIT.java    From citrus-simulator with Apache License 2.0 6 votes vote down vote up
@CitrusTest
public void testLoginUser() {
    http().client(petstoreClient)
            .send()
            .get("/user/login")
            .queryParam("username", "citrus:randomString(10)")
            .queryParam("password", "citrus:randomString(8)")
            .accept("text/plain");

    http().client(petstoreClient)
            .receive()
            .response(HttpStatus.OK)
            .messageType(MessageType.PLAINTEXT)
            .payload("@notEmpty()@")
            .header("X-Rate-Limit", "@isNumber()@")
            .header("X-Expires-After", "@matchesDatePattern('yyyy-MM-dd'T'hh:mm:ss')@");
}
 
Example #2
Source File: SimulatorRestIT.java    From citrus-simulator with Apache License 2.0 6 votes vote down vote up
@CitrusTest
public void testLoginUser() {
    http().client(petstoreClient)
            .send()
            .get("/user/login")
            .queryParam("username", "citrus:randomString(10)")
            .queryParam("password", "citrus:randomString(8)")
            .accept("text/plain");

    http().client(petstoreClient)
            .receive()
            .response(HttpStatus.OK)
            .messageType(MessageType.PLAINTEXT)
            .payload("@notEmpty()@")
            .header("X-Rate-Limit", "@isNumber()@")
            .header("X-Expires-After", "@matchesDatePattern('yyyy-MM-dd'T'hh:mm:ss')@");
}
 
Example #3
Source File: SendMessageActionConverter.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Override
public TestActionModel convert(SendModel model) {
    TestActionModel action = super.convert(model);

    if (model.getMessage() != null) {
        action.add(new Property<>("message.name", "message.name", "MessageName", model.getMessage().getName(), false));

        action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(model.getMessage().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                            .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    } else {
        action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
        action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    }

    return action;
}
 
Example #4
Source File: HttpSteps.java    From yaks with Apache License 2.0 6 votes vote down vote up
/**
 * Maps content type value to Citrus message type used later on for selecting
 * the right message validator implementation.
 *
 * @param contentType
 * @return
 */
default String getMessageType(String contentType) {
    List<MediaType> binaryMediaTypes = Arrays.asList(MediaType.APPLICATION_OCTET_STREAM,
            MediaType.APPLICATION_PDF,
            MediaType.IMAGE_GIF,
            MediaType.IMAGE_JPEG,
            MediaType.IMAGE_PNG,
            MediaType.valueOf("application/zip"));

    if (contentType.equals(MediaType.APPLICATION_JSON_VALUE) ||
            contentType.equals(MediaType.APPLICATION_JSON_UTF8_VALUE)) {
        return MessageType.JSON.name();
    } else if (contentType.equals(MediaType.APPLICATION_XML_VALUE)) {
        return MessageType.XML.name();
    } else if (contentType.equals(MediaType.APPLICATION_XHTML_XML_VALUE)) {
        return MessageType.XHTML.name();
    } else if (contentType.equals(MediaType.TEXT_PLAIN_VALUE) ||
            contentType.equals(MediaType.TEXT_HTML_VALUE)) {
        return MessageType.PLAINTEXT.name();
    } else if (binaryMediaTypes.stream().anyMatch(mediaType -> contentType.equals(mediaType.getType()))) {
        return MessageType.BINARY.name();
    }

    return CitrusSettings.DEFAULT_MESSAGE_TYPE;
}
 
Example #5
Source File: WsReceiveMessageActionConverter.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Override
public TestActionModel convert(ReceiveModel model) {
    TestActionModel action = super.convert(model);

    if (model.getMessage() != null) {
        action.add(new Property<>("message.name", "message.name", "MessageName", model.getMessage().getName(), false));

        action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(model.getMessage().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    } else {
        action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
        action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    }

    return action;
}
 
Example #6
Source File: WsSendMessageActionConverter.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Override
public TestActionModel convert(SendModel model) {
    TestActionModel action = super.convert(model);

    if (model.getMessage() != null) {
        action.add(new Property<>("message.name", "message.name", "MessageName", model.getMessage().getName(), false));

        action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(model.getMessage().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                            .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    } else {
        action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
        action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    }

    return action;
}
 
Example #7
Source File: ReceiveMessageActionConverter.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Override
public TestActionModel convert(ReceiveModel model) {
    TestActionModel action = super.convert(model);

    if (model.getMessage() != null) {
        action.add(new Property<>("message.name", "message.name", "MessageName", model.getMessage().getName(), false));

        action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(model.getMessage().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    } else {
        action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
        action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    }

    return action;
}
 
Example #8
Source File: IntiallyPublishedAPITestIT.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 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"));
}
 
Example #9
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 #10
Source File: ResponsePolicyEmptyStringTestIT.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("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"));
}
 
Example #11
Source File: RequestPolicyTestIT.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
@CitrusTest(name = "RequestPolicyTest")
public void run() {
	description("Test a Request-Policy");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/request-policy-test-${apiNumber}");
	variable("apiName", "Request Policy Test ${apiNumber}");
	variable("status", "unpublished");
	

	echo("####### Importing API: '${apiName}' on path: '${apiPath}' with following settings: #######");
	createVariable("requestPolicy", "Request 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_request-policy.json");
	createVariable("expectedReturnCode", "0");
	action(swaggerImport);
	
	echo("####### Validate API: '${apiName}' on path: '${apiPath}' has correct settings #######");
	http().client("apiManager")
		.send()
		.get("/proxies")
		.name("api")
		.header("Content-Type", "application/json");

	http().client("apiManager")
		.receive()
		.response(HttpStatus.OK)
		.messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.validate("$.[?(@.path=='${apiPath}')].state", "unpublished")
		.validate("$.[?(@.path=='${apiPath}')].outboundProfiles._default.requestPolicy", "@assertThat(containsString(Request policy 1))@")
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId");
}
 
Example #12
Source File: AllOutboundPoliciesTestIT.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
@CitrusTest(name = "AllOutboundPoliciesTest")
public void run() {
	description("Test a Request-Policy");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/all-outbound-policies-${apiNumber}");
	variable("apiName", "All Outbound Policies ${apiNumber}");
	variable("status", "unpublished");
	

	echo("####### Importing API: '${apiName}' on path: '${apiPath}' with following settings: #######");
	createVariable("requestPolicy", "Request policy 1");
	createVariable("responsePolicy", "Response policy 1");
	createVariable("routePolicy", "Routing policy 1");
	createVariable("faultHandlerPolicy", "Faulthandler 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_all-policies.json");
	createVariable("expectedReturnCode", "0");
	action(swaggerImport);
	
	echo("####### Validate API: '${apiName}' on path: '${apiPath}' has correct settings #######");
	http().client("apiManager")
		.send()
		.get("/proxies")
		.name("api")
		.header("Content-Type", "application/json");

	http().client("apiManager")
		.receive()
		.response(HttpStatus.OK)
		.messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.validate("$.[?(@.path=='${apiPath}')].state", "unpublished")
		.validate("$.[?(@.path=='${apiPath}')].outboundProfiles._default.requestPolicy", "@assertThat(containsString(Request policy 1))@")
		.validate("$.[?(@.path=='${apiPath}')].outboundProfiles._default.responsePolicy", "@assertThat(containsString(Response policy 1))@")
		.validate("$.[?(@.path=='${apiPath}')].outboundProfiles._default.routePolicy", "@assertThat(containsString(Routing policy 1))@")
		.validate("$.[?(@.path=='${apiPath}')].outboundProfiles._default.faultHandlerPolicy", "@assertThat(containsString(Faulthandler policy 1))@")
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId");
}
 
Example #13
Source File: InvalidDevelopmentOrgTestIT.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
@CitrusTest
public void runNonDevOrg() {
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/invalid-org-${apiNumber}");
	variable("apiName", "Invalid organization ${apiNumber}");
	// Directly use an admin-account, otherwise the OrgAdmin organization is used by default
	variable("oadminUsername1", "apiadmin"); 
	variable("oadminPassword1", "changeme");
	variable("testOrgName", "NonDevOrg ${apiNumber}");
	
	
	http().client("apiManager")
		.send()
		.post("/organizations")
		.name("anotherOrgCreatedRequest")
		.header("Content-Type", "application/json")
		.payload("{\"name\": \"NonDevOrg ${apiNumber}\", \"description\": \"Org without dev permission\", \"enabled\": true, \"development\": false }");

	http().client("apiManager")
		.receive()
		.response(HttpStatus.CREATED)
		.messageType(MessageType.JSON)
		.validate("$.name", "${testOrgName}")
		.extractFromPayload("$.id", "noPermOrgId");
	
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/basic/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/organizations/dynamic-organization.json");
	createVariable("state", "published");
	
	createVariable("expectedReturnCode", "57");
	action(swaggerImport);
	
}
 
Example #14
Source File: OrgAdminCustomPoliciesTestIT.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
@CitrusTest(name = "OrgAdminTriesToPublishTestIT")
public void run() {
	description("OrgAdmin wants to use a custom policy.");
	
	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

	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/policies/1_request-policy.json");
	createVariable("requestPolicy", "Request policy 1");
	createVariable("expectedReturnCode", "0");
	createVariable("apiManagerUser", "${oadminUsername1}"); // This is an org-admin user
	createVariable("apiManagerPass", "${oadminPassword1}");
	action(swaggerImport);
	
	echo("####### Validate API: '${apiName}' on path: '${apiPath}' has correct settings #######");
	http().client("apiManager")
		.send()
		.get("/proxies")
		.name("api")
		.header("Content-Type", "application/json");

	http().client("apiManager")
		.receive()
		.response(HttpStatus.OK)
		.messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.validate("$.[?(@.path=='${apiPath}')].state", "unpublished")
		.validate("$.[?(@.path=='${apiPath}')].outboundProfiles._default.requestPolicy", "@assertThat(containsString(Request policy 1))@")
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId");
}
 
Example #15
Source File: OrgAdminUnpublishedTestIT.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
@CitrusTest(name = "OrgAdminUnpublishedTestIT")
public void run() {
	description("OrgAdmins should be able to register unpublished APIs and manage them.");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/org-admin-${apiNumber}");
	variable("apiName", "OrgAdmin-Unpublished-${apiNumber}");
	variable("ignoreAdminAccount", "true"); // This tests simulate to use only an Org-Admin-Account

	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/1_no-change-config.json");
	createVariable("expectedReturnCode", "0");
	createVariable("apiManagerUser", "${oadminUsername1}"); // This is an org-admin user
	createVariable("apiManagerPass", "${oadminPassword1}");
	action(swaggerImport);
	
	echo("####### Validate API: '${apiName}' on path: '${apiPath}' has been imported using OrgAdmin only #######");
	http().client("apiManager")
		.send()
		.get("/proxies")
		.name("api")
		.header("Content-Type", "application/json");

	http().client("apiManager")
		.receive()
		.response(HttpStatus.OK)
		.messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId");
	
	echo("####### Re-Import another Swagger-File still unpublished. #######");
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/basic/petstore2.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/basic/1_no-change-config.json");
	createVariable("expectedReturnCode", "0");
	createVariable("apiManagerUser", "${oadminUsername1}"); // This is an org-admin user
	createVariable("apiManagerPass", "${oadminPassword1}");
	action(swaggerImport);
}
 
Example #16
Source File: NoAuthenticationGivenTestIT.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
@CitrusTest(name = "NoAuthenticationGivenTest")
public void run() {
	description("Verify no error appears, if Authentication is not configured! Must be Passthrough");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/no-authn-test-${apiNumber}");
	variable("apiName", "No AuthN Test ${apiNumber}");
	variable("status", "unpublished");
	

	echo("####### Importing API: '${apiName}' on path: '${apiPath}' with following settings: #######");
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/security/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/security/2_no_authn.json");
	createVariable("expectedReturnCode", "0");
	action(swaggerImport);
	
	echo("####### Validate API: '${apiName}' on path: '${apiPath}' with Passthrough-Security #######");
	http().client("apiManager")
		.send()
		.get("/proxies")
		.name("api")
		.header("Content-Type", "application/json");

	http().client("apiManager")
		.receive()
		.response(HttpStatus.OK)
		.messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.validate("$.[?(@.path=='${apiPath}')].state", "unpublished")
		.validate("$.[?(@.path=='${apiPath}')].securityProfiles[0].devices[0].type", "passThrough")
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId");
}
 
Example #17
Source File: OutboundNoAuthWithPoliciesTestIT.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("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);
}
 
Example #18
Source File: SimpleStagingTestIT.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
@CitrusTest(name = "SimpleStagingTest")
public void run() {
	description("Import the API with production stage settings");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/my-stage-test-${apiNumber}");
	variable("apiName", "Stage-Test-${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/staging/1_no-change-config.json");
	createVariable("stage", "prod"); // << Program will search for file: 1_no-change-config.prod.json
	createVariable("expectedReturnCode", "0");
	action(swaggerImport);

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

	http().client("apiManager")
		.receive()
		.response(HttpStatus.OK)
		.messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.validate("$.[?(@.path=='${apiPath}')].state", "published") // State must be published in "prod"
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId");
}
 
Example #19
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 #20
Source File: SpecialCharactersAPITestIT.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 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);
}
 
Example #21
Source File: RoutingPolicyTestIT.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("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"));
}
 
Example #22
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 #23
Source File: SwaggerFromFileInConfigurationTestIT.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 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);
}
 
Example #24
Source File: SwaggerFromURLRefFileTestIT.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.");
	
	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);
}
 
Example #25
Source File: CorsProfileBasicTestIT.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
@CitrusTest(name = "CorsProfileBasicTest")
public void run() {
	description("Importing & validating CORS-Profile");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/api-cors-profile-test-${apiNumber}");
	variable("apiName", "API CORS-Profile Test ${apiNumber}");
	variable("status", "unpublished");
	

	echo("####### 1. Importing API: '${apiName}' on path: '${apiPath}' with following settings: #######");
	createVariable("status", "unpublished");
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/security/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/cors/1_api-with_default_cors.json");
	createVariable("expectedReturnCode", "0");
	action(swaggerImport);
	
	echo("####### Validate API: '${apiName}' on path: '${apiPath}' has correct settings #######");
	http().client("apiManager")
		.send()
		.get("/proxies")
		.name("api")
		.header("Content-Type", "application/json");

	http().client("apiManager")
		.receive()
		.response(HttpStatus.OK)
		.messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.validate("$.[?(@.path=='${apiPath}')].state", "unpublished")
		.validate("$.[?(@.path=='${apiPath}')].corsProfiles.[?(@.name=='New CORS Profile')].allowedHeaders[0]", "Authorization")
		.validate("$.[?(@.path=='${apiPath}')].corsProfiles.[?(@.name=='New CORS Profile')].exposedHeaders[0]", "via")
		.validate("$.[?(@.path=='${apiPath}')].inboundProfiles._default.corsProfile", "New CORS Profile")
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId");
}
 
Example #26
Source File: WSDLFromURLRefFileInConfigurationTestIT.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 WSDL-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-wsdl-in-configuration-${apiNumber}");
	variable("apiName", "Ref-File-WSDL 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/wsdl/wsdl-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").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")
		.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/wsdl/wsdl-file-with-username.url");
	createVariable("status", "unpublished");
	createVariable("expectedReturnCode", "10");
	swaggerImport.doExecute(context);
}
 
Example #27
Source File: WSDLFromURLRefFileTestIT.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 WSDL-File can be taken from a URL using a REF-File.");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/ref-file-wsdl-${apiNumber}");
	variable("apiName", "Ref-File-WSDL 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/wsdl/wsdl-file-with-username.url");
	createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/wsdl/wsdl-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").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")
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId"));
	
	echo("####### Re-Import API from URL without a change #######");
	createVariable(ImportTestAction.API_DEFINITION, "/com/axway/apim/test/files/wsdl/wsdl-file-with-username.url");
	createVariable(ImportTestAction.API_CONFIG, "/com/axway/apim/test/files/wsdl/wsdl-minimal-config.json");
	createVariable("status", "unpublished");
	createVariable("expectedReturnCode", "10");
	swaggerImport.doExecute(context);
}
 
Example #28
Source File: SendResponseActionConverter.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
@Override
public TestActionModel convert(SendResponseModel model) {
    TestActionModel action = super.convert(model);

    ResponseHeadersType headers = model.getHeaders();
    if (headers != null) {
        action.add(new Property<>("status", "status", "Status", model.getHeaders().getStatus(), true)
                    .options(Stream.of(HttpStatus.values()).map(HttpStatus::toString).collect(Collectors.toList())));
        action.add(new Property<>("reason", "reason", "Reason", model.getHeaders().getReasonPhrase(), false)
                    .options(Stream.of(HttpStatus.values()).map(HttpStatus::getReasonPhrase).collect(Collectors.toList())));

        action.add(new Property<>("version", "version", "Version", Optional.ofNullable(model.getHeaders().getVersion()).orElse("HTTP/1.1"), false));
    }

    if (model.getBody() != null) {
        action.add(new Property<>("message.name", "message.name", "MessageName", model.getBody().getName(), false));

        action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(model.getBody().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    } else {
        action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
        action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    }

    return action;
}
 
Example #29
Source File: ReceiveResponseActionConverter.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
@Override
public TestActionModel convert(ReceiveResponseModel model) {
    TestActionModel action = super.convert(model);

    ResponseHeadersType headers = model.getHeaders();
    if (headers != null) {
        action.add(new Property<>("status", "status", "Status", model.getHeaders().getStatus(), true)
                    .options(Stream.of(HttpStatus.values()).map(HttpStatus::toString).collect(Collectors.toList())));
        action.add(new Property<>("reason", "reason", "Reason", model.getHeaders().getReasonPhrase(), false)
                    .options(Stream.of(HttpStatus.values()).map(HttpStatus::getReasonPhrase).collect(Collectors.toList())));

        action.add(new Property<>("version", "version", "Version", Optional.ofNullable(model.getHeaders().getVersion()).orElse("HTTP/1.1"), false));
    }

    if (model.getBody() != null) {
        action.add(new Property<>("message.name", "message.name", "MessageName", model.getBody().getName(), false));

        action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(model.getBody().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    } else {
        action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
        action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    }

    return action;
}
 
Example #30
Source File: UnpublishedPublishedApiKeyTestIT.java    From apimanager-swagger-promote with Apache License 2.0 4 votes vote down vote up
@CitrusTest(name = "UnpublishedPublishedApiKeyTest")
public void run() {
	description("Some checks for the API-Key security device");
	
	variable("apiNumber", RandomNumberFunction.getRandomNumber(3, true));
	variable("apiPath", "/api-key-test-${apiNumber}");
	variable("apiName", "API Key Test ${apiNumber}");
	

	echo("####### Importing UNPUBLISHED API: '${apiName}' on path: '${apiPath}' with following settings: #######");
	createVariable("apiKeyFieldName", "KeyId");
	createVariable("takeFrom", "HEADER");
	createVariable("removeCredentialsOnSuccess", "false");
	createVariable("status", "unpublished");
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/security/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/security/1_api-apikey.json");
	createVariable("expectedReturnCode", "0");
	action(swaggerImport);
	
	echo("####### Validate API: '${apiName}' on path: '${apiPath}' with correct settings #######");
	http().client("apiManager")
		.send()
		.get("/proxies")
		.name("api")
		.header("Content-Type", "application/json");

	http().client("apiManager")
		.receive()
		.response(HttpStatus.OK)
		.messageType(MessageType.JSON)
		.validate("$.[?(@.path=='${apiPath}')].name", "${apiName}")
		.validate("$.[?(@.path=='${apiPath}')].state", "unpublished")
		.validate("$.[?(@.path=='${apiPath}')].securityProfiles[0].devices[0].type", "apiKey")
		.validate("$.[?(@.path=='${apiPath}')].securityProfiles[0].devices[0].properties.takeFrom", "${takeFrom}")
		.validate("$.[?(@.path=='${apiPath}')].securityProfiles[0].devices[0].properties.apiKeyFieldName", "${apiKeyFieldName}")
		.validate("$.[?(@.path=='${apiPath}')].securityProfiles[0].devices[0].properties.removeCredentialsOnSuccess", "${removeCredentialsOnSuccess}")
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "apiId");
	
	echo("####### Change the API-Security settings and at the same time set it to PUBLISHED #######");
	createVariable("apiKeyFieldName", "KeyId-Test");
	createVariable("takeFrom", "QUERY");
	createVariable("removeCredentialsOnSuccess", "true");
	createVariable("status", "published");
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/basic/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/security/1_api-apikey.json");
	createVariable("expectedReturnCode", "0");
	action(swaggerImport);
	
	echo("####### Validate the Security-Settings have been changed (without changing the API-ID) #######");
	http().client("apiManager")
		.send()
		.get("/proxies/${apiId}")
		.name("api")
		.header("Content-Type", "application/json");

	http().client("apiManager")
		.receive()
		.response(HttpStatus.OK)
		.messageType(MessageType.JSON)
		.validate("$.[?(@.id=='${apiId}')].id", "${apiId}")
		.validate("$.[?(@.id=='${apiId}')].securityProfiles[0].devices[0].properties.takeFrom", "${takeFrom}")
		.validate("$.[?(@.id=='${apiId}')].securityProfiles[0].devices[0].properties.apiKeyFieldName", "${apiKeyFieldName}")
		.validate("$.[?(@.id=='${apiId}')].securityProfiles[0].devices[0].properties.removeCredentialsOnSuccess", "${removeCredentialsOnSuccess}")
		.validate("$.[?(@.id=='${apiId}')].state", "published");
	
	echo("####### Change some settings of the PUBLISHED API, which leads to a new API-ID #######");
	createVariable("apiKeyFieldName", "KeyId-Test-Published");
	createVariable("takeFrom", "HEADER");
	createVariable("removeCredentialsOnSuccess", "false");
	createVariable("status", "published");
	createVariable("enforce", "true");
	createVariable(ImportTestAction.API_DEFINITION,  "/com/axway/apim/test/files/basic/petstore.json");
	createVariable(ImportTestAction.API_CONFIG,  "/com/axway/apim/test/files/security/1_api-apikey.json");
	createVariable("expectedReturnCode", "0");
	action(swaggerImport);
	
	echo("####### Validate the Security-Settings have been changed (without changing the API-ID) #######");
	http().client("apiManager")
		.send()
		.get("/proxies")
		.name("api")
		.header("Content-Type", "application/json");

	http().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")
		.validate("$.[?(@.path=='${apiPath}')].securityProfiles[0].devices[0].properties.takeFrom", "${takeFrom}")
		.validate("$.[?(@.path=='${apiPath}')].securityProfiles[0].devices[0].properties.apiKeyFieldName", "${apiKeyFieldName}")
		.validate("$.[?(@.path=='${apiPath}')].securityProfiles[0].devices[0].properties.removeCredentialsOnSuccess", "${removeCredentialsOnSuccess}")
		.extractFromPayload("$.[?(@.path=='${apiPath}')].id", "newApiId")
		.validate("$.[?(@.path=='${apiPath}')].id", "@assertThat(not(equalTo(${apiId})))@");
	
	echo("First API-ID: ${apiId}");
	echo("New   API-ID: ${newApiId}");
	
}