ApplicationSlaManagementResource implements ApplicationSlaManagementEndpoint { @GET @Path("/{applicationName}") @Override public ApplicationSlaRepresentation getApplicationSLA(@PathParam("applicationName") String applicationName, @QueryParam("extended") boolean extended) { ApplicationSLA applicationSLA = applicationSlaManagementService.getApplicationSLA(applicationName); if (applicationSLA == null) { throw new WebApplicationException(new IllegalArgumentException("SLA not defined for " + applicationName), Status.NOT_FOUND); } String cellId = extended ? configuration.getCellName() : null; ReservationUsage reservationUsage = extended ? reservationUsageCalculator.buildCapacityGroupUsage(applicationName) : null; return asRepresentation(applicationSLA, cellId, reservationUsage); } @Inject  ApplicationSlaManagementResource(MasterConfiguration configuration,
                                            ApplicationSlaManagementService applicationSlaManagementService,
                                            ReservationUsageCalculator reservationUsageCalculator); @GET @Override List<ApplicationSlaRepresentation> getApplicationSLAs(@QueryParam("extended") boolean extended, @QueryParam("schedulerName") String schedulerName); @GET @Path("/{applicationName}") @Override ApplicationSlaRepresentation getApplicationSLA(@PathParam("applicationName") String applicationName,
                                                          @QueryParam("extended") boolean extended); @POST @Override Response addApplicationSLA(ApplicationSlaRepresentation applicationSLA); @PUT @Path("/{applicationName}") @Override Response updateApplicationSLA(@PathParam("applicationName") String applicationName,
                                         ApplicationSlaRepresentation applicationSLA); @DELETE @Path("/{applicationName}") @Override Response removeApplicationSLA(@PathParam("applicationName") String applicationName);  }
@Test public void getApplicationByName() { String targetName = SAMPLE_SLA.getAppName(); when(capacityManagementService.getApplicationSLA(targetName)).thenReturn(SAMPLE_SLA); testClient.get().uri(targetName).exchange() .expectStatus().isOk() .expectBody(ApplicationSlaRepresentation.class).value(result -> assertThat(result.getAppName()).isEqualTo(targetName)); verify(capacityManagementService, times(1)).getApplicationSLA(targetName); }
@Test public void getNonExistingApplicationByNameFails() { String myMissingApp = "myMissingApp"; when(capacityManagementService.getApplicationSLA(any())).thenReturn(null); testClient.get().uri(myMissingApp).exchange() .expectStatus().isNotFound(); verify(capacityManagementService, times(1)).getApplicationSLA(myMissingApp); }