Search in sources :

Example 66 with ApiEntity

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

the class SwaggerService_TransformTest method shouldTransformAPIWithServerUrlAndContextPath.

@Test
public void shouldTransformAPIWithServerUrlAndContextPath() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.json", MediaType.APPLICATION_JSON);
    Map<String, String> pageConfigurationEntity = new HashMap<>();
    pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINTS_AS_SERVERS, "true");
    pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINT_AS_BASEPATH, "true");
    pageEntity.setConfiguration(pageConfigurationEntity);
    OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent(), false);
    final ApiEntity apiEntity = getApiEntity();
    swaggerService.transform(descriptor, Arrays.asList(new PageConfigurationOAITransformer(pageEntity), new EntrypointsOAITransformer(pageEntity, apiEntity)));
    assertNotNull(descriptor.toJson());
    final JsonNode node = Json.mapper().readTree(descriptor.toJson());
    assertEquals("https://apis.gravitee.io/test", node.get("servers").get(0).get("url").asText());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) OAIDescriptor(io.gravitee.rest.api.service.swagger.OAIDescriptor) EntrypointsOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer) PageConfigurationOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 67 with ApiEntity

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

the class SwaggerService_TransformTest method shouldTransformAPIWithOriginalServer.

@Test
public void shouldTransformAPIWithOriginalServer() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.json", MediaType.APPLICATION_JSON);
    Map<String, String> pageConfigurationEntity = new HashMap<>();
    pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINTS_AS_SERVERS, "false");
    pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINT_AS_BASEPATH, "false");
    pageEntity.setConfiguration(pageConfigurationEntity);
    OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent(), false);
    final ApiEntity apiEntity = getApiEntity();
    swaggerService.transform(descriptor, Arrays.asList(new PageConfigurationOAITransformer(pageEntity), new EntrypointsOAITransformer(pageEntity, apiEntity)));
    assertNotNull(descriptor.toJson());
    final JsonNode node = Json.mapper().readTree(descriptor.toJson());
    assertEquals("https://demo.gravitee.io/gateway/echo", node.get("servers").get(0).get("url").asText());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) OAIDescriptor(io.gravitee.rest.api.service.swagger.OAIDescriptor) EntrypointsOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer) PageConfigurationOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 68 with ApiEntity

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

the class SwaggerService_TransformTest method shouldTransformAPIWithServerUrl.

@Test
public void shouldTransformAPIWithServerUrl() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.json", MediaType.APPLICATION_JSON);
    Map<String, String> pageConfigurationEntity = new HashMap<>();
    pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINTS_AS_SERVERS, "true");
    pageEntity.setConfiguration(pageConfigurationEntity);
    OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent(), false);
    final ApiEntity apiEntity = getApiEntity();
    swaggerService.transform(descriptor, Arrays.asList(new PageConfigurationOAITransformer(pageEntity), new EntrypointsOAITransformer(pageEntity, apiEntity)));
    assertNotNull(descriptor.toJson());
    final JsonNode node = Json.mapper().readTree(descriptor.toJson());
    assertEquals("https://apis.gravitee.io", node.get("servers").get(0).get("url").asText());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) OAIDescriptor(io.gravitee.rest.api.service.swagger.OAIDescriptor) EntrypointsOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer) PageConfigurationOAITransformer(io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 69 with ApiEntity

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

the class TopApiServiceTest method shouldDelete.

@Test
public void shouldDelete() {
    final ApiEntity api1 = new ApiEntity();
    api1.setId("1");
    api1.setName("name");
    api1.setVersion("version");
    api1.setDescription("description");
    final ApiEntity api2 = new ApiEntity();
    api2.setId("2");
    when(parameterService.findAll(eq(PORTAL_TOP_APIS), any(Function.class), any(Predicate.class), any(ParameterReferenceType.class))).thenReturn(asList(api1, api2));
    topApiService.delete("1");
    verify(parameterService).save(PORTAL_TOP_APIS, singletonList("2"), ParameterReferenceType.ENVIRONMENT);
}
Also used : Function(java.util.function.Function) ParameterReferenceType(io.gravitee.rest.api.model.parameters.ParameterReferenceType) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) UpdateTopApiEntity(io.gravitee.rest.api.model.UpdateTopApiEntity) TopApiEntity(io.gravitee.rest.api.model.TopApiEntity) NewTopApiEntity(io.gravitee.rest.api.model.NewTopApiEntity) Predicate(java.util.function.Predicate) Test(org.junit.Test)

Example 70 with ApiEntity

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

the class UserServiceTest method shouldNotDeleteIfAPIPO.

@Test
public void shouldNotDeleteIfAPIPO() throws TechnicalException {
    ApiEntity apiEntity = mock(ApiEntity.class);
    PrimaryOwnerEntity primaryOwnerEntity = mock(PrimaryOwnerEntity.class);
    when(apiEntity.getPrimaryOwner()).thenReturn(primaryOwnerEntity);
    when(primaryOwnerEntity.getId()).thenReturn(USER_NAME);
    when(apiService.findByUser(USER_NAME, null, false)).thenReturn(Collections.singleton(apiEntity));
    try {
        userService.delete(USER_NAME);
        fail("should throw StillPrimaryOwnerException");
    } catch (StillPrimaryOwnerException e) {
        // success
        verify(membershipService, never()).removeMemberMemberships(MembershipMemberType.USER, USER_NAME);
        verify(userRepository, never()).update(any());
        verify(searchEngineService, never()).delete(any(), eq(false));
    }
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) 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