Search in sources :

Example 1 with Headers

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);
}
Also used : Geo(com.adobe.target.delivery.v1.model.Geo) Headers(kong.unirest.Headers) GetRequest(kong.unirest.GetRequest) HttpResponse(kong.unirest.HttpResponse) ClientConfig(com.adobe.target.edge.client.ClientConfig) Test(org.junit.jupiter.api.Test)

Aggregations

Geo (com.adobe.target.delivery.v1.model.Geo)1 ClientConfig (com.adobe.target.edge.client.ClientConfig)1 GetRequest (kong.unirest.GetRequest)1 Headers (kong.unirest.Headers)1 HttpResponse (kong.unirest.HttpResponse)1 Test (org.junit.jupiter.api.Test)1