Skip to content
This repository has been archived by the owner on Jul 29, 2021. It is now read-only.

feat(groups): restrict pages and documentation to a set of groups #34

Merged
merged 1 commit into from Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -32,7 +32,7 @@
<name>Gravitee.io APIM - Repository - Test</name>

<properties>
<gravitee-repository.version>1.9.0</gravitee-repository.version>
<gravitee-repository.version>1.10.0-SNAPSHOT</gravitee-repository.version>
<commons-io.version>1.3.2</commons-io.version>
<jackson-mapper-asl.version>1.9.13</jackson-mapper-asl.version>
<javax.inject.version>1</javax.inject.version>
Expand Down
17 changes: 12 additions & 5 deletions src/test/java/io/gravitee/repository/PageRepositoryTest.java
Expand Up @@ -21,10 +21,7 @@
import io.gravitee.repository.management.model.PageType;
import org.junit.Test;

import java.util.Collection;
import java.util.Date;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -60,7 +57,17 @@ private void assertFindPage(Page page) {
assertEquals("content", "Content of the page", page.getContent());
assertEquals("api", "my-api", page.getApi());
assertEquals("type", PageType.MARKDOWN, page.getType());
assertNull("source", page.getSource());
assertEquals("last contributor", "john_doe", page.getLastContributor());
assertEquals("order", 2, page.getOrder());
assertTrue("published", page.isPublished());
assertEquals("source type", "sourceType", page.getSource().getType());
assertEquals("source configuration", "sourceConfiguration", page.getSource().getConfiguration());
assertTrue("configuration try it", page.getConfiguration().isTryIt());
assertEquals("configuration try it URL", "http://company.com", page.getConfiguration().getTryItURL());
assertTrue("homepage", page.isHomepage());
assertEquals("excludedGroups", Arrays.asList("grp1", "grp2"), page.getExcludedGroups());
assertEquals("created at", new Date(1439022010883L), page.getCreatedAt());
assertEquals("updated at", new Date(1119022010883L), page.getUpdatedAt());
}

@Test
Expand Down
22 changes: 17 additions & 5 deletions src/test/java/io/gravitee/repository/PlanRepositoryTest.java
Expand Up @@ -21,9 +21,7 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.*;

import static io.gravitee.repository.utils.DateUtils.parse;
import static org.junit.Assert.*;
Expand All @@ -46,6 +44,20 @@ public void shouldFindById() throws Exception {
assertNotNull(plan);
assertTrue(plan.isPresent());
assertEquals("my-plan", plan.get().getId());
assertEquals("Free plan", plan.get().getName());
assertEquals("Description of the free plan", plan.get().getDescription());
assertEquals("api1", plan.get().getApis().stream().findFirst().get());
assertEquals(Plan.PlanSecurityType.API_KEY, plan.get().getSecurity());
assertEquals(Plan.PlanValidationType.AUTO, plan.get().getValidation());
assertEquals(Plan.PlanType.API, plan.get().getType());
assertEquals(Plan.Status.PUBLISHED, plan.get().getStatus());
assertEquals(2, plan.get().getOrder());
assertEquals(new Date(1506964899000L), plan.get().getCreatedAt());
assertEquals(new Date(1507032062000L), plan.get().getUpdatedAt());
assertEquals(new Date(1506878460000L), plan.get().getPublishedAt());
assertEquals(new Date(1507611600000L), plan.get().getClosedAt());
assertEquals(Arrays.asList("charac 1", "charac 2"), plan.get().getCharacteristics());
assertEquals("grp1", plan.get().getExcludedGroups().get(0));
}

