2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2018 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalsdk.analytics.gmap.map.layer;
40 import java.awt.Color;
41 import java.awt.Graphics2D;
42 import java.awt.geom.AffineTransform;
43 import java.awt.geom.Rectangle2D;
44 import java.awt.image.BufferedImage;
46 import javax.servlet.http.HttpServletRequest;
48 import org.junit.Before;
49 import org.junit.Test;
50 import org.mockito.Mockito;
51 import org.onap.portalsdk.analytics.gmap.line.Line;
52 import org.onap.portalsdk.analytics.gmap.map.ColorProperties;
53 import org.onap.portalsdk.analytics.gmap.map.NovaMap;
54 import org.onap.portalsdk.analytics.gmap.node.Node;
55 import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite;
56 import org.springframework.test.util.ReflectionTestUtils;
58 public class SwingLayerTest {
60 SwingLayer swingLayer;
62 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
63 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
69 novaMap = new NovaMap();
70 swingLayer = new SwingLayer(novaMap);
71 novaMap.setBoundingBox(10, 10);
72 novaMap.setNode(new Node(novaMap));
73 novaMap.setLine(new Line(novaMap));
74 novaMap.setColorProperties(new ColorProperties(novaMap));
75 novaMap.setZoomLevel(10);
76 novaMap.addShowList("test-1");
77 novaMap.addShowList("test-2", 10);
78 novaMap.addSwingLayer(swingLayer);
79 novaMap.setCurrentYearMonth("2018/05");
80 novaMap.setDefaultBoundary(new Rectangle2D.Double());
81 novaMap.setShowLegend(true);
82 ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform());
83 Node nodeObj = new Node(new NovaMap());
84 nodeObj.addNode(13.13d, 10.10d, "nodeType", "nodeID", "type=domestic|year=2016", 13, true, true);
85 nodeObj.addNode(13.14d, 10.11d, "nodeType", "nodeID", "type=international|year=2017", 13, true, true);
86 nodeObj.addNode(13.15d, 10.12d, "nodeType", "nodeID", "type=local|year=2018", 13, true, true);
87 novaMap.setNode(nodeObj);
88 swingLayer = new SwingLayer(novaMap);
89 BufferedImage image = new BufferedImage(novaMap.getBoundingBox().width, novaMap.getBoundingBox().height, BufferedImage.TYPE_INT_ARGB);
90 g2d = image.createGraphics();
91 BufferedImage legendImage = new BufferedImage(novaMap.getBoundingBox().width, (int) (20 * novaMap.getShowListSize()) + 20,
92 BufferedImage.TYPE_INT_ARGB);
93 g2Legend = legendImage.createGraphics();
94 g2Legend.setBackground(Color.WHITE);
98 public void teestPaintLayer_WhenID1NotEqualToID2() {
99 Mockito.when(mockedRequest.getAttribute("server_process_id")).thenReturn("1");
100 Mockito.when(mockedRequest.getSession().getAttribute("server_process_id")).thenReturn("2");
101 swingLayer.paintLayer(mockedRequest, g2d, novaMap.getBoundingBox(), new Rectangle2D.Double(), g2Legend);
105 public void teestPaintLayer_WhenID1EqualToID2() {
106 Mockito.when(mockedRequest.getAttribute("server_process_id")).thenReturn("1");
107 Mockito.when(mockedRequest.getSession().getAttribute("server_process_id")).thenReturn("1");
108 Rectangle2D rd = new Rectangle2D.Double();
109 rd.setFrame(14064d, 12366d, 10d, 10d);
110 swingLayer.paintLayer(mockedRequest, g2d, novaMap.getBoundingBox(), rd, g2Legend);