public void testForward() throws Exception { Log log = testForwardLog; GeocodeClient client = new ClientFactory(baseUrl).getGeocode(); GeocodeInvoker invoker = GeocodeInvoker.builder() .address("1600 Amphitheatre Parkway, Mountain View, CA") .sensor(false) .build(); GeocodeResponse response = null; try { long start = System.currentTimeMillis(); response = invoker.geocode(client); long end = System.currentTimeMillis(); log.trace(String.format("Forward geocode took %s ms", end - start)); } catch (Exception e) { log.error(e); fail(); } assertNotNull(response); assertNotNull(response.getStatus()); assertEquals(GeocodeStatus.OK, response.getStatus()); assertNotNull(response.getResults()); assertEquals(1, response.getResults().size()); GeocodeResult result1 = response.getResults().get(0); assertNotNull(result1.getTypes()); assertEquals(Arrays.asList(GeocodeResultType.STREET_ADDRESS), result1.getTypes()); assertEquals( "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", result1.getFormattedAddress()); assertNotNull(result1.getAddressComponents()); assertEquals(8, result1.getAddressComponents().size()); GeocodeAddressComponent addressComponent1 = result1.getAddressComponents().get(0); assertNotNull(addressComponent1.getTypes()); assertEquals( Arrays.asList(GeocodeAddressComponentType.STREET_NUMBER), addressComponent1.getTypes()); assertNotNull(addressComponent1.getLongName()); assertEquals("1600", addressComponent1.getLongName()); assertNotNull(addressComponent1.getShortName()); assertEquals("1600", addressComponent1.getShortName()); GeocodeGeometry geometry = result1.getGeometry(); assertNotNull(geometry); assertNotNull(geometry.getLocationType()); assertEquals(GeocodeLocationType.ROOFTOP, geometry.getLocationType()); validateLocation(geometry.getLocation(), 37.4227820D, -122.0850990D); validateFrame(geometry.getViewPort(), 37.4196344D, -122.0882466D, 37.4259296D, -122.0819514D); assertNull(geometry.getBounds()); }
public void testReverse() throws Exception { Log log = testReverseLog; GeocodeClient client = new ClientFactory(baseUrl).getGeocode(); GeocodeInvoker invoker = GeocodeInvoker.builder().latLng(40.714224D, -73.961452D).sensor(false).build(); GeocodeResponse response = null; try { long start = System.currentTimeMillis(); response = invoker.geocode(client); long end = System.currentTimeMillis(); log.trace(String.format("Reverse geocode took %s ms", end - start)); } catch (Exception e) { log.error(e); fail(); } assertNotNull(response); assertNotNull(response.getStatus()); assertEquals(GeocodeStatus.OK, response.getStatus()); assertNotNull(response.getResults()); assertEquals(8, response.getResults().size()); GeocodeResult result1 = response.getResults().get(0); assertNotNull(result1.getTypes()); assertEquals(Arrays.asList(GeocodeResultType.STREET_ADDRESS), result1.getTypes()); assertEquals("279-281 Bedford Ave, Brooklyn, NY 11211, USA", result1.getFormattedAddress()); assertNotNull(result1.getAddressComponents()); assertEquals(8, result1.getAddressComponents().size()); GeocodeAddressComponent addressComponent1 = result1.getAddressComponents().get(0); assertNotNull(addressComponent1.getTypes()); assertEquals( Arrays.asList(GeocodeAddressComponentType.STREET_NUMBER), addressComponent1.getTypes()); assertNotNull(addressComponent1.getLongName()); assertEquals("279-281", addressComponent1.getLongName()); assertNotNull(addressComponent1.getShortName()); assertEquals("279-281", addressComponent1.getShortName()); GeocodeGeometry geometry = result1.getGeometry(); assertNotNull(geometry); assertNotNull(geometry.getLocationType()); assertEquals(GeocodeLocationType.RANGE_INTERPOLATED, geometry.getLocationType()); validateLocation(geometry.getLocation(), 40.7142215D, -73.9614454D); validateFrame(geometry.getViewPort(), 40.7110552D, -73.9646313D, 40.7173505D, -73.9583361D); validateFrame(geometry.getBounds(), 40.7139010D, -73.9616800D, 40.7145047D, -73.9612874D); }