diff options
author | Boslet, Cory <cory.boslet@att.com> | 2020-07-06 09:58:17 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@att.com> | 2020-07-06 09:58:17 -0400 |
commit | b7c956f3fa521e2031a7b7051ba2f42e6ac30cf5 (patch) | |
tree | 342aa19a7a86684b69500eef3313eaaa9cb2e87a /so-optimization-clients/src/test/java | |
parent | 47cb76e07dd671bab171432141fa89f6c2a1c95f (diff) |
Moved sniro and oof clients into their own project
Moved sniro and oof clients into their own project
Remove methods that arnt used to avoid comp error
Refactored the conductor call to not use the urn property reader so
that we dont have to import bpmn core.
Replaced the auth method and removed unused import.
Issue-ID: SO-3021
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: Ie281ef95fef984890b10297f434b8336e9017921
Diffstat (limited to 'so-optimization-clients/src/test/java')
6 files changed, 573 insertions, 0 deletions
diff --git a/so-optimization-clients/src/test/java/org/onap/so/BaseIntegrationTest.java b/so-optimization-clients/src/test/java/org/onap/so/BaseIntegrationTest.java new file mode 100644 index 0000000000..7dccfd3208 --- /dev/null +++ b/so-optimization-clients/src/test/java/org/onap/so/BaseIntegrationTest.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * 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; + +import java.io.IOException; +import java.io.InputStream; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.onap.so.client.oof.OofClient; +import org.onap.so.client.sniro.SniroClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import com.github.tomakehurst.wiremock.WireMockServer; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +@ContextConfiguration +@AutoConfigureWireMock(port = 0) +public abstract class BaseIntegrationTest { + + @Value("${wiremock.server.port}") + protected String wireMockPort; + + @SpyBean + protected SniroClient sniroClient; + + @SpyBean + protected OofClient oofClient; + + @Autowired + protected WireMockServer wireMockServer; + + @Before + public void baseTestBefore() { + wireMockServer.resetAll(); + } +} + + diff --git a/so-optimization-clients/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java b/so-optimization-clients/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java new file mode 100644 index 0000000000..62d9ecee44 --- /dev/null +++ b/so-optimization-clients/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * 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; + +import ch.vorburger.exec.ManagedProcessException; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; +import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import javax.sql.DataSource; + +@Configuration +@Profile({"test"}) +public class EmbeddedMariaDbConfig { + + @Bean + MariaDB4jSpringService mariaDB4jSpringService() { + MariaDB4jSpringService service = new MariaDB4jSpringService(); + + + service.getConfiguration().addArg("--lower_case_table_names=1"); + return service; + } + + @Bean + DataSource dataSource(MariaDB4jSpringService mariaDB4jSpringService, + @Value("${mariaDB4j.databaseName}") String databaseName, + @Value("${spring.datasource.username}") String datasourceUsername, + @Value("${spring.datasource.password}") String datasourcePassword, + @Value("${spring.datasource.driver-class-name}") String datasourceDriver) throws ManagedProcessException { + // Create our database with default root user and no password + mariaDB4jSpringService.getDB().createDB(databaseName); + + DBConfigurationBuilder config = mariaDB4jSpringService.getConfiguration(); + + return DataSourceBuilder.create().username(datasourceUsername).password(datasourcePassword) + .url(config.getURL(databaseName)).driverClassName(datasourceDriver).build(); + } +} diff --git a/so-optimization-clients/src/test/java/org/onap/so/IntegrationTestSuite.java b/so-optimization-clients/src/test/java/org/onap/so/IntegrationTestSuite.java new file mode 100644 index 0000000000..50bbc1845f --- /dev/null +++ b/so-optimization-clients/src/test/java/org/onap/so/IntegrationTestSuite.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * 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; + +import org.junit.runner.RunWith; +import com.googlecode.junittoolbox.SuiteClasses; +import com.googlecode.junittoolbox.WildcardPatternSuite; + +@RunWith(WildcardPatternSuite.class) +@SuiteClasses({"**/*IT.class"}) +public class IntegrationTestSuite { + +} diff --git a/so-optimization-clients/src/test/java/org/onap/so/TestApplication.java b/so-optimization-clients/src/test/java/org/onap/so/TestApplication.java new file mode 100644 index 0000000000..fe965b4444 --- /dev/null +++ b/so-optimization-clients/src/test/java/org/onap/so/TestApplication.java @@ -0,0 +1,43 @@ +package org.onap.so; +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * 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========================================================= + */ + + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.Profile; + +@SpringBootApplication +@Profile("test") +@ComponentScan(basePackages = {"org.onap.so"}, + excludeFilters = {@Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class)}) +public class TestApplication { + public static void main(String... args) { + SpringApplication.run(TestApplication.class, args); + System.getProperties().setProperty("mso.db", "MARIADB"); + System.getProperties().setProperty("server.name", "Springboot"); + + + } +} diff --git a/so-optimization-clients/src/test/java/org/onap/so/client/oof/OofClientTestIT.java b/so-optimization-clients/src/test/java/org/onap/so/client/oof/OofClientTestIT.java new file mode 100644 index 0000000000..a54d34a944 --- /dev/null +++ b/so-optimization-clients/src/test/java/org/onap/so/client/oof/OofClientTestIT.java @@ -0,0 +1,218 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Intel Corp. All rights reserved. + * ================================================================================ + * 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 + * + * 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.client.oof; + +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.urlEqualTo; +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; +import org.onap.so.BaseIntegrationTest; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.client.oof.beans.LicenseInfo; +import org.onap.so.client.oof.beans.ModelInfo; +import org.onap.so.client.oof.beans.OofRequest; +import org.onap.so.client.oof.beans.OofRequestParameters; +import org.onap.so.client.oof.beans.PlacementDemand; +import org.onap.so.client.oof.beans.PlacementInfo; +import org.onap.so.client.oof.beans.RequestInfo; +import org.onap.so.client.oof.beans.ResourceModelInfo; +import org.onap.so.client.oof.beans.ServiceInfo; +import org.onap.so.client.oof.beans.SubscriberInfo; +import org.skyscreamer.jsonassert.JSONAssert; +import org.springframework.beans.factory.annotation.Autowired; +import com.fasterxml.jackson.core.JsonProcessingException; + + +public class OofClientTestIT extends BaseIntegrationTest { + + @Autowired + private OofClient client; + + @Test + public void testPostDemands_success() throws BadResponseException, JsonProcessingException { + String mockResponse = + "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"status\", \"requestStatus\": \"accepted\"}"; + + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationName("modelCustomizationName-Service"); + modelInfo.setModelInvariantId("modelInvariantId-Service"); + modelInfo.setModelName("modelName-Service"); + modelInfo.setModelType("modelType-Service"); + modelInfo.setModelVersion("modelVersion-Service"); + modelInfo.setModelVersionId("modelVersionId-Service"); + + ServiceInfo serviceInfo = new ServiceInfo(); + serviceInfo.setModelInfo(modelInfo); + serviceInfo.setServiceInstanceId("serviceInstanceId"); + serviceInfo.setServiceName("serviceName"); + + SubscriberInfo subscriberInfo = new SubscriberInfo(); + subscriberInfo.setGlobalSubscriberId("globalSubscriberId"); + subscriberInfo.setSubscriberCommonSiteId("subscriberCommonSiteId"); + subscriberInfo.setSubscriberName("subscriberName"); + + ResourceModelInfo resourceModelInfo = new ResourceModelInfo(); + resourceModelInfo.setModelType("modelType"); + resourceModelInfo.setModelCustomizationName("modelCustomizationName"); + resourceModelInfo.setModelInvariantId("invarianteId"); + resourceModelInfo.setModelName("modelName"); + resourceModelInfo.setModelVersion("version"); + resourceModelInfo.setModelVersionId("versionId"); + + PlacementDemand placementDemand = new PlacementDemand(); + placementDemand.setResourceModelInfo(resourceModelInfo); + placementDemand.setResourceModuleName("resourceModuleName"); + placementDemand.setServiceResourceId("serviceResourceId"); + placementDemand.setTenantId("tenantId"); + + OofRequestParameters oofRequestParameters = new OofRequestParameters(); + oofRequestParameters.setCustomerLatitude("customerLatitude"); + oofRequestParameters.setCustomerLongitude("customerLongitude"); + oofRequestParameters.setCustomerName("customerName"); + + ArrayList<PlacementDemand> placementDemands = new ArrayList<>(); + placementDemands.add(placementDemand); + + PlacementInfo placementInfo = new PlacementInfo(); + placementInfo.setPlacementDemands(placementDemands); + placementInfo.setRequestParameters(oofRequestParameters); + placementInfo.setSubscriberInfo(subscriberInfo); + + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setTransactionId("transactionId"); + List<String> optimizer = new ArrayList<>(); + optimizer.add("optimizer1"); + optimizer.add("optimizer2"); + requestInfo.setOptimizers(optimizer); + requestInfo.setCallbackUrl("callBackUrl"); + requestInfo.setNumSolutions(1); + requestInfo.setRequestId("requestId"); + requestInfo.setSourceId("sourceId"); + requestInfo.setTimeout(30L); + requestInfo.setRequestType("requestType"); + + OofRequest oofRequest = new OofRequest(); + oofRequest.setRequestInformation(requestInfo); + oofRequest.setPlacementInformation(placementInfo); + oofRequest.setServiceInformation(serviceInfo); + oofRequest.setLicenseInformation(new LicenseInfo()); + + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + client.postDemands(oofRequest); + + String oofRequestOutput = oofRequest.toJsonString(); + JSONAssert.assertEquals("{\n" + " \"requestInfo\" : {\n" + " \"transactionId\" : \"transactionId\",\n" + + " \"requestId\" : \"requestId\",\n" + " \"callbackUrl\" : \"callBackUrl\",\n" + + " \"sourceId\" : \"sourceId\",\n" + " \"requestType\" : \"requestType\",\n" + + " \"numSolutions\" : 1,\n" + " \"optimizers\" : [ \"optimizer1\", \"optimizer2\" ],\n" + + " \"timeout\" : 30\n" + " },\n" + " \"serviceInfo\" : {\n" + + " \"serviceInstanceId\" : \"serviceInstanceId\",\n" + " \"serviceName\" : \"serviceName\",\n" + + " \"modelInfo\" : {\n" + " \"modelType\" : \"modelType-Service\",\n" + + " \"modelInvariantId\" : \"modelInvariantId-Service\",\n" + + " \"modelVersionId\" : \"modelVersionId-Service\",\n" + + " \"modelName\" : \"modelName-Service\",\n" + + " \"modelVersion\" : \"modelVersion-Service\",\n" + + " \"modelCustomizationName\" : \"modelCustomizationName-Service\"\n" + " }\n" + " },\n" + + " \"placementInfo\" : {\n" + " \"requestParameters\" : {\n" + + " \"customerLatitude\" : \"customerLatitude\",\n" + + " \"customerLongitude\" : \"customerLongitude\",\n" + + " \"customerName\" : \"customerName\"\n" + " },\n" + " \"subscriberInfo\" : {\n" + + " \"globalSubscriberId\" : \"globalSubscriberId\",\n" + + " \"subscriberName\" : \"subscriberName\",\n" + + " \"subscriberCommonSiteId\" : \"subscriberCommonSiteId\"\n" + " },\n" + + " \"placementDemands\" : [ {\n" + " \"resourceModuleName\" : \"resourceModuleName\",\n" + + " \"serviceResourceId\" : \"serviceResourceId\",\n" + " \"tenantId\" : \"tenantId\",\n" + + " \"resourceModelInfo\" : {\n" + " \"modelType\" : \"modelType\",\n" + + " \"modelInvariantId\" : \"invarianteId\",\n" + " \"modelVersionId\" : \"versionId\",\n" + + " \"modelName\" : \"modelName\",\n" + " \"modelVersion\" : \"version\",\n" + + " \"modelCustomizationName\" : \"modelCustomizationName\"\n" + " }\n" + " } ]\n" + + " },\n" + " \"licenseInfo\" : { \n" + " \"licenseDemands\" : [ ]\n" + "}\n" + "}", + oofRequestOutput.replace("\r\n", "\n"), false); + } + + @Test + public void testAsyncResponse_success() throws BadResponseException, JsonProcessingException { + String mockResponse = + "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"status\", \"requestStatus\": \"accepted\"}"; + + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + client.postDemands(new OofRequest()); + } + + @Test(expected = BadResponseException.class) + public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException { + String mockResponse = + "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}"; + + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + + client.postDemands(new OofRequest()); + + // TODO assertEquals("missing data", ); + + } + + @Test(expected = BadResponseException.class) + public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException { + String mockResponse = + "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}"; + + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + + client.postDemands(new OofRequest()); + + } + + @Test(expected = BadResponseException.class) + public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException { + String mockResponse = + "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}"; + + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + + client.postDemands(new OofRequest()); + + } + + @Test(expected = BadResponseException.class) + public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException { + String mockResponse = "{ }"; + + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + + client.postDemands(new OofRequest()); + } + +} diff --git a/so-optimization-clients/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java b/so-optimization-clients/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java new file mode 100644 index 0000000000..56c52388f8 --- /dev/null +++ b/so-optimization-clients/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * 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.client.sniro; + +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.urlEqualTo; +import org.junit.Test; +import org.onap.so.BaseIntegrationTest; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.client.sniro.beans.SniroConductorRequest; +import org.onap.so.client.sniro.beans.SniroManagerRequest; +import org.springframework.beans.factory.annotation.Autowired; +import com.fasterxml.jackson.core.JsonProcessingException; + + +public class SniroClientTestIT extends BaseIntegrationTest { + + @Autowired + private SniroClient client; + + + @Test(expected = Test.None.class) + public void testPostDemands_success() throws BadResponseException, JsonProcessingException { + String mockResponse = + "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}"; + + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + client.postDemands(new SniroManagerRequest()); + + } + + @Test(expected = BadResponseException.class) + public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException { + String mockResponse = + "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}"; + + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + + client.postDemands(new SniroManagerRequest()); + + // TODO assertEquals("missing data", ); + + } + + @Test(expected = BadResponseException.class) + public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException { + String mockResponse = + "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}"; + + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + + client.postDemands(new SniroManagerRequest()); + + } + + @Test(expected = BadResponseException.class) + public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException { + String mockResponse = + "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}"; + + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + + client.postDemands(new SniroManagerRequest()); + + } + + @Test(expected = BadResponseException.class) + public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException { + String mockResponse = "{ }"; + + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + + client.postDemands(new SniroManagerRequest()); + } + + @Test(expected = Test.None.class) + public void testPostRelease_success() throws BadResponseException, JsonProcessingException { + String mockResponse = "{\"status\": \"success\", \"message\": \"corys cool\"}"; + + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + client.postRelease(new SniroConductorRequest()); + } + + @Test(expected = BadResponseException.class) + public void testPostRelease_error_failed() throws BadResponseException, JsonProcessingException { + String mockResponse = "{\"status\": \"failure\", \"message\": \"corys cool\"}"; + + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + client.postRelease(new SniroConductorRequest()); + } + + @Test(expected = BadResponseException.class) + public void testPostRelease_error_noStatus() throws BadResponseException, JsonProcessingException { + String mockResponse = "{\"status\": \"\", \"message\": \"corys cool\"}"; + + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + client.postRelease(new SniroConductorRequest()); + + } + + @Test(expected = BadResponseException.class) + public void testPostRelease_error_noMessage() throws BadResponseException, JsonProcessingException { + String mockResponse = "{\"status\": \"failure\", \"message\": null}"; + + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + client.postRelease(new SniroConductorRequest()); + + } + + @Test(expected = BadResponseException.class) + public void testPostRelease_error_empty() throws BadResponseException, JsonProcessingException { + String mockResponse = "{ }"; + + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + client.postRelease(new SniroConductorRequest()); + + } + +} |