use of io.gravitee.rest.api.service.exceptions.ApplicationMetadataNotFoundException in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMetadataResourceTest method init.
@Before
public void init() {
resetAllMocks();
ApplicationMetadataEntity applicationMetadataEntity1 = new ApplicationMetadataEntity();
applicationMetadataEntity1.setKey(METADATA_1);
ApplicationMetadataEntity applicationMetadataEntity2 = new ApplicationMetadataEntity();
applicationMetadataEntity2.setKey(METADATA_2);
when(referenceMetadataMapper.convert(any())).thenCallRealMethod();
when(referenceMetadataMapper.convert(any(), any())).thenCallRealMethod();
when(referenceMetadataMapper.convert(any(), any(), any())).thenCallRealMethod();
doReturn(Arrays.asList(applicationMetadataEntity1, applicationMetadataEntity2)).when(applicationMetadataService).findAllByApplication(APPLICATION);
doReturn(applicationMetadataEntity1).when(applicationMetadataService).findByIdAndApplication(METADATA_1, APPLICATION);
doReturn(null).when(applicationMetadataService).findByIdAndApplication(METADATA_2, APPLICATION);
when(applicationMetadataService.create(any())).thenAnswer(invocation -> {
NewApplicationMetadataEntity newApplicationMetadataEntity = invocation.getArgument(0);
if (newApplicationMetadataEntity.getApplicationId().equals(UNKNOWN_APPLICATION)) {
throw new ApplicationNotFoundException(UNKNOWN_APPLICATION);
}
return applicationMetadataEntity1;
});
when(applicationMetadataService.update(any())).thenAnswer(invocation -> {
UpdateApplicationMetadataEntity updateApplicationMetadataEntity = invocation.getArgument(0);
if (updateApplicationMetadataEntity.getApplicationId().equals(UNKNOWN_APPLICATION)) {
throw new ApplicationNotFoundException(UNKNOWN_APPLICATION);
}
if (updateApplicationMetadataEntity.getKey().equals(UNKNOWN_METADATA)) {
throw new ApplicationMetadataNotFoundException(updateApplicationMetadataEntity.getApplicationId(), UNKNOWN_METADATA);
}
return applicationMetadataEntity1;
});
doThrow(ApplicationNotFoundException.class).when(applicationMetadataService).findAllByApplication(UNKNOWN_APPLICATION);
doThrow(ApplicationNotFoundException.class).when(applicationMetadataService).findByIdAndApplication(any(), eq(UNKNOWN_APPLICATION));
doThrow(ApplicationNotFoundException.class).when(applicationMetadataService).delete(any(), eq(UNKNOWN_APPLICATION));
doThrow(ApplicationMetadataNotFoundException.class).when(applicationMetadataService).findByIdAndApplication(UNKNOWN_METADATA, APPLICATION);
doThrow(ApplicationMetadataNotFoundException.class).when(applicationMetadataService).delete(eq(UNKNOWN_METADATA), any());
}
Aggregations