@Test public void add_entry_point_should_return_created_response_on_handler_success() throws Exception { EntryPointMappingJson entryPoint = mock(EntryPointMappingJson.class); AsyncResponse asyncResponse = mock(AsyncResponse.class); String entryPointKey = "entryPointKey"; ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class); AddEntryPointResponse responseBody = mock(AddEntryPointResponse.class); when(responseBody.getConfiguration()).thenReturn(entryPoint); entryPointResources.addEntryPoint(USER_PROD, asyncResponse, entryPointKey, entryPoint); verify(addEntryPointSubscriber).onNext(addEntryPointEventCaptor.capture()); addEntryPointEventCaptor.getValue().onSuccess(responseBody); assertThat(addEntryPointEventCaptor.getValue().getKey().getID()).isEqualTo(entryPointKey); assertThat(addEntryPointEventCaptor.getValue().getConfiguration()).isEqualTo(entryPoint); verify(asyncResponse).resume(responseCaptor.capture()); assertThat(responseCaptor.getValue()).isNotNull(); assertThat(responseCaptor.getValue().getStatus()).isEqualTo(Status.CREATED.getStatusCode()); assertThat(responseCaptor.getValue().getEntity()).isEqualTo(entryPoint); }
@PUT @Path("/{id : .+}") @Timed public void addEntryPoint(@Auth final User user, @Suspended AsyncResponse asyncResponse, @PathParam("id") String key, @Valid EntryPointMappingJson configuration) { EntryPointKey entryPointKey = new EntryPointKeyDefaultImpl(key); addEntryPointSubscriber.onNext(new AddEntryPointEvent(CorrelationId.newCorrelationId(), entryPointKey, configuration) { @Override public void onSuccess(AddEntryPointResponse addEntryPointResponse) { asyncResponse.resume(status(CREATED).entity(addEntryPointResponse.getConfiguration()).build()); } @Override public void onError(Throwable throwable) { asyncResponse.resume(throwable); } }); }
EntryPointResources { @PUT @Path("/{id : .+}") @Timed public void addEntryPoint(@Auth final User user, @Suspended AsyncResponse asyncResponse, @PathParam("id") String key, @Valid EntryPointMappingJson configuration) { EntryPointKey entryPointKey = new EntryPointKeyDefaultImpl(key); addEntryPointSubscriber.onNext(new AddEntryPointEvent(CorrelationId.newCorrelationId(), entryPointKey, configuration) { @Override public void onSuccess(AddEntryPointResponse addEntryPointResponse) { asyncResponse.resume(status(CREATED).entity(addEntryPointResponse.getConfiguration()).build()); } @Override public void onError(Throwable throwable) { asyncResponse.resume(throwable); } }); } }
EntryPointResources { @PUT @Path("/{id : .+}") @Timed public void addEntryPoint(@Auth final User user, @Suspended AsyncResponse asyncResponse, @PathParam("id") String key, @Valid EntryPointMappingJson configuration) { EntryPointKey entryPointKey = new EntryPointKeyDefaultImpl(key); addEntryPointSubscriber.onNext(new AddEntryPointEvent(CorrelationId.newCorrelationId(), entryPointKey, configuration) { @Override public void onSuccess(AddEntryPointResponse addEntryPointResponse) { asyncResponse.resume(status(CREATED).entity(addEntryPointResponse.getConfiguration()).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); }
EntryPointResources { @PUT @Path("/{id : .+}") @Timed public void addEntryPoint(@Auth final User user, @Suspended AsyncResponse asyncResponse, @PathParam("id") String key, @Valid EntryPointMappingJson configuration) { EntryPointKey entryPointKey = new EntryPointKeyDefaultImpl(key); addEntryPointSubscriber.onNext(new AddEntryPointEvent(CorrelationId.newCorrelationId(), entryPointKey, configuration) { @Override public void onSuccess(AddEntryPointResponse addEntryPointResponse) { asyncResponse.resume(status(CREATED).entity(addEntryPointResponse.getConfiguration()).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); }
EntryPointResources { @PUT @Path("/{id : .+}") @Timed public void addEntryPoint(@Auth final User user, @Suspended AsyncResponse asyncResponse, @PathParam("id") String key, @Valid EntryPointMappingJson configuration) { EntryPointKey entryPointKey = new EntryPointKeyDefaultImpl(key); addEntryPointSubscriber.onNext(new AddEntryPointEvent(CorrelationId.newCorrelationId(), entryPointKey, configuration) { @Override public void onSuccess(AddEntryPointResponse addEntryPointResponse) { asyncResponse.resume(status(CREATED).entity(addEntryPointResponse.getConfiguration()).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);  }