Search in sources :

Example 51 with PageEntity

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

the class PlanService_UpdateTest method shouldUpdate_WithNewPublished_GeneralConditionPage.

@Test
public void shouldUpdate_WithNewPublished_GeneralConditionPage() throws TechnicalException {
    final String PAGE_ID = "PAGE_ID_TEST";
    when(plan.getStatus()).thenReturn(Plan.Status.PUBLISHED);
    when(plan.getType()).thenReturn(Plan.PlanType.API);
    when(plan.getSecurity()).thenReturn(Plan.PlanSecurityType.API_KEY);
    when(plan.getValidation()).thenReturn(Plan.PlanValidationType.AUTO);
    when(plan.getApi()).thenReturn(API_ID);
    when(plan.getGeneralConditions()).thenReturn(PAGE_ID);
    when(planRepository.findById(PLAN_ID)).thenReturn(Optional.of(plan));
    when(parameterService.findAsBoolean(any(), eq(ParameterReferenceType.ENVIRONMENT))).thenReturn(true);
    UpdatePlanEntity updatePlan = mock(UpdatePlanEntity.class);
    when(updatePlan.getId()).thenReturn(PLAN_ID);
    when(updatePlan.getValidation()).thenReturn(PlanValidationType.AUTO);
    when(updatePlan.getName()).thenReturn("NameUpdated");
    when(updatePlan.getGeneralConditions()).thenReturn(PAGE_ID);
    when(planRepository.update(any())).thenAnswer(returnsFirstArg());
    when(apiService.findById(API_ID)).thenReturn(apiEntity);
    PageEntity unpublishedPage = new PageEntity();
    unpublishedPage.setId(PAGE_ID);
    unpublishedPage.setOrder(1);
    unpublishedPage.setType("MARKDOWN");
    unpublishedPage.setPublished(true);
    doReturn(unpublishedPage).when(pageService).findById(PAGE_ID);
    planService.update(updatePlan);
    verify(planRepository).update(any());
    verify(parameterService).findAsBoolean(any(), eq(ParameterReferenceType.ENVIRONMENT));
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) UpdatePlanEntity(io.gravitee.rest.api.model.UpdatePlanEntity) Test(org.junit.Test)

Example 52 with PageEntity

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

the class SwaggerService_ParseTest method shouldParseSwaggerV2_json.

@Test
public void shouldParseSwaggerV2_json() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/swagger-v2.json", MediaType.APPLICATION_JSON);
    SwaggerDescriptor descriptor = swaggerService.parse(pageEntity.getContent(), false);
    assertNotNull(descriptor);
    validateV3(Json.mapper().readTree(descriptor.toJson()), false);
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) SwaggerDescriptor(io.gravitee.rest.api.service.swagger.SwaggerDescriptor) Test(org.junit.Test)

Example 53 with PageEntity

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

the class SwaggerService_ParseTest method shouldParseSwaggerV3_json.

@Test
public void shouldParseSwaggerV3_json() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.json", MediaType.APPLICATION_JSON);
    SwaggerDescriptor descriptor = swaggerService.parse(pageEntity.getContent(), false);
    assertNotNull(descriptor);
    validateV3(Json.mapper().readTree(descriptor.toJson()));
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) SwaggerDescriptor(io.gravitee.rest.api.service.swagger.SwaggerDescriptor) Test(org.junit.Test)

Example 54 with PageEntity

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

the class SwaggerService_ParseTest method shouldNotParseSwaggerV1WithoutInfo_json.

@Test
public void shouldNotParseSwaggerV1WithoutInfo_json() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/swagger-v1-no-info.json", MediaType.APPLICATION_JSON);
    OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent());
    assertNotNull(descriptor.getMessages());
    assertEquals("attribute info.title is missing", descriptor.getMessages().get(0));
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) OAIDescriptor(io.gravitee.rest.api.service.swagger.OAIDescriptor) Test(org.junit.Test)

Example 55 with PageEntity

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

the class SwaggerService_ParseTest method shouldParseSwaggerV3_yaml.

@Test
public void shouldParseSwaggerV3_yaml() throws IOException {
    PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.yaml", MediaType.TEXT_PLAIN);
    SwaggerDescriptor descriptor = swaggerService.parse(pageEntity.getContent(), false);
    assertNotNull(descriptor);
    validateV3(Yaml.mapper().readTree(descriptor.toYaml()));
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) SwaggerDescriptor(io.gravitee.rest.api.service.swagger.SwaggerDescriptor) Test(org.junit.Test)

Aggregations

PageEntity (io.gravitee.rest.api.model.PageEntity)67 Test (org.junit.Test)48 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)15 OAIDescriptor (io.gravitee.rest.api.service.swagger.OAIDescriptor)15 Page (io.gravitee.rest.api.portal.rest.model.Page)13 Response (javax.ws.rs.core.Response)13 UpdatePageEntity (io.gravitee.rest.api.model.UpdatePageEntity)9 PageConfigurationOAITransformer (io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)6 EntrypointsOAITransformer (io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer)6 SwaggerDescriptor (io.gravitee.rest.api.service.swagger.SwaggerDescriptor)5 Before (org.junit.Before)5 Page (io.gravitee.repository.management.model.Page)4 NewPageEntity (io.gravitee.rest.api.model.NewPageEntity)4 PageNotFoundException (io.gravitee.rest.api.service.exceptions.PageNotFoundException)4 ArgumentMatchers (org.mockito.ArgumentMatchers)4 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 PageRepository (io.gravitee.repository.management.api.PageRepository)3 PageReferenceType (io.gravitee.repository.management.model.PageReferenceType)3