use of io.gravitee.rest.api.model.UpdateApplicationMetadataEntity 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());
}
use of io.gravitee.rest.api.model.UpdateApplicationMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ReferenceMetadataMapperTest method testConvertInputToUpdateMetadataEntity.
@Test
public void testConvertInputToUpdateMetadataEntity() {
// init
ReferenceMetadataInput metadataInput = new ReferenceMetadataInput();
metadataInput.setDefaultValue(METADATA_DEFAULT_VALUE);
metadataInput.setValue(METADATA_VALUE);
metadataInput.setFormat(ReferenceMetadataFormatType.valueOf(METADATA_FORMAT));
metadataInput.setName(METADATA_NAME);
// Test
final UpdateApplicationMetadataEntity updateApplicationMetadataEntity = referenceMetadataMapper.convert(metadataInput, METADATA_APPLICATION_ID, METADATA_KEY);
assertNotNull(updateApplicationMetadataEntity);
assertEquals(METADATA_APPLICATION_ID, updateApplicationMetadataEntity.getApplicationId());
assertEquals(METADATA_DEFAULT_VALUE, updateApplicationMetadataEntity.getDefaultValue());
assertEquals(METADATA_NAME, updateApplicationMetadataEntity.getName());
assertEquals(METADATA_KEY, updateApplicationMetadataEntity.getKey());
assertEquals(METADATA_VALUE, updateApplicationMetadataEntity.getValue());
assertEquals(MetadataFormat.valueOf(METADATA_FORMAT), updateApplicationMetadataEntity.getFormat());
}
use of io.gravitee.rest.api.model.UpdateApplicationMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMetadataResourceTest method shouldUpdateMetadata.
@Test
public void shouldUpdateMetadata() {
ReferenceMetadataInput metadataInput = new ReferenceMetadataInput().name(METADATA_1_NAME).defaultValue(METADATA_1_DEFAULT_VALUE).format(ReferenceMetadataFormatType.valueOf(METADATA_1_FORMAT)).value(METADATA_1_VALUE);
final Response response = target(APPLICATION).path("metadata").path(METADATA_1).request().put(Entity.json(metadataInput));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
ArgumentCaptor<UpdateApplicationMetadataEntity> updateMetadataEntityCaptor = ArgumentCaptor.forClass(UpdateApplicationMetadataEntity.class);
Mockito.verify(applicationMetadataService).update(updateMetadataEntityCaptor.capture());
final UpdateApplicationMetadataEntity uodateMetadataEntityCaptorValue = updateMetadataEntityCaptor.getValue();
assertEquals(APPLICATION, uodateMetadataEntityCaptorValue.getApplicationId());
assertEquals(METADATA_1, uodateMetadataEntityCaptorValue.getKey());
assertEquals(METADATA_1_NAME, uodateMetadataEntityCaptorValue.getName());
assertEquals(METADATA_1_VALUE, uodateMetadataEntityCaptorValue.getValue());
assertEquals(METADATA_1_DEFAULT_VALUE, uodateMetadataEntityCaptorValue.getDefaultValue());
assertEquals(MetadataFormat.valueOf(METADATA_1_FORMAT), uodateMetadataEntityCaptorValue.getFormat());
}
Aggregations