summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/NovaMapTest.java
blob: 7be34b742c7c5ea33698747c3e8dc6843f054754 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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());
	}
	
	
}