@Test
Expand Down Expand Up @@ -102,7 +114,7 @@ public void shouldCreate() throws Exception {

@Test
public void shouldUpdate() throws Exception {
Optional<Plan> optional = planRepository.findById("my-plan");
Optional<Plan> optional = planRepository.findById("updated-plan");
Assert.assertTrue("Plan to update not found", optional.isPresent());

final Plan plan = optional.get();
Expand All @@ -111,7 +123,7 @@ public void shouldUpdate() throws Exception {

planRepository.update(plan);

Optional<Plan> optionalUpdated = planRepository.findById("my-plan");
Optional<Plan> optionalUpdated = planRepository.findById("updated-plan");
Assert.assertTrue("View to update not found", optionalUpdated.isPresent());

final Plan planUpdated = optionalUpdated.get();
Expand Down
Expand Up @@ -28,6 +28,7 @@

import static io.gravitee.repository.utils.DateUtils.parse;
import static java.util.Arrays.asList;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static java.util.Optional.empty;
import static java.util.Optional.of;
Expand Down Expand Up @@ -528,12 +529,30 @@ public PlanRepository planRepository() throws Exception {

final Plan plan2 = mock(Plan.class);
when(plan2.getId()).thenReturn("my-plan");
when(plan2.getName()).thenReturn("New plan");
when(plan2.getName()).thenReturn("Free plan");
when(plan2.getDescription()).thenReturn("Description of the free plan");
when(plan2.getApis()).thenReturn(singleton("api1"));
when(plan2.getSecurity()).thenReturn(Plan.PlanSecurityType.API_KEY);
when(plan2.getValidation()).thenReturn(Plan.PlanValidationType.AUTO);
when(plan2.getType()).thenReturn(Plan.PlanType.API);
when(plan2.getStatus()).thenReturn(Plan.Status.PUBLISHED);
when(plan2.getOrder()).thenReturn(2);
when(plan2.getCreatedAt()).thenReturn(new Date(1506964899000L));
when(plan2.getUpdatedAt()).thenReturn(new Date(1507032062000L));
when(plan2.getPublishedAt()).thenReturn(new Date(1506878460000L));
when(plan2.getClosedAt()).thenReturn(new Date(1507611600000L));
when(plan2.getCharacteristics()).thenReturn(Arrays.asList("charac 1", "charac 2"));
when(plan2.getExcludedGroups()).thenReturn(singletonList("grp1"));

final Plan updatedPlan = mock(Plan.class);
when(updatedPlan.getId()).thenReturn("updated-plan");
when(updatedPlan.getName()).thenReturn("New plan");

when(planRepository.create(any(Plan.class))).thenReturn(plan);

when(planRepository.findById("new-plan")).thenReturn(of(plan));
when(planRepository.findById("my-plan")).thenReturn(of(plan2));
when(planRepository.findById("updated-plan")).thenReturn(of(updatedPlan));

when(planRepository.findById("stores")).thenReturn(Optional.empty());

Expand Down Expand Up @@ -619,6 +638,21 @@ public PageRepository pageRepository() throws Exception {
when(findApiPage.getContent()).thenReturn("Content of the page");
when(findApiPage.getApi()).thenReturn("my-api");
when(findApiPage.getType()).thenReturn(PageType.MARKDOWN);
when(findApiPage.getLastContributor()).thenReturn("john_doe");
when(findApiPage.getOrder()).thenReturn(2);
when(findApiPage.isPublished()).thenReturn(true);
PageSource pageSource = new PageSource();
pageSource.setType("sourceType");
pageSource.setConfiguration("sourceConfiguration");
when(findApiPage.getSource()).thenReturn(pageSource);
PageConfiguration pageConfiguration = new PageConfiguration();
pageConfiguration.setTryIt(true);
pageConfiguration.setTryItURL("http://company.com");
when(findApiPage.getConfiguration()).thenReturn(pageConfiguration);
when(findApiPage.isHomepage()).thenReturn(true);
when(findApiPage.getExcludedGroups()).thenReturn(Arrays.asList("grp1", "grp2"));
when(findApiPage.getCreatedAt()).thenReturn(new Date(1439022010883L));
when(findApiPage.getUpdatedAt()).thenReturn(new Date(1119022010883L));

// shouldFindApiPageByApiId
when(pageRepository.findApiPageByApiId("my-api")).thenReturn(newSet(findApiPage));
Expand Down
15 changes: 14 additions & 1 deletion src/test/resources/data/page-tests/pages.json
Expand Up @@ -5,8 +5,21 @@
"content": "Content of the page",
"api": "my-api",
"type": "MARKDOWN",
"lastContributor": "john_doe",
"order": 2,
"published": true,
"source": {
"type": "sourceType",
"configuration": "sourceConfiguration"
},
"configuration": {
"tryItURL": "http://company.com",
"tryIt": true
},
"homepage": true,
"excludedGroups": [ "grp1", "grp2" ],
"createdAt": 1439022010883,
"updatedAt": 1439022010883
"updatedAt": 1119022010883
},
{
"id":"updatePage",
Expand Down
21 changes: 20 additions & 1 deletion src/test/resources/data/plan-tests/plans.json
Expand Up @@ -3,7 +3,26 @@
"id":"my-plan",
"name":"Free plan",
"description": "Description of the free plan",
"apis": ["api1"]
"apis": ["api1"],
"security": "API_KEY",
"validation": "AUTO",
"type": "API",
"status": "PUBLISHED",
"order": 2,
"createdAt": 1506964899000,
"updatedAt": 1507032062000,
"publishedAt": 1506878460000,
"closedAt": 1507611600000,
"characteristics": [
"charac 1",
"charac 2"
],
"excludedGroups": [ "grp1" ]
},
{
"id":"updated-plan",
"name":"old plan",
"apis": ["api3"]
},
{
"id":"products",
Expand Down