diff options
author | grabinsk <maciej.grabinski@nokia.com> | 2019-04-05 10:13:48 +0200 |
---|---|---|
committer | grabinsk <maciej.grabinski@nokia.com> | 2019-05-22 15:36:41 +0200 |
commit | 41216decc9e167ee85aff6391f67dcf4b94f489c (patch) | |
tree | 4aceeba43aef18bb58121b20acf6dad34bc814cd /prh-commons/src/test/java/org | |
parent | 2cf649dda43c7fc7650b5d0047ccc57108918724 (diff) |
replace generated model classes with immutables
Change-Id: I5a1330e356522d2e315f7e243a2e65b90e4f6ddd
Issue-ID: DCAEGEN2-1391
Signed-off-by: grabinsk <maciej.grabinski@nokia.com>
Diffstat (limited to 'prh-commons/src/test/java/org')
2 files changed, 98 insertions, 240 deletions
diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModelTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModelTest.java index 4bafd90e..3f396e82 100644 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModelTest.java +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModelTest.java @@ -20,139 +20,68 @@ package org.onap.dcaegen2.services.prh.model; -import com.google.gson.GsonBuilder; +import com.google.gson.Gson; import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; + +import java.io.InputStreamReader; +import java.util.Objects; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; class AaiPnfResultModelTest { - private static final String SOME_AAI_PNF_JSON = "{" + - "\"pnf-name\":\"some pnfName\"," + - "\"pnf-name2\":\"some pnfName2\"," + - "\"selflink\":\"some selflink\"," + - "\"pnf-name2-source\":\"some pnfName2Source\"," + - "\"pnf-id\":\"some pnfId\"," + - "\"equip-type\":\"some equipType\"," + - "\"equip-vendor\":\"some equipVendor\"," + - "\"equip-model\":\"some equipModel\"," + - "\"management-option\":\"some managementOption\"," + - "\"ipaddress-v4-oam\":\"some ipaddressV4Oam\"," + - "\"sw-version\":\"some swVersion\"," + - "\"in-maint\":false," + - "\"frame-id\":\"some frameId\"," + - "\"serial-number\":\"some serialNumber\"," + - "\"ipaddress-v4-loopback-0\":\"some ipaddressV4Loopback0\"," + - "\"ipaddress-v6-loopback-0\":\"some ipaddressV6Loopback0\"," + - "\"ipaddress-v4-aim\":\"some ipaddressV4Aim\"," + - "\"ipaddress-v6-aim\":\"some ipaddressV6Aim\"," + - "\"ipaddress-v6-oam\":\"some ipaddressV6Oam\"," + - "\"inv-status\":\"some invStatus\"," + - "\"resource-version\":\"some resourceVersion\"," + - "\"prov-status\":\"some provStatus\"," + - "\"nf-role\":\"some nfRole\"," + - "\"relationship-list\":{\"relationship\":[{}]}" + - "}"; - - private static AaiPnfResultModel getAaiPnfResultModel() { - AaiPnfResultModel aaiPnf = new AaiPnfResultModel(); - aaiPnf.setPnfName("some pnfName"); - aaiPnf.setPnfName2("some pnfName2"); - aaiPnf.setSelflink("some selflink"); - aaiPnf.setPnfName2Source("some pnfName2Source"); - aaiPnf.setPnfId("some pnfId"); - aaiPnf.setEquipType("some equipType"); - aaiPnf.setEquipVendor("some equipVendor"); - aaiPnf.setEquipModel("some equipModel"); - aaiPnf.setManagementOption("some managementOption"); - aaiPnf.setIpaddressV4Oam("some ipaddressV4Oam"); - aaiPnf.setSwVersion("some swVersion"); - aaiPnf.setInMaint(false); - aaiPnf.setFrameId("some frameId"); - aaiPnf.setSerialNumber("some serialNumber"); - aaiPnf.setIpaddressV4Loopback0("some ipaddressV4Loopback0"); - aaiPnf.setIpaddressV6Loopback0("some ipaddressV6Loopback0"); - aaiPnf.setIpaddressV4Aim("some ipaddressV4Aim"); - aaiPnf.setIpaddressV6Aim("some ipaddressV6Aim"); - aaiPnf.setIpaddressV6Oam("some ipaddressV6Oam"); - aaiPnf.setInvStatus("some invStatus"); - aaiPnf.setResourceVersion("some resourceVersion"); - aaiPnf.setProvStatus("some provStatus"); - aaiPnf.setNfRole("some nfRole"); - aaiPnf.setRelationshipList(getSomeRelationshipList()); - return aaiPnf; - } - - private static Relationship getSomeRelationshipList() { - return new Relationship().addRelationshipItem( - new RelationshipDict()); - } - @Test - void shouldSerializeAaiPnf() { - String json = new GsonBuilder().create().toJson(getAaiPnfResultModel()); + void shouldParseAaiPnf() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + AaiPnfResultModel pnf = gson.fromJson(new InputStreamReader(Objects.requireNonNull( + ClassLoader.getSystemResourceAsStream("some_aai_pnf.json"))), AaiPnfResultModel.class); + + assertThat(pnf.getPnfName()).isEqualTo("some pnfName"); + assertThat(pnf.getPnfName2()).isEqualTo("some pnfName2"); + assertThat(pnf.getSelflink()).isEqualTo("some selflink"); + assertThat(pnf.getPnfName2Source()).isEqualTo("some pnfName2Source"); + assertThat(pnf.getPnfId()).isEqualTo("some pnfId"); + assertThat(pnf.getEquipType()).isEqualTo("some equipType"); + assertThat(pnf.getEquipVendor()).isEqualTo("some equipVendor"); + assertThat(pnf.getEquipModel()).isEqualTo("some equipModel"); + assertThat(pnf.getManagementOption()).isEqualTo("some managementOption"); + assertThat(pnf.getIpaddressV4Oam()).isEqualTo("some ipaddressV4Oam"); + assertThat(pnf.getSwVersion()).isEqualTo("some swVersion"); + assertThat(pnf.isInMaint()).isFalse(); + assertThat(pnf.getFrameId()).isEqualTo("some frameId"); + assertThat(pnf.getSerialNumber()).isEqualTo("some serialNumber"); + assertThat(pnf.getIpaddressV4Loopback0()).isEqualTo("some ipaddressV4Loopback0"); + assertThat(pnf.getIpaddressV6Loopback0()).isEqualTo("some ipaddressV6Loopback0"); + assertThat(pnf.getIpaddressV4Aim()).isEqualTo("some ipaddressV4Aim"); + assertThat(pnf.getIpaddressV6Aim()).isEqualTo("some ipaddressV6Aim"); + assertThat(pnf.getIpaddressV6Oam()).isEqualTo("some ipaddressV6Oam"); + assertThat(pnf.getInvStatus()).isEqualTo("some invStatus"); + assertThat(pnf.getResourceVersion()).isEqualTo("some resourceVersion"); + assertThat(pnf.getProvStatus()).isEqualTo("some provStatus"); + assertThat(pnf.getNfRole()).isEqualTo("some nfRole"); - assertEquals(SOME_AAI_PNF_JSON, json); + assertThat(pnf.getRelationshipList().getRelationship()).hasSize(1); + RelationshipDict relationshipDict = pnf.getRelationshipList().getRelationship().get(0); + assertThat(relationshipDict.getRelatedTo()).isEqualTo("some relatedTo"); + assertThat(relationshipDict.getRelationshipData()).hasSize(1); + RelationshipData relationshipData = relationshipDict.getRelationshipData().get(0); + assertThat(relationshipData.getRelationshipKey()).isEqualTo("some relationshipKey"); + assertThat(relationshipData.getRelationshipValue()).isEqualTo("some relationshipValue"); } @Test - void shouldParseAaiPnf() { - AaiPnfResultModel pnf = new GsonBuilder().create().fromJson(SOME_AAI_PNF_JSON, AaiPnfResultModel.class); - - assertEquals("some pnfName", pnf.getPnfName()); - assertEquals("some pnfName2", pnf.getPnfName2()); - assertEquals("some selflink", pnf.getSelflink()); - assertEquals("some pnfName2Source", pnf.getPnfName2Source()); - assertEquals("some pnfId", pnf.getPnfId()); - assertEquals("some equipType", pnf.getEquipType()); - assertEquals("some equipVendor", pnf.getEquipVendor()); - assertEquals("some equipModel", pnf.getEquipModel()); - assertEquals("some managementOption", pnf.getManagementOption()); - assertEquals("some ipaddressV4Oam", pnf.getIpaddressV4Oam()); - assertEquals("some swVersion", pnf.getSwVersion()); - assertEquals(false, pnf.isInMaint()); - assertEquals("some frameId", pnf.getFrameId()); - assertEquals("some serialNumber", pnf.getSerialNumber()); - assertEquals("some ipaddressV4Loopback0", pnf.getIpaddressV4Loopback0()); - assertEquals("some ipaddressV6Loopback0", pnf.getIpaddressV6Loopback0()); - assertEquals("some ipaddressV4Aim", pnf.getIpaddressV4Aim()); - assertEquals("some ipaddressV6Aim", pnf.getIpaddressV6Aim()); - assertEquals("some ipaddressV6Oam", pnf.getIpaddressV6Oam()); - assertEquals("some invStatus", pnf.getInvStatus()); - assertEquals("some resourceVersion", pnf.getResourceVersion()); - assertEquals("some provStatus", pnf.getProvStatus()); - assertEquals("some nfRole", pnf.getNfRole()); - assertEquals(1, pnf.getRelationshipList().getRelationship().size()); + void shouldProvideEmptyRelationshipListForEmptyJson() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + AaiPnfResultModel pnf = gson.fromJson("{}", AaiPnfResultModel.class); + assertThat(pnf.getRelationshipList()).isNotNull(); + assertThat(pnf.getRelationshipList().getRelationship()).isEmpty(); } @Test - void shouldBePrintable() { - String s = getAaiPnfResultModel().toString(); - assertThat(s).contains("some pnfName"); - assertThat(s).contains("some pnfName2"); - assertThat(s).contains("some selflink"); - assertThat(s).contains("some pnfName2Source"); - assertThat(s).contains("some pnfId"); - assertThat(s).contains("some equipType"); - assertThat(s).contains("some equipVendor"); - assertThat(s).contains("some equipModel"); - assertThat(s).contains("some managementOption"); - assertThat(s).contains("some ipaddressV4Oam"); - assertThat(s).contains("some swVersion"); - assertThat(s).contains("false"); - assertThat(s).contains("some frameId"); - assertThat(s).contains("some serialNumber"); - assertThat(s).contains("some ipaddressV4Loopback0"); - assertThat(s).contains("some ipaddressV6Loopback0"); - assertThat(s).contains("some ipaddressV4Aim"); - assertThat(s).contains("some ipaddressV6Aim"); - assertThat(s).contains("some ipaddressV6Oam"); - assertThat(s).contains("some invStatus"); - assertThat(s).contains("some resourceVersion"); - assertThat(s).contains("some provStatus"); - assertThat(s).contains("some nfRole"); + void shouldIgnoreUnexpectedFieldsInJson() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + gson.fromJson("{\"foo\":\"bar\"}", AaiPnfResultModel.class); } - }
\ No newline at end of file diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModelTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModelTest.java index 2b02436b..5f9ca14d 100644 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModelTest.java +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModelTest.java @@ -20,141 +20,70 @@ package org.onap.dcaegen2.services.prh.model; -import com.google.gson.GsonBuilder; +import com.google.gson.Gson; import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; + +import java.io.InputStreamReader; +import java.util.Objects; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; class AaiServiceInstanceResultModelTest { - private static final String SOME_AAI_SERVICE_INSTANCE_JSON = "{" + - "\"service-instance-id\":\"some serviceInstanceId\"," + - "\"service-instance-name\":\"some serviceInstanceName\"," + - "\"service-type\":\"some serviceType\"," + - "\"service-role\":\"some serviceRole\"," + - "\"environment-context\":\"some environmentContext\"," + - "\"workload-context\":\"some workloadContext\"," + - "\"created-at\":\"some createdAt\"," + - "\"updated-at\":\"some updatedAt\"," + - "\"description\":\"some description\"," + - "\"model-invariant-id\":\"some modelInvariantId\"," + - "\"model-version-id\":\"some modelVersionId\"," + - "\"persona-model-version\":\"some personaModelVersion\"," + - "\"widget-model-id\":\"some widgetModelId\"," + - "\"widget-model-version\":\"some widgetModelVersion\"," + - "\"bandwidth-total\":\"some bandwidthTotal\"," + - "\"bandwidth-up-wan1\":\"some bandwidthUpWan1\"," + - "\"bandwidth-down-wan1\":\"some bandwidthDownWan1\"," + - "\"bandwidth-up-wan2\":\"some bandwidthUpWan2\"," + - "\"bandwidth-down-wan2\":\"some bandwidthDownWan2\"," + - "\"vhn-portal-url\":\"some vhnPortalUrl\"," + - "\"service-instance-location-id\":\"some serviceInstanceLocationId\"," + - "\"resource-version\":\"some resourceVersion\"," + - "\"selflink\":\"some selflink\"," + - "\"orchestration-status\":\"some orchestrationStatus\"," + - "\"relationship-list\":{\"relationship\":[{}]}" + - "}"; + @Test + void shouldParseAaiServiceInstance() { + AaiServiceInstanceResultModel serviceInstance = PrhModelAwareGsonBuilder.createGson().fromJson( + new InputStreamReader(Objects.requireNonNull( + ClassLoader.getSystemResourceAsStream("some_aai_service_instance.json"))), + AaiServiceInstanceResultModel.class); - private static AaiServiceInstanceResultModel getSomeAaiServiceInstance() { - AaiServiceInstanceResultModel serviceInstance = new AaiServiceInstanceResultModel(); - serviceInstance.setServiceInstanceId("some serviceInstanceId"); - serviceInstance.setServiceInstanceName("some serviceInstanceName"); - serviceInstance.setServiceType("some serviceType"); - serviceInstance.setServiceRole("some serviceRole"); - serviceInstance.setEnvironmentContext("some environmentContext"); - serviceInstance.setWorkloadContext("some workloadContext"); - serviceInstance.setCreatedAt("some createdAt"); - serviceInstance.setUpdatedAt("some updatedAt"); - serviceInstance.setDescription("some description"); - serviceInstance.setModelInvariantId("some modelInvariantId"); - serviceInstance.setModelVersionId("some modelVersionId"); - serviceInstance.setPersonaModelVersion("some personaModelVersion"); - serviceInstance.setWidgetModelId("some widgetModelId"); - serviceInstance.setWidgetModelVersion("some widgetModelVersion"); - serviceInstance.setBandwidthTotal("some bandwidthTotal"); - serviceInstance.setBandwidthUpWan1("some bandwidthUpWan1"); - serviceInstance.setBandwidthDownWan1("some bandwidthDownWan1"); - serviceInstance.setBandwidthUpWan2("some bandwidthUpWan2"); - serviceInstance.setBandwidthDownWan2("some bandwidthDownWan2"); - serviceInstance.setVhnPortalUrl("some vhnPortalUrl"); - serviceInstance.setServiceInstanceLocationId("some serviceInstanceLocationId"); - serviceInstance.setResourceVersion("some resourceVersion"); - serviceInstance.setSelflink("some selflink"); - serviceInstance.setOrchestrationStatus("some orchestrationStatus"); - serviceInstance.setRelationshipList(getSomeRelationshipList()); - return serviceInstance; - } + assertThat(serviceInstance.getServiceInstanceId()).isEqualTo("some serviceInstanceId"); + assertThat(serviceInstance.getServiceInstanceName()).isEqualTo("some serviceInstanceName"); + assertThat(serviceInstance.getServiceType()).isEqualTo("some serviceType"); + assertThat(serviceInstance.getServiceRole()).isEqualTo("some serviceRole"); + assertThat(serviceInstance.getEnvironmentContext()).isEqualTo("some environmentContext"); + assertThat(serviceInstance.getWorkloadContext()).isEqualTo("some workloadContext"); + assertThat(serviceInstance.getCreatedAt()).isEqualTo("some createdAt"); + assertThat(serviceInstance.getUpdatedAt()).isEqualTo("some updatedAt"); + assertThat(serviceInstance.getDescription()).isEqualTo("some description"); + assertThat(serviceInstance.getModelInvariantId()).isEqualTo("some modelInvariantId"); + assertThat(serviceInstance.getModelVersionId()).isEqualTo("some modelVersionId"); + assertThat(serviceInstance.getPersonaModelVersion()).isEqualTo("some personaModelVersion"); + assertThat(serviceInstance.getWidgetModelId()).isEqualTo("some widgetModelId"); + assertThat(serviceInstance.getWidgetModelVersion()).isEqualTo("some widgetModelVersion"); + assertThat(serviceInstance.getBandwidthTotal()).isEqualTo("some bandwidthTotal"); + assertThat(serviceInstance.getBandwidthUpWan1()).isEqualTo("some bandwidthUpWan1"); + assertThat(serviceInstance.getBandwidthDownWan1()).isEqualTo("some bandwidthDownWan1"); + assertThat(serviceInstance.getBandwidthUpWan2()).isEqualTo("some bandwidthUpWan2"); + assertThat(serviceInstance.getBandwidthDownWan2()).isEqualTo("some bandwidthDownWan2"); + assertThat(serviceInstance.getVhnPortalUrl()).isEqualTo("some vhnPortalUrl"); + assertThat(serviceInstance.getServiceInstanceLocationId()).isEqualTo("some serviceInstanceLocationId"); + assertThat(serviceInstance.getResourceVersion()).isEqualTo("some resourceVersion"); + assertThat(serviceInstance.getSelflink()).isEqualTo("some selflink"); + assertThat(serviceInstance.getOrchestrationStatus()).isEqualTo("some orchestrationStatus"); - private static Relationship getSomeRelationshipList() { - return new Relationship().addRelationshipItem( - new RelationshipDict()); + RelationshipDict relationshipDict = serviceInstance.getRelationshipList().getRelationship().get(0); + assertThat(relationshipDict.getRelatedTo()).isEqualTo("some relatedTo"); + assertThat(relationshipDict.getRelationshipData()).hasSize(1); + RelationshipData relationshipData = relationshipDict.getRelationshipData().get(0); + assertThat(relationshipData.getRelationshipKey()).isEqualTo("some relationshipKey"); + assertThat(relationshipData.getRelationshipValue()).isEqualTo("some relationshipValue"); } - @Test - void shouldSerializeAaiServiceInstance() { - String json = new GsonBuilder().create().toJson(getSomeAaiServiceInstance()); - assertEquals(SOME_AAI_SERVICE_INSTANCE_JSON, json); - } @Test - void shouldParseAaiServiceInstance() { - AaiServiceInstanceResultModel serviceInstance = new GsonBuilder().create() - .fromJson(SOME_AAI_SERVICE_INSTANCE_JSON, AaiServiceInstanceResultModel.class); - - assertEquals("some serviceInstanceId", serviceInstance.getServiceInstanceId()); - assertEquals("some serviceInstanceName", serviceInstance.getServiceInstanceName()); - assertEquals("some serviceType", serviceInstance.getServiceType()); - assertEquals("some serviceRole", serviceInstance.getServiceRole()); - assertEquals("some environmentContext", serviceInstance.getEnvironmentContext()); - assertEquals("some workloadContext", serviceInstance.getWorkloadContext()); - assertEquals("some createdAt", serviceInstance.getCreatedAt()); - assertEquals("some updatedAt", serviceInstance.getUpdatedAt()); - assertEquals("some description", serviceInstance.getDescription()); - assertEquals("some modelInvariantId", serviceInstance.getModelInvariantId()); - assertEquals("some modelVersionId", serviceInstance.getModelVersionId()); - assertEquals("some personaModelVersion", serviceInstance.getPersonaModelVersion()); - assertEquals("some widgetModelId", serviceInstance.getWidgetModelId()); - assertEquals("some widgetModelVersion", serviceInstance.getWidgetModelVersion()); - assertEquals("some bandwidthTotal", serviceInstance.getBandwidthTotal()); - assertEquals("some bandwidthUpWan1", serviceInstance.getBandwidthUpWan1()); - assertEquals("some bandwidthDownWan1", serviceInstance.getBandwidthDownWan1()); - assertEquals("some bandwidthUpWan2", serviceInstance.getBandwidthUpWan2()); - assertEquals("some bandwidthDownWan2", serviceInstance.getBandwidthDownWan2()); - assertEquals("some vhnPortalUrl", serviceInstance.getVhnPortalUrl()); - assertEquals("some serviceInstanceLocationId", serviceInstance.getServiceInstanceLocationId()); - assertEquals("some resourceVersion", serviceInstance.getResourceVersion()); - assertEquals("some selflink", serviceInstance.getSelflink()); - assertEquals("some orchestrationStatus", serviceInstance.getOrchestrationStatus()); - assertEquals(1, serviceInstance.getRelationshipList().getRelationship().size()); + void shouldProvideEmptyRelationshipListForEmptyJson() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + AaiServiceInstanceResultModel serviceInstance = gson.fromJson("{}", AaiServiceInstanceResultModel.class); + assertThat(serviceInstance.getRelationshipList()).isNotNull(); + assertThat(serviceInstance.getRelationshipList().getRelationship()).isEmpty(); } @Test - void shouldBePrintable() { - String s = getSomeAaiServiceInstance().toString(); - assertThat(s).contains("some serviceInstanceId"); - assertThat(s).contains("some serviceInstanceName"); - assertThat(s).contains("some serviceType"); - assertThat(s).contains("some serviceRole"); - assertThat(s).contains("some environmentContext"); - assertThat(s).contains("some workloadContext"); - assertThat(s).contains("some createdAt"); - assertThat(s).contains("some updatedAt"); - assertThat(s).contains("some description"); - assertThat(s).contains("some modelInvariantId"); - assertThat(s).contains("some modelVersionId"); - assertThat(s).contains("some personaModelVersion"); - assertThat(s).contains("some widgetModelId"); - assertThat(s).contains("some widgetModelVersion"); - assertThat(s).contains("some bandwidthTotal"); - assertThat(s).contains("some bandwidthUpWan1"); - assertThat(s).contains("some bandwidthDownWan1"); - assertThat(s).contains("some bandwidthUpWan2"); - assertThat(s).contains("some bandwidthDownWan2"); - assertThat(s).contains("some vhnPortalUrl"); - assertThat(s).contains("some serviceInstanceLocationId"); - assertThat(s).contains("some resourceVersion"); - assertThat(s).contains("some selflink"); - assertThat(s).contains("some orchestrationStatus"); + void shouldIgnoreUnexpectedFieldsInJson() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + gson.fromJson("{\"foo\":\"bar\"}", AaiServiceInstanceResultModel.class); } + }
\ No newline at end of file |