diff options
author | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-04-08 14:14:34 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-04-08 14:24:59 -0400 |
commit | f47919f1fe367b612fa9c96d34c59f01a541e882 (patch) | |
tree | 5b6aa2fc36747d868897e68ccbec0c6db0aee81c /cloudify-client/src/test/java/org | |
parent | 54452b80a1cf4d22ef750bc1377f8c1b05431d57 (diff) |
Replaced all tabs with spaces in java and pom.xml
Added in maven plugins to enforce coding style rules
Added in eclipse java formatting xml
Change-Id: I3727bbf4ce8dc66abfd8ad21b6cfd0890c5d3ff0
Issue-ID: SO-1765
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'cloudify-client/src/test/java/org')
9 files changed, 694 insertions, 699 deletions
diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java index d38c7468db..4028b71109 100644 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java @@ -19,9 +19,9 @@ */ package org.onap.so.cloudify; + import org.junit.Before; import org.junit.Test; - import com.openpojo.reflection.PojoClass; import com.openpojo.reflection.PojoClassFilter; import com.openpojo.reflection.filters.FilterEnum; @@ -35,29 +35,26 @@ import com.openpojo.validation.test.impl.SetterTester; public class BeanMultiTest { - Validator validator; - PojoClassFilter enumFilter; - private PojoClassFilter filterTestClasses = new FilterTestClasses(); - - @Before - public void setup(){ - enumFilter = new FilterEnum(); - validator = ValidatorBuilder.create() - .with(new SetterMustExistRule(), - new GetterMustExistRule()) - .with(new SetterTester(), - new GetterTester()) - .build(); - } - @Test - public void validateBeansMsoApihandlerBeans() { - - validator.validate("org.onap.so.cloudify.v3.model",enumFilter); - } - - private static class FilterTestClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.getSourcePath().contains("/src/test/java"); - } - } + Validator validator; + PojoClassFilter enumFilter; + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + @Before + public void setup() { + enumFilter = new FilterEnum(); + validator = ValidatorBuilder.create().with(new SetterMustExistRule(), new GetterMustExistRule()) + .with(new SetterTester(), new GetterTester()).build(); + } + + @Test + public void validateBeansMsoApihandlerBeans() { + + validator.validate("org.onap.so.cloudify.v3.model", enumFilter); + } + + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/src/test/java"); + } + } } diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java index fc55eaf19c..88974acb11 100644 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java @@ -25,79 +25,83 @@ import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.junit.Assert.assertEquals; - import org.apache.http.HttpStatus; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.onap.so.cloudify.v3.model.Execution; - import com.github.tomakehurst.wiremock.junit.WireMockRule; public class CloudifyClientTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); - @Test - public void clientCreate(){ - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - CloudifyClient cc = new CloudifyClient("http://localhost:"+port); - cc.setToken("token"); - CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class); - Execution x = crx.execute(); - assertEquals("123", x.getId()); - } + @Test + public void clientCreate() { + wireMockRule.stubFor( + get(urlPathEqualTo("/testUrl")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + CloudifyClient cc = new CloudifyClient("http://localhost:" + port); + cc.setToken("token"); + CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class); + Execution x = crx.execute(); + assertEquals("123", x.getId()); + } - @Test - public void clientCreateWithBadConnector(){ - thrown.expect(CloudifyResponseException.class); - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - CloudifyClientConnector ccc = new CloudifyClientConnector(){ - @Override - public <T> CloudifyResponse request(CloudifyRequest<T> request) { - throw new CloudifyResponseException("test case", 401); - }}; - CloudifyClient cc = new CloudifyClient("http://localhost:"+port, ccc); -// cc.setToken("token"); - CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class); - Execution x = crx.execute(); - } + @Test + public void clientCreateWithBadConnector() { + thrown.expect(CloudifyResponseException.class); + wireMockRule.stubFor( + get(urlPathEqualTo("/testUrl")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + CloudifyClientConnector ccc = new CloudifyClientConnector() { + @Override + public <T> CloudifyResponse request(CloudifyRequest<T> request) { + throw new CloudifyResponseException("test case", 401); + } + }; + CloudifyClient cc = new CloudifyClient("http://localhost:" + port, ccc); + // cc.setToken("token"); + CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class); + Execution x = crx.execute(); + } - @Test - public void clientCreateWithBadConnectorAndToken(){ - thrown.expect(CloudifyResponseException.class); - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - CloudifyClientConnector ccc = new CloudifyClientConnector(){ - @Override - public <T> CloudifyResponse request(CloudifyRequest<T> request) { - throw new CloudifyResponseException("test case", 401); - }}; - CloudifyClient cc = new CloudifyClient("http://localhost:"+port, ccc); - cc.setToken("token"); - CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class); - Execution x = crx.execute(); - } + @Test + public void clientCreateWithBadConnectorAndToken() { + thrown.expect(CloudifyResponseException.class); + wireMockRule.stubFor( + get(urlPathEqualTo("/testUrl")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + CloudifyClientConnector ccc = new CloudifyClientConnector() { + @Override + public <T> CloudifyResponse request(CloudifyRequest<T> request) { + throw new CloudifyResponseException("test case", 401); + } + }; + CloudifyClient cc = new CloudifyClient("http://localhost:" + port, ccc); + cc.setToken("token"); + CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class); + Execution x = crx.execute(); + } - @Test - public void clientCreateWithTenant(){ - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - CloudifyClient cc = new CloudifyClient("http://localhost:"+port, "other_tenant"); - cc.setToken("token"); - cc.property("property", "value"); - CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class); - Execution x = crx.execute(); - assertEquals("123", x.getId()); - } + @Test + public void clientCreateWithTenant() { + wireMockRule.stubFor( + get(urlPathEqualTo("/testUrl")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + CloudifyClient cc = new CloudifyClient("http://localhost:" + port, "other_tenant"); + cc.setToken("token"); + cc.property("property", "value"); + CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class); + Execution x = crx.execute(); + assertEquals("123", x.getId()); + } } diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java index ba43dc9e78..77152a2dd0 100644 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java @@ -25,32 +25,32 @@ import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.junit.Assert.assertEquals; - import org.apache.http.HttpStatus; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; - import com.github.tomakehurst.wiremock.junit.WireMockRule; public class CloudifyClientTokenProviderTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); - @Test - public void createTokenProvider() { - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl/api/v3/tokens")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("{\"role\": \"user\", \"value\": \"tokenVal\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); + @Test + public void createTokenProvider() { + wireMockRule.stubFor(get(urlPathEqualTo("/testUrl/api/v3/tokens")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"role\": \"user\", \"value\": \"tokenVal\"}").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); - CloudifyClientTokenProvider cctp = new CloudifyClientTokenProvider("http://localhost:"+port+"/testUrl", "user", "pswd"); - String token = cctp.getToken(); - assertEquals("tokenVal", token); - token = cctp.getToken(); - assertEquals("tokenVal", token); - cctp.expireToken(); - } + CloudifyClientTokenProvider cctp = + new CloudifyClientTokenProvider("http://localhost:" + port + "/testUrl", "user", "pswd"); + String token = cctp.getToken(); + assertEquals("tokenVal", token); + token = cctp.getToken(); + assertEquals("tokenVal", token); + cctp.expireToken(); + } } diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java index 4475fff093..c85b88f7f3 100644 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java @@ -24,7 +24,6 @@ import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; - import com.github.tomakehurst.wiremock.http.Fault; import com.github.tomakehurst.wiremock.junit.WireMockRule; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -43,11 +42,9 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.assertEquals; - import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; - import org.onap.so.cloudify.base.client.CloudifyConnectException; import org.onap.so.cloudify.base.client.CloudifyRequest; import org.onap.so.cloudify.base.client.CloudifyResponseException; @@ -56,199 +53,203 @@ import org.onap.so.cloudify.base.client.HttpMethod; import org.onap.so.cloudify.v3.model.Deployment; public class HttpClientConnectorTest { - - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void sunnyDay_POST(){ - wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - Deployment deployment = new Deployment(); - deployment.setId("id"); - request.entity(deployment, "application/json"); - request.endpoint("http://localhost:"+port+"/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.header("Content-Type","application/json"); - request.method(HttpMethod.POST); - conector.request(request); - verify(postRequestedFor(urlEqualTo("/testUrl"))); - } - - - @Test - public void sunnyDay_GET(){ - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:"+port+"/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.GET); - conector.request(request); - verify(getRequestedFor(urlEqualTo("/testUrl"))); - } - - @Test - public void sunnyDay_PUT(){ - wireMockRule.stubFor(put(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:"+port+"/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.PUT); - conector.request(request); - verify(putRequestedFor(urlEqualTo("/testUrl"))); - } - - - @Test - public void sunnyDay_DELETE(){ - wireMockRule.stubFor(delete(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:"+port+"/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.DELETE); - conector.request(request); - verify(deleteRequestedFor(urlEqualTo("/testUrl"))); - } - - - @Test - public void rainyDay_PATCH(){ - thrown.expect(HttpClientException.class); - thrown.expectMessage("Unrecognized HTTP Method: PATCH"); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:123123/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.PATCH); - conector.request(request); - - } - - @Test - public void rainyDayRunTimeException(){ - wireMockRule.stubFor(post(urlEqualTo("/503")).willReturn( - aResponse().withStatus(503).withHeader("Content-Type", "text/plain").withBody("failure"))); - thrown.expect(RuntimeException.class); - thrown.expectMessage("Unexpected client exception"); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:123123/503"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.POST); - conector.request(request); - - } - - @Test - public void rainyDayBadUri() { - wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - thrown.expect(HttpClientException.class); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - Deployment deployment = new Deployment(); - deployment.setId("id"); - request.entity(deployment, "application/json"); - request.endpoint("(@#$@(#*$&asfasdf"); - request.setBasicAuthentication("USER","PASSWORD"); - request.header("Content-Type","application/json"); - request.method(HttpMethod.POST); - conector.request(request); - } - - @Test - public void sunnyDayWithJsonEntity_POST(){ - wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - - Deployment deployment = new Deployment(); - deployment.setId("id"); - - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(null, HttpMethod.POST, "/", Entity.json(deployment), null); - - request.endpoint("http://localhost:"+port); - request.path("testUrl"); - request.header("Content-Type","application/json"); - request.header("Content-Type", null); - - request.returnType(Deployment.class); - assertEquals(Deployment.class, request.returnType()); - - Entity<Deployment> t = request.json(deployment); - assertEquals(t.getEntity().getId(), "id"); - - request.queryParam("test", "one").queryParam("test", "two"); - - conector.request(request); - - verify(postRequestedFor(urlEqualTo("/testUrl?test=two"))); - } - - @Test - public void sunnyDayWithStreamEntity_POST() { - wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - - InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)); - - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(null, HttpMethod.POST, "/testUrl", Entity.stream(is), null); - - request.endpoint("http://localhost:"+port); - request.setBasicAuthentication("USER","PASSWORD"); - request.header("Content-Type","application/json"); - - conector.request(request); - verify(postRequestedFor(urlEqualTo("/testUrl"))); - } - - @Test - public void rainyDayGarbageData(){ - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn( - aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE))); - thrown.expect(CloudifyConnectException.class); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:"+port+"/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.GET); - conector.request(request); - } - - @Test - public void rainyDayEmptyResponse(){ - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_NOT_FOUND))); - - thrown.expect(HttpClientException.class); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:"+port+"/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.GET); - conector.request(request); // gets down to "Get here on an error response (4XX-5XX)", then tries to throw a CloudifyResponseException, which calls getEntity, which tries to parse an HTML error page as a JSON, which causes the HttpClientException. - } - - -}
\ No newline at end of file + + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void sunnyDay_POST() { + wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); + Deployment deployment = new Deployment(); + deployment.setId("id"); + request.entity(deployment, "application/json"); + request.endpoint("http://localhost:" + port + "/testUrl"); + request.setBasicAuthentication("USER", "PASSWORD"); + request.header("Content-Type", "application/json"); + request.method(HttpMethod.POST); + conector.request(request); + verify(postRequestedFor(urlEqualTo("/testUrl"))); + } + + + @Test + public void sunnyDay_GET() { + wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); + request.endpoint("http://localhost:" + port + "/testUrl"); + request.setBasicAuthentication("USER", "PASSWORD"); + request.method(HttpMethod.GET); + conector.request(request); + verify(getRequestedFor(urlEqualTo("/testUrl"))); + } + + @Test + public void sunnyDay_PUT() { + wireMockRule.stubFor(put(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); + request.endpoint("http://localhost:" + port + "/testUrl"); + request.setBasicAuthentication("USER", "PASSWORD"); + request.method(HttpMethod.PUT); + conector.request(request); + verify(putRequestedFor(urlEqualTo("/testUrl"))); + } + + + @Test + public void sunnyDay_DELETE() { + wireMockRule.stubFor(delete(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); + request.endpoint("http://localhost:" + port + "/testUrl"); + request.setBasicAuthentication("USER", "PASSWORD"); + request.method(HttpMethod.DELETE); + conector.request(request); + verify(deleteRequestedFor(urlEqualTo("/testUrl"))); + } + + + @Test + public void rainyDay_PATCH() { + thrown.expect(HttpClientException.class); + thrown.expectMessage("Unrecognized HTTP Method: PATCH"); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); + request.endpoint("http://localhost:123123/testUrl"); + request.setBasicAuthentication("USER", "PASSWORD"); + request.method(HttpMethod.PATCH); + conector.request(request); + + } + + @Test + public void rainyDayRunTimeException() { + wireMockRule.stubFor(post(urlEqualTo("/503")) + .willReturn(aResponse().withStatus(503).withHeader("Content-Type", "text/plain").withBody("failure"))); + thrown.expect(RuntimeException.class); + thrown.expectMessage("Unexpected client exception"); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); + request.endpoint("http://localhost:123123/503"); + request.setBasicAuthentication("USER", "PASSWORD"); + request.method(HttpMethod.POST); + conector.request(request); + + } + + @Test + public void rainyDayBadUri() { + wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + thrown.expect(HttpClientException.class); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); + Deployment deployment = new Deployment(); + deployment.setId("id"); + request.entity(deployment, "application/json"); + request.endpoint("(@#$@(#*$&asfasdf"); + request.setBasicAuthentication("USER", "PASSWORD"); + request.header("Content-Type", "application/json"); + request.method(HttpMethod.POST); + conector.request(request); + } + + @Test + public void sunnyDayWithJsonEntity_POST() { + wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + + Deployment deployment = new Deployment(); + deployment.setId("id"); + + CloudifyRequest<Deployment> request = + new CloudifyRequest<Deployment>(null, HttpMethod.POST, "/", Entity.json(deployment), null); + + request.endpoint("http://localhost:" + port); + request.path("testUrl"); + request.header("Content-Type", "application/json"); + request.header("Content-Type", null); + + request.returnType(Deployment.class); + assertEquals(Deployment.class, request.returnType()); + + Entity<Deployment> t = request.json(deployment); + assertEquals(t.getEntity().getId(), "id"); + + request.queryParam("test", "one").queryParam("test", "two"); + + conector.request(request); + + verify(postRequestedFor(urlEqualTo("/testUrl?test=two"))); + } + + @Test + public void sunnyDayWithStreamEntity_POST() { + wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + + InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)); + + CloudifyRequest<Deployment> request = + new CloudifyRequest<Deployment>(null, HttpMethod.POST, "/testUrl", Entity.stream(is), null); + + request.endpoint("http://localhost:" + port); + request.setBasicAuthentication("USER", "PASSWORD"); + request.header("Content-Type", "application/json"); + + conector.request(request); + verify(postRequestedFor(urlEqualTo("/testUrl"))); + } + + @Test + public void rainyDayGarbageData() { + wireMockRule.stubFor( + get(urlPathEqualTo("/testUrl")).willReturn(aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE))); + thrown.expect(CloudifyConnectException.class); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); + request.endpoint("http://localhost:" + port + "/testUrl"); + request.setBasicAuthentication("USER", "PASSWORD"); + request.method(HttpMethod.GET); + conector.request(request); + } + + @Test + public void rainyDayEmptyResponse() { + wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_NOT_FOUND))); + + thrown.expect(HttpClientException.class); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); + request.endpoint("http://localhost:" + port + "/testUrl"); + request.setBasicAuthentication("USER", "PASSWORD"); + request.method(HttpMethod.GET); + conector.request(request); // gets down to "Get here on an error response (4XX-5XX)", then tries to throw a + // CloudifyResponseException, which calls getEntity, which tries to parse an HTML + // error page as a JSON, which causes the HttpClientException. + } + + +} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java index 87b51e9357..6010726669 100644 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java @@ -1,20 +1,15 @@ /* - * ============LICENSE_START======================================================= - * ONAP : SO - * ================================================================================ - * Copyright (C) 2018 Nokia. - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * ============LICENSE_START======================================================= ONAP : SO + * ================================================================================ Copyright (C) 2018 Nokia. + * ============================================================================= Licensed under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy + * of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. * ============LICENSE_END========================================================= */ package org.onap.so.cloudify.connector.http; @@ -23,7 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; - import java.net.URI; import java.net.URISyntaxException; import org.apache.http.HttpRequest; @@ -73,7 +67,7 @@ public class HttpClientRedirectStrategyTest { } private void assertHttpUriRequestFor(String methodName, Class<? extends HttpUriRequest> expectedHttpMethodClass) - throws URISyntaxException, ProtocolException { + throws URISyntaxException, ProtocolException { // GIVEN HttpRequest request = mock(HttpRequest.class, RETURNS_DEEP_STUBS); given(request.getRequestLine().getMethod()).willReturn(methodName); @@ -81,8 +75,8 @@ public class HttpClientRedirectStrategyTest { HttpContext context = null; URI expectedUri = new URI("http://localhost/host"); // WHEN - HttpUriRequest httpUriRequest = new TestableHttpClientRedirectStrategy(expectedUri) - .getRedirect(request, response, context); + HttpUriRequest httpUriRequest = + new TestableHttpClientRedirectStrategy(expectedUri).getRedirect(request, response, context); // THEN assertThat(httpUriRequest).isInstanceOf(expectedHttpMethodClass); assertThat(httpUriRequest.getURI()).isEqualTo(expectedUri); @@ -98,20 +92,22 @@ public class HttpClientRedirectStrategyTest { URI expectedUri = new URI("http://localhost/host"); HttpContext context = null; // WHEN - HttpUriRequest httpUriRequest = new TestableHttpClientRedirectStrategy(expectedUri) - .getRedirect(request, response, context); + HttpUriRequest httpUriRequest = + new TestableHttpClientRedirectStrategy(expectedUri).getRedirect(request, response, context); // THEN assertThat(httpUriRequest).isInstanceOf(HttpGet.class); assertThat(httpUriRequest.getURI()).isEqualTo(expectedUri); } @Test - public void getRedirect_shouldCopyHttpRequestAndSetNewUri_forMovedTemporarilyStatus() throws URISyntaxException, ProtocolException { + public void getRedirect_shouldCopyHttpRequestAndSetNewUri_forMovedTemporarilyStatus() + throws URISyntaxException, ProtocolException { assertHttpRequestIsCopied(HttpStatus.SC_MOVED_TEMPORARILY); } @Test - public void getRedirect_shouldCopyHttpRequestAndSetNewUri_forTemporaryRedirectStatus() throws URISyntaxException, ProtocolException { + public void getRedirect_shouldCopyHttpRequestAndSetNewUri_forTemporaryRedirectStatus() + throws URISyntaxException, ProtocolException { assertHttpRequestIsCopied(HttpStatus.SC_TEMPORARY_REDIRECT); } @@ -125,8 +121,8 @@ public class HttpClientRedirectStrategyTest { URI expectedUri = new URI("http://localhost/host"); HttpContext context = null; // WHEN - HttpUriRequest httpUriRequest = new TestableHttpClientRedirectStrategy(expectedUri) - .getRedirect(request, response, context); + HttpUriRequest httpUriRequest = + new TestableHttpClientRedirectStrategy(expectedUri).getRedirect(request, response, context); // THEN assertThat(httpUriRequest).isInstanceOf(HttpGet.class); assertThat(httpUriRequest.getURI()).isEqualTo(expectedUri); @@ -139,9 +135,10 @@ public class HttpClientRedirectStrategyTest { public TestableHttpClientRedirectStrategy(URI expectedUri) { this.expectedUri = expectedUri; } + @Override public URI getLocationURI(HttpRequest request, HttpResponse response, HttpContext context) { return expectedUri; } } -}
\ No newline at end of file +} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java index 6155cf287c..cba3bf8fdc 100644 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java @@ -27,11 +27,9 @@ import static com.github.tomakehurst.wiremock.client.WireMock.put; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.junit.Assert.assertEquals; - import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; - import org.apache.http.HttpStatus; import org.junit.Rule; import org.junit.Test; @@ -42,106 +40,105 @@ import org.onap.so.cloudify.v3.client.BlueprintsResource.ListBlueprints; import org.onap.so.cloudify.v3.client.BlueprintsResource.UploadBlueprint; import org.onap.so.cloudify.v3.model.Blueprint; import org.onap.so.cloudify.v3.model.Blueprints; - import com.github.tomakehurst.wiremock.junit.WireMockRule; public class BlueprintsResourceTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void cloudifyClientBlueprintFromStream() { - wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - BlueprintsResource br = c.blueprints(); - InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)); - UploadBlueprint ub = br.uploadFromStream("123", "blueprint.json", is); - Blueprint b = ub.execute(); - assertEquals("123", b.getId()); - } - - @Test - public void cloudifyClientBlueprintFromUrl() { - wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - BlueprintsResource br = c.blueprints(); - UploadBlueprint ub = br.uploadFromUrl("123", "blueprint.json", "http://localhost:"+port+"/blueprint"); - Blueprint b = ub.execute(); - assertEquals("123", b.getId()); - } - - @Test - public void cloudifyClientBlueprintDelete() { - wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - BlueprintsResource br = c.blueprints(); - DeleteBlueprint db = br.deleteById("123"); - Blueprint b = db.execute(); - assertEquals("123", b.getId()); - } - - @Test - public void cloudifyClientBlueprintList() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"items\": [{\"id\": \"123\"}]}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - BlueprintsResource br = c.blueprints(); - ListBlueprints lb = br.list(); - Blueprints b = lb.execute(); - assertEquals("123", b.getItems().get(0).getId()); - } - - @Test - public void cloudifyClientBlueprintGetById() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - BlueprintsResource br = c.blueprints(); - GetBlueprint gb = br.getById("123"); - Blueprint b = gb.execute(); - assertEquals("123", b.getId()); - } - - @Test - public void cloudifyClientBlueprintGetMetadataById() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - BlueprintsResource br = c.blueprints(); - GetBlueprint gb = br.getMetadataById("123"); - Blueprint b = gb.execute(); - assertEquals("123", b.getId()); - } + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void cloudifyClientBlueprintFromStream() { + wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/123")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + BlueprintsResource br = c.blueprints(); + InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)); + UploadBlueprint ub = br.uploadFromStream("123", "blueprint.json", is); + Blueprint b = ub.execute(); + assertEquals("123", b.getId()); + } + + @Test + public void cloudifyClientBlueprintFromUrl() { + wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/123")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + BlueprintsResource br = c.blueprints(); + UploadBlueprint ub = br.uploadFromUrl("123", "blueprint.json", "http://localhost:" + port + "/blueprint"); + Blueprint b = ub.execute(); + assertEquals("123", b.getId()); + } + + @Test + public void cloudifyClientBlueprintDelete() { + wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/blueprints/123")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + BlueprintsResource br = c.blueprints(); + DeleteBlueprint db = br.deleteById("123"); + Blueprint b = db.execute(); + assertEquals("123", b.getId()); + } + + @Test + public void cloudifyClientBlueprintList() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"items\": [{\"id\": \"123\"}]}").withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + BlueprintsResource br = c.blueprints(); + ListBlueprints lb = br.list(); + Blueprints b = lb.execute(); + assertEquals("123", b.getItems().get(0).getId()); + } + + @Test + public void cloudifyClientBlueprintGetById() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/123")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + BlueprintsResource br = c.blueprints(); + GetBlueprint gb = br.getById("123"); + Blueprint b = gb.execute(); + assertEquals("123", b.getId()); + } + + @Test + public void cloudifyClientBlueprintGetMetadataById() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/123")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + BlueprintsResource br = c.blueprints(); + GetBlueprint gb = br.getMetadataById("123"); + Blueprint b = gb.execute(); + assertEquals("123", b.getId()); + } } diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java index 071b7638e6..2acd4ba5a3 100644 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java @@ -28,10 +28,8 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; - import java.util.HashMap; import java.util.Map; - import org.apache.http.HttpStatus; import org.junit.Rule; import org.junit.Test; @@ -45,104 +43,103 @@ import org.onap.so.cloudify.v3.model.CreateDeploymentParams; import org.onap.so.cloudify.v3.model.Deployment; import org.onap.so.cloudify.v3.model.Deployments; import org.onap.so.cloudify.v3.model.DeploymentOutputs; - import com.github.tomakehurst.wiremock.junit.WireMockRule; public class DeploymentsResourceTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void cloudifyDeploymentsCreate() { - wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/deployments/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - DeploymentsResource br = c.deployments(); - - CreateDeploymentParams cdp = new CreateDeploymentParams(); - cdp.setBlueprintId("123"); - Map<String, Object> inputs = new HashMap<String, Object>(); - cdp.setInputs(inputs); - CreateDeployment cd = br.create("123", cdp); - Deployment d = cd.execute(); - assertEquals("123", d.getId()); - } - - @Test - public void cloudifyDeploymentsList() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"items\": {\"id\": \"123\" } } ") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - DeploymentsResource br = c.deployments(); - ListDeployments ld = br.list(); - Deployments d = ld.execute(); - assertEquals("123", d.getItems().get(0).getId()); - } - - @Test - public void cloudifyDeploymentsGet() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - DeploymentsResource br = c.deployments(); - GetDeployment gd = br.byId("123"); - Deployment d = gd.execute(); - assertEquals("123", d.getId()); - } - - @Test - public void cloudifyDeploymentsGetOutputs() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123/outputs")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"deployment_id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - DeploymentsResource br = c.deployments(); - GetDeploymentOutputs gdo = br.outputsById("123"); - DeploymentOutputs d = gdo.execute(); - assertEquals("123", d.getDeploymentId()); - - Map<String, Object> map = new HashMap<String, Object>(); - map.put("test", "answer"); - assertEquals("answer", d.getMapValue(map, "test", String.class)); - - Integer i = d.getMapValue(map, "nil", Integer.class); - assertNull( i ); - - i = d.getMapValue(map, "test", Integer.class); - assertNull( i ); - } - - @Test - public void cloudifyDeploymentsDelete() { - wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/deployments/name")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - DeploymentsResource br = c.deployments(); - DeleteDeployment cd = br.deleteByName("name"); - Deployment d = cd.execute(); - assertEquals("123", d.getId()); - } + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void cloudifyDeploymentsCreate() { + wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/deployments/123")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + DeploymentsResource br = c.deployments(); + + CreateDeploymentParams cdp = new CreateDeploymentParams(); + cdp.setBlueprintId("123"); + Map<String, Object> inputs = new HashMap<String, Object>(); + cdp.setInputs(inputs); + CreateDeployment cd = br.create("123", cdp); + Deployment d = cd.execute(); + assertEquals("123", d.getId()); + } + + @Test + public void cloudifyDeploymentsList() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"items\": {\"id\": \"123\" } } ").withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + DeploymentsResource br = c.deployments(); + ListDeployments ld = br.list(); + Deployments d = ld.execute(); + assertEquals("123", d.getItems().get(0).getId()); + } + + @Test + public void cloudifyDeploymentsGet() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + DeploymentsResource br = c.deployments(); + GetDeployment gd = br.byId("123"); + Deployment d = gd.execute(); + assertEquals("123", d.getId()); + } + + @Test + public void cloudifyDeploymentsGetOutputs() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123/outputs")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"deployment_id\": \"123\" }").withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + DeploymentsResource br = c.deployments(); + GetDeploymentOutputs gdo = br.outputsById("123"); + DeploymentOutputs d = gdo.execute(); + assertEquals("123", d.getDeploymentId()); + + Map<String, Object> map = new HashMap<String, Object>(); + map.put("test", "answer"); + assertEquals("answer", d.getMapValue(map, "test", String.class)); + + Integer i = d.getMapValue(map, "nil", Integer.class); + assertNull(i); + + i = d.getMapValue(map, "test", Integer.class); + assertNull(i); + } + + @Test + public void cloudifyDeploymentsDelete() { + wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/deployments/name")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + DeploymentsResource br = c.deployments(); + DeleteDeployment cd = br.deleteByName("name"); + Deployment d = cd.execute(); + assertEquals("123", d.getId()); + } } diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java index 098b5cf387..7b63c6eecb 100644 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java @@ -27,7 +27,6 @@ import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.junit.Assert.assertEquals; - import org.apache.http.HttpStatus; import org.junit.Rule; import org.junit.Test; @@ -42,129 +41,134 @@ import org.onap.so.cloudify.v3.model.CancelExecutionParams; import org.onap.so.cloudify.v3.model.Execution; import org.onap.so.cloudify.v3.model.Executions; import org.onap.so.cloudify.v3.model.StartExecutionParams; - import com.github.tomakehurst.wiremock.junit.WireMockRule; public class ExecutionsResourceTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void cloudifyClientExecutions() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"items\": [{ \"id\": \"345\" }, { \"id\": \"123\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - ListExecutions lx = xr.list(); - Executions x = lx.execute(); - assertEquals("123", x.getItems().get(1).getId()); - } - - @Test - public void cloudifyClientExecutionsSorted() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"items\": [{ \"id\": \"123\" }, { \"id\": \"345\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - ListExecutions lx = xr.listSorted("id"); - Executions x = lx.execute(); - assertEquals("345", x.getItems().get(1).getId()); - } - - @Test - public void cloudifyClientExecutionsFilter() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"items\": [{ \"id\": \"121\" }, { \"id\": \"123\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - ListExecutions lx = xr.listFiltered("a=b", "id"); - Executions x = lx.execute(); - assertEquals("123", x.getItems().get(1).getId()); - } - - @Test - public void cloudifyClientExecutionById() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - GetExecution gx = xr.byId("123"); - Execution x = gx.execute(); - assertEquals("123", x.getId()); - } - - @Test - public void cloudifyClientStartExecution() { - wireMockRule.stubFor(post(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - - StartExecutionParams params = new StartExecutionParams(); - StartExecution sx = xr.start(params); - Execution x = sx.execute(); - assertEquals("123", x.getId()); - } - - @Test - public void cloudifyClientUpdateExecution() { - thrown.expect(HttpClientException.class); - thrown.expectMessage("Unrecognized HTTP Method: PATCH"); - - wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - - UpdateExecution ux = xr.updateStatus("123", "good"); - Execution x = ux.execute(); - assertEquals("123", x.getId()); - } - - @Test - public void cloudifyClientCancelExecution() { - wireMockRule.stubFor(post(urlPathEqualTo("/api/v3/executions/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - - CancelExecutionParams params = new CancelExecutionParams(); - CancelExecution cx = xr.cancel("123", params); - Execution x = cx.execute(); - assertEquals("123", x.getId()); - } - - + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void cloudifyClientExecutions() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse() + .withHeader("Content-Type", "application/json") + .withBody( + "{\"items\": [{ \"id\": \"345\" }, { \"id\": \"123\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + ExecutionsResource xr = c.executions(); + ListExecutions lx = xr.list(); + Executions x = lx.execute(); + assertEquals("123", x.getItems().get(1).getId()); + } + + @Test + public void cloudifyClientExecutionsSorted() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse() + .withHeader("Content-Type", "application/json") + .withBody( + "{\"items\": [{ \"id\": \"123\" }, { \"id\": \"345\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + ExecutionsResource xr = c.executions(); + ListExecutions lx = xr.listSorted("id"); + Executions x = lx.execute(); + assertEquals("345", x.getItems().get(1).getId()); + } + + @Test + public void cloudifyClientExecutionsFilter() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse() + .withHeader("Content-Type", "application/json") + .withBody( + "{\"items\": [{ \"id\": \"121\" }, { \"id\": \"123\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + ExecutionsResource xr = c.executions(); + ListExecutions lx = xr.listFiltered("a=b", "id"); + Executions x = lx.execute(); + assertEquals("123", x.getItems().get(1).getId()); + } + + @Test + public void cloudifyClientExecutionById() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions/123")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + ExecutionsResource xr = c.executions(); + GetExecution gx = xr.byId("123"); + Execution x = gx.execute(); + assertEquals("123", x.getId()); + } + + @Test + public void cloudifyClientStartExecution() { + wireMockRule.stubFor(post(urlPathEqualTo("/api/v3/executions")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + ExecutionsResource xr = c.executions(); + + StartExecutionParams params = new StartExecutionParams(); + StartExecution sx = xr.start(params); + Execution x = sx.execute(); + assertEquals("123", x.getId()); + } + + @Test + public void cloudifyClientUpdateExecution() { + thrown.expect(HttpClientException.class); + thrown.expectMessage("Unrecognized HTTP Method: PATCH"); + + wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/executions")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + ExecutionsResource xr = c.executions(); + + UpdateExecution ux = xr.updateStatus("123", "good"); + Execution x = ux.execute(); + assertEquals("123", x.getId()); + } + + @Test + public void cloudifyClientCancelExecution() { + wireMockRule.stubFor(post(urlPathEqualTo("/api/v3/executions/123")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + ExecutionsResource xr = c.executions(); + + CancelExecutionParams params = new CancelExecutionParams(); + CancelExecution cx = xr.cancel("123", params); + Execution x = cx.execute(); + assertEquals("123", x.getId()); + } + + } diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java index c5f3be4ce2..d38d0401c3 100644 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java @@ -26,7 +26,6 @@ import static com.github.tomakehurst.wiremock.client.WireMock.patch; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static org.junit.Assert.assertEquals; - import org.apache.http.HttpStatus; import org.junit.Rule; import org.junit.Test; @@ -38,61 +37,60 @@ import org.onap.so.cloudify.v3.client.NodeInstancesResource.UpdateNodeInstance; import org.onap.so.cloudify.v3.model.NodeInstance; import org.onap.so.cloudify.v3.model.NodeInstances; import org.onap.so.cloudify.v3.model.UpdateNodeInstanceParams; - import com.github.tomakehurst.wiremock.junit.WireMockRule; public class NodeInstancesResourceTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void nodeInstanceGet() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances/123")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"node_instance\": { \"id\": \"123\" } }").withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + NodeInstancesResource nir = c.nodeInstances(); + GetNodeInstance gni = nir.byId("123"); + NodeInstance ni = gni.execute(); + assertEquals("123", ni.getId()); + } + + @Test + public void nodeInstanceList() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + // .withBody(" { \"items\": [ { \"node_instance\": { \"id\": \"123\" } } ] } ") + .withBody(" { \"items\": [ { \"id\": \"123\" } ] } ").withStatus(HttpStatus.SC_OK))); - @Test - public void nodeInstanceGet() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"node_instance\": { \"id\": \"123\" } }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); + int port = wireMockRule.port(); - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - NodeInstancesResource nir = c.nodeInstances(); - GetNodeInstance gni = nir.byId("123"); - NodeInstance ni = gni.execute(); - assertEquals("123", ni.getId()); - } + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + NodeInstancesResource nir = c.nodeInstances(); + ListNodeInstances lni = nir.list(); + NodeInstances ni = lni.execute(); + assertEquals("123", ni.getItems().get(0).getId()); + } - @Test - public void nodeInstanceList() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances")).willReturn(aResponse().withHeader("Content-Type", "application/json") -// .withBody(" { \"items\": [ { \"node_instance\": { \"id\": \"123\" } } ] } ") - .withBody(" { \"items\": [ { \"id\": \"123\" } ] } ") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); + @Test + public void nodeInstanceUpdate() { + wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/node-instances/")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"node_instance\": { \"id\": \"123\" } }").withStatus(HttpStatus.SC_OK))); - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - NodeInstancesResource nir = c.nodeInstances(); - ListNodeInstances lni = nir.list(); - NodeInstances ni = lni.execute(); - assertEquals("123", ni.getItems().get(0).getId()); - } - - @Test - public void nodeInstanceUpdate() { - wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/node-instances/")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"node_instance\": { \"id\": \"123\" } }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); + int port = wireMockRule.port(); - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - NodeInstancesResource nir = c.nodeInstances(); - UpdateNodeInstanceParams params = new UpdateNodeInstanceParams(); + Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); + NodeInstancesResource nir = c.nodeInstances(); + UpdateNodeInstanceParams params = new UpdateNodeInstanceParams(); - UpdateNodeInstance uni = nir.update("123", params); - thrown.expect(HttpClientException.class); /// ??????? - NodeInstance ni = uni.execute(); - } + UpdateNodeInstance uni = nir.update("123", params); + thrown.expect(HttpClientException.class); /// ??????? + NodeInstance ni = uni.execute(); + } } |