EntryPointResources { @PATCH @Path("/{id : .+}/autoreload/swap") public void swapAutoReload(@Auth final User user, @Suspended AsyncResponse asyncResponse, @PathParam("id") String key) { EntryPointKey entryPointKey = new EntryPointKeyDefaultImpl(key); autoReloadConfigSubscriber.onNext(new AutoReloadConfigEvent(CorrelationId.newCorrelationId(), entryPointKey) { @Override public void onSuccess(AutoReloadConfigResponse autoReloadResponse) { asyncResponse.resume(status(PARTIAL_CONTENT).build()); } @Override public void onError(Throwable throwable) { asyncResponse.resume(throwable); } }); } EntryPointResources(EntryPointRepository repository, HaproxyResources haproxyResources,
                               Subscriber<AutoReloadConfigEvent> autoReloadConfigSubscriber,
                               Subscriber<AddEntryPointEvent> addEntryPointSubscriber,
                               Subscriber<UpdateEntryPointEvent> updateEntryPointSubscriber,
                               Subscriber<DeleteEntryPointEvent> deleteEntryPointSubscriber,
                               Subscriber<TryCommitPendingConfigurationEvent> tryCommitPendingConfigurationSubscriber,
                               Subscriber<TryCommitCurrentConfigurationEvent> tryCommitCurrentConfigurationSubscriber,
                               Subscriber<RegisterServerEvent> registerServerSubscriber,
                               Subscriber<CommitCompletedEvent> commitSuccessSubscriber,
                               Subscriber<CommitFailedEvent> commitFailureSubscriber); @GET @Timed Set<String> getEntryPoints(@Auth final User user); @GET @Path("/{id : .+}/autoreload") Boolean isAutoreloaded(@Auth final User user, @PathParam("id") String entryPointKey); @PATCH @Path("/{id : .+}/autoreload/swap") void swapAutoReload(@Auth final User user, @Suspended AsyncResponse asyncResponse, @PathParam("id") String key); @PUT @Path("/{id : .+}") @Timed void addEntryPoint(@Auth final User user, @Suspended AsyncResponse asyncResponse, @PathParam("id") String key, @Valid EntryPointMappingJson configuration); @PATCH @Path("/{id : .+}") @Timed void updateEntryPoint(@Auth final User user, @Suspended AsyncResponse asyncResponse, @PathParam("id") String id, @Valid UpdatedEntryPointMappingJson updatedConfiguration); @GET @Path("/{id : .+}/current") @Timed EntryPointMappingJson getCurrent(@Auth final User user, @PathParam("id") String id); @DELETE @Path("/{id : .+}") @Timed Response deleteEntrypoint(@Auth final User user, @PathParam("id") String id); @GET @Path("/{id : .+}/pending") @Timed EntryPointMappingJson getPending(@Auth final User user, @PathParam("id") String id); @GET @Path("/{id : .+}/committing") @Timed EntryPointMappingJson getCommitting(@Auth final User user, @PathParam("id") String id); @POST @Path("/{id : .+}/try-commit-current") @Produces(MediaType.TEXT_PLAIN) String tryCommitCurrent(@Auth final User user, @PathParam("id") String id); @POST @Path("/{id : .+}/try-commit-pending") @Produces(MediaType.TEXT_PLAIN) String tryCommitPending(@Auth final User user, @PathParam("id") String id); @POST @Path("/{id : .+}/backend/{backend}/register-server") @Produces(MediaType.TEXT_PLAIN) String registerServer( @Auth final User user, 
    							@PathParam("id") String id,
                                 @PathParam("backend") String backend,
                                 IncomingEntryPointBackendServerJsonRepresentation serverJson); @POST @Path("/{id : .+}/send-commit-success/{correlationId}") @Produces(MediaType.TEXT_PLAIN) String sendCommitSuccess(@Auth final User user, 
    									@PathParam("id") String id, @PathParam("correlationId") String correlationId); @POST @Path("/{id : .+}/send-commit-failure/{correlationId}") @Produces(MediaType.TEXT_PLAIN) String sendCommitFailure(@Auth final User user,
    									@PathParam("id") String id, @PathParam("correlationId") String correlationId);  }
@Test public void swap_auto_reload_should_return_partial_response_on_handler_success() throws Exception { AsyncResponse asyncResponse = mock(AsyncResponse.class); String entryPointKey = "entryPointKey"; ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class); entryPointResources.swapAutoReload(USER_PROD, asyncResponse, entryPointKey); verify(autoReloadConfigSubscriber).onNext(autoReloadEventCaptor.capture()); autoReloadEventCaptor.getValue().onSuccess(mock(AutoReloadConfigResponse.class)); assertThat(autoReloadEventCaptor.getValue().getKey().getID()).isEqualTo(entryPointKey); verify(asyncResponse).resume(responseCaptor.capture()); assertThat(responseCaptor.getValue()).isNotNull(); assertThat(responseCaptor.getValue().getStatus()).isEqualTo(Status.PARTIAL_CONTENT.getStatusCode()); }
@Test public void swap_auto_reload_should_call_resume_with_error_on_handler_error() throws Exception { AsyncResponse asyncResponse = mock(AsyncResponse.class); String entryPointKey = "entryPointKey"; RuntimeException exception = new RuntimeException(); entryPointResources.swapAutoReload(USER_PROD, asyncResponse, entryPointKey); verify(autoReloadConfigSubscriber).onNext(autoReloadEventCaptor.capture()); autoReloadEventCaptor.getValue().onError(exception); assertThat(autoReloadEventCaptor.getValue().getKey().getID()).isEqualTo(entryPointKey); verify(asyncResponse).resume(exception); }