Search in sources :

Example 1 with PlansResponse

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

the class ApiPlansResourceTest method shouldGetApiPlansWithPrivateAPIAndReadPermission.

@Test
public void shouldGetApiPlansWithPrivateAPIAndReadPermission() {
    doReturn(true).when(groupService).isUserAuthorizedToAccessApiData(any(), any(), any());
    doReturn(true).when(permissionService).hasPermission(any(), any(), any());
    final Response response = target(API).path("plans").request().get();
    assertEquals(OK_200, response.getStatus());
    PlansResponse plansResponse = response.readEntity(PlansResponse.class);
    List<Plan> plans = plansResponse.getData();
    assertNotNull(plans);
    assertEquals(2, plans.size());
}
Also used : PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) Plan(io.gravitee.rest.api.portal.rest.model.Plan) Test(org.junit.Test)

Example 2 with PlansResponse

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

the class ApiPlansResourceTest method shouldGetApiPlansWithPublicAPI.

@Test
public void shouldGetApiPlansWithPublicAPI() {
    doReturn(true).when(groupService).isUserAuthorizedToAccessApiData(any(), any(), any());
    final Response response = target(API).path("plans").request().get();
    assertEquals(OK_200, response.getStatus());
    PlansResponse plansResponse = response.readEntity(PlansResponse.class);
    List<Plan> plans = plansResponse.getData();
    assertNotNull(plans);
    assertEquals(2, plans.size());
}
Also used : PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) Plan(io.gravitee.rest.api.portal.rest.model.Plan) Test(org.junit.Test)

Example 3 with PlansResponse

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

the class ApiPlansResourceTest method shouldGetApiPlansWithPublicAPI_WithGCU.

@Test
public void shouldGetApiPlansWithPublicAPI_WithGCU() {
    PageEntity page = new PageEntity();
    final String PAGE_ID = "PAGE_ID_CGU";
    page.setId(PAGE_ID);
    page.setPublished(true);
    page.setContent("Some CGU");
    page.setType(PageType.MARKDOWN.name());
    doReturn(page).when(pageService).findById(any(), any());
    plan1.setGeneralConditions(PAGE_ID);
    plan2.setGeneralConditions(PAGE_ID);
    doReturn(true).when(groupService).isUserAuthorizedToAccessApiData(any(), any(), any());
    final Response response = target(API).path("plans").request().get();
    assertEquals(OK_200, response.getStatus());
    PlansResponse plansResponse = response.readEntity(PlansResponse.class);
    List<Plan> plans = plansResponse.getData();
    assertNotNull(plans);
    assertEquals(2, plans.size());
    for (Plan plan : plans) {
        assertEquals(PAGE_ID, plan.getGeneralConditions());
    }
}
Also used : PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) Plan(io.gravitee.rest.api.portal.rest.model.Plan) Test(org.junit.Test)

Example 4 with PlansResponse

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

the class ApiPlansResourceTest method shouldGetNoApiPlan.

@Test
public void shouldGetNoApiPlan() {
    doReturn(false).when(groupService).isUserAuthorizedToAccessApiData(any(), any(), any());
    final Response response = target(API).path("plans").request().get();
    assertEquals(OK_200, response.getStatus());
    PlansResponse plansResponse = response.readEntity(PlansResponse.class);
    List<Plan> plans = plansResponse.getData();
    assertNotNull(plans);
    assertEquals(0, plans.size());
}
Also used : PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) Plan(io.gravitee.rest.api.portal.rest.model.Plan) Test(org.junit.Test)

Example 5 with PlansResponse

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

the class ApiPlansResourceTest method shouldGetEmptyListPrivateAPIAndNoReadPermission.

@Test
public void shouldGetEmptyListPrivateAPIAndNoReadPermission() {
    doReturn(false).when(permissionService).hasPermission(any(), any(), any());
    ApiEntity mockApi = new ApiEntity();
    mockApi.setId(API);
    mockApi.setVisibility(Visibility.PRIVATE);
    doReturn(mockApi).when(apiService).findById(API);
    Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
    doReturn(mockApis).when(apiService).findPublishedByUser(any());
    final Response response = target(API).path("plans").request().get();
    assertEquals(OK_200, response.getStatus());
    PlansResponse plansResponse = response.readEntity(PlansResponse.class);
    List<Plan> plans = plansResponse.getData();
    assertNotNull(plans);
    assertEquals(0, plans.size());
}
Also used : PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) PlansResponse(io.gravitee.rest.api.portal.rest.model.PlansResponse) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Plan(io.gravitee.rest.api.portal.rest.model.Plan) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)5 Plan (io.gravitee.rest.api.portal.rest.model.Plan)5 PlansResponse (io.gravitee.rest.api.portal.rest.model.PlansResponse)5 Response (javax.ws.rs.core.Response)5 Test (org.junit.Test)5 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 HashSet (java.util.HashSet)1