From 34b0436df1ad8a11e29c588842ac491a6a6d7b26 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Wed, 21 Jul 2021 17:40:43 +0200 Subject: add junit coverage Issue-ID: SO-3715 Signed-off-by: Lukasz Muszkieta Change-Id: I6da3048f6af8e0db671929b72ae0d5e468dd134b --- .../so/client/sdn/common/SdnCommonTasksTest.java | 104 ---------------- .../onap/so/client/sdnc/SdnCommonTasksTest.java | 133 +++++++++++++++++++++ 2 files changed, 133 insertions(+), 104 deletions(-) delete mode 100644 so-sdn-clients/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java create mode 100644 so-sdn-clients/src/test/java/org/onap/so/client/sdnc/SdnCommonTasksTest.java (limited to 'so-sdn-clients') diff --git a/so-sdn-clients/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java b/so-sdn-clients/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java deleted file mode 100644 index a8816e1b04..0000000000 --- a/so-sdn-clients/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.client.sdn.common; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import java.util.LinkedHashMap; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.so.client.exception.BadResponseException; -import org.onap.so.client.exception.MapperException; -import org.onap.so.client.sdnc.SdnCommonTasks; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; - - -public class SdnCommonTasksTest { - - - SdnCommonTasks sdnCommonTasks = new SdnCommonTasks(); - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void buildJsonRequestTest() throws MapperException { - String jsonStr = sdnCommonTasks.buildJsonRequest(""); - Assert.assertNotNull(jsonStr); - } - - @Test - public void buildJsonRequestTestException() throws MapperException { - expectedException.expect(MapperException.class); - sdnCommonTasks.buildJsonRequest(new Object()); - } - - @Test - public void getHttpHeadersTest() { - HttpHeaders result = sdnCommonTasks.getHttpHeaders("auth", true); - - assertEquals("auth", result.getFirst("Authorization")); - assertEquals(MediaType.APPLICATION_JSON.toString(), result.getFirst("Content-Type")); - assertEquals(MediaType.APPLICATION_JSON.toString(), result.getFirst("Accept")); - } - - @Test - public void getHttpHeadersGetRequestTest() { - HttpHeaders result = sdnCommonTasks.getHttpHeaders("auth", false); - - assertEquals("auth", result.getFirst("Authorization")); - assertEquals(MediaType.APPLICATION_JSON.toString(), result.getFirst("Accept")); - assertFalse(result.containsKey("Content-Type")); - } - - @Test - public void validateSDNResponseTest() throws BadResponseException { - String jsonResponse = "{\"output\":{\"response-code\":\"0\",\"response-message\":\"success\"}}"; - LinkedHashMap responseMap = new LinkedHashMap<>(); - LinkedHashMap output = new LinkedHashMap<>(); - output.put("response-code", "0"); - output.put("response-message", "success"); - responseMap.put("output", output); - assertEquals(jsonResponse, sdnCommonTasks.validateSDNResponse(responseMap)); - } - - @Test - public void validateSDNResponseTestException() throws BadResponseException { - expectedException.expect(BadResponseException.class); - LinkedHashMap responseMap = new LinkedHashMap(); - Assert.assertNotNull(sdnCommonTasks.validateSDNResponse(responseMap)); - } - - @Test - public void validateSDNResponseTestRespCodeNot200() throws BadResponseException { - expectedException.expect(BadResponseException.class); - LinkedHashMap responseMap = new LinkedHashMap<>(); - LinkedHashMap output = new LinkedHashMap<>(); - output.put("response-code", "300"); - output.put("response-message", "Failed"); - responseMap.put("output", output); - sdnCommonTasks.validateSDNResponse(responseMap); - } - -} diff --git a/so-sdn-clients/src/test/java/org/onap/so/client/sdnc/SdnCommonTasksTest.java b/so-sdn-clients/src/test/java/org/onap/so/client/sdnc/SdnCommonTasksTest.java new file mode 100644 index 0000000000..fa3bf1d16c --- /dev/null +++ b/so-sdn-clients/src/test/java/org/onap/so/client/sdnc/SdnCommonTasksTest.java @@ -0,0 +1,133 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2021 - 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import java.util.LinkedHashMap; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.client.exception.MapperException; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; + + +public class SdnCommonTasksTest { + + + SdnCommonTasks sdnCommonTasks = new SdnCommonTasks(); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void buildJsonRequestTest() throws MapperException { + String jsonStr = sdnCommonTasks.buildJsonRequest(""); + Assert.assertNotNull(jsonStr); + } + + @Test + public void buildJsonRequestTestException() throws MapperException { + expectedException.expect(MapperException.class); + sdnCommonTasks.buildJsonRequest(new Object()); + } + + @Test + public void getHttpHeadersTest() { + HttpHeaders result = sdnCommonTasks.getHttpHeaders("auth", true); + + assertEquals("auth", result.getFirst("Authorization")); + assertEquals(MediaType.APPLICATION_JSON.toString(), result.getFirst("Content-Type")); + assertEquals(MediaType.APPLICATION_JSON.toString(), result.getFirst("Accept")); + } + + @Test + public void getHttpHeadersGetRequestTest() { + HttpHeaders result = sdnCommonTasks.getHttpHeaders("auth", false); + + assertEquals("auth", result.getFirst("Authorization")); + assertEquals(MediaType.APPLICATION_JSON.toString(), result.getFirst("Accept")); + assertFalse(result.containsKey("Content-Type")); + } + + @Test + public void validateSDNResponseTest() throws BadResponseException { + String jsonResponse = "{\"output\":{\"response-code\":\"0\",\"response-message\":\"success\"}}"; + LinkedHashMap responseMap = new LinkedHashMap<>(); + LinkedHashMap output = new LinkedHashMap<>(); + output.put("response-code", "0"); + output.put("response-message", "success"); + responseMap.put("output", output); + assertEquals(jsonResponse, sdnCommonTasks.validateSDNResponse(responseMap)); + } + + @Test + public void validateSDNResponseTestException() throws BadResponseException { + expectedException.expect(BadResponseException.class); + LinkedHashMap responseMap = new LinkedHashMap(); + Assert.assertNotNull(sdnCommonTasks.validateSDNResponse(responseMap)); + } + + @Test + public void validateSDNResponseTestRespCodeNot200() throws BadResponseException { + expectedException.expect(BadResponseException.class); + LinkedHashMap responseMap = new LinkedHashMap<>(); + LinkedHashMap output = new LinkedHashMap<>(); + output.put("response-code", "300"); + output.put("response-message", "Failed"); + responseMap.put("output", output); + sdnCommonTasks.validateSDNResponse(responseMap); + } + + @Test + public void validateSDNResponse_emptyWhenNoSerializerFoundForValue() throws Exception { + LinkedHashMap output = new LinkedHashMap<>(); + output.put("key1", new Object()); + String result = sdnCommonTasks.validateSDNResponse(output); + assertThat(result).isEmpty(); + } + + @Test + public void validateSDNGetResponse_success() throws Exception { + LinkedHashMap output = new LinkedHashMap<>(); + output.put("key1", "value1"); + String result = sdnCommonTasks.validateSDNGetResponse(output); + assertThat(result).isEqualTo("{\"key1\":\"value1\"}"); + } + + @Test(expected = BadResponseException.class) + public void validateSDNGetResponse_exWhenNoSerializerFoundForValue() throws Exception { + LinkedHashMap output = new LinkedHashMap<>(); + output.put("key1", new Object()); + sdnCommonTasks.validateSDNGetResponse(output); + } + + @Test(expected = BadResponseException.class) + public void validateSDNGetResponse_exWhenMapEmpty() throws Exception { + sdnCommonTasks.validateSDNGetResponse(new LinkedHashMap<>()); + } +} -- cgit 1.2.3-korg