package org.opennms.features.topology.app.internal;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.junit.Test;
import org.opennms.features.topology.api.BoundingBox;
import org.opennms.features.topology.api.Point;

public class MapViewPortTest {
    
    @Test
    public void testGetBounds() {
        DefaultMapViewManager viewManager = new DefaultMapViewManager();
        viewManager.setMapBounds(new BoundingBox(0,0, 8000,4000));
        viewManager.setViewPort(400, 300);
        
        BoundingBox boundingBox = viewManager.getCurrentBoundingBox();
        assertNotNull(boundingBox);
        assertEquals(4000, boundingBox.getCenter().getX());
        assertEquals(2000, boundingBox.getCenter().getY());
        assertEquals(8000, boundingBox.getWidth());
        assertEquals(6000, boundingBox.getHeight());
        assertEquals(0, boundingBox.getX());
        assertEquals(-1000, boundingBox.getY());
        
        assertEquals(0.0, viewManager.getScale(), 0.0);
        
        viewManager.setScale(1.0);
        boundingBox = viewManager.getCurrentBoundingBox();
        assertEquals(4000, boundingBox.getCenter().getX());
        assertEquals(2000, boundingBox.getCenter().getY());
        assertEquals(200, boundingBox.getWidth());
        assertEquals(150, boundingBox.getHeight());
        assertEquals(3900, boundingBox.getX());
        assertEquals(1925, boundingBox.getY());
        
        viewManager.setBoundingBox(new BoundingBox(0,0, 1265, 600));
        
        assertEquals(0.5, viewManager.getScale(), 0.0001);
        
    }
    
    @Test
    public void testPanMap() {
        DefaultMapViewManager viewManager = new DefaultMapViewManager();
        viewManager.setMapBounds(new BoundingBox(0,0, 8000,4000));
        viewManager.setViewPort(400, 300);
        
        
        BoundingBox box = viewManager.getCurrentBoundingBox();
        assertNotNull(box);
        assertEquals(4000, box.getCenter().getX());
        assertEquals(2000, box.getCenter().getY());
        assertEquals(8000, box.getWidth());
        assertEquals(6000, box.getHeight());
        assertEquals(0, box.getX());
        assertEquals(-1000, box.getY());
        
        viewManager.setCenter(new Point(3900, 1900));
        
        box = viewManager.getCurrentBoundingBox();
        assertNotNull(box);
        assertEquals(3900, box.getCenter().getX());
        assertEquals(1900, box.getCenter().getY());
        assertEquals(8000, box.getWidth());
        assertEquals(6000, box.getHeight());
        assertEquals(-100, box.getX());
        assertEquals(-1100, box.getY());
    }
    


}

@@ -295,25 +295,56 @@
 tTest %7B%0A    
+private double m_delta = 0.001;
 %0A
-
     @Test%0A  
@@ -691,32 +691,34 @@
 ssertEquals(4000
+.0
 , boundingBox.ge
@@ -725,32 +725,39 @@
 tCenter().getX()
+, 0.001
 );%0A        asser
@@ -760,32 +760,34 @@
 ssertEquals(2000
+.0
 , boundingBox.ge
@@ -794,32 +794,39 @@
 tCenter().getY()
+, 0.001
 );%0A        asser
@@ -1228,32 +1228,41 @@
 tCenter().getX()
+, m_delta
 );%0A        asser
@@ -1297,32 +1297,41 @@
 tCenter().getY()
+, m_delta
 );%0A        asser
@@ -2056,32 +2056,41 @@
 tCenter().getX()
+, m_delta
 );%0A        asser
@@ -2117,32 +2117,41 @@
 tCenter().getY()
+, m_delta
 );%0A        asser
@@ -2500,24 +2500,33 @@
 ter().getX()
+, m_delta
 );%0A        a
@@ -2561,24 +2561,33 @@
 ter().getY()
+, m_delta
 );%0A        a

fix assertEquals update for floating point