Search in sources :

Example 96 with ApiEntity

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

the class ApiResourceNotAdminTest method shouldGetApi.

@Test
public void shouldGetApi() {
    final Response response = envTarget(API).request().get();
    assertEquals(OK_200, response.getStatus());
    final ApiEntity responseApi = response.readEntity(ApiEntity.class);
    assertNotNull(responseApi);
    assertEquals(API, responseApi.getName());
}
Also used : Response(javax.ws.rs.core.Response) UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Test(org.junit.Test)

Example 97 with ApiEntity

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

the class ApisResourceTest method shouldImportApiFromGraviteeIODefinitionV1.

@Test
public void shouldImportApiFromGraviteeIODefinitionV1() {
    reset(apiService, swaggerService);
    String apiDefinition = "{}";
    ApiEntity createdApi = new ApiEntity();
    createdApi.setGraviteeDefinitionVersion("1.0.0");
    createdApi.setId("my-beautiful-api");
    doReturn(createdApi).when(apiDuplicatorService).createWithImportedDefinition(any(), any(), eq(GraviteeContext.getCurrentOrganization()), eq(GraviteeContext.getCurrentEnvironment()));
    final Response response = envTarget().path("import").request().post(Entity.json(apiDefinition));
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    verify(apiService, times(0)).migrate(any());
}
Also used : Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) NewApiEntity(io.gravitee.rest.api.model.api.NewApiEntity) Test(org.junit.Test)

Example 98 with ApiEntity

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

the class ApisResourceTest method shouldNotCreateApi_withoutPath.

@Test
public void shouldNotCreateApi_withoutPath() {
    final NewApiEntity apiEntity = new NewApiEntity();
    apiEntity.setName("My beautiful api");
    apiEntity.setVersion("v1");
    apiEntity.setDescription("my description");
    ApiEntity returnedApi = new ApiEntity();
    returnedApi.setId("my-beautiful-api");
    doReturn(returnedApi).when(apiService).create(Mockito.any(NewApiEntity.class), Mockito.eq(USER_NAME));
    final Response response = envTarget().request().post(Entity.json(apiEntity));
    assertEquals(HttpStatusCode.BAD_REQUEST_400, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) NewApiEntity(io.gravitee.rest.api.model.api.NewApiEntity) NewApiEntity(io.gravitee.rest.api.model.api.NewApiEntity) Test(org.junit.Test)

Example 99 with ApiEntity

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

the class ApisResourceTest method shouldImportApiWithoutMigrationFromGraviteeIODefinitionIfAlreadyV2.

@Test
public void shouldImportApiWithoutMigrationFromGraviteeIODefinitionIfAlreadyV2() {
    reset(apiService, swaggerService);
    String apiDefinition = "{}";
    ApiEntity createdApi = new ApiEntity();
    createdApi.setGraviteeDefinitionVersion("2.0.0");
    createdApi.setId("my-beautiful-api");
    doReturn(createdApi).when(apiDuplicatorService).createWithImportedDefinition(any(), any(), eq(GraviteeContext.getCurrentOrganization()), eq(GraviteeContext.getCurrentEnvironment()));
    final Response response = envTarget().path("import").queryParam("definitionVersion", "2.0.0").request().post(Entity.json(apiDefinition));
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    verify(apiService, times(0)).migrate(any());
}
Also used : Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) NewApiEntity(io.gravitee.rest.api.model.api.NewApiEntity) Test(org.junit.Test)

Example 100 with ApiEntity

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

the class ApisResourceTest method shouldCreateApi.

@Test
public void shouldCreateApi() {
    final NewApiEntity apiEntity = new NewApiEntity();
    apiEntity.setName("My beautiful api");
    apiEntity.setVersion("v1");
    apiEntity.setDescription("my description");
    apiEntity.setContextPath("/myapi");
    apiEntity.setEndpoint("http://localhost:9099/");
    ApiEntity returnedApi = new ApiEntity();
    returnedApi.setId("my-beautiful-api");
    doReturn(returnedApi).when(apiService).create(Mockito.any(NewApiEntity.class), Mockito.eq(USER_NAME));
    final Response response = envTarget().request().post(Entity.json(apiEntity));
    assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
    assertEquals(envTarget().path("my-beautiful-api").getUri().toString(), response.getHeaders().getFirst(HttpHeaders.LOCATION));
}
Also used : Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) NewApiEntity(io.gravitee.rest.api.model.api.NewApiEntity) NewApiEntity(io.gravitee.rest.api.model.api.NewApiEntity) Test(org.junit.Test)

Aggregations

ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)273 Test (org.junit.Test)180 Response (javax.ws.rs.core.Response)65 Before (org.junit.Before)46 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)35 Error (io.gravitee.rest.api.portal.rest.model.Error)32 java.util (java.util)30 Collectors (java.util.stream.Collectors)27 Mockito.doReturn (org.mockito.Mockito.doReturn)27 Mockito (org.mockito.Mockito)25 ArgumentMatchers (org.mockito.ArgumentMatchers)24 UpdateApiEntity (io.gravitee.rest.api.model.api.UpdateApiEntity)23 Assert (org.junit.Assert)22 Collections.singletonList (java.util.Collections.singletonList)21 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)20 IOException (java.io.IOException)20 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)19 Entity (javax.ws.rs.client.Entity)19 HashSet (java.util.HashSet)18 Api (io.gravitee.repository.management.model.Api)17