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)
@ApiOperation(value = "Create an application metadata", notes = "User must have the APPLICATION_METADATA[CREATE] permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Application metadata successfully created", response = ApplicationMetadataEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_METADATA, acls = RolePermissionAction.CREATE) })
public Response createApplicationMetadata(@Valid @NotNull final NewApplicationMetadataEntity metadata) {
// prevent creation of a metadata on an another APPLICATION
metadata.setApplicationId(application);
final ApplicationMetadataEntity applicationMetadataEntity = metadataService.create(metadata);
return Response.created(this.getLocationHeader(applicationMetadataEntity.getKey())).entity(applicationMetadataEntity).build();
}
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() {
Mockito.reset(applicationMetadataService);
NewApplicationMetadataEntity newMetadata = new NewApplicationMetadataEntity();
newMetadata.setName("my-metadata-name");
ApplicationMetadataEntity createdMetadata = new ApplicationMetadataEntity();
createdMetadata.setKey("my-metadata-id");
when(applicationMetadataService.create(any())).thenReturn(createdMetadata);
final Response response = envTarget().path(APPLICATION).path("metadata").request().post(Entity.json(newMetadata));
assertEquals(CREATED_201, response.getStatus());
assertEquals(envTarget().path(APPLICATION).path("metadata").path("my-metadata-id").getUri().toString(), response.getHeaders().getFirst(HttpHeaders.LOCATION));
}
Aggregations