use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class DatafileWorker method doWork.
@NonNull
@Override
public Result doWork() {
DatafileConfig datafileConfig = getDataConfig(getInputData());
String datafileUrl = datafileConfig.getUrl();
DatafileCache datafileCache = new DatafileCache(datafileConfig.getKey(), new Cache(this.getApplicationContext(), LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(DatafileCache.class));
datafileLoader.getDatafile(datafileUrl, datafileCache, null);
return Result.success();
}
use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class DatafileClientTest method request300.
@Test
public void request300() throws IOException {
URL url = new URL(new DatafileConfig("1", null).getUrl());
when(client.openConnection(url)).thenReturn(urlConnection);
when(urlConnection.getResponseCode()).thenReturn(300);
datafileClient.request(url.toString());
ArgumentCaptor<Client.Request> captor1 = ArgumentCaptor.forClass(Client.Request.class);
ArgumentCaptor<Integer> captor2 = ArgumentCaptor.forClass(Integer.class);
ArgumentCaptor<Integer> captor3 = ArgumentCaptor.forClass(Integer.class);
verify(client).execute(captor1.capture(), captor2.capture(), captor3.capture());
assertEquals(Integer.valueOf(DatafileClient.REQUEST_BACKOFF_TIMEOUT), captor2.getValue());
assertEquals(Integer.valueOf(DatafileClient.REQUEST_RETRIES_POWER), captor3.getValue());
Object response = captor1.getValue().execute();
assertNull(response);
verify(logger).error("Unexpected response from data file cdn, status: {}", 300);
verify(urlConnection).disconnect();
}
use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class DatafileClientTest method handlesIOException.
@Test
public void handlesIOException() throws IOException {
URL url = new URL(new DatafileConfig("1", null).getUrl());
when(client.openConnection(url)).thenReturn(urlConnection);
when(urlConnection.getResponseCode()).thenReturn(200);
doThrow(new IOException()).when(urlConnection).connect();
datafileClient.request(url.toString());
ArgumentCaptor<Client.Request> captor1 = ArgumentCaptor.forClass(Client.Request.class);
ArgumentCaptor<Integer> captor2 = ArgumentCaptor.forClass(Integer.class);
ArgumentCaptor<Integer> captor3 = ArgumentCaptor.forClass(Integer.class);
verify(client).execute(captor1.capture(), captor2.capture(), captor3.capture());
assertEquals(Integer.valueOf(DatafileClient.REQUEST_BACKOFF_TIMEOUT), captor2.getValue());
assertEquals(Integer.valueOf(DatafileClient.REQUEST_RETRIES_POWER), captor3.getValue());
Object response = captor1.getValue().execute();
assertNull(response);
verify(logger).error(contains("Error making request"), any(IOException.class));
verify(urlConnection).disconnect();
verify(urlConnection).disconnect();
}
use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class DatafileClientTest method request201.
@Test
public void request201() throws IOException {
URL url = new URL(new DatafileConfig("1", null).getUrl());
when(client.openConnection(url)).thenReturn(urlConnection);
when(urlConnection.getResponseCode()).thenReturn(201);
when(client.readStream(urlConnection)).thenReturn("{}");
datafileClient.request(url.toString());
ArgumentCaptor<Client.Request> captor1 = ArgumentCaptor.forClass(Client.Request.class);
ArgumentCaptor<Integer> captor2 = ArgumentCaptor.forClass(Integer.class);
ArgumentCaptor<Integer> captor3 = ArgumentCaptor.forClass(Integer.class);
verify(client).execute(captor1.capture(), captor2.capture(), captor3.capture());
assertEquals(Integer.valueOf(DatafileClient.REQUEST_BACKOFF_TIMEOUT), captor2.getValue());
assertEquals(Integer.valueOf(DatafileClient.REQUEST_RETRIES_POWER), captor3.getValue());
Object response = captor1.getValue().execute();
assertTrue(String.class.isInstance(response));
assertEquals("{}", response);
verify(logger).info("Requesting data file from {}", url);
verify(client).saveLastModified(urlConnection);
verify(client).readStream(urlConnection);
verify(urlConnection).disconnect();
}
use of com.optimizely.ab.android.shared.DatafileConfig in project android-sdk by optimizely.
the class DatafileClientTest method handlesNullResponse.
@Test
public void handlesNullResponse() throws MalformedURLException {
URL url = new URL(new DatafileConfig("1", null).getUrl());
when(client.execute(any(Client.Request.class), eq(DatafileClient.REQUEST_BACKOFF_TIMEOUT), eq(DatafileClient.REQUEST_RETRIES_POWER))).thenReturn(null);
assertNull(datafileClient.request(url.toString()));
}
Aggregations