use of io.gravitee.rest.api.model.ApiMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiMetadataResource method createApiMetadata.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create an API metadata", notes = "User must have the API_METADATA[CREATE] permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "A new API metadata", response = ApiMetadataEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_METADATA, acls = RolePermissionAction.CREATE) })
public Response createApiMetadata(@Valid @NotNull final NewApiMetadataEntity metadata) {
// prevent creation of a metadata on an another API
metadata.setApiId(api);
final ApiMetadataEntity apiMetadataEntity = metadataService.create(metadata);
ApiEntity apiEntity = apiService.fetchMetadataForApi(apiService.findById(api));
searchEngineService.index(apiEntity, false);
return Response.created(this.getLocationHeader(apiMetadataEntity.getKey())).entity(apiMetadataEntity).build();
}
use of io.gravitee.rest.api.model.ApiMetadataEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiMetadataResourceTest method shouldCreateMetadata.
@Test
public void shouldCreateMetadata() {
NewApiMetadataEntity newMetadata = new NewApiMetadataEntity();
newMetadata.setName("my-metadata-name");
ApiMetadataEntity createdMetadata = new ApiMetadataEntity();
createdMetadata.setKey("my-metadata-id");
when(apiMetadataService.create(any())).thenReturn(createdMetadata);
final Response response = envTarget().path(API).path("metadata").request().post(Entity.json(newMetadata));
assertEquals(CREATED_201, response.getStatus());
assertEquals(envTarget().path(API).path("metadata").path("my-metadata-id").getUri().toString(), response.getHeaders().getFirst(HttpHeaders.LOCATION));
verify(searchEngineService, times(1)).index(any(), eq(false));
}
Aggregations