@Test public void testFetchApplicationId() throws InterruptedException, ExecutionException, ParseException, IOException { //setup MockHttpAsyncClientWrapper clientWrapper = new MockHttpAsyncClientWrapper(); clientWrapper.setAppId("AppId"); clientWrapper.setFailureOn(false); CdsProfileFetcher fetcher = new CdsProfileFetcher(); fetcher.setHttpClient(clientWrapper.getClient()); // the first time we try to fetch the profile, we might get a "pending" task status // since the profile fetcher uses asynchronous calls to retrieve the profile from CDS // this is mimic'ed with clientWrapper.setTaskAsPending(); clientWrapper.setTaskAsPending(); ProfileFetcherResult result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.PENDING, result.getStatus()); Assert.assertNull(result.getAppId()); // mimic task completion clientWrapper.setTaskAsComplete(); result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.COMPLETE, result.getStatus()); Assert.assertEquals("AppId", result.getAppId()); }
@Test public void testFetchApplicationIdFailureWithNon200StatusCode() throws InterruptedException, ExecutionException, ParseException, IOException { //setup MockHttpAsyncClientWrapper clientWrapper = new MockHttpAsyncClientWrapper(); clientWrapper.setAppId("AppId"); clientWrapper.setFailureOn(false); CdsProfileFetcher fetcher = new CdsProfileFetcher(); fetcher.setHttpClient(clientWrapper.getClient()); // the first time we try to fetch the profile, we might get a "pending" task status // since the profile fetcher uses asynchronous calls to retrieve the profile from CDS // this is mimic'ed with clientWrapper.setTaskAsPending(); clientWrapper.setTaskAsPending(); ProfileFetcherResult result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.PENDING, result.getStatus()); Assert.assertNull(result.getAppId()); // mimic task completion with 404 status code clientWrapper.setTaskAsComplete(); clientWrapper.setStatusCode(404); result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.FAILED, result.getStatus()); Assert.assertNull(result.getAppId()); }