From 815674c947f970e9e57e06c8907758f88032b30a Mon Sep 17 00:00:00 2001 From: Dmitry Puzikov Date: Fri, 20 Mar 2020 09:11:38 +0100 Subject: Fix unit tests Add asserts where required, fix tiny issues. Replaced getters-setters with Lombok annotations. Change-Id: I9d75c871870fffe82876e14dd2eb9d3585ecb916 Issue-ID: SDC-2708 Signed-off-by: Dmitry Puzikov --- .../be/components/validation/ApiResourceEnum.java | 8 +-- .../api/client/RegistrationRequest.java | 39 ++---------- .../api/client/ServerListResponse.java | 15 ++--- .../api/client/TopicRegistrationResponse.java | 23 +++---- .../api/client/TopicUnregistrationResponse.java | 19 +----- .../components/validation/ApiResourceEnumTest.java | 12 ++-- .../api/client/RegistrationRequestTest.java | 73 +++++++--------------- .../api/client/ServerListResponseTest.java | 25 +++----- .../api/client/TopicRegistrationResponseTest.java | 46 +++----------- .../client/TopicUnregistrationResponseTest.java | 12 +++- 10 files changed, 81 insertions(+), 191 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ApiResourceEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ApiResourceEnum.java index 1a10ac94b1..7f217b95b1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ApiResourceEnum.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ApiResourceEnum.java @@ -20,9 +20,12 @@ package org.openecomp.sdc.be.components.validation; +import lombok.Getter; + /** * Created by chaya on 11/14/2017. */ +@Getter public enum ApiResourceEnum { ENVIRONMENT_ID("Environment ID"), @@ -34,9 +37,4 @@ public enum ApiResourceEnum { ApiResourceEnum(String value) { this.value = value; } - - public String getValue() { - return this.value; - } - } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java index 8377749a64..1ce3621d84 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java @@ -21,7 +21,11 @@ package org.openecomp.sdc.be.distribution.api.client; import java.util.List; +import lombok.Getter; +import lombok.Setter; +@Getter +@Setter public class RegistrationRequest { private String apiPublicKey; private String distrEnvName; @@ -41,39 +45,4 @@ public class RegistrationRequest { this.distEnvEndPoints = distEnvEndPoints; this.isConsumerToSdcDistrStatusTopic = isConsumerToSdcDistrStatusTopic; } - - public String getApiPublicKey() { - return apiPublicKey; - } - - public String getDistrEnvName() { - return distrEnvName; - } - - public Boolean getIsConsumerToSdcDistrStatusTopic() { - return isConsumerToSdcDistrStatusTopic; - } - public List getDistEnvEndPoints() { - return distEnvEndPoints; - } - - public void setDistEnvEndPoints(List distEnvEndPoints) { - this.distEnvEndPoints = distEnvEndPoints; - } - - public String getManagerApiPublicKey() { - return managerApiPublicKey; - } - - public void setManagerApiPublicKey(String managerApiPublicKey) { - this.managerApiPublicKey = managerApiPublicKey; - } - - public String getManagerApiSecretKey() { - return managerApiSecretKey; - } - - public void setManagerApiSecretKey(String managerApiSecretKey) { - this.managerApiSecretKey = managerApiSecretKey; - } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/ServerListResponse.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/ServerListResponse.java index 2eebedfd7c..b0db19f541 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/ServerListResponse.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/ServerListResponse.java @@ -21,16 +21,13 @@ package org.openecomp.sdc.be.distribution.api.client; import java.util.List; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +@Getter +@Setter +@NoArgsConstructor(force = true) public class ServerListResponse { - private List uebServerList; - - public List getUebServerList() { - return uebServerList; - } - - public void setUebServerList(List uebServerList) { - this.uebServerList = uebServerList; - } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicRegistrationResponse.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicRegistrationResponse.java index 5d1b0657c6..6b3e9e15e2 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicRegistrationResponse.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicRegistrationResponse.java @@ -20,23 +20,14 @@ package org.openecomp.sdc.be.distribution.api.client; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor(force = true) public class TopicRegistrationResponse { String distrNotificationTopicName; String distrStatusTopicName; - - public void setDistrNotificationTopicName(String distrNotificationTopicName) { - this.distrNotificationTopicName = distrNotificationTopicName; - } - - public void setDistrStatusTopicName(String distrStatusTopicName) { - this.distrStatusTopicName = distrStatusTopicName; - } - - public String getDistrNotificationTopicName() { - return distrNotificationTopicName; - } - - public String getDistrStatusTopicName() { - return distrStatusTopicName; - } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicUnregistrationResponse.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicUnregistrationResponse.java index 621cd37a54..55c3baef24 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicUnregistrationResponse.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/TopicUnregistrationResponse.java @@ -20,6 +20,9 @@ package org.openecomp.sdc.be.distribution.api.client; +import lombok.Getter; + +@Getter public class TopicUnregistrationResponse { String distrNotificationTopicName; String distrStatusTopicName; @@ -33,20 +36,4 @@ public class TopicUnregistrationResponse { this.notificationUnregisterResult = notificationUnregisterResult; this.statusUnregisterResult = statusUnregisterResult; } - - public String getDistrNotificationTopicName() { - return distrNotificationTopicName; - } - - public String getDistrStatusTopicName() { - return distrStatusTopicName; - } - - public CambriaOperationStatus getNotificationUnregisterResult() { - return notificationUnregisterResult; - } - - public CambriaOperationStatus getStatusUnregisterResult() { - return statusUnregisterResult; - } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ApiResourceEnumTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ApiResourceEnumTest.java index 0fe0557656..d2b7b42870 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ApiResourceEnumTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ApiResourceEnumTest.java @@ -20,6 +20,9 @@ package org.openecomp.sdc.be.components.validation; + +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Test; public class ApiResourceEnumTest { @@ -28,13 +31,14 @@ public class ApiResourceEnumTest { return ApiResourceEnum.ENVIRONMENT_ID; } - @Test - public void testGetValue() throws Exception { + @Test + public void testApiResourceEnumConstructor() { ApiResourceEnum testSubject; - String result; // default test testSubject = createTestSubject(); - result = testSubject.getValue(); + assertThat(testSubject) + .isInstanceOf(ApiResourceEnum.class) + .hasFieldOrPropertyWithValue("value", "Environment ID"); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequestTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequestTest.java index db22c1edeb..6fa6bffad2 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequestTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequestTest.java @@ -20,70 +20,41 @@ package org.openecomp.sdc.be.distribution.api.client; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Test; import java.util.LinkedList; import java.util.List; public class RegistrationRequestTest { + private static final String API_KEY = "mock-api-key"; + private static final String DISTR_ENV_NAME = "mock-distr-env-name"; private RegistrationRequest createTestSubject() { - return new RegistrationRequest("", "", false); - } - - @Test - public void testConstructor() throws Exception { - List distEnvEndPoints = new LinkedList<>(); - new RegistrationRequest("mock", "mock", distEnvEndPoints , false); - } - - @Test - public void testGetApiPublicKey() throws Exception { - RegistrationRequest testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getApiPublicKey(); + return new RegistrationRequest(API_KEY, DISTR_ENV_NAME, false); } @Test - public void testGetDistrEnvName() throws Exception { - RegistrationRequest testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getDistrEnvName(); - } - - @Test - public void testGetIsConsumerToSdcDistrStatusTopic() throws Exception { - RegistrationRequest testSubject; - Boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getIsConsumerToSdcDistrStatusTopic(); - } - - @Test - public void testGetDistEnvEndPoints() throws Exception { - RegistrationRequest testSubject; - List result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getDistEnvEndPoints(); + public void testConstructorThreeArgs() throws Exception { + List distEnvEndPoints = new LinkedList<>(); + RegistrationRequest request = new RegistrationRequest(API_KEY, DISTR_ENV_NAME, true ); + assertThat(request) + .isInstanceOf(RegistrationRequest.class) + .hasFieldOrPropertyWithValue("apiPublicKey", API_KEY) + .hasFieldOrPropertyWithValue("distrEnvName", DISTR_ENV_NAME) + .hasFieldOrPropertyWithValue("isConsumerToSdcDistrStatusTopic", true); } @Test - public void testSetDistEnvEndPoints() throws Exception { - RegistrationRequest testSubject; - List distEnvEndPoints = null; - - // default test - testSubject = createTestSubject(); - testSubject.setDistEnvEndPoints(distEnvEndPoints); + public void testConstructorFourArgs() throws Exception { + List distEnvEndPoints = new LinkedList<>(); + RegistrationRequest request = new RegistrationRequest(API_KEY, DISTR_ENV_NAME, distEnvEndPoints , false); + assertThat(request) + .isInstanceOf(RegistrationRequest.class) + .hasFieldOrPropertyWithValue("apiPublicKey", API_KEY) + .hasFieldOrPropertyWithValue("distrEnvName", DISTR_ENV_NAME) + .hasFieldOrPropertyWithValue("distEnvEndPoints", distEnvEndPoints) + .hasFieldOrPropertyWithValue("isConsumerToSdcDistrStatusTopic", false); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/ServerListResponseTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/ServerListResponseTest.java index b89e96696c..d1b3853c47 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/ServerListResponseTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/ServerListResponseTest.java @@ -20,33 +20,26 @@ package org.openecomp.sdc.be.distribution.api.client; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; import org.junit.Test; import java.util.List; public class ServerListResponseTest { - - private ServerListResponse createTestSubject() { - return new ServerListResponse(); - } - @Test - public void testGetUebServerList() throws Exception { + public void testServerResponseCOnstructor() { ServerListResponse testSubject; - List result; // default test testSubject = createTestSubject(); - result = testSubject.getUebServerList(); + assertThat(testSubject) + .isInstanceOf(ServerListResponse.class) + .hasFieldOrPropertyWithValue("uebServerList", null); } - @Test - public void testSetUebServerList() throws Exception { - ServerListResponse testSubject; - List uebServerList = null; - - // default test - testSubject = createTestSubject(); - testSubject.setUebServerList(uebServerList); + private ServerListResponse createTestSubject() { + return new ServerListResponse(); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/TopicRegistrationResponseTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/TopicRegistrationResponseTest.java index ee75237b33..96590e6f15 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/TopicRegistrationResponseTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/TopicRegistrationResponseTest.java @@ -20,51 +20,23 @@ package org.openecomp.sdc.be.distribution.api.client; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Test; public class TopicRegistrationResponseTest { - - private TopicRegistrationResponse createTestSubject() { - return new TopicRegistrationResponse(); - } - - @Test - public void testSetDistrNotificationTopicName() throws Exception { - TopicRegistrationResponse testSubject; - String distrNotificationTopicName = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setDistrNotificationTopicName(distrNotificationTopicName); - } - - @Test - public void testSetDistrStatusTopicName() throws Exception { - TopicRegistrationResponse testSubject; - String distrStatusTopicName = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setDistrStatusTopicName(distrStatusTopicName); - } - @Test - public void testGetDistrNotificationTopicName() throws Exception { + public void testTopicRegistrationResponseConstructor() throws Exception { TopicRegistrationResponse testSubject; - String result; - // default test testSubject = createTestSubject(); - result = testSubject.getDistrNotificationTopicName(); + assertThat(testSubject) + .isInstanceOf(TopicRegistrationResponse.class) + .hasFieldOrPropertyWithValue("distrNotificationTopicName", null) + .hasFieldOrPropertyWithValue("distrStatusTopicName", null); } - @Test - public void testGetDistrStatusTopicName() throws Exception { - TopicRegistrationResponse testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getDistrStatusTopicName(); + private TopicRegistrationResponse createTestSubject() { + return new TopicRegistrationResponse(); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/TopicUnregistrationResponseTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/TopicUnregistrationResponseTest.java index 79088b5d5c..79e43bccb1 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/TopicUnregistrationResponseTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/distribution/api/client/TopicUnregistrationResponseTest.java @@ -20,22 +20,27 @@ package org.openecomp.sdc.be.distribution.api.client; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Test; public class TopicUnregistrationResponseTest { + private static final String NOTIF_TOPIC_NAME = "notif-mock-topic-name"; + private static final String STATUS_TOPIC_NAME = "status-mock-topic-name"; private TopicUnregistrationResponse createTestSubject() { - return new TopicUnregistrationResponse("", "", CambriaOperationStatus.AUTHENTICATION_ERROR, CambriaOperationStatus.AUTHENTICATION_ERROR); + return new TopicUnregistrationResponse(NOTIF_TOPIC_NAME, STATUS_TOPIC_NAME, CambriaOperationStatus.AUTHENTICATION_ERROR, CambriaOperationStatus.AUTHENTICATION_ERROR); } @Test - public void testGetDistrNotificationTopicName() throws Exception { + public void testTopicUnregistrationResponseConstructor() throws Exception { TopicUnregistrationResponse testSubject; String result; // default test testSubject = createTestSubject(); result = testSubject.getDistrNotificationTopicName(); + assertThat(result).isEqualTo(NOTIF_TOPIC_NAME); } @Test @@ -46,6 +51,7 @@ public class TopicUnregistrationResponseTest { // default test testSubject = createTestSubject(); result = testSubject.getDistrStatusTopicName(); + assertThat(result).isEqualTo(STATUS_TOPIC_NAME); } @Test @@ -56,6 +62,7 @@ public class TopicUnregistrationResponseTest { // default test testSubject = createTestSubject(); result = testSubject.getNotificationUnregisterResult(); + assertThat(result).isEqualTo(CambriaOperationStatus.AUTHENTICATION_ERROR); } @Test @@ -66,5 +73,6 @@ public class TopicUnregistrationResponseTest { // default test testSubject = createTestSubject(); result = testSubject.getStatusUnregisterResult(); + assertThat(result).isEqualTo(CambriaOperationStatus.AUTHENTICATION_ERROR); } } -- cgit 1.2.3-korg