diff options
author | Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com> | 2018-06-08 16:40:16 -0400 |
---|---|---|
committer | Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com> | 2018-06-14 10:03:31 -0400 |
commit | f51a3e2b128f0b96bc9ed67dfc3081f4b41d1303 (patch) | |
tree | db4f24c3bc4e70bcda2916d7fa7027e9ab984cf3 /ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap | |
parent | 1ffd6b689a0176875b401fb089bd33db96f07b62 (diff) |
Junit Test Cases & Raptors
Issue-ID: PORTAL-273. PORTAL-301
Covered JUNITS for sdk modules and RAPTOR reports fixes
Change-Id: Ifaf3bf06f0ec123051a791cc8e7f10662f97a525
Signed-off-by: Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap')
9 files changed, 915 insertions, 11 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineCollectionTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineCollectionTest.java new file mode 100644 index 00000000..13b7fbfe --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineCollectionTest.java @@ -0,0 +1,141 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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.portalsdk.analytics.gmap.line; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.List; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; + +public class LineCollectionTest { + + LineCollection lineCollection; + LineInfo lineInfo; + private String LINE_ID = "lineID"; + private String LINE_TYPE = "test"; + private String NODE1 = "nodeID1"; + private String NODE2 = "nodeID2"; + + @Before + public void init() throws Exception { + lineCollection = new LineCollection(); + lineInfo = new LineInfo(NODE1, NODE2); + lineInfo.setLineID(LINE_ID); + lineInfo.setLineType(LINE_TYPE); + lineCollection.addLine(lineInfo); + lineCollection.addSelectedLine(LINE_ID); + } + + @Test + public void testGetLineCollection() { + List<LineInfo> lineInfoList = lineCollection.getLineCollection(); + assertNotNull(lineInfoList); + assertEquals(1,lineCollection.getSize()); + } + + @Test + public void testGetSelectedLine() { + Set<String> selectedLine = lineCollection.getSelectedLine(); + assertNotNull(selectedLine); + } + + @Test + public void testContainsSelectedLine() { + assertEquals(true,lineCollection.containSelectedLine(LINE_ID)); + } + + @Test + public void testRemoveSelectedLine() { + lineCollection.removeSelectedLine(LINE_ID); + assertEquals(false,lineCollection.containSelectedLine(LINE_ID)); + } + + @Test + public void testClearAllCollection() { + lineCollection.addSelectedLine(LINE_ID); + lineCollection.clearAllCollection(); + assertEquals(false,lineCollection.containSelectedLine(LINE_ID)); + } + + @Test + public void testGetLineByLineID() { + LineInfo lineInfo = lineCollection.getLine(LINE_ID); + assertEquals("lineID", lineInfo.getLineID()); + } + + @Test + public void testGetLineByLineIDAndType() { + LineInfo lineInfo = lineCollection.getLine(LINE_ID,LINE_TYPE); + assertEquals("lineID", lineInfo.getLineID()); + assertEquals("test", lineInfo.getLineType()); + } + + @Test + public void testGetLineByNode() { + LineInfo lineInfo = lineCollection.getLine(NODE1,NODE2,true); + assertEquals("nodeID1", lineInfo.getNodeID1()); + assertEquals("nodeID2", lineInfo.getNodeID2()); + } + + @Test + public void testGetWildCardLine() { + String[] lineIDArr = lineCollection.getWildCardLine("li"); + assertEquals("lineID", lineIDArr[0]); + } + + @Test + public void testRemoveLineByLineID() { + LineInfo lineInfo = lineCollection.removeLine(LINE_ID); + LineInfo lineInfo1 = lineCollection.getLine(lineInfo.getLineID()); + lineCollection.addLine(lineInfo1); + assertNull(lineInfo1); + } + + @Test + public void testRemoveLineByLineIDAndType() { + LineInfo lineInfo = lineCollection.removeLine(LINE_ID,LINE_TYPE); + LineInfo lineInfo1 = lineCollection.getLine(lineInfo.getLineID()); + assertNull(lineInfo1); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineInfoTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineInfoTest.java new file mode 100644 index 00000000..5ff6e78b --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineInfoTest.java @@ -0,0 +1,117 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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.portalsdk.analytics.gmap.line; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; + +public class LineInfoTest { + + LineInfo lineInfo; + + private String NODE_ID1 = "nodeID1"; + private String NODE_ID2 = "nodeID2"; + private String LINE_ID = "lineID"; + private String LINE_TYPE = "lineType"; + private String LINE_DESCRIPTION = "lineDescription"; + private boolean MOVEABLE = true; + private boolean DELETEABLE = true; + private int STATE = 1; + + @Before + public void init() { + lineInfo = new LineInfo(NODE_ID1, NODE_ID2); + lineInfo.setNodeID1(NODE_ID1); + lineInfo.setNodeID2(NODE_ID2); + lineInfo.setLineID(LINE_ID); + lineInfo.setLineType(LINE_TYPE); + lineInfo.setDescription(LINE_DESCRIPTION); + lineInfo.setMoveable(MOVEABLE); + lineInfo.setDeleteable(DELETEABLE); + lineInfo.setState(STATE); + Map<String, String> lineAttributes = new HashMap<>(); + lineAttributes.put("x_length", "200cm"); + lineInfo.initializeAttributes(lineAttributes); + lineInfo.setAttribute("x_length", "300cm"); + } + + @Test + public void testNotNull() { + assertNotNull(lineInfo); + } + + @Test + public void testLineInfoProperties() { + assertEquals(NODE_ID1, lineInfo.getNodeID1()); + assertEquals(NODE_ID2, lineInfo.getNodeID2()); + assertEquals(LINE_ID, lineInfo.getLineID()); + assertEquals(LINE_TYPE, lineInfo.getLineType()); + assertEquals(LINE_DESCRIPTION, lineInfo.getDescription()); + assertEquals(MOVEABLE, lineInfo.isMoveable()); + assertEquals(DELETEABLE, lineInfo.isDeleteable()); + assertEquals(STATE, lineInfo.getState()); + assertEquals("300cm", lineInfo.getAttribute("x_length")); + } + + @Test + public void testClone() { + LineInfo lineInfo2 = lineInfo.clone(); + assertEquals(NODE_ID1, lineInfo2.getNodeID1()); + assertEquals(NODE_ID2, lineInfo2.getNodeID2()); + assertEquals(LINE_ID, lineInfo2.getLineID()); + assertEquals(LINE_TYPE, lineInfo2.getLineType()); + assertEquals(LINE_DESCRIPTION, lineInfo2.getDescription()); + assertEquals(MOVEABLE, lineInfo2.isMoveable()); + assertEquals(DELETEABLE, lineInfo2.isDeleteable()); + assertEquals(STATE, lineInfo2.getState()); + } + + @Test + public void getAttributeInternalKeys() { + List<String> list = lineInfo.getAttributeInternalKeys(); + assertEquals("length", list.get(0)); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineTest.java index c3ea5ead..dc4171ce 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineTest.java @@ -37,23 +37,55 @@ */ package org.onap.portalsdk.analytics.gmap.line; +import static org.junit.Assert.assertNotNull; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; import org.onap.portalsdk.analytics.gmap.map.NovaMap; - +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.test.util.ReflectionTestUtils; +@RunWith(PowerMockRunner.class) +@PrepareForTest({Line.class}) public class LineTest { + Line line; + Point2D screenPoint; + private String LINE_ID = "lineID"; + private String LINE_TYPE = "test"; + private String NODE1 = "nodeID1"; + private String NODE2 = "nodeID2"; - public Line mockLineTest() - { + @Before + public void init() throws Exception{ NovaMap novaMap= new NovaMap(); novaMap.setDataLoaded("dataLoaded"); - Line line = new Line(novaMap); - return line; + ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform()); + LineCollection lineCollection = Mockito.mock(LineCollection.class); + ArrayList<LineInfo> list = new ArrayList<LineInfo>(); + LineInfo lineInfo = new LineInfo(NODE1, NODE2); + lineInfo.setLineID(LINE_ID); + lineInfo.setLineType(LINE_TYPE); + lineCollection.addLine(lineInfo); + lineCollection.addSelectedLine(LINE_ID); + list.add(lineInfo); + PowerMockito.whenNew(LineCollection.class).withNoArguments().thenReturn(lineCollection); + Mockito.when(lineCollection.getLineCollection()).thenReturn(list); + screenPoint = Mockito.mock(Point2D.class); + line = new Line(novaMap); } @Test - public void lineExistTest() - { - Line line = mockLineTest(); + public void lineExistTest(){ + assertNotNull(line); + line.lineExist(screenPoint); } } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/ColorPropertiesTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/ColorPropertiesTest.java new file mode 100644 index 00000000..07d9a926 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/ColorPropertiesTest.java @@ -0,0 +1,93 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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.portalsdk.analytics.gmap.map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.awt.Color; + +import org.junit.Before; +import org.junit.Test; + +public class ColorPropertiesTest { + + ColorProperties colorProperties; + private String TYPE = "type"; + private String COLOR = "10,10,10"; + private String SHAPE = "circle"; + private String SIZE = "100"; + private int NUMBER = 1; + + @Before + public void init() { + NovaMap map = new NovaMap(); + colorProperties = new ColorProperties(map); + colorProperties.setColor(TYPE, COLOR); + colorProperties.setShape(TYPE, SHAPE); + colorProperties.setSize(TYPE, SIZE); + colorProperties.setShape(TYPE, NUMBER, SHAPE); + } + + @Test + public void testNotNull() { + assertNotNull(colorProperties); + } + + @Test + public void testGetColor() { + Color color1 = new Color(10,10,10); + Color color2 = colorProperties.getColor(TYPE); + assertEquals(true, color1.equals(color2)); + } + + @Test + public void testGetShape() { + assertEquals(SHAPE, colorProperties.getShape(TYPE)); + } + + @Test + public void testGetShapeWithNumber() { + assertEquals(SHAPE, colorProperties.getShape(TYPE, NUMBER)); + } + + @Test + public void testGetSize() { + assertEquals(100, colorProperties.getSize(TYPE)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/NovaMapTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/NovaMapTest.java new file mode 100644 index 00000000..7be34b74 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/NovaMapTest.java @@ -0,0 +1,148 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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.portalsdk.analytics.gmap.map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.awt.Rectangle; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.util.HashSet; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.gmap.line.Line; +import org.onap.portalsdk.analytics.gmap.map.layer.SwingLayer; +import org.onap.portalsdk.analytics.gmap.node.Node; +import org.springframework.test.util.ReflectionTestUtils; + +public class NovaMapTest { + + NovaMap novaMap; + private SwingLayer swingLayer; + + @Before + public void init() { + novaMap = new NovaMap(); + swingLayer = new SwingLayer(novaMap); + novaMap.setBoundingBox(10, 10); + novaMap.setNode(new Node(novaMap)); + novaMap.setLine(new Line(novaMap)); + novaMap.setColorProperties(new ColorProperties(novaMap)); + novaMap.setZoomLevel(10); + novaMap.addShowList("test-1"); + novaMap.addShowList("test-2", 10); + novaMap.addSwingLayer(swingLayer); + novaMap.setCurrentYearMonth("2018/05"); + novaMap.setDefaultBoundary(new Rectangle2D.Double()); + novaMap.setShowLegend(true); + ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform()); + } + + + @Test + public void testNotNull() { + assertNotNull(novaMap); + } + + @Test + public void testNovaMapProperties() { + assertEquals(Rectangle.class, novaMap.getBoundingBox().getClass()); + assertEquals(Node.class, novaMap.getNode().getClass()); + assertEquals(Line.class, novaMap.getLine().getClass()); + assertEquals(ColorProperties.class, novaMap.getColorProperties().getClass()); + assertEquals(10, novaMap.getZoomLevel()); + assertEquals(HashSet.class, novaMap.getShowList().getClass()); + assertEquals(SwingLayer.class, novaMap.getSwingLayers().get(0).getClass()); + assertEquals("2018/05", novaMap.getCurrentYearMonth()); + assertNotNull(novaMap.getDefaultBoundary()); + assertTrue(novaMap.isShowLegend()); + assertEquals(2, novaMap.getShowListSize()); + assertTrue(novaMap.containsShowList("test-1")); + assertTrue(novaMap.containsShowList("test-2", 10)); + novaMap.removeShowList("test-1"); + novaMap.removeShowList("test-2", 10); + novaMap.clearShowList(); + assertEquals(0, novaMap.getShowListSize()); + novaMap.removeSwingLayer(swingLayer); + novaMap.clearSwingLayers(); + assertNotEquals(null, novaMap.getTransform()); + } + + @Test + public void testGetBestZoomLevel() { + novaMap.getBestZoomLevel(13.13d, 28.28d, 23.13d, 38.28d, 10d, 10d); + } + + @Test + public void testGetPixelPos() { + novaMap.getPixelPos(13.13d, 28.28d); + } + + @Test + public void testGetLonLatFromPixel() { + novaMap.getLonLatFromPixel(10, 20); + } + + @Test + public void testGetImage() { + HttpServletRequest reuqest = Mockito.mock(HttpServletRequest.class); + novaMap.getImage(reuqest, new Rectangle2D.Double()); + } + + @Test + public void testSingleLeftClick() { + novaMap.singleLeftClick(13.13d, 10.10d, new Rectangle2D.Double()); + } + + @Test(expected=NullPointerException.class) + public void testSingleLeftClick_WhenTransFormIsNull() { + ReflectionTestUtils.setField(novaMap, "transform", null); + Rectangle2D.Double rd =new Rectangle2D.Double(); + rd.setRect(10d, 10d, 10d, 10d); + novaMap.singleLeftClick(13.13d, 10.10d, new Rectangle2D.Double()); + } + + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/layer/SwingLayerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/layer/SwingLayerTest.java new file mode 100644 index 00000000..e52d01b6 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/layer/SwingLayerTest.java @@ -0,0 +1,112 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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.portalsdk.analytics.gmap.map.layer; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.gmap.line.Line; +import org.onap.portalsdk.analytics.gmap.map.ColorProperties; +import org.onap.portalsdk.analytics.gmap.map.NovaMap; +import org.onap.portalsdk.analytics.gmap.node.Node; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.springframework.test.util.ReflectionTestUtils; + +public class SwingLayerTest { + + SwingLayer swingLayer; + NovaMap novaMap; + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + Graphics2D g2d; + Graphics2D g2Legend; + + @Before + public void init() { + novaMap = new NovaMap(); + swingLayer = new SwingLayer(novaMap); + novaMap.setBoundingBox(10, 10); + novaMap.setNode(new Node(novaMap)); + novaMap.setLine(new Line(novaMap)); + novaMap.setColorProperties(new ColorProperties(novaMap)); + novaMap.setZoomLevel(10); + novaMap.addShowList("test-1"); + novaMap.addShowList("test-2", 10); + novaMap.addSwingLayer(swingLayer); + novaMap.setCurrentYearMonth("2018/05"); + novaMap.setDefaultBoundary(new Rectangle2D.Double()); + novaMap.setShowLegend(true); + ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform()); + Node nodeObj = new Node(new NovaMap()); + nodeObj.addNode(13.13d, 10.10d, "nodeType", "nodeID", "type=domestic|year=2016", 13, true, true); + nodeObj.addNode(13.14d, 10.11d, "nodeType", "nodeID", "type=international|year=2017", 13, true, true); + nodeObj.addNode(13.15d, 10.12d, "nodeType", "nodeID", "type=local|year=2018", 13, true, true); + novaMap.setNode(nodeObj); + swingLayer = new SwingLayer(novaMap); + BufferedImage image = new BufferedImage(novaMap.getBoundingBox().width, novaMap.getBoundingBox().height, BufferedImage.TYPE_INT_ARGB); + g2d = image.createGraphics(); + BufferedImage legendImage = new BufferedImage(novaMap.getBoundingBox().width, (int) (20 * novaMap.getShowListSize()) + 20, + BufferedImage.TYPE_INT_ARGB); + g2Legend = legendImage.createGraphics(); + g2Legend.setBackground(Color.WHITE); + } + + @Test + public void teestPaintLayer_WhenID1NotEqualToID2() { + Mockito.when(mockedRequest.getAttribute("server_process_id")).thenReturn("1"); + Mockito.when(mockedRequest.getSession().getAttribute("server_process_id")).thenReturn("2"); + swingLayer.paintLayer(mockedRequest, g2d, novaMap.getBoundingBox(), new Rectangle2D.Double(), g2Legend); + } + + @Test + public void teestPaintLayer_WhenID1EqualToID2() { + Mockito.when(mockedRequest.getAttribute("server_process_id")).thenReturn("1"); + Mockito.when(mockedRequest.getSession().getAttribute("server_process_id")).thenReturn("1"); + Rectangle2D rd = new Rectangle2D.Double(); + rd.setFrame(14064d, 12366d, 10d, 10d); + swingLayer.paintLayer(mockedRequest, g2d, novaMap.getBoundingBox(), rd, g2Legend); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeCollectionTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeCollectionTest.java new file mode 100644 index 00000000..1bd35c37 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeCollectionTest.java @@ -0,0 +1,122 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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.portalsdk.analytics.gmap.node; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class NodeCollectionTest { + + NodeCollection nodeCollection; + private String NODE_ID = "nodeID"; + private String NODE_TYPE = "nodeType"; + + @Before + public void init() { + nodeCollection = new NodeCollection(); + NodeInfo nodeInfo = new NodeInfo(NODE_ID); + nodeInfo.setNodeType(NODE_TYPE); + nodeCollection.setNodeID(NODE_ID); + nodeCollection.addNode(nodeInfo); + nodeCollection.addSelectedNode(NODE_ID); + nodeCollection.addSelectedNode(NODE_ID, NODE_TYPE); + } + + @Test + public void testNotNull() { + assertNotNull(nodeCollection); + } + + @Test + public void testGetNode() { + NodeInfo nodeInfo = nodeCollection.getNode(NODE_ID+NODE_TYPE); + assertEquals(NODE_TYPE, nodeInfo.getNodeType()); + assertEquals(NODE_ID, nodeInfo.getNodeID()); + } + + @Test + public void testContainSelectedNodeByNodeID() { + assertEquals(true, nodeCollection.containSelectedNode(NODE_ID)); + } + + @Test + public void testContainSelectedNodeByNodeIDAndType() { + assertEquals(true, nodeCollection.containSelectedNode(NODE_ID, NODE_TYPE)); + } + + @Test + public void testRemoveSelectedNodeByNodeID() { + nodeCollection.removeSelectedNode(NODE_ID); + assertEquals(false, nodeCollection.containSelectedNode(NODE_ID)); + } + + @Test + public void testRemoveSelectedNodeByNodeIDAndNodeType() { + nodeCollection.removeSelectedNode(NODE_ID, NODE_TYPE); + assertEquals(false, nodeCollection.containSelectedNode(NODE_ID, NODE_TYPE)); + } + + @Test + public void testGetNodeID() { + assertEquals(NODE_ID, nodeCollection.getNodeID()); + } + + @Test + public void testGetSelectedNode() { + assertEquals(2, nodeCollection.getSelectedNode().size()); + } + + @Test + public void testClearNode() { + nodeCollection.clearNode(); + } + + @Test + public void testClearAllCollection() { + nodeCollection.clearAllCollection(); + } + + @Test + public void testGetSize() { + nodeCollection.clearAllCollection(); + assertEquals(0, nodeCollection.getSize()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeInfoTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeInfoTest.java new file mode 100644 index 00000000..bdc66784 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeInfoTest.java @@ -0,0 +1,130 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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.portalsdk.analytics.gmap.node; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; + +public class NodeInfoTest { + + NodeInfo nodeInfo; + + private String NODE_ID = "nodeID"; + private String NODE_TYPE = "nodeType"; + private boolean MOVEABLE = true; + private boolean DELETEABLE = true; + private int STATE = 1; + + @Before + public void init() { + nodeInfo = new NodeInfo(NODE_ID); + nodeInfo.setNodeID(NODE_ID); + nodeInfo.setNodeType(NODE_TYPE); + nodeInfo.setMoveable(MOVEABLE); + nodeInfo.setDeleteable(DELETEABLE); + nodeInfo.setState(STATE); + List<String> lineIDs = new ArrayList<>(); + lineIDs.add("test"); + nodeInfo.setLineIDS(lineIDs); + } + + @Test + public void testNotNull() { + assertNotNull(nodeInfo); + } + + @Test + public void testNodeInfoProperties() { + assertEquals(NODE_ID, nodeInfo.getNodeID()); + assertEquals(NODE_TYPE, nodeInfo.getNodeType()); + assertEquals(MOVEABLE, nodeInfo.isMoveable()); + assertEquals(DELETEABLE, nodeInfo.isDeleteable()); + assertEquals(STATE, nodeInfo.getState()); + } + + @Test + public void testAddLineID() { + nodeInfo.addLineID("test", "test"); + assertEquals("test>>test", nodeInfo.getLineID("test", "test")); + } + + @Test + public void testremoveLineID() { + nodeInfo.removeLineID("test", "test"); + assertEquals(null, nodeInfo.getLineID("test", "test")); + } + + @Test + public void testGetLineIDS() { + nodeInfo.getLineIDS(); + assertEquals("test", nodeInfo.getLineIDS().get(0)); + } + + @Test + public void testPrintLineIDS() { + nodeInfo.printLineIDS(); + } + + @Test + public void testCloneLineIDS() { + assertEquals("test",nodeInfo.cloneLineIDS().get(0)); + } + + @Test + public void testInitializeAttributes() { + Map<String,String >nodeAttributes = new HashMap<>(); + nodeAttributes.put("test", "test"); + nodeInfo.initializeAttributes(nodeAttributes); + assertEquals("test",nodeInfo.getAttribute("test")); + assertEquals("test",nodeInfo.getAttributeKeys().get(0)); + } + + @Test + public void testClone() { + assertEquals("test",nodeInfo.clone().cloneLineIDS().get(0)); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java index 1f7b710e..a6cd2933 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java @@ -1,5 +1,5 @@ /* - * ============LICENxSE_START========================================== + * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== * Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -40,13 +40,18 @@ package org.onap.portalsdk.analytics.gmap.node; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.awt.Point; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.junit.Test; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.gmap.map.ColorProperties; import org.onap.portalsdk.analytics.gmap.map.NovaMap; import org.onap.portalsdk.analytics.gmap.node.Node; +import org.springframework.test.util.ReflectionTestUtils; public class NodeTest { @@ -158,8 +163,12 @@ public class NodeTest { @Test public void testNodeExist() { - Node nodeObj = new Node(new NovaMap()); - + NovaMap novaMap = new NovaMap(); + novaMap.addShowList("nodeType"); + novaMap.addShowList("nodeType"); + novaMap.setColorProperties(new ColorProperties(novaMap)); + ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform()); + Node nodeObj = new Node(novaMap); nodeObj.addNode(13.13d, 10.10d, "nodeType", "nodeID", "type=domestic|year=2016", 13, true, true); nodeObj.addNode(13.14d, 10.11d, "nodeType", "nodeID", "type=international|year=2017", 13, true, true); nodeObj.addNode(13.15d, 10.12d, "nodeType", "nodeID", "type=local|year=2018", 13, true, true); |