Pnf pojo improvements 27/91527/2
authorMichal Kabaj <michal.kabaj@nokia.com>
Fri, 19 Jul 2019 10:12:28 +0000 (12:12 +0200)
committerMichal Kabaj <michal.kabaj@nokia.com>
Fri, 19 Jul 2019 10:12:28 +0000 (12:12 +0200)
- added builder
- immutable
- improved json serialization

Change-Id: If0c9128dfd27d1c04e2f8683bade16700789276e
Issue-ID: VID-478
Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com>
vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfs/Pnf.java
vid-app-common/src/test/java/org/onap/vid/aai/model/AaiGetPnfs/PnfTest.java
vid-app-common/src/test/java/org/onap/vid/bl/AaiServiceTest.java
vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java

index e9d8c64..2d54563 100644 (file)
@@ -3,13 +3,14 @@
  * VID
  * ================================================================================
  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nokia.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * 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.
 package org.onap.vid.aai.model.AaiGetPnfs;
 
 import com.fasterxml.jackson.annotation.JsonAlias;
+import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import org.onap.vid.aai.model.AaiRelationResponse;
 
 @JsonIgnoreProperties(ignoreUnknown = true)
-public class Pnf extends AaiRelationResponse {
+public final class Pnf extends AaiRelationResponse {
+
+    private final String pnfId;
+    private final String pnfName;
+    private final String pnfName2;
+    private final String pnfName2Source;
+    private final String equipType;
+    private final String equipVendor;
+    private final String equipModel;
+
+    @JsonCreator
+    public Pnf(
+        @JsonAlias("pnf-id") String pnfId, @JsonAlias("pnf-name") String pnfName,
+        @JsonAlias("pnf-name2") String pnfName2, @JsonAlias("pnf-name2-source") String pnfName2Source,
+        @JsonAlias("equip-type") String equipType, @JsonAlias("equip-vendor") String equipVendor,
+        @JsonAlias("equip-model") String equipModel) {
 
-    private String pnfName;
-    private String pnfName2;
-    private String pnfName2Source;
-    private String pnfId;
-    private String equipType;
-    private String equipVendor;
-    private String equipModel;
-
-    public String getPnfName() {
-        return pnfName;
-    }
-
-    @JsonAlias("pnf-name")
-    public void setPnfName(String pnfName) {
+        this.pnfId = pnfId;
         this.pnfName = pnfName;
+        this.pnfName2 = pnfName2;
+        this.pnfName2Source = pnfName2Source;
+        this.equipType = equipType;
+        this.equipVendor = equipVendor;
+        this.equipModel = equipModel;
     }
 
-    public String getEquipType() {
-        return equipType;
-    }
-
-    @JsonAlias("equip-type")
-    public void setEquipType(String equipType) {
-        this.equipType = equipType;
+    public static Builder builder() {
+        return new Builder();
     }
 
-    public String getEquipVendor() {
-        return equipVendor;
+    public String getPnfId() {
+        return pnfId;
     }
 
-    @JsonAlias("equip-vendor")
-    public void setEquipVendor(String equipVendor) {
-        this.equipVendor = equipVendor;
+    public String getPnfName() {
+        return pnfName;
     }
 
     public String getPnfName2() {
         return pnfName2;
     }
 
-    @JsonAlias("pnf-name2")
-    public void setPnfName2(String pnfName2) {
-        this.pnfName2 = pnfName2;
+    public String getPnfName2Source() {
+        return pnfName2Source;
     }
 
-    public String getPnfId() {
-        return pnfId;
+    public String getEquipType() {
+        return equipType;
     }
 
-    @JsonAlias("pnf-id")
-    public void setPnfId(String pnfId) {
-        this.pnfId = pnfId;
+    public String getEquipVendor() {
+        return equipVendor;
     }
 
     public String getEquipModel() {
         return equipModel;
     }
 
-    @JsonAlias("equip-model")
-    public void setEquipModel(String equipModel) {
-        this.equipModel = equipModel;
+    public static class Builder {
+
+        private String pnfId;
+        private String pnfName;
+        private String pnfName2;
+        private String pnfName2Source;
+        private String equipType;
+        private String equipVendor;
+        private String equipModel;
+
+        public Builder withPnfId(String pnfId) {
+            this.pnfId = pnfId;
+            return this;
+        }
+
+        public Builder withPnfName(String pnfName) {
+            this.pnfName = pnfName;
+            return this;
+        }
+
+        public Builder withPnfName2(String pnfName2) {
+            this.pnfName2 = pnfName2;
+            return this;
+        }
+
+        public Builder withPnfName2Source(String pnfName2Source) {
+            this.pnfName2Source = pnfName2Source;
+            return this;
+        }
+
+        public Builder withEquipType(String equipType) {
+            this.equipType = equipType;
+            return this;
+        }
+
+        public Builder withEquipVendor(String equipVendor) {
+            this.equipVendor = equipVendor;
+            return this;
+        }
+
+        public Builder withEquipModel(String equipModel) {
+            this.equipModel = equipModel;
+            return this;
+        }
+
+        public Pnf build() {
+            return new Pnf(pnfId, pnfName, pnfName2, pnfName2Source, equipType, equipVendor, equipModel);
+        }
     }
-
-    public String getPnfName2Source() { return pnfName2Source; }
-
-    @JsonAlias("pnf-name2-source")
-    public void setPnfName2Source(String pnfName2Source) { this.pnfName2Source = pnfName2Source; }
 }
 
index 2d7d2aa..7a5d3ad 100644 (file)
@@ -3,13 +3,14 @@
  * VID
  * ================================================================================
  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nokia.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * 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.
 
 package org.onap.vid.aai.model.AaiGetPnfs;
 
-import org.junit.Test;
+import static org.assertj.core.api.Assertions.assertThat;
 
-import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
-import static org.hamcrest.MatcherAssert.assertThat;
+import org.junit.Test;
 
 public class PnfTest {
 
     @Test
-    public void shouldHaveValidGettersAndSetters(){
-        assertThat(Pnf.class, hasValidGettersAndSetters());
-    }
+    public void builder_shouldProperlyConstructObject() {
+        Pnf pnf = Pnf.builder()
+            .withPnfId("pnfId")
+            .withPnfName("TestPnf")
+            .withPnfName2("pnfName2")
+            .withPnfName2Source("pnfNameSource")
+            .withEquipModel("model")
+            .withEquipType("type")
+            .withEquipVendor("vendor")
+            .build();
 
+        assertThat(pnf.getPnfId()).isEqualTo("pnfId");
+        assertThat(pnf.getPnfName()).isEqualTo("TestPnf");
+        assertThat(pnf.getPnfName2()).isEqualTo("pnfName2");
+        assertThat(pnf.getPnfName2Source()).isEqualTo("pnfNameSource");
+        assertThat(pnf.getEquipModel()).isEqualTo("model");
+        assertThat(pnf.getEquipType()).isEqualTo("type");
+        assertThat(pnf.getEquipVendor()).isEqualTo("vendor");
+    }
 }
index 1b50681..1d45565 100644 (file)
@@ -67,8 +67,7 @@ public class AaiServiceTest {
 
     @Test
     public void testGetSpecificPnf(){
-        Pnf pnf = new Pnf();
-        pnf.setPnfId("11111");
+        Pnf pnf = Pnf.builder().withPnfId("11111").build();
         AaiResponse<Pnf> aaiResponse = new AaiResponse<>(pnf, "aaaa", 200);
         Mockito.doReturn(aaiResponse).when(aaiClientInterface).getSpecificPnf(Mockito.anyString());
         AaiResponse<Pnf> specificPnf = aaiService.getSpecificPnf("1345667");
index 2df28d9..a60aa7e 100644 (file)
@@ -173,7 +173,15 @@ public class AaiControllerTest {
     @Test
     public void getSpecificPnf_shouldReturnPnfObjectForPnfId() throws Exception {
         String pnfId = "MyPnfId";
-        Pnf pnf = createPnf(pnfId);
+        Pnf pnf = Pnf.builder()
+            .withPnfId(pnfId)
+            .withPnfName("TestPnf")
+            .withPnfName2("pnfName2")
+            .withPnfName2Source("pnfNameSource")
+            .withEquipModel("model")
+            .withEquipType("type")
+            .withEquipVendor("vendor")
+            .build();
         AaiResponse<Pnf> aaiResponse = new AaiResponse<>(pnf, "", HttpStatus.OK.value());
         given(aaiService.getSpecificPnf(pnfId)).willReturn(aaiResponse);
 
@@ -197,13 +205,6 @@ public class AaiControllerTest {
             .andExpect(content().string(expectedErrorMessage));
     }
 
-    private Pnf createPnf(String pnfId) {
-        Pnf pnf = new Pnf();
-        pnf.setPnfId(pnfId);
-        pnf.setPnfName("TestPnf");
-        return pnf;
-    }
-
     public void getPNFInstances_shouldReturnOKResponseFromAAIService() throws Exception {
         String globalCustomerId = "testCustomerId";
         String serviceType = "testServiceType";
index 068cc00..bb47180 100644 (file)
@@ -213,7 +213,7 @@ public class AaiServiceImplTest {
 
        @Test
        public void shouldGetSpecificPnf() {
-               AaiResponse<Pnf> expectedResponse = new AaiResponse<>(new Pnf(), null, HttpStatus.SC_OK);
+               AaiResponse<Pnf> expectedResponse = new AaiResponse<>(Pnf.builder().build(), null, HttpStatus.SC_OK);
                when(aaiClient.getSpecificPnf(anyString())).thenReturn(expectedResponse);
 
                AaiResponse<Pnf> actualResponse = aaiService.getSpecificPnf(anyString());