Search in sources :

Example 1 with ApplicationMetadataNotFoundException

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());
}
Also used : NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) UpdateApplicationMetadataEntity(io.gravitee.rest.api.model.UpdateApplicationMetadataEntity) ApplicationMetadataEntity(io.gravitee.rest.api.model.ApplicationMetadataEntity) UpdateApplicationMetadataEntity(io.gravitee.rest.api.model.UpdateApplicationMetadataEntity) ApplicationNotFoundException(io.gravitee.rest.api.service.exceptions.ApplicationNotFoundException) NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) ApplicationMetadataNotFoundException(io.gravitee.rest.api.service.exceptions.ApplicationMetadataNotFoundException) Before(org.junit.Before)

Aggregations

ApplicationMetadataEntity (io.gravitee.rest.api.model.ApplicationMetadataEntity)1 NewApplicationMetadataEntity (io.gravitee.rest.api.model.NewApplicationMetadataEntity)1 UpdateApplicationMetadataEntity (io.gravitee.rest.api.model.UpdateApplicationMetadataEntity)1 ApplicationMetadataNotFoundException (io.gravitee.rest.api.service.exceptions.ApplicationMetadataNotFoundException)1 ApplicationNotFoundException (io.gravitee.rest.api.service.exceptions.ApplicationNotFoundException)1 Before (org.junit.Before)1