Skip to content

Commit

Permalink
fix(gateway): Updated integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: matejpopda <20053580+matejpopda@users.noreply.github.com>
  • Loading branch information
matejpopda committed Aug 8, 2023
1 parent 08bfefa commit 5027e74
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ public ResponseEntity<String> checkConformance(@PathVariable String serviceId) {
@HystrixCommand
public ResponseEntity<String> checkValidateLegacy(@RequestBody String serviceId) {

System.out.println(serviceId);

if (serviceId.startsWith("serviceID")) {
serviceId = serviceId.replace("serviceID=", "");
}
System.out.println(serviceId);
return checkConformance(serviceId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import io.restassured.RestAssured;
import org.apache.http.HttpStatus;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.zowe.apiml.util.TestWithStartedInstances;
import org.zowe.apiml.util.categories.GatewayTest;
Expand All @@ -25,44 +26,79 @@
* This is an integration test class for ValidateAPIController.java
* It tests ValidateAPIController with service verificationOnboardService.java
* <p>
* The test senario is:
* The test scenario is:
* Send serviceId to validateAPIController then the controller will call verificationOnboardService.java
* to check if the service is registered and metadata can be retrieved then it will return appropriate message
* The controller recieve the response from the service and then will post response.
* The controller receive the response from the service and then will post response.
*/
@GatewayTest
public class ValidateAPITest implements TestWithStartedInstances {

private String gatewayUrl;

@BeforeEach
public void relaxedHTTPS() {
RestAssured.useRelaxedHTTPSValidation();
}

@Test
@TestsNotMeantForZowe
void testPostEndpoint() {
given()
.log().all()
.param("serviceID","discoverableclient")
.when()
.post(getLegacyEndpointURLPost())
.then()
.assertThat()
.statusCode(HttpStatus.SC_OK);

public ValidateAPITest() {
initGatewayService();
}

@Test
@TestsNotMeantForZowe
void givenValidServiceId() {
void testGetEndpoint() {
given()
.log().all()
.body("discoverableclient")
.when()
.post(gatewayUrl)
.get(getEndpointURLGet() + "/discoverableclient")
.then()
.assertThat()
.statusCode(HttpStatus.SC_OK);

}

@Test
@TestsNotMeantForZowe
void testGetEndpointNonConformant() {
given()
.log().all()
.when()
.get(getEndpointURLGet() + "/nonConformantServiceBecauseNameIsTooLongAndContainsCapitalLettersqwertyuiop")
.then()
.assertThat()
.statusCode(HttpStatus.SC_BAD_REQUEST);

}

private String getEndpointURLGet() {
GatewayServiceConfiguration gatewayServiceConfiguration = ConfigReader.environmentConfiguration().getGatewayServiceConfiguration();
String gatewayScheme = gatewayServiceConfiguration.getScheme();
String gatewayHost = gatewayServiceConfiguration.getHost();
int gatewayPort = gatewayServiceConfiguration.getExternalPort();
RestAssured.port = gatewayPort;
RestAssured.useRelaxedHTTPSValidation();

return String.format("%s://%s:%d%s", gatewayScheme, gatewayHost, gatewayPort, "/gateway/api/v1/conformance");
}

private void initGatewayService() {
private String getLegacyEndpointURLPost() {
GatewayServiceConfiguration gatewayServiceConfiguration = ConfigReader.environmentConfiguration().getGatewayServiceConfiguration();
String gatewayScheme = gatewayServiceConfiguration.getScheme();
String gatewayHost = gatewayServiceConfiguration.getHost();
int gatewayPort = gatewayServiceConfiguration.getExternalPort();
RestAssured.port = gatewayPort;
RestAssured.useRelaxedHTTPSValidation();

gatewayUrl = String.format("%s://%s:%d%s", gatewayScheme, gatewayHost, gatewayPort, "/validate");
return String.format("%s://%s:%d%s", gatewayScheme, gatewayHost, gatewayPort, "/validate");
}
}

0 comments on commit 5027e74

Please sign in to comment.