@Test public void testValidDrugInteractions() throws Exception { MockCacheManager.Create(); MockHttpTransport mockTransport = MockHelper.makeMockHttpTransport(EXPECTED_RESPONSE_BODY); DrugInteractionsHandler handler = new DrugInteractionsHandler(mockTransport); Client client = new Client("first", null, "last", LocalDate.now().minusYears(32).minusDays(10), 0); client.setGender(Gender.FEMALE); List<String> interactions = Collections.emptyList(); interactions = handler.getInteractions(client, DRUG1, DRUG2); assertEquals(7, interactions.size()); assertEquals("pain (1 - 6 months, 2 - 5 years)", interactions.get(0)); assertEquals("fatigue", interactions.get(1)); assertEquals("arthralgia (2 - 5 years)", interactions.get(2)); assertEquals("pain in extremity", interactions.get(3)); assertEquals("drug ineffective (1 month - 5 years, 10+ years)", interactions.get(4)); assertEquals("headache", interactions.get(5)); assertEquals("nausea (1 - 12 months)", interactions.get(6)); }
public List<String> getInteractions(Client client, String drug1, String drug2) throws IOException, BadDrugNameException, BadGatewayException { Optional<DrugInteractionsResponse> cachedResponse = getCachedData( new TypeReference<DrugInteractionsResponse>() { }, drug1, drug2); if (cachedResponse.isPresent()) { return cachedResponse.get().calculateClientInteractions(client); } try { HttpResponse response = makeRequest(createURL(drug1, drug2)); int statusCode = response.getStatusCode(); if (statusCode == STUDY_NOT_DONE || statusCode == BAD_GATEWAY) { response = makeRequest(createURL(drug2, drug1)); int secondStatusCode = response.getStatusCode(); if (secondStatusCode != BAD_GATEWAY) { statusCode = secondStatusCode; } } return handleInteractionsResponse(client, response, statusCode, drug1, drug2); } catch (IOException exc) { throw new IOException("The drug interactions API could not be reached. " + "Check your internet connection and try again.", exc); } }
DrugInteractionsHandler extends WebAPIHandler { public List<String> getInteractions(Client client, String drug1, String drug2) throws IOException, BadDrugNameException, BadGatewayException { Optional<DrugInteractionsResponse> cachedResponse = getCachedData( new TypeReference<DrugInteractionsResponse>() { }, drug1, drug2); if (cachedResponse.isPresent()) { return cachedResponse.get().calculateClientInteractions(client); } try { HttpResponse response = makeRequest(createURL(drug1, drug2)); int statusCode = response.getStatusCode(); if (statusCode == STUDY_NOT_DONE || statusCode == BAD_GATEWAY) { response = makeRequest(createURL(drug2, drug1)); int secondStatusCode = response.getStatusCode(); if (secondStatusCode != BAD_GATEWAY) { statusCode = secondStatusCode; } } return handleInteractionsResponse(client, response, statusCode, drug1, drug2); } catch (IOException exc) { throw new IOException("The drug interactions API could not be reached. " + "Check your internet connection and try again.", exc); } } }
DrugInteractionsHandler extends WebAPIHandler { public List<String> getInteractions(Client client, String drug1, String drug2) throws IOException, BadDrugNameException, BadGatewayException { Optional<DrugInteractionsResponse> cachedResponse = getCachedData( new TypeReference<DrugInteractionsResponse>() { }, drug1, drug2); if (cachedResponse.isPresent()) { return cachedResponse.get().calculateClientInteractions(client); } try { HttpResponse response = makeRequest(createURL(drug1, drug2)); int statusCode = response.getStatusCode(); if (statusCode == STUDY_NOT_DONE || statusCode == BAD_GATEWAY) { response = makeRequest(createURL(drug2, drug1)); int secondStatusCode = response.getStatusCode(); if (secondStatusCode != BAD_GATEWAY) { statusCode = secondStatusCode; } } return handleInteractionsResponse(client, response, statusCode, drug1, drug2); } catch (IOException exc) { throw new IOException("The drug interactions API could not be reached. " + "Check your internet connection and try again.", exc); } } DrugInteractionsHandler();  DrugInteractionsHandler(HttpTransport httpTransport); }
DrugInteractionsHandler extends WebAPIHandler { public List<String> getInteractions(Client client, String drug1, String drug2) throws IOException, BadDrugNameException, BadGatewayException { Optional<DrugInteractionsResponse> cachedResponse = getCachedData( new TypeReference<DrugInteractionsResponse>() { }, drug1, drug2); if (cachedResponse.isPresent()) { return cachedResponse.get().calculateClientInteractions(client); } try { HttpResponse response = makeRequest(createURL(drug1, drug2)); int statusCode = response.getStatusCode(); if (statusCode == STUDY_NOT_DONE || statusCode == BAD_GATEWAY) { response = makeRequest(createURL(drug2, drug1)); int secondStatusCode = response.getStatusCode(); if (secondStatusCode != BAD_GATEWAY) { statusCode = secondStatusCode; } } return handleInteractionsResponse(client, response, statusCode, drug1, drug2); } catch (IOException exc) { throw new IOException("The drug interactions API could not be reached. " + "Check your internet connection and try again.", exc); } } DrugInteractionsHandler();  DrugInteractionsHandler(HttpTransport httpTransport); @Override List<String> getData(Object... arguments); List<String> getInteractions(Client client, String drug1, String drug2); }
DrugInteractionsHandler extends WebAPIHandler { public List<String> getInteractions(Client client, String drug1, String drug2) throws IOException, BadDrugNameException, BadGatewayException { Optional<DrugInteractionsResponse> cachedResponse = getCachedData( new TypeReference<DrugInteractionsResponse>() { }, drug1, drug2); if (cachedResponse.isPresent()) { return cachedResponse.get().calculateClientInteractions(client); } try { HttpResponse response = makeRequest(createURL(drug1, drug2)); int statusCode = response.getStatusCode(); if (statusCode == STUDY_NOT_DONE || statusCode == BAD_GATEWAY) { response = makeRequest(createURL(drug2, drug1)); int secondStatusCode = response.getStatusCode(); if (secondStatusCode != BAD_GATEWAY) { statusCode = secondStatusCode; } } return handleInteractionsResponse(client, response, statusCode, drug1, drug2); } catch (IOException exc) { throw new IOException("The drug interactions API could not be reached. " + "Check your internet connection and try again.", exc); } } DrugInteractionsHandler();  DrugInteractionsHandler(HttpTransport httpTransport); @Override List<String> getData(Object... arguments); List<String> getInteractions(Client client, String drug1, String drug2);  }