e52d01b62dfaa759b3f0133d1fcfff16c1181b60
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2018 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 package org.onap.portalsdk.analytics.gmap.map.layer;
39
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;
45
46 import javax.servlet.http.HttpServletRequest;
47
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;
57
58 public class SwingLayerTest {
59         
60         SwingLayer swingLayer;
61         NovaMap novaMap;
62         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
63         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
64         Graphics2D g2d;
65         Graphics2D g2Legend;
66
67         @Before
68         public void init() {
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);
95         }
96         
97         @Test
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);
102         }
103         
104         @Test
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);
111         }
112 }