Search in sources :

Example 1 with ImportSwaggerDescriptorEntity

use of io.gravitee.rest.api.model.ImportSwaggerDescriptorEntity in project gravitee-management-rest-api by gravitee-io.

the class ApisResourceTest method shouldImportApiFromSwager.

@Test
public void shouldImportApiFromSwager() {
    reset(apiService, swaggerService);
    ImportSwaggerDescriptorEntity swaggerDescriptor = new ImportSwaggerDescriptorEntity();
    swaggerDescriptor.setPayload("my-payload");
    ApiEntity createdApi = new ApiEntity();
    createdApi.setId("my-beautiful-api");
    doReturn(createdApi).when(apiService).createFromSwagger(any(), any(), any());
    final Response response = envTarget().path("import").path("swagger").request().post(Entity.json(swaggerDescriptor));
    assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
    assertEquals(envTarget().path("my-beautiful-api").getUri().toString(), response.getHeaders().getFirst(HttpHeaders.LOCATION));
    verify(swaggerService).createAPI(argThat(argument -> argument.getPayload().equalsIgnoreCase(swaggerDescriptor.getPayload())), eq(DefinitionVersion.valueOfLabel("1.0.0")));
}
Also used : Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) ArgumentMatchers(org.mockito.ArgumentMatchers) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) Test(org.junit.Test) Entity(javax.ws.rs.client.Entity) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) Mockito(org.mockito.Mockito) ImportSwaggerDescriptorEntity(io.gravitee.rest.api.model.ImportSwaggerDescriptorEntity) HttpHeaders(javax.ws.rs.core.HttpHeaders) DefinitionVersion(io.gravitee.definition.model.DefinitionVersion) Response(javax.ws.rs.core.Response) NewApiEntity(io.gravitee.rest.api.model.api.NewApiEntity) Assert.assertEquals(org.junit.Assert.assertEquals) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) NewApiEntity(io.gravitee.rest.api.model.api.NewApiEntity) ImportSwaggerDescriptorEntity(io.gravitee.rest.api.model.ImportSwaggerDescriptorEntity) Test(org.junit.Test)

Aggregations

HttpStatusCode (io.gravitee.common.http.HttpStatusCode)1 DefinitionVersion (io.gravitee.definition.model.DefinitionVersion)1 ImportSwaggerDescriptorEntity (io.gravitee.rest.api.model.ImportSwaggerDescriptorEntity)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 NewApiEntity (io.gravitee.rest.api.model.api.NewApiEntity)1 GraviteeContext (io.gravitee.rest.api.service.common.GraviteeContext)1 Entity (javax.ws.rs.client.Entity)1 HttpHeaders (javax.ws.rs.core.HttpHeaders)1 Response (javax.ws.rs.core.Response)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Test (org.junit.Test)1 ArgumentMatchers (org.mockito.ArgumentMatchers)1 Mockito (org.mockito.Mockito)1