use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_CreateOrUpdatePagesTest method shouldCreateOrUpdatePages.
@Test
public void shouldCreateOrUpdatePages() throws TechnicalException {
PageEntity page1 = new PageEntity();
page1.setId(UuidString.generateRandom());
page1.setName("Page 1");
page1.setType("SWAGGER");
page1.setReferenceType("API");
page1.setReferenceId(API_ID);
PageEntity page2 = new PageEntity();
page2.setId(UuidString.generateRandom());
page2.setName("Page 2");
page2.setType("MARKDOWN");
page2.setReferenceType("API");
page2.setReferenceId(API_ID);
PageEntity page3 = new PageEntity();
page3.setId(UuidString.generateRandom());
page3.setName("Sub Page 3");
page3.setType("ASCIIDOC");
page3.setParentId(page1.getId());
page3.setReferenceType("API");
page3.setReferenceId(API_ID);
when(pageRepository.create(any(Page.class))).thenAnswer(returnsFirstArg());
when(pageRepository.update(any(Page.class))).thenAnswer(returnsFirstArg());
String page1NewId = UuidString.generateForEnvironment(ENVIRONMENT_ID, API_ID, page1.getId());
Page page = new Page();
page.setId(page1NewId);
page.setName(page1.getName());
page.setType(page1.getType());
page.setReferenceType(PageReferenceType.valueOf(page1.getReferenceType()));
page.setReferenceId(page1.getReferenceId());
page.setVisibility("PUBLIC");
// Simulate the fact that page 1 is already created
when(pageRepository.findById(page1NewId)).thenReturn(Optional.of(page));
when(pageRepository.findById(argThat(id -> !id.equals(page1NewId)))).thenThrow(new PageNotFoundException(""));
when(planService.findByApi(anyString())).thenReturn(Collections.emptySet());
pageService.createOrUpdatePages(List.of(page1, page2, page3), ENVIRONMENT_ID, API_ID);
ArgumentCaptor<Page> createdPagesCaptor = ArgumentCaptor.forClass(Page.class);
verify(pageRepository, times(2)).create(createdPagesCaptor.capture());
List<Page> createdPages = createdPagesCaptor.getAllValues();
assertThat(createdPages.size()).isEqualTo(2);
assertThat(createdPages).extracting(Page::getName).containsExactly("Sub Page 3", "Page 2");
// New parent id of page 3 must be new id of page 1
assertThat(createdPages.get(0)).extracting(Page::getParentId).isEqualTo(page1NewId);
assertThat(createdPages).extracting(Page::getId).doesNotContain(page2.getId(), page3.getId());
ArgumentCaptor<Page> updatedPageCaptor = ArgumentCaptor.forClass(Page.class);
verify(pageRepository, times(1)).update(updatedPageCaptor.capture());
List<Page> updatedPages = updatedPageCaptor.getAllValues();
assertThat(updatedPages.size()).isEqualTo(1);
assertThat(updatedPages).extracting(Page::getName, Page::getId).containsExactly(tuple("Page 1", page1NewId));
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PlanService_PublishTest method shouldPublish_WithPublishGCPage.
@Test
public void shouldPublish_WithPublishGCPage() throws TechnicalException {
final String GC_PAGE_ID = "GC_PAGE_ID";
when(plan.getStatus()).thenReturn(Plan.Status.STAGING);
when(plan.getType()).thenReturn(Plan.PlanType.API);
when(plan.getValidation()).thenReturn(Plan.PlanValidationType.AUTO);
when(plan.getApi()).thenReturn(API_ID);
when(plan.getGeneralConditions()).thenReturn(GC_PAGE_ID);
when(planRepository.findById(PLAN_ID)).thenReturn(Optional.of(plan));
when(planRepository.update(plan)).thenAnswer(returnsFirstArg());
when(apiService.findById(API_ID)).thenReturn(apiEntity);
PageEntity page = mock(PageEntity.class);
when(page.getId()).thenReturn(GC_PAGE_ID);
when(page.isPublished()).thenReturn(true);
when(pageService.findById(page.getId())).thenReturn(page);
planService.publish(PLAN_ID);
verify(plan, times(1)).setStatus(Plan.Status.PUBLISHED);
verify(planRepository, times(1)).update(plan);
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PlanService_PublishTest method shouldNotPublish_WithNotPublishGCPage.
@Test(expected = PlanGeneralConditionStatusException.class)
public void shouldNotPublish_WithNotPublishGCPage() throws TechnicalException {
final String GC_PAGE_ID = "GC_PAGE_ID";
when(plan.getStatus()).thenReturn(Plan.Status.STAGING);
when(plan.getType()).thenReturn(Plan.PlanType.API);
when(plan.getValidation()).thenReturn(Plan.PlanValidationType.AUTO);
when(plan.getApi()).thenReturn(API_ID);
when(plan.getGeneralConditions()).thenReturn(GC_PAGE_ID);
when(planRepository.findById(PLAN_ID)).thenReturn(Optional.of(plan));
PageEntity page = mock(PageEntity.class);
when(page.getId()).thenReturn(GC_PAGE_ID);
when(page.isPublished()).thenReturn(false);
when(pageService.findById(page.getId())).thenReturn(page);
planService.publish(PLAN_ID);
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PortalPagesResourceAnonymousTest method shouldGetPage_LoginOptional.
@Test
public void shouldGetPage_LoginOptional() {
PageEntity page = new PageEntity();
page.setPublished(true);
page.setVisibility(Visibility.PUBLIC);
doReturn(page).when(pageService).findById(any(), any());
doReturn(false).when(configService).portalLoginForced();
// final Response response = envTarget(PAGE_NAME).request().get();
//
// assertNotNull("Response should be present", response);
// assertEquals("Response should be 200", OK.getStatusCode(), response.getStatus());
}
use of io.gravitee.rest.api.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PortalPagesResourceAnonymousTest method shouldNotGetPage_LoginRequired.
@Test
public void shouldNotGetPage_LoginRequired() {
PageEntity page = new PageEntity();
page.setPublished(true);
page.setVisibility(Visibility.PUBLIC);
doReturn(page).when(pageService).findById(any(), any());
doReturn(true).when(configService).portalLoginForced();
// final Response response = envTarget(PAGE_NAME).request().get();
//
// assertNotNull("Response should be present", response);
// assertEquals("Response should be 401", UNAUTHORIZED.getStatusCode(), response.getStatus());
}
Aggregations