use of kong.unirest.Headers in project target-java-sdk by adobe.
the class DefaultGeoClientTest method testDefaultGeoClient.
@Test
void testDefaultGeoClient() {
String domain = "test.com";
ClientConfig clientConfig = ClientConfig.builder().organizationId("testOrgId").onDeviceConfigHostname(domain).build();
DefaultGeoClient geoClient = spy(DefaultGeoClient.class);
geoClient.start(clientConfig);
String ip = "127.0.0.1";
String url = "https://" + domain + DefaultGeoClient.GEO_PATH;
String city = "SAN FRANCISCO";
String regionCode = "CA";
String countryCode = "US";
float latitude = 37.74f;
float longitude = -122.24f;
GetRequest request = mock(GetRequest.class);
@SuppressWarnings("rawtypes") HttpResponse response = mock(HttpResponse.class);
Headers headers = new Headers();
headers.add(DefaultGeoClient.GEO_HEADER_CITY, city);
headers.add(DefaultGeoClient.GEO_HEADER_REGION, regionCode);
headers.add(DefaultGeoClient.GEO_HEADER_COUNTRY, countryCode);
headers.add(DefaultGeoClient.GEO_HEADER_LATITUDE, String.valueOf(latitude));
headers.add(DefaultGeoClient.GEO_HEADER_LONGITUDE, String.valueOf(longitude));
Mockito.doReturn(response).when(request).asEmpty();
Mockito.doReturn(headers).when(response).getHeaders();
Mockito.doReturn(request).when(geoClient).geoRequest(any(), any(), any());
Geo geoResponse = geoClient.lookupGeo(ip);
verify(geoClient).geoRequest(eq(url), eq(DefaultGeoClient.GEO_IP_HEADER), eq(ip));
assertEquals(city, geoResponse.getCity());
assertEquals(regionCode, geoResponse.getStateCode());
assertEquals(countryCode, geoResponse.getCountryCode());
assertEquals(latitude, geoResponse.getLatitude(), 0.01);
assertEquals(longitude, geoResponse.getLongitude(), 0.01);
}
Aggregations