use of io.gravitee.rest.api.model.NewApplicationMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ReferenceMetadataMapper method convert.
public NewApplicationMetadataEntity convert(ReferenceMetadataInput applicationReferenceMetadataInput, String applicationId) {
final NewApplicationMetadataEntity newApplicationMetadataEntity = new NewApplicationMetadataEntity();
newApplicationMetadataEntity.setApplicationId(applicationId);
newApplicationMetadataEntity.setDefaultValue(applicationReferenceMetadataInput.getDefaultValue());
if (applicationReferenceMetadataInput.getFormat() != null) {
newApplicationMetadataEntity.setFormat(MetadataFormat.valueOf(applicationReferenceMetadataInput.getFormat().name()));
} else {
newApplicationMetadataEntity.setFormat(MetadataFormat.STRING);
}
newApplicationMetadataEntity.setName(applicationReferenceMetadataInput.getName());
newApplicationMetadataEntity.setValue(applicationReferenceMetadataInput.getValue());
return newApplicationMetadataEntity;
}
use of io.gravitee.rest.api.model.NewApplicationMetadataEntity 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.NewApplicationMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMetadataResourceTest method shouldCreateMetadata.
@Test
public void shouldCreateMetadata() {
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").request().post(Entity.json(metadataInput));
assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
assertEquals(target(APPLICATION).path("metadata").path(METADATA_1).getUri().toString(), response.getHeaders().getFirst(HttpHeaders.LOCATION));
ArgumentCaptor<NewApplicationMetadataEntity> newMetadataEntityCaptor = ArgumentCaptor.forClass(NewApplicationMetadataEntity.class);
Mockito.verify(applicationMetadataService).create(newMetadataEntityCaptor.capture());
final NewApplicationMetadataEntity newMetadataEntityCaptorValue = newMetadataEntityCaptor.getValue();
assertEquals(APPLICATION, newMetadataEntityCaptorValue.getApplicationId());
assertEquals(METADATA_1_NAME, newMetadataEntityCaptorValue.getName());
assertEquals(METADATA_1_VALUE, newMetadataEntityCaptorValue.getValue());
assertEquals(METADATA_1_DEFAULT_VALUE, newMetadataEntityCaptorValue.getDefaultValue());
assertEquals(MetadataFormat.valueOf(METADATA_1_FORMAT), newMetadataEntityCaptorValue.getFormat());
}
use of io.gravitee.rest.api.model.NewApplicationMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ReferenceMetadataMapperTest method testConvertInputToNewMetadataEntity.
@Test
public void testConvertInputToNewMetadataEntity() {
// 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 NewApplicationMetadataEntity newApplicationMetadataEntity = referenceMetadataMapper.convert(metadataInput, METADATA_APPLICATION_ID);
assertNotNull(newApplicationMetadataEntity);
assertEquals(METADATA_APPLICATION_ID, newApplicationMetadataEntity.getApplicationId());
assertEquals(METADATA_DEFAULT_VALUE, newApplicationMetadataEntity.getDefaultValue());
assertEquals(METADATA_NAME, newApplicationMetadataEntity.getName());
assertEquals(METADATA_VALUE, newApplicationMetadataEntity.getValue());
assertEquals(MetadataFormat.valueOf(METADATA_FORMAT), newApplicationMetadataEntity.getFormat());
}
use of io.gravitee.rest.api.model.NewApplicationMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMetadataResource method createApplicationMetadata.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_METADATA, acls = RolePermissionAction.CREATE) })
public Response createApplicationMetadata(@PathParam("applicationId") String applicationId, @Valid @NotNull final ReferenceMetadataInput metadata) {
// prevent creation of a metadata on an another APPLICATION
NewApplicationMetadataEntity newApplicationMetadataEntity = this.referenceMetadataMapper.convert(metadata, applicationId);
final ApplicationMetadataEntity applicationMetadataEntity = metadataService.create(newApplicationMetadataEntity);
return Response.created(this.getLocationHeader(applicationMetadataEntity.getKey())).entity(this.referenceMetadataMapper.convert(applicationMetadataEntity)).build();
}
Aggregations