SiriClient extends SiriCommon implements SiriClientHandler,
    SiriRawHandler { @Override public Siri handleRequestWithResponse(SiriClientRequest request) { checkRequest(request); request.resetConnectionStatistics(); return processRequestWithResponse(request, false); } SiriClient(); @Inject void setSubscriptionManager(
      SiriClientSubscriptionManager subscriptionManager); void addServiceDeliveryHandler(SiriServiceDeliveryHandler handler); void removeServiceDeliveryHandler(SiriServiceDeliveryHandler handler); void setIncludeDeliveriesToUnknownSubscription(
      boolean includeDeliveriesToUnknownSubscription); @Override void stop(); @Override Siri handleRequestWithResponse(SiriClientRequest request); @Override void handleRequest(SiriClientRequest request); @Override void handleRequestReconnectIfApplicable(SiriClientRequest request); @Override void handleRawRequest(Reader reader, Writer writer); @Override void getStatus(Map<String, String> status);  }
@Test public void testHandleRequestWithResponseForCheckStatusRequestAndResponse() throws IllegalStateException, IOException, XpathException, SAXException { SiriClientRequest request = new SiriClientRequest(); request.setTargetUrl("http: request.setTargetVersion(ESiriVersion.V1_3); Siri payload = new Siri(); request.setPayload(payload); CheckStatusRequestStructure checkStatusRequest = new CheckStatusRequestStructure(); payload.setCheckStatusRequest(checkStatusRequest); StringBuilder b = new StringBuilder(); b.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"); b.append("<Siri xmlns=\"http: b.append(" <CheckStatusResponse>"); b.append(" </CheckStatusResponse>"); b.append("</Siri>"); HttpResponse response = createResponse(); response.setEntity(new StringEntity(b.toString())); Mockito.when( _httpClientService.executeHttpMethod(Mockito.any(HttpClient.class), Mockito.any(HttpUriRequest.class))).thenReturn(response); Siri siriResponse = _client.handleRequestWithResponse(request); ArgumentCaptor<HttpUriRequest> captor = ArgumentCaptor.forClass(HttpUriRequest.class); Mockito.verify(_httpClientService).executeHttpMethod( Mockito.any(HttpClient.class), captor.capture()); Mockito.verify(_subscriptionManager).handleCheckStatusNotification( Mockito.any(CheckStatusResponseStructure.class)); HttpUriRequest uriRequest = captor.getValue(); assertEquals("http: assertEquals("POST", uriRequest.getMethod()); HttpPost post = (HttpPost) uriRequest; HttpEntity entity = post.getEntity(); String content = getHttpEntityAsString(entity); Document doc = XMLUnit.buildControlDocument(content); assertXpathExists("/s:Siri", doc); assertXpathEvaluatesTo("1.3", "/s:Siri/@version", doc); assertXpathExists("/s:Siri/s:CheckStatusRequest", content); assertXpathExists("/s:Siri/s:CheckStatusRequest/s:RequestTimestamp", doc); assertXpathExists("/s:Siri/s:CheckStatusRequest/s:Address", doc); assertXpathEvaluatesTo("somebody", "/s:Siri/s:CheckStatusRequest/s:RequestorRef", doc); assertXpathExists("/s:Siri/s:CheckStatusRequest/s:MessageIdentifier", doc); String messageId = evaluateXPath( "/s:Siri/s:CheckStatusRequest/s:MessageIdentifier", doc); UUID.fromString(messageId); CheckStatusResponseStructure checkStatusResponse = siriResponse.getCheckStatusResponse(); assertNotNull(checkStatusResponse); }
@Test public void testHandleRequestWithNoPolling() throws Exception { SiriClientRequest request = new SiriClientRequest(); request.setTargetUrl("http: request.setTargetVersion(ESiriVersion.V1_3); request.setSubscribe(false); request.setPollInterval(0); Siri payload = new Siri(); request.setPayload(payload); CheckStatusRequestStructure checkStatusRequest = new CheckStatusRequestStructure(); payload.setCheckStatusRequest(checkStatusRequest); StringBuilder b = new StringBuilder(); b.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"); b.append("<Siri xmlns=\"http: b.append("</Siri>"); HttpResponse response = createResponse(); response.setEntity(new StringEntity(b.toString())); Mockito.when( _httpClientService.executeHttpMethod(Mockito.any(HttpClient.class), Mockito.any(HttpUriRequest.class))).thenReturn(response); _client.handleRequestWithResponse(request); ArgumentCaptor<HttpUriRequest> captor = ArgumentCaptor.forClass(HttpUriRequest.class); Mockito.verify(_httpClientService).executeHttpMethod( Mockito.any(HttpClient.class), captor.capture()); Mockito.verifyNoMoreInteractions(_schedulingService); }
@Test public void testHandleRequestWithPolling() throws Exception { SiriClientRequest request = new SiriClientRequest(); request.setTargetUrl("http: request.setTargetVersion(ESiriVersion.V1_3); request.setSubscribe(false); request.setPollInterval(30); Siri payload = new Siri(); request.setPayload(payload); CheckStatusRequestStructure checkStatusRequest = new CheckStatusRequestStructure(); payload.setCheckStatusRequest(checkStatusRequest); StringBuilder b = new StringBuilder(); b.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"); b.append("<Siri xmlns=\"http: b.append("</Siri>"); HttpResponse response = createResponse(); response.setEntity(new StringEntity(b.toString())); Mockito.when( _httpClientService.executeHttpMethod(Mockito.any(HttpClient.class), Mockito.any(HttpUriRequest.class))).thenReturn(response); _client.handleRequestWithResponse(request); ArgumentCaptor<HttpUriRequest> captor = ArgumentCaptor.forClass(HttpUriRequest.class); Mockito.verify(_httpClientService).executeHttpMethod( Mockito.any(HttpClient.class), captor.capture()); ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); Mockito.verify(_schedulingService).schedule(taskCaptor.capture(), Mockito.eq(30L), Mockito.eq(TimeUnit.SECONDS)); SiriCommon.AsynchronousClientRequest task = (AsynchronousClientRequest) taskCaptor.getValue(); assertSame(request, task.getRequest()); }