aboutsummaryrefslogtreecommitdiffstats
path: root/prh-commons/src
diff options
context:
space:
mode:
authorgrabinsk <maciej.grabinski@nokia.com>2019-04-05 10:13:48 +0200
committergrabinsk <maciej.grabinski@nokia.com>2019-05-22 15:36:41 +0200
commit41216decc9e167ee85aff6391f67dcf4b94f489c (patch)
tree4aceeba43aef18bb58121b20acf6dad34bc814cd /prh-commons/src
parent2cf649dda43c7fc7650b5d0047ccc57108918724 (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')
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModel.java414
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModel.java473
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/Relationship.java61
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/RelationshipData.java53
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/RelationshipDict.java103
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/utils/PrhModelAwareGsonBuilder.java (renamed from prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/utils/GsonSerializer.java)16
-rw-r--r--prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModelTest.java167
-rw-r--r--prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModelTest.java171
-rw-r--r--prh-commons/src/test/resources/some_aai_pnf.json38
-rw-r--r--prh-commons/src/test/resources/some_aai_service_instance.json39
10 files changed, 407 insertions, 1128 deletions
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModel.java
index e6d813f7..424d7f83 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModel.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModel.java
@@ -21,438 +21,186 @@
package org.onap.dcaegen2.services.prh.model;
import com.google.gson.annotations.SerializedName;
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
+import org.springframework.lang.Nullable;
+
/**
* PNF represents a physical network function. typically equipment used in the D1 world. in 1607, this will be populated by SDN-C to represent a premises router that a uCPE connects to. But this can be used to represent any physical device that is not an AIC node or uCPE. ###### Related Nodes - TO complex( pnf LocatedIn complex, MANY2ONE) - TO instance-group( pnf MemberOf instance-group, MANY2MANY) - TO zone( pnf LocatedIn zone, MANY2ONE) - FROM configuration( configuration AppliesTo pnf, ONE2MANY) - FROM esr-thirdparty-sdnc( esr-thirdparty-sdnc AppliesTo pnf, ONE2MANY) - FROM generic-vnf( generic-vnf HostedOn pnf, MANY2MANY) - FROM lag-interface (CHILD of pnf, lag-interface BindsTo pnf, MANY2ONE)(1) - FROM logical-link( logical-link BridgedTo pnf, MANY2MANY) - FROM p-interface (CHILD of pnf, p-interface BindsTo pnf, MANY2ONE)(1) - FROM service-instance( service-instance ComposedOf pnf, ONE2MANY) -(1) IF this PNF node is deleted, this FROM node is DELETED also
*/
-
-public class AaiPnfResultModel {
- @SerializedName("pnf-name")
- private String pnfName = null;
-
- @SerializedName("pnf-name2")
- private String pnfName2 = null;
-
- @SerializedName("selflink")
- private String selflink = null;
-
- @SerializedName("pnf-name2-source")
- private String pnfName2Source = null;
-
- @SerializedName("pnf-id")
- private String pnfId = null;
-
- @SerializedName("equip-type")
- private String equipType = null;
-
- @SerializedName("equip-vendor")
- private String equipVendor = null;
-
- @SerializedName("equip-model")
- private String equipModel = null;
-
- @SerializedName("management-option")
- private String managementOption = null;
-
- @SerializedName("ipaddress-v4-oam")
- private String ipaddressV4Oam = null;
-
- @SerializedName("sw-version")
- private String swVersion = null;
-
- @SerializedName("in-maint")
- private Boolean inMaint = null;
-
- @SerializedName("frame-id")
- private String frameId = null;
-
- @SerializedName("serial-number")
- private String serialNumber = null;
-
- @SerializedName("ipaddress-v4-loopback-0")
- private String ipaddressV4Loopback0 = null;
-
- @SerializedName("ipaddress-v6-loopback-0")
- private String ipaddressV6Loopback0 = null;
-
- @SerializedName("ipaddress-v4-aim")
- private String ipaddressV4Aim = null;
-
- @SerializedName("ipaddress-v6-aim")
- private String ipaddressV6Aim = null;
-
- @SerializedName("ipaddress-v6-oam")
- private String ipaddressV6Oam = null;
-
- @SerializedName("inv-status")
- private String invStatus = null;
-
- @SerializedName("resource-version")
- private String resourceVersion = null;
-
- @SerializedName("prov-status")
- private String provStatus = null;
-
- @SerializedName("nf-role")
- private String nfRole = null;
-
- @SerializedName("relationship-list")
- private Relationship relationshipList = null;
+@Value.Immutable
+@Gson.TypeAdapters(fieldNamingStrategy = true)
+public interface AaiPnfResultModel {
/**
* unique name of Physical Network Function.
- *
- * @return pnfName
**/
- public String getPnfName() {
- return pnfName;
- }
-
- public void setPnfName(String pnfName) {
- this.pnfName = pnfName;
- }
+ @Nullable
+ @SerializedName("pnf-name")
+ String getPnfName();
/**
* name of Physical Network Function.
- *
- * @return pnfName2
**/
- public String getPnfName2() {
- return pnfName2;
- }
-
- public void setPnfName2(String pnfName2) {
- this.pnfName2 = pnfName2;
- }
+ @Nullable
+ @SerializedName("pnf-name2")
+ String getPnfName2();
/**
* URL to endpoint where AAI can get more details.
- *
- * @return selflink
**/
- public String getSelflink() {
- return selflink;
- }
-
- public void setSelflink(String selflink) {
- this.selflink = selflink;
- }
+ @Nullable
+ @SerializedName("selflink")
+ String getSelflink();
/**
* source of name2
- *
- * @return pnfName2Source
**/
- public String getPnfName2Source() {
- return pnfName2Source;
- }
-
- public void setPnfName2Source(String pnfName2Source) {
- this.pnfName2Source = pnfName2Source;
- }
+ @Nullable
+ @SerializedName("pnf-name2-source")
+ String getPnfName2Source();
/**
* id of pnf
- *
- * @return pnfId
**/
- public String getPnfId() {
- return pnfId;
- }
-
- public void setPnfId(String pnfId) {
- this.pnfId = pnfId;
- }
+ @Nullable
+ @SerializedName("pnf-id")
+ String getPnfId();
/**
* Equipment type. Source of truth should define valid values.
- *
- * @return equipType
**/
- public String getEquipType() {
- return equipType;
- }
-
- public void setEquipType(String equipType) {
- this.equipType = equipType;
- }
+ @Nullable
+ @SerializedName("equip-type")
+ String getEquipType();
/**
* Equipment vendor. Source of truth should define valid values.
- *
- * @return equipVendor
**/
- public String getEquipVendor() {
- return equipVendor;
- }
-
- public void setEquipVendor(String equipVendor) {
- this.equipVendor = equipVendor;
- }
+ @Nullable
+ @SerializedName("equip-vendor")
+ String getEquipVendor();
/**
* Equipment model. Source of truth should define valid values.
- *
- * @return equipModel
**/
- public String getEquipModel() {
- return equipModel;
- }
-
- public void setEquipModel(String equipModel) {
- this.equipModel = equipModel;
- }
+ @Nullable
+ @SerializedName("equip-model")
+ String getEquipModel();
/**
* identifier of managed by ATT or customer
- *
- * @return managementOption
**/
- public String getManagementOption() {
- return managementOption;
- }
-
- public void setManagementOption(String managementOption) {
- this.managementOption = managementOption;
- }
+ @Nullable
+ @SerializedName("management-option")
+ String getManagementOption();
/**
* ipv4-oam-address with new naming convention for IP addresses
- *
- * @return ipaddressV4Oam
**/
- public String getIpaddressV4Oam() {
- return ipaddressV4Oam;
- }
-
- public void setIpaddressV4Oam(String ipaddressV4Oam) {
- this.ipaddressV4Oam = ipaddressV4Oam;
- }
+ @Nullable
+ @SerializedName("ipaddress-v4-oam")
+ String getIpaddressV4Oam();
/**
* sw-version is the version of SW for the hosted application on the PNF.
- *
- * @return swVersion
**/
- public String getSwVersion() {
- return swVersion;
- }
-
- public void setSwVersion(String swVersion) {
- this.swVersion = swVersion;
- }
+ @Nullable
+ @SerializedName("sw-version")
+ String getSwVersion();
/**
* Used to indicate whether or not this object is in maintenance mode (maintenance mode &#x3D; true). This field (in conjunction with prov-status) is used to suppress alarms and vSCL on VNFs/VMs.
- *
- * @return inMaint
**/
- public Boolean isInMaint() {
- return inMaint;
- }
-
- public void setInMaint(Boolean inMaint) {
- this.inMaint = inMaint;
- }
+ @Nullable
+ @SerializedName("in-maint")
+ Boolean isInMaint();
/**
* ID of the physical frame (relay rack) where pnf is installed.
- *
- * @return frameId
**/
- public String getFrameId() {
- return frameId;
- }
-
- public void setFrameId(String frameId) {
- this.frameId = frameId;
- }
+ @Nullable
+ @SerializedName("frame-id")
+ String getFrameId();
/**
* Serial number of the device
- *
- * @return serialNumber
**/
- public String getSerialNumber() {
- return serialNumber;
- }
-
- public void setSerialNumber(String serialNumber) {
- this.serialNumber = serialNumber;
- }
+ @Nullable
+ @SerializedName("serial-number")
+ String getSerialNumber();
/**
* IPV4 Loopback 0 address
- *
- * @return ipaddressV4Loopback0
**/
- public String getIpaddressV4Loopback0() {
- return ipaddressV4Loopback0;
- }
-
- public void setIpaddressV4Loopback0(String ipaddressV4Loopback0) {
- this.ipaddressV4Loopback0 = ipaddressV4Loopback0;
- }
+ @Nullable
+ @SerializedName("ipaddress-v4-loopback-0")
+ String getIpaddressV4Loopback0();
/**
* IPV6 Loopback 0 address
- *
- * @return ipaddressV6Loopback0
**/
- public String getIpaddressV6Loopback0() {
- return ipaddressV6Loopback0;
- }
-
- public void setIpaddressV6Loopback0(String ipaddressV6Loopback0) {
- this.ipaddressV6Loopback0 = ipaddressV6Loopback0;
- }
+ @Nullable
+ @SerializedName("ipaddress-v6-loopback-0")
+ String getIpaddressV6Loopback0();
/**
* IPV4 AIM address
- *
- * @return ipaddressV4Aim
**/
- public String getIpaddressV4Aim() {
- return ipaddressV4Aim;
- }
-
- public void setIpaddressV4Aim(String ipaddressV4Aim) {
- this.ipaddressV4Aim = ipaddressV4Aim;
- }
+ @Nullable
+ @SerializedName("ipaddress-v4-aim")
+ String getIpaddressV4Aim();
/**
* IPV6 AIM address
- *
- * @return ipaddressV6Aim
**/
- public String getIpaddressV6Aim() {
- return ipaddressV6Aim;
- }
-
- public void setIpaddressV6Aim(String ipaddressV6Aim) {
- this.ipaddressV6Aim = ipaddressV6Aim;
- }
+ @Nullable
+ @SerializedName("ipaddress-v6-aim")
+ String getIpaddressV6Aim();
/**
* IPV6 OAM address
- *
- * @return ipaddressV6Oam
**/
- public String getIpaddressV6Oam() {
- return ipaddressV6Oam;
- }
-
- public void setIpaddressV6Oam(String ipaddressV6Oam) {
- this.ipaddressV6Oam = ipaddressV6Oam;
- }
+ @Nullable
+ @SerializedName("ipaddress-v6-oam")
+ String getIpaddressV6Oam();
/**
* CANOPI&#39;s inventory status. Only set with values exactly as defined by CANOPI.
- *
- * @return invStatus
**/
- public String getInvStatus() {
- return invStatus;
- }
-
- public void setInvStatus(String invStatus) {
- this.invStatus = invStatus;
- }
+ @Nullable
+ @SerializedName("inv-status")
+ String getInvStatus();
/**
- * Used for optimistic concurrency. Must be empty on create, valid on update and delete.
- *
- * @return resourceVersion
+ * Used for optimistic concurrency. Must be empty on createGson, valid on update and delete.
**/
- public String getResourceVersion() {
- return resourceVersion;
- }
-
- public void setResourceVersion(String resourceVersion) {
- this.resourceVersion = resourceVersion;
- }
+ @Nullable
+ @SerializedName("resource-version")
+ String getResourceVersion();
/**
* Prov Status of this device (not under canopi control) Valid values [PREPROV/NVTPROV/PROV]
- *
- * @return provStatus
**/
- public String getProvStatus() {
- return provStatus;
- }
-
- public void setProvStatus(String provStatus) {
- this.provStatus = provStatus;
- }
+ @Nullable
+ @SerializedName("prov-status")
+ String getProvStatus();
/**
* Nf Role is the role performed by this instance in the network.
- *
- * @return nfRole
**/
- public String getNfRole() {
- return nfRole;
- }
-
- public void setNfRole(String nfRole) {
- this.nfRole = nfRole;
- }
+ @Nullable
+ @SerializedName("nf-role")
+ String getNfRole();
/**
* Get relationshipList
- *
- * @return relationshipList
**/
- public Relationship getRelationshipList() {
- return relationshipList;
- }
-
- public void setRelationshipList(Relationship relationshipList) {
- this.relationshipList = relationshipList;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("class AaiPnfResultModel {\n");
-
- sb.append(" pnfName: ").append(toIndentedString(pnfName)).append("\n");
- sb.append(" pnfName2: ").append(toIndentedString(pnfName2)).append("\n");
- sb.append(" selflink: ").append(toIndentedString(selflink)).append("\n");
- sb.append(" pnfName2Source: ").append(toIndentedString(pnfName2Source)).append("\n");
- sb.append(" pnfId: ").append(toIndentedString(pnfId)).append("\n");
- sb.append(" equipType: ").append(toIndentedString(equipType)).append("\n");
- sb.append(" equipVendor: ").append(toIndentedString(equipVendor)).append("\n");
- sb.append(" equipModel: ").append(toIndentedString(equipModel)).append("\n");
- sb.append(" managementOption: ").append(toIndentedString(managementOption)).append("\n");
- sb.append(" ipaddressV4Oam: ").append(toIndentedString(ipaddressV4Oam)).append("\n");
- sb.append(" swVersion: ").append(toIndentedString(swVersion)).append("\n");
- sb.append(" inMaint: ").append(toIndentedString(inMaint)).append("\n");
- sb.append(" frameId: ").append(toIndentedString(frameId)).append("\n");
- sb.append(" serialNumber: ").append(toIndentedString(serialNumber)).append("\n");
- sb.append(" ipaddressV4Loopback0: ").append(toIndentedString(ipaddressV4Loopback0)).append("\n");
- sb.append(" ipaddressV6Loopback0: ").append(toIndentedString(ipaddressV6Loopback0)).append("\n");
- sb.append(" ipaddressV4Aim: ").append(toIndentedString(ipaddressV4Aim)).append("\n");
- sb.append(" ipaddressV6Aim: ").append(toIndentedString(ipaddressV6Aim)).append("\n");
- sb.append(" ipaddressV6Oam: ").append(toIndentedString(ipaddressV6Oam)).append("\n");
- sb.append(" invStatus: ").append(toIndentedString(invStatus)).append("\n");
- sb.append(" resourceVersion: ").append(toIndentedString(resourceVersion)).append("\n");
- sb.append(" provStatus: ").append(toIndentedString(provStatus)).append("\n");
- sb.append(" nfRole: ").append(toIndentedString(nfRole)).append("\n");
- sb.append(" relationshipList: ").append(toIndentedString(relationshipList)).append("\n");
- sb.append("}");
- return sb.toString();
- }
-
- /**
- * Convert the given object to string with each line indented by 4 spaces
- * (except the first line).
- */
- private String toIndentedString(java.lang.Object o) {
- if (o == null) {
- return "null";
- }
- return o.toString().replace("\n", "\n ");
+ @SerializedName("relationship-list")
+ @Value.Default
+ default Relationship getRelationshipList() {
+ return ImmutableRelationship.builder().build();
}
}
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModel.java
index 7bf8e2e4..67d6ff90 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModel.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModel.java
@@ -21,452 +21,189 @@
package org.onap.dcaegen2.services.prh.model;
import com.google.gson.annotations.SerializedName;
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
+import org.springframework.lang.Nullable;
-public class AaiServiceInstanceResultModel {
- @SerializedName("service-instance-id")
- private String serviceInstanceId = null;
-
- @SerializedName("service-instance-name")
- private String serviceInstanceName = null;
-
- @SerializedName("service-type")
- private String serviceType = null;
-
- @SerializedName("service-role")
- private String serviceRole = null;
-
- @SerializedName("environment-context")
- private String environmentContext = null;
-
- @SerializedName("workload-context")
- private String workloadContext = null;
-
- @SerializedName("created-at")
- private String createdAt = null;
-
- @SerializedName("updated-at")
- private String updatedAt = null;
-
- @SerializedName("description")
- private String description = null;
-
- @SerializedName("model-invariant-id")
- private String modelInvariantId = null;
-
- @SerializedName("model-version-id")
- private String modelVersionId = null;
-
- @SerializedName("persona-model-version")
- private String personaModelVersion = null;
-
- @SerializedName("widget-model-id")
- private String widgetModelId = null;
-
- @SerializedName("widget-model-version")
- private String widgetModelVersion = null;
-
- @SerializedName("bandwidth-total")
- private String bandwidthTotal = null;
-
- @SerializedName("bandwidth-up-wan1")
- private String bandwidthUpWan1 = null;
-
- @SerializedName("bandwidth-down-wan1")
- private String bandwidthDownWan1 = null;
-
- @SerializedName("bandwidth-up-wan2")
- private String bandwidthUpWan2 = null;
-
- @SerializedName("bandwidth-down-wan2")
- private String bandwidthDownWan2 = null;
-
- @SerializedName("vhn-portal-url")
- private String vhnPortalUrl = null;
-
- @SerializedName("service-instance-location-id")
- private String serviceInstanceLocationId = null;
-
- @SerializedName("resource-version")
- private String resourceVersion = null;
-
- @SerializedName("selflink")
- private String selflink = null;
-
- @SerializedName("orchestration-status")
- private String orchestrationStatus = null;
-
- @SerializedName("relationship-list")
- private Relationship relationshipList = null;
+@Value.Immutable
+@Gson.TypeAdapters(fieldNamingStrategy = true)
+public interface AaiServiceInstanceResultModel {
/**
* Uniquely identifies this instance of a service
- *
- * @return serviceInstanceId
**/
- public String getServiceInstanceId() {
- return serviceInstanceId;
- }
-
- public void setServiceInstanceId(String serviceInstanceId) {
- this.serviceInstanceId = serviceInstanceId;
- }
+ @Nullable
+ @SerializedName("service-instance-id")
+ String getServiceInstanceId();
/**
* This field will store a name assigned to the service-instance.
- *
- * @return serviceInstanceName
**/
- public String getServiceInstanceName() {
- return serviceInstanceName;
- }
-
- public void setServiceInstanceName(String serviceInstanceName) {
- this.serviceInstanceName = serviceInstanceName;
- }
+ @Nullable
+ @SerializedName("service-instance-name")
+ String getServiceInstanceName();
/**
* String capturing type of service.
- *
- * @return serviceType
**/
- public String getServiceType() {
- return serviceType;
- }
-
- public void setServiceType(String serviceType) {
- this.serviceType = serviceType;
- }
+ @Nullable
+ @SerializedName("service-type")
+ String getServiceType();
/**
* String capturing the service role.
- *
- * @return serviceRole
**/
- public String getServiceRole() {
- return serviceRole;
- }
-
- public void setServiceRole(String serviceRole) {
- this.serviceRole = serviceRole;
- }
+ @Nullable
+ @SerializedName("service-role")
+ String getServiceRole();
/**
* This field will store the environment context assigned to the service-instance.
- *
- * @return environmentContext
- **/
- public String getEnvironmentContext() {
- return environmentContext;
- }
-
- public void setEnvironmentContext(String environmentContext) {
- this.environmentContext = environmentContext;
- }
+ **/
+ @Nullable
+ @SerializedName("environment-context")
+ String getEnvironmentContext();
/**
* This field will store the workload context assigned to the service-instance.
- *
- * @return workloadContext
- **/
- public String getWorkloadContext() {
- return workloadContext;
- }
-
- public void setWorkloadContext(String workloadContext) {
- this.workloadContext = workloadContext;
- }
+ **/
+ @Nullable
+ @SerializedName("workload-context")
+ String getWorkloadContext();
/**
- * create time of Network Service.
- *
- * @return createdAt
- **/
- public String getCreatedAt() {
- return createdAt;
- }
-
- public void setCreatedAt(String createdAt) {
- this.createdAt = createdAt;
- }
+ * createGson time of Network Service.
+ **/
+ @Nullable
+ @SerializedName("created-at")
+ String getCreatedAt();
/**
* last update of Network Service.
- *
- * @return updatedAt
- **/
- public String getUpdatedAt() {
- return updatedAt;
- }
-
- public void setUpdatedAt(String updatedAt) {
- this.updatedAt = updatedAt;
- }
+ **/
+ @Nullable
+ @SerializedName("updated-at")
+ String getUpdatedAt();
/**
* short description for service-instance.
- *
- * @return description
- **/
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
+ **/
+ @Nullable
+ @SerializedName("description")
+ String getDescription();
/**
* the ASDC model id for this resource or service model.
- *
- * @return modelInvariantId
- **/
- public String getModelInvariantId() {
- return modelInvariantId;
- }
-
- public void setModelInvariantId(String modelInvariantId) {
- this.modelInvariantId = modelInvariantId;
- }
+ **/
+ @Nullable
+ @SerializedName("model-invariant-id")
+ String getModelInvariantId();
/**
* the ASDC model version for this resource or service model.
- *
- * @return modelVersionId
- **/
- public String getModelVersionId() {
- return modelVersionId;
- }
-
- public void setModelVersionId(String modelVersionId) {
- this.modelVersionId = modelVersionId;
- }
+ **/
+ @Nullable
+ @SerializedName("model-version-id")
+ String getModelVersionId();
/**
* the ASDC model version for this resource or service model.
- *
- * @return personaModelVersion
- **/
- public String getPersonaModelVersion() {
- return personaModelVersion;
- }
-
- public void setPersonaModelVersion(String personaModelVersion) {
- this.personaModelVersion = personaModelVersion;
- }
+ **/
+ @Nullable
+ @SerializedName("persona-model-version")
+ String getPersonaModelVersion();
/**
* the ASDC data dictionary widget model. This maps directly to the A&amp;AI widget.
- *
- * @return widgetModelId
- **/
- public String getWidgetModelId() {
- return widgetModelId;
- }
-
- public void setWidgetModelId(String widgetModelId) {
- this.widgetModelId = widgetModelId;
- }
+ **/
+ @Nullable
+ @SerializedName("widget-model-id")
+ String getWidgetModelId();
/**
* the ASDC data dictionary version of the widget model.This maps directly to the A&amp;AI version of the widget.
- *
- * @return widgetModelVersion
- **/
- public String getWidgetModelVersion() {
- return widgetModelVersion;
- }
-
- public void setWidgetModelVersion(String widgetModelVersion) {
- this.widgetModelVersion = widgetModelVersion;
- }
+ **/
+ @Nullable
+ @SerializedName("widget-model-version")
+ String getWidgetModelVersion();
/**
* Indicates the total bandwidth to be used for this service.
- *
- * @return bandwidthTotal
- **/
- public String getBandwidthTotal() {
- return bandwidthTotal;
- }
-
- public void setBandwidthTotal(String bandwidthTotal) {
- this.bandwidthTotal = bandwidthTotal;
- }
+ **/
+ @Nullable
+ @SerializedName("bandwidth-total")
+ String getBandwidthTotal();
/**
* indicates the upstream bandwidth this service will use on the WAN1 port of the physical device.
- *
- * @return bandwidthUpWan1
- **/
- public String getBandwidthUpWan1() {
- return bandwidthUpWan1;
- }
-
- public void setBandwidthUpWan1(String bandwidthUpWan1) {
- this.bandwidthUpWan1 = bandwidthUpWan1;
- }
+ **/
+ @Nullable
+ @SerializedName("bandwidth-up-wan1")
+ String getBandwidthUpWan1();
/**
* indicates the downstream bandwidth this service will use on the WAN1 port of the physical device.
- *
- * @return bandwidthDownWan1
- **/
- public String getBandwidthDownWan1() {
- return bandwidthDownWan1;
- }
-
- public void setBandwidthDownWan1(String bandwidthDownWan1) {
- this.bandwidthDownWan1 = bandwidthDownWan1;
- }
+ **/
+ @Nullable
+ @SerializedName("bandwidth-down-wan1")
+ String getBandwidthDownWan1();
/**
* indicates the upstream bandwidth this service will use on the WAN2 port of the physical device.
- *
- * @return bandwidthUpWan2
- **/
- public String getBandwidthUpWan2() {
- return bandwidthUpWan2;
- }
-
- public void setBandwidthUpWan2(String bandwidthUpWan2) {
- this.bandwidthUpWan2 = bandwidthUpWan2;
- }
+ **/
+ @Nullable
+ @SerializedName("bandwidth-up-wan2")
+ String getBandwidthUpWan2();
/**
* indicates the downstream bandwidth this service will use on the WAN2 port of the physical device.
- *
- * @return bandwidthDownWan2
- **/
- public String getBandwidthDownWan2() {
- return bandwidthDownWan2;
- }
-
- public void setBandwidthDownWan2(String bandwidthDownWan2) {
- this.bandwidthDownWan2 = bandwidthDownWan2;
- }
+ **/
+ @Nullable
+ @SerializedName("bandwidth-down-wan2")
+ String getBandwidthDownWan2();
/**
* URL customers will use to access the vHN Portal.
- *
- * @return vhnPortalUrl
- **/
- public String getVhnPortalUrl() {
- return vhnPortalUrl;
- }
-
- public void setVhnPortalUrl(String vhnPortalUrl) {
- this.vhnPortalUrl = vhnPortalUrl;
- }
+ **/
+ @Nullable
+ @SerializedName("vhn-portal-url")
+ String getVhnPortalUrl();
/**
* An identifier that customers assign to the location where this service is being used.
- *
- * @return serviceInstanceLocationId
- **/
- public String getServiceInstanceLocationId() {
- return serviceInstanceLocationId;
- }
-
- public void setServiceInstanceLocationId(String serviceInstanceLocationId) {
- this.serviceInstanceLocationId = serviceInstanceLocationId;
- }
+ **/
+ @Nullable
+ @SerializedName("service-instance-location-id")
+ String getServiceInstanceLocationId();
/**
- * Used for optimistic concurrency. Must be empty on create, valid on update and delete.
- *
- * @return resourceVersion
- **/
- public String getResourceVersion() {
- return resourceVersion;
- }
-
- public void setResourceVersion(String resourceVersion) {
- this.resourceVersion = resourceVersion;
- }
+ * Used for optimistic concurrency. Must be empty on createGson, valid on update and delete.
+ **/
+ @Nullable
+ @SerializedName("resource-version")
+ String getResourceVersion();
/**
* Path to the controller object.
- *
- * @return selflink
- **/
- public String getSelflink() {
- return selflink;
- }
-
- public void setSelflink(String selflink) {
- this.selflink = selflink;
- }
+ **/
+ @Nullable
+ @SerializedName("selflink")
+ String getSelflink();
/**
* Orchestration status of this service.
- *
- * @return orchestrationStatus
- **/
- public String getOrchestrationStatus() {
- return orchestrationStatus;
- }
-
- public void setOrchestrationStatus(String orchestrationStatus) {
- this.orchestrationStatus = orchestrationStatus;
- }
-
+ **/
+ @Nullable
+ @SerializedName("orchestration-status")
+ String getOrchestrationStatus();
/**
* Get relationshipList
- *
- * @return relationshipList
- **/
- public Relationship getRelationshipList() {
- return relationshipList;
- }
-
- public void setRelationshipList(Relationship relationshipList) {
- this.relationshipList = relationshipList;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("class AaiServiceInstanceResultModel {\n");
-
- sb.append(" serviceInstanceId: ").append(toIndentedString(serviceInstanceId)).append("\n");
- sb.append(" serviceInstanceName: ").append(toIndentedString(serviceInstanceName)).append("\n");
- sb.append(" serviceType: ").append(toIndentedString(serviceType)).append("\n");
- sb.append(" serviceRole: ").append(toIndentedString(serviceRole)).append("\n");
- sb.append(" environmentContext: ").append(toIndentedString(environmentContext)).append("\n");
- sb.append(" workloadContext: ").append(toIndentedString(workloadContext)).append("\n");
- sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n");
- sb.append(" updatedAt: ").append(toIndentedString(updatedAt)).append("\n");
- sb.append(" description: ").append(toIndentedString(description)).append("\n");
- sb.append(" modelInvariantId: ").append(toIndentedString(modelInvariantId)).append("\n");
- sb.append(" modelVersionId: ").append(toIndentedString(modelVersionId)).append("\n");
- sb.append(" personaModelVersion: ").append(toIndentedString(personaModelVersion)).append("\n");
- sb.append(" widgetModelId: ").append(toIndentedString(widgetModelId)).append("\n");
- sb.append(" widgetModelVersion: ").append(toIndentedString(widgetModelVersion)).append("\n");
- sb.append(" bandwidthTotal: ").append(toIndentedString(bandwidthTotal)).append("\n");
- sb.append(" bandwidthUpWan1: ").append(toIndentedString(bandwidthUpWan1)).append("\n");
- sb.append(" bandwidthDownWan1: ").append(toIndentedString(bandwidthDownWan1)).append("\n");
- sb.append(" bandwidthUpWan2: ").append(toIndentedString(bandwidthUpWan2)).append("\n");
- sb.append(" bandwidthDownWan2: ").append(toIndentedString(bandwidthDownWan2)).append("\n");
- sb.append(" vhnPortalUrl: ").append(toIndentedString(vhnPortalUrl)).append("\n");
- sb.append(" serviceInstanceLocationId: ").append(toIndentedString(serviceInstanceLocationId)).append("\n");
- sb.append(" resourceVersion: ").append(toIndentedString(resourceVersion)).append("\n");
- sb.append(" selflink: ").append(toIndentedString(selflink)).append("\n");
- sb.append(" orchestrationStatus: ").append(toIndentedString(orchestrationStatus)).append("\n");
- sb.append(" relationshipList: ").append(toIndentedString(relationshipList)).append("\n");
- sb.append("}");
- return sb.toString();
- }
-
- /**
- * Convert the given object to string with each line indented by 4 spaces
- * (except the first line).
- */
- private String toIndentedString(java.lang.Object o) {
- if (o == null) {
- return "null";
- }
- return o.toString().replace("\n", "\n ");
+ **/
+ @SerializedName("relationship-list")
+ @Value.Default
+ default Relationship getRelationshipList() {
+ return ImmutableRelationship.builder().build();
}
} \ No newline at end of file
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/Relationship.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/Relationship.java
index 094e1a62..d92b7c75 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/Relationship.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/Relationship.java
@@ -21,62 +21,15 @@
package org.onap.dcaegen2.services.prh.model;
import com.google.gson.annotations.SerializedName;
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
-import java.util.ArrayList;
import java.util.List;
-/**
- * dictionary of relationship
- */
-public class Relationship {
- @SerializedName("relationship")
- private List<RelationshipDict> relationship = null;
-
- public Relationship relationship(List<RelationshipDict> relationship) {
- this.relationship = relationship;
- return this;
- }
-
- public Relationship addRelationshipItem(RelationshipDict relationshipItem) {
- if (this.relationship == null) {
- this.relationship = new ArrayList<>();
- }
- this.relationship.add(relationshipItem);
- return this;
- }
-
- /**
- * Get relationship
- *
- * @return relationship
- **/
- public List<RelationshipDict> getRelationship() {
- return relationship;
- }
-
- public void setRelationship(List<RelationshipDict> relationship) {
- this.relationship = relationship;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("class Relationship {\n");
-
- sb.append(" relationship: ").append(toIndentedString(relationship)).append("\n");
- sb.append("}");
- return sb.toString();
- }
-
- /**
- * Convert the given object to string with each line indented by 4 spaces
- * (except the first line).
- */
- private String toIndentedString(java.lang.Object o) {
- if (o == null) {
- return "null";
- }
- return o.toString().replace("\n", "\n ");
- }
+@Value.Immutable
+@Gson.TypeAdapters(fieldNamingStrategy = true)
+public interface Relationship {
+ @SerializedName("relationship")
+ List<RelationshipDict> getRelationship();
} \ No newline at end of file
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/RelationshipData.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/RelationshipData.java
index 8b33b650..4b1670c6 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/RelationshipData.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/RelationshipData.java
@@ -21,64 +21,29 @@
package org.onap.dcaegen2.services.prh.model;
import com.google.gson.annotations.SerializedName;
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
/**
* RelationshipData
*/
-public class RelationshipData {
- @SerializedName("relationship-key")
- private String relationshipKey = null;
-
- @SerializedName("relationship-value")
- private String relationshipValue = null;
+@Value.Immutable
+@Gson.TypeAdapters(fieldNamingStrategy = true)
+public interface RelationshipData {
/**
* A keyword provided by A&amp;AI to indicate an attribute.
*
* @return relationshipKey
**/
- public String getRelationshipKey() {
- return relationshipKey;
- }
-
- public void setRelationshipKey(String relationshipKey) {
- this.relationshipKey = relationshipKey;
- }
+ @SerializedName("relationship-key")
+ String getRelationshipKey();
/**
* Value of the attribute.
*
* @return relationshipValue
**/
- public String getRelationshipValue() {
- return relationshipValue;
- }
-
- public void setRelationshipValue(String relationshipValue) {
- this.relationshipValue = relationshipValue;
- }
-
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("class RelationshipData {\n");
-
- sb.append(" relationshipKey: ").append(toIndentedString(relationshipKey)).append("\n");
- sb.append(" relationshipValue: ").append(toIndentedString(relationshipValue)).append("\n");
- sb.append("}");
- return sb.toString();
- }
-
- /**
- * Convert the given object to string with each line indented by 4 spaces
- * (except the first line).
- */
- private String toIndentedString(java.lang.Object o) {
- if (o == null) {
- return "null";
- }
- return o.toString().replace("\n", "\n ");
- }
-
+ @SerializedName("relationship-value")
+ String getRelationshipValue();
} \ No newline at end of file
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/RelationshipDict.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/RelationshipDict.java
index 0a7a9459..007f371b 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/RelationshipDict.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/RelationshipDict.java
@@ -21,109 +21,48 @@
package org.onap.dcaegen2.services.prh.model;
import com.google.gson.annotations.SerializedName;
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
+import org.springframework.lang.Nullable;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
* RelationshipDict
*/
-public class RelationshipDict {
- @SerializedName("related-to")
- private String relatedTo = null;
-
- @SerializedName("relationship-label")
- private String relationshipLabel = null;
-
- @SerializedName("related-link")
- private String relatedLink = null;
-
- @SerializedName("relationship-data")
- private List<RelationshipData> relationshipData = null;
+@Value.Immutable
+@Gson.TypeAdapters(fieldNamingStrategy = true)
+public interface RelationshipDict {
/**
* A keyword provided by A&amp;AI to indicate type of node.
- *
- * @return relatedTo
**/
- public String getRelatedTo() {
- return relatedTo;
- }
-
- public void setRelatedTo(String relatedTo) {
- this.relatedTo = relatedTo;
- }
+ @Nullable
+ @SerializedName("related-to")
+ String getRelatedTo();
/**
* The edge label for this relationship.
- *
- * @return relationshipLabel
**/
- public String getRelationshipLabel() {
- return relationshipLabel;
- }
-
- public void setRelationshipLabel(String relationshipLabel) {
- this.relationshipLabel = relationshipLabel;
- }
+ @Nullable
+ @SerializedName("relationship-label")
+ String getRelationshipLabel();
/**
* URL to the object in A&amp;AI.
- *
- * @return relatedLink
**/
- public String getRelatedLink() {
- return relatedLink;
- }
-
- public void setRelatedLink(String relatedLink) {
- this.relatedLink = relatedLink;
- }
-
- public RelationshipDict addRelationshipDataItem(RelationshipData relationshipDataItem) {
- if (this.relationshipData == null) {
- this.relationshipData = new ArrayList<RelationshipData>();
- }
- this.relationshipData.add(relationshipDataItem);
- return this;
- }
+ @Nullable
+ @SerializedName("related-link")
+ String getRelatedLink();
/**
- * Get relationshipData
- *
- * @return relationshipData
+ * relationship Data
**/
- public List<RelationshipData> getRelationshipData() {
- return relationshipData;
- }
-
- public void setRelationshipData(List<RelationshipData> relationshipData) {
- this.relationshipData = relationshipData;
- }
-
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("class RelationshipDict {\n");
-
- sb.append(" relatedTo: ").append(toIndentedString(relatedTo)).append("\n");
- sb.append(" relationshipLabel: ").append(toIndentedString(relationshipLabel)).append("\n");
- sb.append(" relatedLink: ").append(toIndentedString(relatedLink)).append("\n");
- sb.append(" relationshipData: ").append(toIndentedString(relationshipData)).append("\n");
- sb.append("}");
- return sb.toString();
- }
-
- /**
- * Convert the given object to string with each line indented by 4 spaces
- * (except the first line).
- */
- private String toIndentedString(java.lang.Object o) {
- if (o == null) {
- return "null";
- }
- return o.toString().replace("\n", "\n ");
+ @SerializedName("relationship-data")
+ @Value.Default
+ default List<RelationshipData> getRelationshipData() {
+ return Collections.emptyList();
}
} \ No newline at end of file
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/utils/GsonSerializer.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/utils/PrhModelAwareGsonBuilder.java
index 9b6a7e60..1974f6da 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/utils/GsonSerializer.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/utils/PrhModelAwareGsonBuilder.java
@@ -20,18 +20,20 @@
package org.onap.dcaegen2.services.prh.model.utils;
+import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapterFactory;
+
import java.util.ServiceLoader;
-public class GsonSerializer {
+public final class PrhModelAwareGsonBuilder {
- private GsonSerializer() {
- }
+ private static final Iterable<TypeAdapterFactory> TYPE_ADAPTER_FACTORIES =
+ ServiceLoader.load(TypeAdapterFactory.class);
- public static <T> String createJsonBody(T type) {
+ public static Gson createGson() {
GsonBuilder gsonBuilder = new GsonBuilder();
- ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
- return gsonBuilder.create().toJson(type);
+ TYPE_ADAPTER_FACTORIES.forEach(gsonBuilder::registerTypeAdapterFactory);
+ return gsonBuilder.create();
}
-} \ No newline at end of file
+}
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
diff --git a/prh-commons/src/test/resources/some_aai_pnf.json b/prh-commons/src/test/resources/some_aai_pnf.json
new file mode 100644
index 00000000..ee158dff
--- /dev/null
+++ b/prh-commons/src/test/resources/some_aai_pnf.json
@@ -0,0 +1,38 @@
+{
+ "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": [
+ {
+ "related-to": "some relatedTo",
+ "relationship-data": [
+ {
+ "relationship-key": "some relationshipKey",
+ "relationship-value": "some relationshipValue"
+ }
+ ]
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/prh-commons/src/test/resources/some_aai_service_instance.json b/prh-commons/src/test/resources/some_aai_service_instance.json
new file mode 100644
index 00000000..31857314
--- /dev/null
+++ b/prh-commons/src/test/resources/some_aai_service_instance.json
@@ -0,0 +1,39 @@
+{
+ "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": [
+ {
+ "related-to": "some relatedTo",
+ "relationship-data": [
+ {
+ "relationship-key": "some relationshipKey",
+ "relationship-value": "some relationshipValue"
+ }
+ ]
+ }
+ ]
+ }
+} \ No newline at end of file