diff options
author | JulienBe <julien.bertozzi@intl.att.com> | 2020-06-18 19:32:33 +0200 |
---|---|---|
committer | Sébastien Determe <sebastien.determe@intl.att.com> | 2020-07-29 12:29:41 +0000 |
commit | 04b7ecf58e76a1364c46a9ef8ac59d730d658dcb (patch) | |
tree | ce58713551c2a8f16e690d860ea1a9992dc08101 /asdctool/src/test/java/org | |
parent | 5e8464585f07210ad4b20ddfee2c23b1cf2d8b2a (diff) |
Improve Utils coverage and improve Sonar score
Issue-ID: SDC-3131
Signed-off-by: JulienBe <julien.bertozzi@intl.att.com>
Change-Id: I784a0ad563141dfb546ec1d227b3eb03e08faef3
Diffstat (limited to 'asdctool/src/test/java/org')
-rw-r--r-- | asdctool/src/test/java/org/openecomp/sdc/asdctool/UtilsTest.java | 150 |
1 files changed, 66 insertions, 84 deletions
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/UtilsTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/UtilsTest.java index 8ea53003e9..636bc54c95 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/UtilsTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/UtilsTest.java @@ -20,96 +20,78 @@ package org.openecomp.sdc.asdctool; -import org.apache.commons.configuration.Configuration; import org.apache.tinkerpop.gremlin.structure.Element; -import org.janusgraph.core.JanusGraph; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + import javax.ws.rs.core.Response; import java.util.HashMap; import java.util.Map; -public class UtilsTest { - - @Test - public void testBuildOkResponse() throws Exception { - int status = 200; - Object entity = null; - Map<String, String> additionalHeaders = null; - Response result; - - // test with mock entity - Object mockEntity = new Object(); - result = Utils.buildOkResponse(status, entity, additionalHeaders); - Assert.assertNotNull(result); - - // test with mock headers - Map<String, String> mockAdditionalHeaders = new HashMap<>(); - mockAdditionalHeaders.put("stam", "stam"); - result = Utils.buildOkResponse(status, mockEntity, mockAdditionalHeaders); - Assert.assertNotNull(result); - } - - @Test - public void testOpenGraph() throws Exception { - Configuration conf = null; - JanusGraph result; - - // default test with null - result = Utils.openGraph(conf); - } +import static org.junit.jupiter.api.Assertions.*; - @Test - public void testVertexLeftContainsRightProps() throws Exception { - Map<String, Object> leftProps = new HashMap<>(); - Map<String, Object> rightProps = null; - boolean result; - - // test 1 with null - rightProps = null; - result = Utils.vertexLeftContainsRightProps(leftProps, rightProps); - Assert.assertEquals(true, result); - - // test 2 with mocks - Map<String, Object> mockLeftProps = new HashMap<>(); - mockLeftProps.put("stam", new Object()); - Map<String, Object> mockRightProps = new HashMap<>(); - mockRightProps.put("stam", new Object()); - result = Utils.vertexLeftContainsRightProps(mockLeftProps, mockRightProps); - Assert.assertEquals(false, result); - - // test 3 with mocks - Object mockObject = new Object(); - mockLeftProps = new HashMap<>(); - mockLeftProps.put("stam", mockObject); - mockRightProps = new HashMap<>(); - mockRightProps.put("stam", mockObject); - result = Utils.vertexLeftContainsRightProps(mockLeftProps, mockRightProps); - Assert.assertEquals(true, result); - } - - @Test(expected=IllegalArgumentException.class) - public void testSetProperties() throws Exception { - Element element = null; - Map<String, Object> properties = null; - - // test 1 - properties = null; - Utils.setProperties(element, properties); - - // test 2 - properties = new HashMap<>(); - properties.put("stam", new Object()); - Utils.setProperties(element, properties); - } - - @Test(expected=NullPointerException.class) - public void testGetProperties() throws Exception { - Element element = null; - Map<String, Object> result; +public class UtilsTest { - // default test - result = Utils.getProperties(element); - } + @Test + public void testBuildOkResponse() { + int status = 200; + Response result; + + Response responseToNulls = Utils.buildOkResponse(105, null, null); + assertNotNull(responseToNulls); + assertEquals(105, responseToNulls.getStatus()); + assertFalse(responseToNulls.hasEntity()); + + // test with mock headers + Map<String, String> mockAdditionalHeaders = new HashMap<>(); + mockAdditionalHeaders.put("stam", "stam"); + result = Utils.buildOkResponse(status, "entity", mockAdditionalHeaders); + assertNotNull(result); + assertEquals(200, result.getStatus()); + assertTrue(result.hasEntity()); + } + + @Test + public void testOpenGraph() { + assertNotNull(Utils.openGraph(null)); + } + + @Test + public void testVertexLeftContainsRightProps() { + assertTrue(Utils.vertexLeftContainsRightProps(new HashMap<>(), null)); + assertTrue(Utils.vertexLeftContainsRightProps(null, null)); + assertTrue(Utils.vertexLeftContainsRightProps(null, new HashMap<>())); + + // test 2 with mocks + Map<String, Object> mockLeftProps = new HashMap<>(); + mockLeftProps.put("stam", new Object()); + Map<String, Object> mockRightProps = new HashMap<>(); + mockRightProps.put("stam", new Object()); + assertFalse(Utils.vertexLeftContainsRightProps(mockLeftProps, mockRightProps)); + + // test 3 with mocks + Object mockObject = new Object(); + mockLeftProps.put("stam", mockObject); + mockRightProps.put("stam", mockObject); + assertTrue(Utils.vertexLeftContainsRightProps(mockLeftProps, mockRightProps)); + mockLeftProps.put("stam", null); + assertFalse(Utils.vertexLeftContainsRightProps(mockLeftProps, mockRightProps)); + mockLeftProps.put("stam", "Woops"); + assertFalse(Utils.vertexLeftContainsRightProps(mockLeftProps, mockRightProps)); + } + + @Test + public void testSetProperties() { + assertDoesNotThrow(() -> Utils.setProperties(null, null)); + assertDoesNotThrow(() -> Utils.setProperties(Mockito.mock(Element.class), null)); + Map<String, Object> properties = new HashMap<>(); + properties.put("stam", new Object()); + assertThrows(IllegalArgumentException.class, () -> Utils.setProperties(null, properties)); + } + + @Test + public void testGetProperties() { + assertDoesNotThrow(() -> Utils.getProperties(null)); + } } |