diff options
Diffstat (limited to 'adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java')
-rw-r--r-- | adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java | 90 |
1 files changed, 42 insertions, 48 deletions
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java index ae3fb8271a..120c3e3493 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/StubOpenStack.java @@ -29,49 +29,43 @@ import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.put; import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; - import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; - import org.apache.http.HttpStatus; - import com.github.tomakehurst.wiremock.WireMockServer; public class StubOpenStack { public static void mockOpenStackResponseAccess(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); } public static void mockOpenStackResponseUnauthorized(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor( - post(urlPathEqualTo("/v2.0/tokens")) + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_UNAUTHORIZED))); + .withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_UNAUTHORIZED))); } public static void mockOpenStackDelete(WireMockServer wireMockServer, String id) { - wireMockServer.stubFor(delete(urlMatching("/mockPublicUrl/stacks/" + id)).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(delete(urlMatching("/mockPublicUrl/stacks/" + id)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); } public static void mockOpenStackGet(WireMockServer wireMockServer, String id) { - wireMockServer.stubFor( - get(urlPathEqualTo("/mockPublicUrl/stacks/" + id)) + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + id)) .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack_Created.json") - .withStatus(HttpStatus.SC_OK))); + .withBodyFile("OpenstackResponse_Stack_Created.json").withStatus(HttpStatus.SC_OK))); } public static void mockOpenStackPostStack_200(WireMockServer wireMockServer, String filename) { wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile(filename).withStatus(HttpStatus.SC_OK))); + .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK))); } public static void mockOpenStackPostTenantWithBodyFile_200(WireMockServer wireMockServer) throws IOException { @@ -79,7 +73,8 @@ public class StubOpenStack { .willReturn(aResponse().withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK))); } - public static void mockOpenStackGetTenantByName(WireMockServer wireMockServer, String tenantName) throws IOException { + public static void mockOpenStackGetTenantByName(WireMockServer wireMockServer, String tenantName) + throws IOException { wireMockServer.stubFor(get(urlMatching("/mockPublicUrl/tenants/[?]name=" + tenantName)) .willReturn(aResponse().withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK))); } @@ -90,55 +85,53 @@ public class StubOpenStack { } public static void mockOpenStackDeleteTenantById_200(WireMockServer wireMockServer, String tenantId) { - wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); } public static void mockOpenStackGetUserById(WireMockServer wireMockServer, String user) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/users/" + user)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/users/" + user)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK))); } public static void mockOpenStackGetUserByName(WireMockServer wireMockServer, String userName) { - wireMockServer.stubFor(get(urlMatching("/mockPublicUrl/users/[?]name=" + userName)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlMatching("/mockPublicUrl/users/[?]name=" + userName)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK))); } public static void mockOpenStackGetUserByName_500(WireMockServer wireMockServer, String userName) { - wireMockServer.stubFor(get(urlMatching("/mockPublicUrl/users/[?]name=" + userName)).willReturn(aResponse() - .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); + wireMockServer.stubFor(get(urlMatching("/mockPublicUrl/users/[?]name=" + userName)) + .willReturn(aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); } public static void mockOpenStackGetRoles_200(WireMockServer wireMockServer, String roleFor) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/" + roleFor + "/roles")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Roles.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/" + roleFor + "/roles")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_Roles.json").withStatus(HttpStatus.SC_OK))); } public static void mockOpenstackPostNetwork(WireMockServer wireMockServer, String responseFile) { - wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile(responseFile) - .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/v2.0/networks")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile(responseFile) + .withStatus(HttpStatus.SC_OK))); } public static void mockOpenstackPutNetwork(WireMockServer wireMockServer, String responseFile, String networkId) { - wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkId)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile(responseFile) - .withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetNeutronNetwork(WireMockServer wireMockServer, String filename,String networkId) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId)) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile(filename).withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile(responseFile) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetNeutronNetwork(WireMockServer wireMockServer, String filename, + String networkId) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK))); } public static void mockOpenStackGetNeutronNetwork_500(WireMockServer wireMockServer, String networkId) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId)) + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)) .willReturn(aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); } @@ -162,6 +155,7 @@ public class StubOpenStack { } public static String getBodyFromFile(String fileName, int port, String urlPath) throws IOException { - return readFile("src/test/resources/__files/" + fileName).replaceAll("port", "http://localhost:" + port + urlPath); + return readFile("src/test/resources/__files/" + fileName).replaceAll("port", + "http://localhost:" + port + urlPath); } } |