@Test public void testGetPatentMetadataForHttp400() throws Exception { ImportedPatent.Builder patentBuilder = initializeWithDummyValues(); String expectedResult = "this is expected result"; OpenPatentWebServiceFacade service = prepareValidService(); String accessToken = "someAccessToken"; Gson gson = new Gson(); String pageContents = gson.toJson(new AuthenticationResponse(accessToken)); CloseableHttpResponse authnHttpResponse1 = mock(CloseableHttpResponse.class); StatusLine authnStatusLine = mock(StatusLine.class); HttpEntity authnHttpEntity1 = mock(HttpEntity.class); when(authnHttpResponse1.getStatusLine()).thenReturn(authnStatusLine); when(authnStatusLine.getStatusCode()).thenReturn(200); when(authnHttpResponse1.getEntity()).thenReturn(authnHttpEntity1); when(authnHttpEntity1.getContent()).thenReturn(new ByteArrayInputStream(pageContents.getBytes())); CloseableHttpResponse authnHttpResponse2 = mock(CloseableHttpResponse.class); HttpEntity authnHttpEntity2 = mock(HttpEntity.class); when(authnHttpResponse2.getStatusLine()).thenReturn(authnStatusLine); when(authnHttpResponse2.getEntity()).thenReturn(authnHttpEntity2); when(authnHttpEntity2.getContent()).thenReturn(new ByteArrayInputStream(pageContents.getBytes())); CloseableHttpResponse getPatentHttpResponse1 = mock(CloseableHttpResponse.class); StatusLine getPatentStatusLine1 = mock(StatusLine.class); HttpEntity getPatentHttpEntity1 = mock(HttpEntity.class); when(getPatentHttpResponse1.getStatusLine()).thenReturn(getPatentStatusLine1); when(getPatentStatusLine1.getStatusCode()).thenReturn(400); when(getPatentHttpResponse1.getEntity()).thenReturn(getPatentHttpEntity1); when(getPatentHttpEntity1.getContent()).thenReturn(new ByteArrayInputStream("".getBytes())); CloseableHttpResponse getPatentHttpResponse2 = mock(CloseableHttpResponse.class); StatusLine getPatentStatusLine2 = mock(StatusLine.class); HttpEntity getPatentHttpEntity2 = mock(HttpEntity.class); when(getPatentHttpResponse2.getStatusLine()).thenReturn(getPatentStatusLine2); when(getPatentStatusLine2.getStatusCode()).thenReturn(200); when(getPatentHttpResponse2.getEntity()).thenReturn(getPatentHttpEntity2); when(getPatentHttpEntity2.getContent()).thenReturn(new ByteArrayInputStream(expectedResult.getBytes())); when(httpClient.execute(any(HttpHost.class), any(HttpGet.class))).thenReturn(authnHttpResponse1, getPatentHttpResponse1, authnHttpResponse2, getPatentHttpResponse2); String patentContents = service.getPatentMetadata(patentBuilder.build()); assertNotNull(patentContents); assertEquals(expectedResult, patentContents); }
@Override public String getPatentMetadata(ImportedPatent patent) throws Exception { return getPatentMetadata(patent, getSecurityToken(), 0); }
OpenPatentWebServiceFacade implements PatentServiceFacade { @Override public String getPatentMetadata(ImportedPatent patent) throws Exception { return getPatentMetadata(patent, getSecurityToken(), 0); } }
OpenPatentWebServiceFacade implements PatentServiceFacade { @Override public String getPatentMetadata(ImportedPatent patent) throws Exception { return getPatentMetadata(patent, getSecurityToken(), 0); } OpenPatentWebServiceFacade(ConnectionDetails connDetails); protected  OpenPatentWebServiceFacade(CloseableHttpClient httpClient, HttpHost authHost, String authUriRoot, HttpHost opsHost,
            String opsUriRoot, String consumerCredential, long throttleSleepTime, int maxRetriesCount,
            JsonParser jsonParser); }
OpenPatentWebServiceFacade implements PatentServiceFacade { @Override public String getPatentMetadata(ImportedPatent patent) throws Exception { return getPatentMetadata(patent, getSecurityToken(), 0); } OpenPatentWebServiceFacade(ConnectionDetails connDetails); protected  OpenPatentWebServiceFacade(CloseableHttpClient httpClient, HttpHost authHost, String authUriRoot, HttpHost opsHost,
            String opsUriRoot, String consumerCredential, long throttleSleepTime, int maxRetriesCount,
            JsonParser jsonParser); @Override String getPatentMetadata(ImportedPatent patent); }
OpenPatentWebServiceFacade implements PatentServiceFacade { @Override public String getPatentMetadata(ImportedPatent patent) throws Exception { return getPatentMetadata(patent, getSecurityToken(), 0); } OpenPatentWebServiceFacade(ConnectionDetails connDetails); protected  OpenPatentWebServiceFacade(CloseableHttpClient httpClient, HttpHost authHost, String authUriRoot, HttpHost opsHost,
            String opsUriRoot, String consumerCredential, long throttleSleepTime, int maxRetriesCount,
            JsonParser jsonParser); @Override String getPatentMetadata(ImportedPatent patent);  }