Search in sources :

Example 6 with NewApplicationMetadataEntity

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();
}
Also used : NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) UpdateApplicationMetadataEntity(io.gravitee.rest.api.model.UpdateApplicationMetadataEntity) ApplicationMetadataEntity(io.gravitee.rest.api.model.ApplicationMetadataEntity) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 7 with NewApplicationMetadataEntity

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));
}
Also used : NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) ApplicationMetadataEntity(io.gravitee.rest.api.model.ApplicationMetadataEntity) Response(javax.ws.rs.core.Response) NewApplicationMetadataEntity(io.gravitee.rest.api.model.NewApplicationMetadataEntity) Test(org.junit.Test)

Aggregations

NewApplicationMetadataEntity (io.gravitee.rest.api.model.NewApplicationMetadataEntity)7 ApplicationMetadataEntity (io.gravitee.rest.api.model.ApplicationMetadataEntity)4 UpdateApplicationMetadataEntity (io.gravitee.rest.api.model.UpdateApplicationMetadataEntity)3 Test (org.junit.Test)3 Response (javax.ws.rs.core.Response)2 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)1 ReferenceMetadataInput (io.gravitee.rest.api.portal.rest.model.ReferenceMetadataInput)1 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)1 ApplicationMetadataNotFoundException (io.gravitee.rest.api.service.exceptions.ApplicationMetadataNotFoundException)1 ApplicationNotFoundException (io.gravitee.rest.api.service.exceptions.ApplicationNotFoundException)1 Before (org.junit.Before)1