OpenPatentWebServiceFacade implements PatentServiceFacade { protected String reauthenticate() throws Exception { currentSecurityToken = authenticate(); return currentSecurityToken; } 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);  }
@Test public void testReauthenticate() throws Exception { OpenPatentWebServiceFacade service = prepareValidService(); CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class); StatusLine statusLine = mock(StatusLine.class); HttpEntity httpEntity = mock(HttpEntity.class); String accessToken = "someAccessToken"; when(httpClient.execute(any(HttpHost.class),any(HttpGet.class))).thenReturn(httpResponse); when(httpResponse.getStatusLine()).thenReturn(statusLine); when(statusLine.getStatusCode()).thenReturn(200); when(httpResponse.getEntity()).thenReturn(httpEntity); Gson gson = new Gson(); String pageContents = gson.toJson(new AuthenticationResponse(accessToken)); InputStream pageInputStream = new ByteArrayInputStream(pageContents.getBytes()); when(httpEntity.getContent()).thenReturn(pageInputStream); String token = service.reauthenticate(); assertNotNull(token); assertEquals(accessToken, token); }
@Test(expected = PatentServiceException.class) public void testReauthenticateResultingNon200() throws Exception { OpenPatentWebServiceFacade service = prepareValidService(); CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class); StatusLine statusLine = mock(StatusLine.class); HttpEntity httpEntity = mock(HttpEntity.class); when(httpClient.execute(any(HttpHost.class),any(HttpGet.class))).thenReturn(httpResponse); when(httpResponse.getStatusLine()).thenReturn(statusLine); when(statusLine.getStatusCode()).thenReturn(404); when(httpResponse.getEntity()).thenReturn(httpEntity); service.reauthenticate(); }