Search in sources :

Example 11 with PageEntity

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

the class SwaggerService_TransformTest method getPage.

private PageEntity getPage(String resource, String contentType) throws IOException {
    URL url = Resources.getResource(resource);
    String descriptor = Resources.toString(url, Charsets.UTF_8);
    PageEntity pageEntity = new PageEntity();
    pageEntity.setContent(descriptor);
    pageEntity.setContentType(contentType);
    PageConfigurationEntity pageConfigurationEntity = new PageConfigurationEntity();
    pageConfigurationEntity.setTryIt(true);
    pageConfigurationEntity.setTryItURL("https://my.domain.com/v1");
    pageEntity.setConfiguration(pageConfigurationEntity);
    return pageEntity;
}
Also used : PageEntity(io.gravitee.management.model.PageEntity) PageConfigurationEntity(io.gravitee.management.model.PageConfigurationEntity) URL(java.net.URL)

Example 12 with PageEntity

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

the class PageService_CreateTest method shouldCreatePage.

@Test
public void shouldCreatePage() throws TechnicalException {
    final String name = "MARKDOWN";
    final String contrib = "contrib";
    final String content = "content";
    final String type = "MARKDOWN";
    when(page1.getId()).thenReturn(PAGE_ID);
    when(page1.getName()).thenReturn(name);
    when(page1.getApi()).thenReturn(API_ID);
    when(page1.getType()).thenReturn(PageType.valueOf(type));
    when(page1.getLastContributor()).thenReturn(contrib);
    when(page1.getOrder()).thenReturn(1);
    when(page1.getContent()).thenReturn(content);
    when(pageRepository.findById(anyString())).thenReturn(Optional.empty());
    when(pageRepository.create(any())).thenReturn(page1);
    when(newPage.getName()).thenReturn(name);
    when(newPage.getOrder()).thenReturn(1);
    when(newPage.getContent()).thenReturn(content);
    when(newPage.getLastContributor()).thenReturn(contrib);
    when(newPage.getType()).thenReturn(io.gravitee.management.model.PageType.SWAGGER);
    final PageEntity createdPage = pageService.createApiPage(API_ID, newPage);
    verify(pageRepository).create(argThat(new ArgumentMatcher<Page>() {

        public boolean matches(Object argument) {
            final Page pageToCreate = (Page) argument;
            return pageToCreate.getId().split("-").length == 5 && API_ID.equals(pageToCreate.getApi()) && name.equals(pageToCreate.getName()) && contrib.equals(pageToCreate.getLastContributor()) && content.equals(pageToCreate.getContent()) && io.gravitee.management.model.PageType.SWAGGER.name().equals(pageToCreate.getType().name()) && pageToCreate.getCreatedAt() != null && pageToCreate.getUpdatedAt() != null && pageToCreate.getCreatedAt().equals(pageToCreate.getUpdatedAt());
        }
    }));
    assertNotNull(createdPage);
    assertEquals(5, createdPage.getId().split("-").length);
    assertEquals(1, createdPage.getOrder());
    assertEquals(content, createdPage.getContent());
    assertEquals(contrib, createdPage.getLastContributor());
    assertEquals(type, createdPage.getType());
}
Also used : NewPageEntity(io.gravitee.management.model.NewPageEntity) PageEntity(io.gravitee.management.model.PageEntity) ArgumentMatcher(org.mockito.ArgumentMatcher) Page(io.gravitee.repository.management.model.Page) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 13 with PageEntity

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

the class PageService_FindByIdTest method shouldFindById.

@Test
public void shouldFindById() throws TechnicalException {
    when(page1.getId()).thenReturn(PAGE_ID);
    when(page1.getOrder()).thenReturn(1);
    when(pageRepository.findById(PAGE_ID)).thenReturn(Optional.of(page1));
    final PageEntity pageEntity = pageService.findById(PAGE_ID);
    assertNotNull(pageEntity);
    assertEquals(1, pageEntity.getOrder());
    assertEquals(PAGE_ID, pageEntity.getId());
}
Also used : PageEntity(io.gravitee.management.model.PageEntity) Test(org.junit.Test)

Aggregations

PageEntity (io.gravitee.management.model.PageEntity)13 Test (org.junit.Test)11 ApiEntity (io.gravitee.management.model.ApiEntity)5 Response (javax.ws.rs.core.Response)5 NewPageEntity (io.gravitee.management.model.NewPageEntity)2 PageConfigurationEntity (io.gravitee.management.model.PageConfigurationEntity)1 UpdatePageEntity (io.gravitee.management.model.UpdatePageEntity)1 RolePermissionAction (io.gravitee.management.model.permissions.RolePermissionAction)1 Permissions (io.gravitee.management.rest.security.Permissions)1 Page (io.gravitee.repository.management.model.Page)1 URL (java.net.URL)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1 Matchers.anyString (org.mockito.Matchers.anyString)1