@Test public void onResponseReceived_OK_Complete() { final SystemSchema schema = newSchema(); newConnection( createConnector( schema ) ); Replicant.context().request( schema.getId(), ValueUtil.randomString(), () -> { final replicant.Request r = Replicant.context().currentRequest( schema.getId() ); final RequestCallback chainedCallback = mock( RequestCallback.class ); final Request request = mock( Request.class ); final Response response = mock( Response.class ); when( response.getStatusCode() ).thenReturn( 200 ); when( response.getHeader( SharedConstants.REQUEST_COMPLETE_HEADER ) ).thenReturn( "1" ); final TestSpyEventHandler handler = registerTestSpyEventHandler(); new ReplicantRequestCallback( r, chainedCallback ) .onResponseReceived( request, response ); handler.assertEventCount( 1 ); handler.assertNextEvent( RequestCompletedEvent.class, e -> { assertEquals( e.getRequestId(), r.getRequestId() ); assertTrue( e.isNormalCompletion() ); assertFalse( e.isExpectingResults() ); } ); verify( chainedCallback ).onResponseReceived( request, response ); } ); }
@Override public void onResponseReceived( final Request request, final Response response ) { final int statusCode = response.getStatusCode(); if ( Response.SC_OK == statusCode ) { final boolean messageComplete = "1".equals( response.getHeader( SharedConstants.REQUEST_COMPLETE_HEADER ) ); _replicantRequest.onSuccess( messageComplete, () -> _callback.onResponseReceived( request, response ) ); } else { onError( request, new InvalidHttpResponseException( statusCode, response.getStatusText() ) ); } }
ReplicantRequestCallback implements RequestCallback { @Override public void onResponseReceived( final Request request, final Response response ) { final int statusCode = response.getStatusCode(); if ( Response.SC_OK == statusCode ) { final boolean messageComplete = "1".equals( response.getHeader( SharedConstants.REQUEST_COMPLETE_HEADER ) ); _replicantRequest.onSuccess( messageComplete, () -> _callback.onResponseReceived( request, response ) ); } else { onError( request, new InvalidHttpResponseException( statusCode, response.getStatusText() ) ); } } }
ReplicantRequestCallback implements RequestCallback { @Override public void onResponseReceived( final Request request, final Response response ) { final int statusCode = response.getStatusCode(); if ( Response.SC_OK == statusCode ) { final boolean messageComplete = "1".equals( response.getHeader( SharedConstants.REQUEST_COMPLETE_HEADER ) ); _replicantRequest.onSuccess( messageComplete, () -> _callback.onResponseReceived( request, response ) ); } else { onError( request, new InvalidHttpResponseException( statusCode, response.getStatusText() ) ); } } ReplicantRequestCallback( @Nonnull final replicant.Request replicantRequest, @Nonnull final RequestCallback callback ); }
ReplicantRequestCallback implements RequestCallback { @Override public void onResponseReceived( final Request request, final Response response ) { final int statusCode = response.getStatusCode(); if ( Response.SC_OK == statusCode ) { final boolean messageComplete = "1".equals( response.getHeader( SharedConstants.REQUEST_COMPLETE_HEADER ) ); _replicantRequest.onSuccess( messageComplete, () -> _callback.onResponseReceived( request, response ) ); } else { onError( request, new InvalidHttpResponseException( statusCode, response.getStatusText() ) ); } } ReplicantRequestCallback( @Nonnull final replicant.Request replicantRequest, @Nonnull final RequestCallback callback ); @Override void onResponseReceived( final Request request, final Response response ); @Override void onError( final Request request, final Throwable exception ); }
ReplicantRequestCallback implements RequestCallback { @Override public void onResponseReceived( final Request request, final Response response ) { final int statusCode = response.getStatusCode(); if ( Response.SC_OK == statusCode ) { final boolean messageComplete = "1".equals( response.getHeader( SharedConstants.REQUEST_COMPLETE_HEADER ) ); _replicantRequest.onSuccess( messageComplete, () -> _callback.onResponseReceived( request, response ) ); } else { onError( request, new InvalidHttpResponseException( statusCode, response.getStatusText() ) ); } } ReplicantRequestCallback( @Nonnull final replicant.Request replicantRequest, @Nonnull final RequestCallback callback ); @Override void onResponseReceived( final Request request, final Response response ); @Override void onError( final Request request, final Throwable exception );  }