diff options
author | Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> | 2019-03-04 15:49:50 +0100 |
---|---|---|
committer | Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> | 2019-03-14 14:30:44 +0100 |
commit | 1d08ac7a18f134c9d707d2c280f9531829ef1bf3 (patch) | |
tree | b719064d7441c97cc6da05bdb987a019c3894eb5 /vid-app-common | |
parent | e603e0dfbd8bacbb9cf944d209f155651639c250 (diff) |
Increasing test coverage for vid.mso.rest
Change-Id: I48a5827875f9d0023f183cff58b0aaed0e28910b
Issue-ID: VID-387
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Diffstat (limited to 'vid-app-common')
14 files changed, 612 insertions, 794 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/InstanceIdsTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/InstanceIdsTest.java new file mode 100644 index 000000000..e40bab6c1 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/InstanceIdsTest.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2019 Nokia 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.vid.mso.rest; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + +public class InstanceIdsTest { + + private InstanceIds instanceIds; + + private String propertyName = "testProperty"; + private String additionalProperty = "testAdditionalProperty"; + private String networkInstanceId = "testNetworkId"; + private String serviceInstanceId = "testServiceId"; + + @BeforeMethod + public void setUp() { + instanceIds = new InstanceIds(); + } + + @Test + public void shouldHaveProperSettersAndGetters() { + assertThat(InstanceIds.class, hasValidGettersAndSettersExcluding("additionalProperties")); + } + + @Test + public void shouldHaveProperGetterAndSetterForAdditionalProperties() { + // when + instanceIds.setAdditionalProperty(propertyName,additionalProperty); + + // then + assertThat( instanceIds.getAdditionalProperties().get(propertyName) ).isEqualTo(additionalProperty); + } + + @Test + public void shouldProperlyConvertRelatedInstanceObjectToString() { + // given + instanceIds.setNetworkInstanceId(networkInstanceId); + instanceIds.setServiceInstanceId(serviceInstanceId); + instanceIds.setAdditionalProperty(propertyName,additionalProperty); + + // when + String response = instanceIds.toString(); + + // then + assertThat(response).contains( + "[networkInstanceId="+networkInstanceId + + ",serviceInstanceId="+serviceInstanceId + + ",vfModuleInstanceId=<null>," + + "vnfInstanceId=<null>" + + ",volumeGroupInstanceId=<null>" + + ",additionalProperties={"+propertyName+"="+additionalProperty+"}]" + ); + } + + @Test + public void shouldProperlyCheckIfObjectsAreEqual() { + assertThat(InstanceIds.class, hasValidBeanEqualsExcluding("additionalProperties")); + } +} diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java index 39d633f70..7caafed00 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java @@ -28,7 +28,6 @@ import org.apache.http.message.BasicHttpResponse; import org.apache.http.message.BasicStatusLine; import org.mockito.Mock; import org.onap.portalsdk.core.util.SystemProperties; -import org.onap.vid.changeManagement.RelatedInstanceList; import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.client.SyncRestClient; import org.onap.vid.controller.LocalWebConfig; @@ -37,10 +36,6 @@ import org.onap.vid.mso.MsoResponseWrapper; import org.onap.vid.mso.MsoResponseWrapperInterface; import org.onap.vid.mso.MsoUtil; import org.onap.vid.mso.RestObject; -import org.onap.vid.mso.model.CloudConfiguration; -import org.onap.vid.mso.model.ModelInfo; -import org.onap.vid.mso.model.RequestInfo; -import org.onap.vid.mso.model.RequestParameters; import org.onap.vid.mso.model.RequestReferences; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.web.WebAppConfiguration; @@ -49,9 +44,6 @@ import org.testng.annotations.Test; import static org.mockito.ArgumentMatchers.any; -import java.util.LinkedList; -import java.util.List; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.ArgumentMatchers.eq; @@ -82,7 +74,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyCreateServiceInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -112,7 +104,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyCreateE2eSvcInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -130,7 +122,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyCreateVnf() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -148,7 +140,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyCreateNwInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -166,7 +158,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyCreateVolumeGroupInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -184,7 +176,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyCreateVfModuleInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -202,7 +194,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyScaleOutVFModuleInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); RequestDetailsWrapper<RequestDetails> wrappedRequestDetails = new RequestDetailsWrapper<>(requestDetails); String endpoint = "testEndpoint"; @@ -221,7 +213,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyCreateConfigurationInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails); String endpoint = "testEndpoint"; @@ -240,7 +232,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyDeleteE2eSvcInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); org.onap.vid.mso.rest.RequestDetailsWrapper wrappedRequestDetails = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails); String endpoint = "testEndpoint"; @@ -259,7 +251,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyDeleteSvcInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -277,7 +269,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyUnassignSvcInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -295,7 +287,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyDeleteVnf() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -313,7 +305,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyDeleteVfModule() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -331,7 +323,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyDeleteVolumeGroupInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -349,7 +341,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyDeleteNwInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -445,7 +437,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyCompleteManualTask() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); RestObject restObject = generateMockMsoRestObject(); String endpoint = "testEndpoint"; @@ -473,7 +465,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyReplaceVnf() { // given - org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest(); + org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -491,7 +483,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyReplaceVnfWithStatus202() { // given - org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest(); + org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = createOkResponse(); @@ -509,7 +501,7 @@ public class MsoRestClientTest { @Test( expectedExceptions = MsoTestException.class) public void shouldThrowExceptionWhenReplaceVnfGetsWrongParameters() { // given - org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest(); + org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest(); when( client.post( eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class) ) ).thenThrow(new MsoTestException("test-post-exception")); @@ -520,7 +512,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyDeleteConfiguration() { // given - org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest(); + org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest(); org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper = new org.onap.vid.mso.rest.RequestDetailsWrapper(requestDetails); String endpoint = "testEndpoint"; @@ -548,7 +540,7 @@ public class MsoRestClientTest { @Test public void shouldProperlySetConfigurationActiveStatus() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -576,7 +568,7 @@ public class MsoRestClientTest { @Test public void shouldProperlySetPortOnConfigurationStatus() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -605,7 +597,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyChangeManagementUpdate() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails); String endpoint = "testEndpoint"; @@ -627,7 +619,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyUpdateVnfAndUpdateInstance() { // given - org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest(); + org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -646,7 +638,7 @@ public class MsoRestClientTest { @Test( expectedExceptions = MsoTestException.class ) public void shouldThrowExceptionWhenUpdateVnfAndUpdateInstanceGetsWrongParameter() { // given - org.onap.vid.changeManagement.RequestDetails requestDetails = generateChangeManagementMockMsoRequest(); + org.onap.vid.changeManagement.RequestDetails requestDetails = MsoRestClientTestUtil.generateChangeManagementMockMsoRequest(); String endpoint = ""; when(client.put(eq(baseUrl), anyMap(), any(RequestDetailsWrapper.class), eq(String.class))).thenThrow(new MsoTestException("test-post-exception")); @@ -660,7 +652,7 @@ public class MsoRestClientTest { @Test public void shouldProperlySetServiceInstanceStatus() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); RestObject<String> restObject = generateMockMsoRestObject(); String endpoint = "testEndpoint"; @@ -686,7 +678,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyRemoveRelationshipFromServiceInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -715,7 +707,7 @@ public class MsoRestClientTest { @Test public void shouldProperlyAddRelationshipToServiceInstance() { // given - RequestDetails requestDetails = generateMockMsoRequest(); + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); String endpoint = "testEndpoint"; HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse"); @@ -760,7 +752,7 @@ public class MsoRestClientTest { public void shouldProperlyPerformPostRequest() { // given - RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(generateMockMsoRequest()); + RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(MsoRestClientTestUtil.generateMockMsoRequest()); String endpoint = "testEndpoint"; HttpResponse<String> expectedResponse = HttpResponse.fallback("testOkResponse"); @@ -789,77 +781,6 @@ public class MsoRestClientTest { return new HttpResponse<>(responseBase ,String.class, new JsonMapper()); } - private RequestDetails generateMockMsoRequest() { - RequestDetails requestDetails = new RequestDetails(); - - CloudConfiguration cloudConfiguration = new CloudConfiguration(); - cloudConfiguration.setTenantId("tenant-id"); - cloudConfiguration.setLcpCloudRegionId("lcp-region"); - requestDetails.setCloudConfiguration(cloudConfiguration); - - ModelInfo modelInfo = new ModelInfo(); - modelInfo.setModelInvariantId("model-invarient-id"); - modelInfo.setModelCustomizationName("modelCustomizationName"); - modelInfo.setModelType("test-model-type"); - requestDetails.setModelInfo(modelInfo); - - RequestInfo requestInfo = new RequestInfo(); - requestInfo.setRequestorId("ok883e"); - requestInfo.setSource("VID"); - requestDetails.setRequestInfo(requestInfo); - RequestParameters requestParameters = new RequestParameters(); - - requestParameters.setSubscriptionServiceType("subscriber-service-type"); - requestParameters.setAdditionalProperty("a", 1); - requestParameters.setAdditionalProperty("b", 2); - requestParameters.setAdditionalProperty("c", 3); - requestParameters.setAdditionalProperty("d", 4); - String payload = "{\"existing_software_version\": \"3.1\",\"new_software_version\": \"3.2\", \"operations_timeout\": \"3600\"}"; - requestParameters.setAdditionalProperty("payload", payload); - - requestDetails.setRequestParameters(requestParameters); - return requestDetails; - } - - private org.onap.vid.changeManagement.RequestDetails generateChangeManagementMockMsoRequest() { - List<RelatedInstanceList> relatedInstances = new LinkedList<>(); - relatedInstances.add(new RelatedInstanceList()); - - org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails(); - - requestDetails.setVnfName("test-vnf-name"); - requestDetails.setVnfInstanceId("test-vnf-instance_id"); - requestDetails.setRelatedInstList(relatedInstances); - - CloudConfiguration cloudConfiguration = new CloudConfiguration(); - cloudConfiguration.setTenantId("tenant-id"); - cloudConfiguration.setLcpCloudRegionId("lcp-region"); - requestDetails.setCloudConfiguration(cloudConfiguration); - - ModelInfo modelInfo = new ModelInfo(); - modelInfo.setModelInvariantId("model-invarient-id"); - modelInfo.setModelCustomizationName("modelCustomizationName"); - modelInfo.setModelType("test-model-type"); - requestDetails.setModelInfo(modelInfo); - - RequestInfo requestInfo = new RequestInfo(); - requestInfo.setRequestorId("ok883e"); - requestInfo.setSource("VID"); - requestDetails.setRequestInfo(requestInfo); - - RequestParameters requestParameters = new RequestParameters(); - requestParameters.setSubscriptionServiceType("subscriber-service-type"); - requestParameters.setAdditionalProperty("a", 1); - requestParameters.setAdditionalProperty("b", 2); - requestParameters.setAdditionalProperty("c", 3); - requestParameters.setAdditionalProperty("d", 4); - String payload = "{\"existing_software_version\": \"3.1\",\"new_software_version\": \"3.2\", \"operations_timeout\": \"3600\"}"; - requestParameters.setAdditionalProperty("payload", payload); - - requestDetails.setRequestParameters(requestParameters); - return requestDetails; - } - private RestObject<String> generateMockMsoRestObject() { RestObject<String> restObject = new RestObject<>(); diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java index 2a607b511..1720e0467 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java @@ -36,6 +36,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.xebialabs.restito.semantics.Action; import com.xebialabs.restito.server.StubServer; import java.io.IOException; +import java.util.LinkedList; +import java.util.List; import java.util.function.BiFunction; import java.util.function.Function; import javax.ws.rs.core.HttpHeaders; @@ -46,8 +48,13 @@ import org.glassfish.grizzly.http.util.HttpStatus; import org.json.JSONObject; import org.junit.Assert; import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.changeManagement.RelatedInstanceList; import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.mso.MsoResponseWrapper; +import org.onap.vid.mso.model.CloudConfiguration; +import org.onap.vid.mso.model.ModelInfo; +import org.onap.vid.mso.model.RequestInfo; +import org.onap.vid.mso.model.RequestParameters; class MsoRestClientTestUtil implements AutoCloseable { private final StubServer server; @@ -123,6 +130,74 @@ class MsoRestClientTestUtil implements AutoCloseable { verifyServer(server, endpoint, Method.GET); } + static org.onap.vid.changeManagement.RequestDetails generateMockMsoRequest() { + org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails(); + requestDetails.setVnfInstanceId("vnf-instance-id"); + requestDetails.setVnfName("vnf-name"); + CloudConfiguration cloudConfiguration = new CloudConfiguration(); + cloudConfiguration.setTenantId("tenant-id"); + cloudConfiguration.setLcpCloudRegionId("lcp-region"); + requestDetails.setCloudConfiguration(cloudConfiguration); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelInvariantId("model-invarient-id"); + modelInfo.setModelCustomizationName("modelCustomizationName"); + requestDetails.setModelInfo(modelInfo); + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setRequestorId("ok883e"); + requestInfo.setSource("VID"); + requestDetails.setRequestInfo(requestInfo); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setSubscriptionServiceType("subscriber-service-type"); + requestParameters.setAdditionalProperty("a", 1); + requestParameters.setAdditionalProperty("b", 2); + requestParameters.setAdditionalProperty("c", 3); + requestParameters.setAdditionalProperty("d", 4); + String payload = "{\"existing_software_version\": \"3.1\",\"new_software_version\": \"3.2\", \"operations_timeout\": \"3600\"}"; + requestParameters.setAdditionalProperty("payload", payload); + + requestDetails.setRequestParameters(requestParameters); + return requestDetails; + } + + static org.onap.vid.changeManagement.RequestDetails generateChangeManagementMockMsoRequest() { + List<RelatedInstanceList> relatedInstances = new LinkedList<>(); + relatedInstances.add(new RelatedInstanceList()); + + org.onap.vid.changeManagement.RequestDetails requestDetails = new org.onap.vid.changeManagement.RequestDetails(); + + requestDetails.setVnfName("test-vnf-name"); + requestDetails.setVnfInstanceId("test-vnf-instance_id"); + requestDetails.setRelatedInstList(relatedInstances); + + CloudConfiguration cloudConfiguration = new CloudConfiguration(); + cloudConfiguration.setTenantId("tenant-id"); + cloudConfiguration.setLcpCloudRegionId("lcp-region"); + requestDetails.setCloudConfiguration(cloudConfiguration); + + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelInvariantId("model-invarient-id"); + modelInfo.setModelCustomizationName("modelCustomizationName"); + modelInfo.setModelType("test-model-type"); + requestDetails.setModelInfo(modelInfo); + + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setRequestorId("ok883e"); + requestInfo.setSource("VID"); + requestDetails.setRequestInfo(requestInfo); + + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setSubscriptionServiceType("subscriber-service-type"); + requestParameters.setAdditionalProperty("a", 1); + requestParameters.setAdditionalProperty("b", 2); + requestParameters.setAdditionalProperty("c", 3); + requestParameters.setAdditionalProperty("d", 4); + String payload = "{\"existing_software_version\": \"3.1\",\"new_software_version\": \"3.2\", \"operations_timeout\": \"3600\"}"; + requestParameters.setAdditionalProperty("payload", payload); + + requestDetails.setRequestParameters(requestParameters); + return requestDetails; + } + private void verifyServer(StubServer server, String endpoint, Method httpMethod) { verifyHttp(server).once( method(httpMethod), diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RelatedInstanceTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RelatedInstanceTest.java index 1a8aa3b48..c76298442 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RelatedInstanceTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RelatedInstanceTest.java @@ -3,13 +3,14 @@ * VID * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nokia. 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. @@ -20,94 +21,66 @@ package org.onap.vid.mso.rest; -import org.junit.Test; -import org.onap.vid.mso.model.ModelInfo; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; -import java.util.Map; +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class RelatedInstanceTest { - private RelatedInstance createTestSubject() { - return new RelatedInstance(); - } + private RelatedInstance relatedInstance = new RelatedInstance(); - - @Test - public void testGetModelInfo() throws Exception { - RelatedInstance testSubject; - ModelInfo result; + private String instanceId = "testInstanceId"; + private String InstanceName = "testInstance"; + private String propertyName = "testProperty"; + private String additionalProperty = "testAdditionalProperty"; - // default test - testSubject = createTestSubject(); - result = testSubject.getModelInfo(); + @BeforeMethod + public void setUp() { + relatedInstance = new RelatedInstance(); } - @Test - public void testSetModelInfo() throws Exception { - RelatedInstance testSubject; - ModelInfo modelInfo = null; - - // default test - testSubject = createTestSubject(); - testSubject.setModelInfo(modelInfo); + public void shouldHaveProperGettersAndSetters() { + assertThat(RelatedInstance.class, hasValidGettersAndSettersExcluding("additionalProperties")); } - @Test - public void testToString() throws Exception { - RelatedInstance testSubject; - String result; + public void shouldHaveProperGetterAndSetterForAdditionalProperties() { + // when + relatedInstance.setAdditionalProperty(propertyName,additionalProperty); - // default test - testSubject = createTestSubject(); - result = testSubject.toString(); + // then + assertThat( relatedInstance.getAdditionalProperties().get(propertyName) ).isEqualTo(additionalProperty); } - @Test - public void testGetAdditionalProperties() throws Exception { - RelatedInstance testSubject; - Map<String, Object> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getAdditionalProperties(); + public void shouldProperlyConvertRelatedInstanceObjectToString() { + // given + relatedInstance.setInstanceId(instanceId); + relatedInstance.setInstanceName(InstanceName); + relatedInstance.setAdditionalProperty(propertyName,additionalProperty); + + // when + String response = relatedInstance.toString(); + + // then + assertThat(response).contains( + "instanceName="+InstanceName+"," + + "instanceId="+instanceId+"," + + "modelInfo=<null>," + + "additionalProperties={"+propertyName+"="+additionalProperty+"}]" + ); } - @Test - public void testSetAdditionalProperty() throws Exception { - RelatedInstance testSubject; - String name = ""; - Object value = null; - - // default test - testSubject = createTestSubject(); - testSubject.setAdditionalProperty(name, value); + public void shouldProperlyCheckIfObjectsAreEqual() { + assertThat(RelatedInstance.class, hasValidBeanEqualsExcluding("additionalProperties")); } - - @Test - public void testHashCode() throws Exception { - RelatedInstance testSubject; - int result; - // default test - testSubject = createTestSubject(); - result = testSubject.hashCode(); - } - - - @Test - public void testEquals() throws Exception { - RelatedInstance testSubject; - Object other = null; - boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.equals(other); - } -} +}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestDetailsTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestDetailsTest.java index 2ae7535dc..575ceab7c 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestDetailsTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestDetailsTest.java @@ -20,185 +20,114 @@ package org.onap.vid.mso.rest; -import org.junit.Test; -import org.onap.vid.mso.model.CloudConfiguration; -import org.onap.vid.mso.model.ModelInfo; -import org.onap.vid.mso.model.RequestInfo; - +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import org.assertj.core.api.AssertionsForClassTypes; +import org.onap.vid.exceptions.NotFoundException; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.Collections; import java.util.List; import java.util.Map; +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.testng.AssertJUnit.assertEquals; + public class RequestDetailsTest { - private RequestDetails createTestSubject() { - return new RequestDetails(); - } + private RequestDetails requestDetails; - - @Test - public void testGetCloudConfiguration() throws Exception { - RequestDetails testSubject; - CloudConfiguration result; + private String propertyName = "testProperty"; + private String additionalProperty = "testAdditionalProperty"; - // default test - testSubject = createTestSubject(); - result = testSubject.getCloudConfiguration(); - } + private static final ImmutableList<String> LCP_CLOUD_REGION_ID_PATH = + ImmutableList.of("requestDetails", "cloudConfiguration", "lcpCloudRegionId"); - - @Test - public void testSetCloudConfiguration() throws Exception { - RequestDetails testSubject; - CloudConfiguration cloudConfiguration = null; - // default test - testSubject = createTestSubject(); - testSubject.setCloudConfiguration(cloudConfiguration); + @BeforeMethod + public void setUp() { + requestDetails = new RequestDetails(); } - @Test - public void testGetModelInfo() throws Exception { - RequestDetails testSubject; - ModelInfo result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getModelInfo(); + public void shouldHaveProperSettersAndGetters() { + assertThat(RequestDetails.class, hasValidGettersAndSettersExcluding("additionalProperties")); } - @Test - public void testSetModelInfo() throws Exception { - RequestDetails testSubject; - ModelInfo modelInfo = null; + public void shouldHaveProperGetterAndSetterForAdditionalProperties() { + // when + requestDetails.setAdditionalProperty(propertyName,additionalProperty); - // default test - testSubject = createTestSubject(); - testSubject.setModelInfo(modelInfo); + // then + AssertionsForClassTypes.assertThat( requestDetails.getAdditionalProperties().get(propertyName) ).isEqualTo(additionalProperty); } - @Test - public void testGetRelatedInstanceList() throws Exception { - RequestDetails testSubject; - List<RelatedInstanceWrapper> result; + public void shouldProperlyConvertRelatedInstanceObjectToString() { + // given + requestDetails.setAdditionalProperty(propertyName,additionalProperty); - // default test - testSubject = createTestSubject(); - result = testSubject.getRelatedInstanceList(); - } - - - @Test - public void testSetRelatedInstanceList() throws Exception { - RequestDetails testSubject; - List<RelatedInstanceWrapper> relatedInstanceList = null; + // when + String response = requestDetails.toString(); - // default test - testSubject = createTestSubject(); - testSubject.setRelatedInstanceList(relatedInstanceList); + // then + AssertionsForClassTypes.assertThat(response).contains( + "additionalProperties={"+propertyName+"="+additionalProperty+"}]" + ); } - @Test - public void testGetRequestInfo() throws Exception { - RequestDetails testSubject; - RequestInfo result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getRequestInfo(); + public void shouldProperlyCheckIfObjectsAreEqual() { + assertThat(RequestDetails.class, hasValidBeanEqualsExcluding("additionalProperties")); } - - @Test - public void testSetRequestInfo() throws Exception { - RequestDetails testSubject; - RequestInfo requestInfo = null; + @DataProvider + public static Object[][] extractValueByPathDataProvider() { - // default test - testSubject = createTestSubject(); - testSubject.setRequestInfo(requestInfo); - } + RequestDetails requestDetails1 = new RequestDetails(); + Map cloudConfiguration = ImmutableMap.of("lcpCloudRegionId", "lcp1"); + requestDetails1.setAdditionalProperty("requestDetails", + ImmutableMap.of("cloudConfiguration", cloudConfiguration)); - - @Test - public void testGetSubscriberInfo() throws Exception { - RequestDetails testSubject; - SubscriberInfo result; - // default test - testSubject = createTestSubject(); - result = testSubject.getSubscriberInfo(); - } - - - @Test - public void testSetSubscriberInfo() throws Exception { - RequestDetails testSubject; - SubscriberInfo subscriberInfo = null; + return new Object[][] { + { requestDetails1, LCP_CLOUD_REGION_ID_PATH, String.class, "lcp1" }, + { requestDetails1, ImmutableList.of("requestDetails", "cloudConfiguration"), Map.class, cloudConfiguration }, - // default test - testSubject = createTestSubject(); - testSubject.setSubscriberInfo(subscriberInfo); + }; } - - @Test - public void testToString() throws Exception { - RequestDetails testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.toString(); + @Test(dataProvider = "extractValueByPathDataProvider") + public void testExtractValueByPath(RequestDetails requestDetails, List<String> keys, Class clz, Object expectedValue) { + assertEquals(expectedValue, requestDetails.extractValueByPathUsingAdditionalProperties(keys, clz)); } - - @Test - public void testGetAdditionalProperties() throws Exception { - RequestDetails testSubject; - Map<String, Object> result; + @DataProvider + public static Object[][] extractValueByPathDataProviderThrowException() { + RequestDetails requestDetails1 = new RequestDetails(); + requestDetails1.setAdditionalProperty("requestDetails", + ImmutableMap.of("cloudConfiguration", "notMap")); - // default test - testSubject = createTestSubject(); - result = testSubject.getAdditionalProperties(); - } + RequestDetails requestDetails2 = new RequestDetails(); + requestDetails2.setAdditionalProperty("requestDetails", + ImmutableMap.of("cloudConfiguration", Collections.EMPTY_MAP)); - - @Test - public void testSetAdditionalProperty() throws Exception { - RequestDetails testSubject; - String name = ""; - Object value = null; - - // default test - testSubject = createTestSubject(); - testSubject.setAdditionalProperty(name, value); - } - - - @Test - public void testHashCode() throws Exception { - RequestDetails testSubject; - int result; - - // default test - testSubject = createTestSubject(); - result = testSubject.hashCode(); + return new Object[][] { + { new RequestDetails(), LCP_CLOUD_REGION_ID_PATH, String.class}, + { requestDetails1, LCP_CLOUD_REGION_ID_PATH, String.class}, + { requestDetails1, ImmutableList.of("requestDetails", "abc"), String.class}, + { requestDetails2, LCP_CLOUD_REGION_ID_PATH, String.class}, + }; } - - @Test - public void testEquals() throws Exception { - RequestDetails testSubject; - Object other = null; - boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.equals(other); + @Test(dataProvider = "extractValueByPathDataProviderThrowException", expectedExceptions = NotFoundException.class) + public void testExtractValueByPathThrowException(RequestDetails requestDetails, List<String> keys, Class clz) { + requestDetails.extractValueByPathUsingAdditionalProperties(keys, clz); } } diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestDetailsWrapperTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestDetailsWrapperTest.java new file mode 100644 index 000000000..d30f0b671 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestDetailsWrapperTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2019 Nokia 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.vid.mso.rest; + +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RequestDetailsWrapperTest { + + private RequestDetailsWrapper requestDetailsWrapper; + + @Test + public void shouldHaveProperConstructorAndGet(){ + // given + RequestDetails requestDetails = MsoRestClientTestUtil.generateMockMsoRequest(); + + // when + requestDetailsWrapper = new RequestDetailsWrapper(requestDetails); + + // then + assertThat(requestDetailsWrapper.getRequestDetails()).isEqualToComparingFieldByField(requestDetails); + } +} diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestListTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestListTest.java index 12c11e091..f7e6deea8 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestListTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestListTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,86 +20,57 @@ package org.onap.vid.mso.rest; -import java.util.List; -import java.util.Map; +import org.assertj.core.api.AssertionsForClassTypes; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; -import org.junit.Test; +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding; +import static org.hamcrest.MatcherAssert.assertThat; public class RequestListTest { - private RequestList createTestSubject() { - return new RequestList(); - } + private RequestList requestList; - @Test - public void testGetRequestList() throws Exception { - RequestList testSubject; - List<RequestWrapper> result; + private String propertyName = "testProperty"; + private String additionalProperty = "testAdditionalProperty"; - // default test - testSubject = createTestSubject(); - result = testSubject.getRequestList(); + @BeforeMethod + public void setUp() { + requestList = new RequestList(); } @Test - public void testSetRequestList() throws Exception { - RequestList testSubject; - List<RequestWrapper> l = null; - - // default test - testSubject = createTestSubject(); - testSubject.setRequestList(l); + public void shouldHaveProperSettersAndGetters() { + assertThat(RequestList.class, hasValidGettersAndSettersExcluding("additionalProperties")); } @Test - public void testToString() throws Exception { - RequestList testSubject; - String result; + public void shouldHaveProperGetterAndSetterForAdditionalProperties() { + // when + requestList.setAdditionalProperty(propertyName,additionalProperty); - // default test - testSubject = createTestSubject(); - result = testSubject.toString(); + // then + AssertionsForClassTypes.assertThat( requestList.getAdditionalProperties().get(propertyName) ).isEqualTo(additionalProperty); } @Test - public void testGetAdditionalProperties() throws Exception { - RequestList testSubject; - Map<String, Object> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getAdditionalProperties(); + public void shouldProperlyCheckIfObjectsAreEqual() { + assertThat(RequestList.class, hasValidBeanEqualsExcluding("additionalProperties")); } @Test - public void testSetAdditionalProperty() throws Exception { - RequestList testSubject; - String name = ""; - Object value = null; - - // default test - testSubject = createTestSubject(); - testSubject.setAdditionalProperty(name, value); - } - - @Test - public void testHashCode() throws Exception { - RequestList testSubject; - int result; - - // default test - testSubject = createTestSubject(); - result = testSubject.hashCode(); - } - - @Test - public void testEquals() throws Exception { - RequestList testSubject; - Object other = null; - boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.equals(other); + public void shouldProperlyConvertRelatedInstanceObjectToString() { + // given + requestList.setAdditionalProperty(propertyName,additionalProperty); + + // when + String response = requestList.toString(); + + // then + System.out.println(response); + AssertionsForClassTypes.assertThat(response).contains( + "additionalProperties={"+propertyName+"="+additionalProperty+"}]" + ); } } diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestStatusTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestStatusTest.java new file mode 100644 index 000000000..ab1f4340d --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestStatusTest.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2019 Nokia 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.vid.mso.rest; + +import org.assertj.core.api.AssertionsForClassTypes; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding; +import static org.hamcrest.MatcherAssert.assertThat; + +public class RequestStatusTest { + + private RequestStatus RequestStatus; + + private String propertyName = "testProperty"; + private String additionalProperty = "testAdditionalProperty"; + + @BeforeMethod + public void setUp() { + RequestStatus = new RequestStatus(); + } + + @Test + public void shouldHaveProperSettersAndGetters() { + assertThat(RequestStatus.class, hasValidGettersAndSettersExcluding("additionalProperties")); + } + + @Test + public void shouldHaveProperGetterAndSetterForAdditionalProperties() { + // when + RequestStatus.setAdditionalProperty(propertyName,additionalProperty); + + // then + AssertionsForClassTypes.assertThat( RequestStatus.getAdditionalProperties().get(propertyName) ).isEqualTo(additionalProperty); + } + + @Test + public void shouldProperlyCheckIfObjectsAreEqual() { + assertThat(RequestStatus.class, hasValidBeanEqualsExcluding("additionalProperties")); + } + + @Test + public void shouldProperlyConvertRelatedInstanceObjectToString() { + // given + RequestStatus.setAdditionalProperty(propertyName,additionalProperty); + RequestStatus.setRequestState("testState"); + RequestStatus.setTimestamp("100"); + + // when + String response = RequestStatus.toString(); + + // then + System.out.println(response); + AssertionsForClassTypes.assertThat(response).contains( + "percentProgress=<null>," + + "requestState=testState," + + "statusMessage=<null>," + + "timestamp=100," + + "wasRolledBack=<null>," + + "additionalProperties={"+propertyName+"="+additionalProperty+"}]" + ); + } + +} diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestTest.java index 1f8898e2a..0b5e288d7 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,102 +20,68 @@ package org.onap.vid.mso.rest; -import org.junit.Test; -public class RequestTest { - - private Request createTestSubject() { - return new Request(); - } - - @Test - public void testGetInstanceIds() throws Exception { - Request testSubject; - InstanceIds result; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; - // default test - testSubject = createTestSubject(); - result = testSubject.getInstanceIds(); - } - - @Test - public void testSetInstanceIds() throws Exception { - Request testSubject; - InstanceIds instanceIds = null; - - // default test - testSubject = createTestSubject(); - testSubject.setInstanceIds(instanceIds); - } +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; - @Test - public void testGetRequestDetails() throws Exception { - Request testSubject; - RequestDetails result; +public class RequestTest { - // default test - testSubject = createTestSubject(); - result = testSubject.getRequestDetails(); - } - @Test - public void testSetRequestDetails() throws Exception { - Request testSubject; - RequestDetails requestDetails = null; + private Request request; - // default test - testSubject = createTestSubject(); - testSubject.setRequestDetails(requestDetails); - } + private String propertyName = "testProperty"; + private String additionalProperty = "testAdditionalProperty"; - @Test - public void testGetRequestStatus() throws Exception { - Request testSubject; - RequestStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getRequestStatus(); + @BeforeMethod + public void setUp() { + request = new Request(); } @Test - public void testSetRequestStatus() throws Exception { - Request testSubject; - RequestStatus requestStatus = null; - - // default test - testSubject = createTestSubject(); - testSubject.setRequestStatus(requestStatus); + public void shouldHaveProperSettersAndGetters() { + assertThat(Request.class, hasValidGettersAndSettersExcluding("additionalProperties")); } @Test - public void testToString() throws Exception { - Request testSubject; - String result; + public void shouldHaveProperGetterAndSetterForAdditionalProperties() { + // when + request.setAdditionalProperty(propertyName,additionalProperty); - // default test - testSubject = createTestSubject(); - result = testSubject.toString(); + // then + assertThat( request.getAdditionalProperties().get(propertyName) ).isEqualTo(additionalProperty); } @Test - public void testEquals() throws Exception { - Request testSubject; - Object other = null; - boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.equals(other); + public void shouldProperlyConvertRelatedInstanceObjectToString() { + // given + request.setFinishTime("100"); + request.setRequestId("testRequest"); + request.setAdditionalProperty(propertyName,additionalProperty); + + // when + String response = request.toString(); + + // then + assertThat(response).contains( + "[instanceIds=<null>," + + "requestDetails=<null>," + + "requestStatus=<null>," + + "finishTime="+100+"," + + "requestId=testRequest," + + "requestScope=<null>," + + "requestType=<null>," + + "startTime=<null>," + + "additionalProperties={"+propertyName+"="+additionalProperty+"}]" + ); } @Test - public void testHashCode() throws Exception { - Request testSubject; - int result; - - // default test - testSubject = createTestSubject(); - result = testSubject.hashCode(); + public void shouldProperlyCheckIfObjectsAreEqual() { + assertThat(Request.class, hasValidBeanEqualsExcluding("additionalProperties")); } } diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestWrapperTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestWrapperTest.java index 2a8e6d9b1..3e9b710c9 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestWrapperTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/RequestWrapperTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,31 +20,15 @@ package org.onap.vid.mso.rest; -import org.junit.Test; +import org.testng.annotations.Test; -public class RequestWrapperTest { - - private RequestWrapper createTestSubject() { - return new RequestWrapper(); - } - - @Test - public void testGetRequest() throws Exception { - RequestWrapper testSubject; - Request result; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; +import static org.hamcrest.MatcherAssert.assertThat; - // default test - testSubject = createTestSubject(); - result = testSubject.getRequest(); - } +public class RequestWrapperTest { @Test - public void testSetRequest() throws Exception { - RequestWrapper testSubject; - Request request = null; - - // default test - testSubject = createTestSubject(); - testSubject.setRequest(request); + public void shouldHaveProperSettersAndGetters() { + assertThat(RequestWrapper.class, hasValidGettersAndSetters()); } } diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/ResponseTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/ResponseTest.java index 0a25e6d6a..a29e2a589 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/ResponseTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/ResponseTest.java @@ -20,51 +20,15 @@ package org.onap.vid.mso.rest; -import org.junit.Test; +import org.testng.annotations.Test; -public class ResponseTest { - - private Response createTestSubject() { - return new Response(); - } - - @Test - public void testGetStatus() throws Exception { - Response testSubject; - int result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getStatus(); - } - - @Test - public void testSetStatus() throws Exception { - Response testSubject; - int status = 0; - - // default test - testSubject = createTestSubject(); - testSubject.setStatus(status); - } - - @Test - public void testGetEntity() throws Exception { - Response testSubject; - RequestList result; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; +import static org.hamcrest.MatcherAssert.assertThat; - // default test - testSubject = createTestSubject(); - result = testSubject.getEntity(); - } +public class ResponseTest { @Test - public void testSetEntity() throws Exception { - Response testSubject; - RequestList entity = null; - - // default test - testSubject = createTestSubject(); - testSubject.setEntity(entity); + public void shouldHaveProperSettersAndGetters() { + assertThat(Response.class, hasValidGettersAndSetters()); } } diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/SubscriberInfoTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/SubscriberInfoTest.java new file mode 100644 index 000000000..5a7cd3b51 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/SubscriberInfoTest.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2019 Nokia 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.vid.mso.rest; + +import org.assertj.core.api.AssertionsForClassTypes; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsExcluding; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding; +import static org.hamcrest.MatcherAssert.assertThat; + +public class SubscriberInfoTest { + + private SubscriberInfo SubscriberInfo; + + private String propertyName = "testProperty"; + private String additionalProperty = "testAdditionalProperty"; + + @BeforeMethod + public void setUp() { + SubscriberInfo = new SubscriberInfo(); + } + + @Test + public void shouldHaveProperSettersAndGetters() { + assertThat(SubscriberInfo.class, hasValidGettersAndSettersExcluding("additionalProperties")); + } + + @Test + public void shouldHaveProperGetterAndSetterForAdditionalProperties() { + // when + SubscriberInfo.setAdditionalProperty(propertyName,additionalProperty); + + // then + AssertionsForClassTypes.assertThat( SubscriberInfo.getAdditionalProperties().get(propertyName) ).isEqualTo(additionalProperty); + } + + @Test + public void shouldProperlyCheckIfObjectsAreEqual() { + assertThat(SubscriberInfo.class, hasValidBeanEqualsExcluding("additionalProperties")); + } + + @Test + public void shouldProperlyConvertRelatedInstanceObjectToString() { + // given + SubscriberInfo.setAdditionalProperty(propertyName,additionalProperty); + SubscriberInfo.setGlobalSubscriberId("testSubscriberId"); + SubscriberInfo.setSubscriberName("testSubscriberName"); + + // when + String response = SubscriberInfo.toString(); + + // then + System.out.println(response); + AssertionsForClassTypes.assertThat(response).contains( + "globalSubscriberId=testSubscriberId," + + "subscriberCommonSiteId=<null>," + + "subscriberName=testSubscriberName," + + "additionalProperties={"+propertyName+"="+additionalProperty+"}]" + ); + } +} diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskListTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskListTest.java index 41ed6b9ca..4a8d40cbd 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskListTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskListTest.java @@ -20,33 +20,15 @@ package org.onap.vid.mso.rest; -import java.util.List; +import org.testng.annotations.Test; -import org.junit.Test; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; +import static org.hamcrest.MatcherAssert.assertThat; public class TaskListTest { - private TaskList createTestSubject() { - return new TaskList(); - } - @Test - public void testGetTaskList() throws Exception { - TaskList testSubject; - List<Task> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getTaskList(); - } - - @Test - public void testSetTaskList() throws Exception { - TaskList testSubject; - List<Task> taskList = null; - - // default test - testSubject = createTestSubject(); - testSubject.setTaskList(taskList); + public void shouldHaveProperSettersAndGetters() { + assertThat(TaskList.class, hasValidGettersAndSetters()); } } diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskTest.java index 81ae19d81..5d1e480fe 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskTest.java @@ -20,253 +20,15 @@ package org.onap.vid.mso.rest; -import java.util.List; +import org.testng.annotations.Test; -import org.junit.Test; +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; +import static org.hamcrest.MatcherAssert.assertThat; public class TaskTest { - private Task createTestSubject() { - return new Task(); - } - - @Test - public void testGetTaskId() throws Exception { - Task testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getTaskId(); - } - - @Test - public void testSetTaskId() throws Exception { - Task testSubject; - String taskId = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setTaskId(taskId); - } - - @Test - public void testGetType() throws Exception { - Task testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getType(); - } - - @Test - public void testSetType() throws Exception { - Task testSubject; - String type = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setType(type); - } - - @Test - public void testGetNfRole() throws Exception { - Task testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getNfRole(); - } - - @Test - public void testSetNfRole() throws Exception { - Task testSubject; - String nfRole = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setNfRole(nfRole); - } - - @Test - public void testGetSubscriptionServiceType() throws Exception { - Task testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getSubscriptionServiceType(); - } - - @Test - public void testSetSubscriptionServiceType() throws Exception { - Task testSubject; - String subscriptionServiceType = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setSubscriptionServiceType(subscriptionServiceType); - } - - @Test - public void testGetOriginalRequestId() throws Exception { - Task testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getOriginalRequestId(); - } - - @Test - public void testSetOriginalRequestId() throws Exception { - Task testSubject; - String originalRequestId = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setOriginalRequestId(originalRequestId); - } - @Test - public void testGetOriginalRequestorId() throws Exception { - Task testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getOriginalRequestorId(); - } - - @Test - public void testSetOriginalRequestorId() throws Exception { - Task testSubject; - String originalRequestorId = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setOriginalRequestorId(originalRequestorId); - } - - @Test - public void testGetErrorSource() throws Exception { - Task testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getErrorSource(); - } - - @Test - public void testSetErrorSource() throws Exception { - Task testSubject; - String errorSource = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setErrorSource(errorSource); - } - - @Test - public void testGetErrorCode() throws Exception { - Task testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getErrorCode(); - } - - @Test - public void testSetErrorCode() throws Exception { - Task testSubject; - String errorCode = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setErrorCode(errorCode); - } - - @Test - public void testGetErrorMessage() throws Exception { - Task testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getErrorMessage(); - } - - @Test - public void testSetErrorMessage() throws Exception { - Task testSubject; - String errorMessage = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setErrorMessage(errorMessage); - } - - @Test - public void testGetBuildingBlockName() throws Exception { - Task testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getBuildingBlockName(); - } - - @Test - public void testSetBuildingBlockName() throws Exception { - Task testSubject; - String buildingBlockName = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setBuildingBlockName(buildingBlockName); - } - - @Test - public void testGetBuildingBlockStep() throws Exception { - Task testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getBuildingBlockStep(); - } - - @Test - public void testSetBuildingBlockStep() throws Exception { - Task testSubject; - String buildingBlockStep = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setBuildingBlockStep(buildingBlockStep); - } - - @Test - public void testGetValidResponses() throws Exception { - Task testSubject; - List<String> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getValidResponses(); - } - - @Test - public void testSetValidResponses() throws Exception { - Task testSubject; - List<String> validResponses = null; - - // default test - testSubject = createTestSubject(); - testSubject.setValidResponses(validResponses); + public void shouldHaveProperSettersAndGetters() { + assertThat(Task.class, hasValidGettersAndSetters()); } } |