package com.lbslocal.api.view;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import com.lbslocal.api.objects.external.GetZoomRadius;
import com.lbslocal.api.objects.external.MapOptions;
import com.lbslocal.api.objects.external.MapSize;
import com.lbslocal.api.objects.external.Point;
import com.lbslocal.test.helpers.HttpClient;
import com.lbslocal.test.helpers.Response;
import com.lbslocal.test.helpers.TestConstants;
import com.lbslocal.test.helpers.XmlParser;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class MapRenderTest {
private MapOptions options;
private XStream xstream;
public MapRenderTest() throws IOException {
xstream = new XStream(new DomDriver("UTF-8"));
xstream.processAnnotations(GetZoomRadius.class);
}
@Before
public void setUp() {
givenADefaultMapOptions();
}
@Test
public void shouldGetZoomRadius() throws Exception {
String xmlToBeSent = TestConstants.XML_HEADER + xstream.toXML(createAZoomRadius());
Response responseFromWs =
HttpClient.doPost(
TestConstants.getMapRenderUrl(),
xmlToBeSent);
String body = responseFromWs.getBody();
Assert.assertEquals("200", responseFromWs.getStatusCode());
Assert.assertEquals("text/xml;charset=UTF-8", responseFromWs.getContentType());
Assert.assertTrue(body.startsWith("<?xml version='1.0' encoding='UTF-8'?>"));
Document xmlParsed = XmlParser.parse(body);
Response responseFromImage =
HttpClient.doGet(
xmlParsed
.getElementsByTagName("url")
.item(0)
.getFirstChild()
.getNodeValue());
Assert.assertEquals("200", responseFromImage.getStatusCode());
}
private GetZoomRadius createAZoomRadius() throws IOException {
Point point = new Point();
point.setX(-46.638818);
point.setY(-23.548943);
GetZoomRadius resource = new GetZoomRadius();
resource.setPoint(point);
resource.setMapOptions(this.options);
resource.setRadius(500);
resource.setToken(TestConstants.getToken());
return resource;
}
private void givenADefaultMapOptions() {
MapSize mapSize = new MapSize();
mapSize.setWidth(500);
mapSize.setHeight(500);
this.options = new MapOptions();
this.options.setScaleBar(true);
this.options.setMapSize(mapSize);
}
}