Search in sources :

Example 1 with UpdatePlanEntity

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

the class PlanService_UpdateTest method shouldNotUpdate_withNotPublished_GCUPage.

private void shouldNotUpdate_withNotPublished_GCUPage(Plan.Status planStatus) throws TechnicalException {
    final String PAGE_ID = "PAGE_ID_TEST";
    when(plan.getStatus()).thenReturn(planStatus);
    when(plan.getType()).thenReturn(Plan.PlanType.API);
    when(plan.getSecurity()).thenReturn(Plan.PlanSecurityType.API_KEY);
    when(plan.getApi()).thenReturn(API_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.getName()).thenReturn("NameUpdated");
    when(updatePlan.getGeneralConditions()).thenReturn(PAGE_ID);
    PageEntity unpublishedPage = new PageEntity();
    unpublishedPage.setId(PAGE_ID);
    unpublishedPage.setOrder(1);
    unpublishedPage.setType("MARKDOWN");
    unpublishedPage.setPublished(false);
    doReturn(unpublishedPage).when(pageService).findById(PAGE_ID);
    planService.update(updatePlan);
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) UpdatePlanEntity(io.gravitee.rest.api.model.UpdatePlanEntity)

Example 2 with UpdatePlanEntity

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

the class PlanService_UpdateTest method shouldUpdate.

@Test
public void shouldUpdate() throws TechnicalException {
    when(plan.getStatus()).thenReturn(Plan.Status.STAGING);
    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(planRepository.findById(PLAN_ID)).thenReturn(Optional.of(plan));
    when(parameterService.findAsBoolean(any(), eq(ParameterReferenceType.ENVIRONMENT))).thenReturn(true);
    when(apiService.findById(API_ID)).thenReturn(apiEntity);
    UpdatePlanEntity updatePlan = mock(UpdatePlanEntity.class);
    when(updatePlan.getId()).thenReturn(PLAN_ID);
    when(updatePlan.getValidation()).thenReturn(PlanValidationType.AUTO);
    when(updatePlan.getName()).thenReturn("NameUpdated");
    when(planRepository.update(any())).thenAnswer(returnsFirstArg());
    planService.update(updatePlan);
    verify(planRepository).update(any());
    verify(parameterService).findAsBoolean(any(), eq(ParameterReferenceType.ENVIRONMENT));
}
Also used : UpdatePlanEntity(io.gravitee.rest.api.model.UpdatePlanEntity) Test(org.junit.Test)

Example 3 with UpdatePlanEntity

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

the class PlanService_UpdateTest method shouldUpdateAndUpdateApiDefinition.

@Test
public void shouldUpdateAndUpdateApiDefinition() throws TechnicalException {
    when(plan.getStatus()).thenReturn(Plan.Status.STAGING);
    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(planRepository.findById(PLAN_ID)).thenReturn(Optional.of(plan));
    when(parameterService.findAsBoolean(any(), eq(ParameterReferenceType.ENVIRONMENT))).thenReturn(true);
    when(apiEntity.getGraviteeDefinitionVersion()).thenReturn(DefinitionVersion.V2.getLabel());
    when(apiService.findById(API_ID)).thenReturn(apiEntity);
    UpdatePlanEntity updatePlan = mock(UpdatePlanEntity.class);
    when(updatePlan.getId()).thenReturn(PLAN_ID);
    when(updatePlan.getValidation()).thenReturn(PlanValidationType.AUTO);
    when(updatePlan.getName()).thenReturn("NameUpdated");
    when(planRepository.update(any())).thenAnswer(returnsFirstArg());
    planService.update(updatePlan);
    verify(planRepository).update(any());
    verify(parameterService).findAsBoolean(any(), eq(ParameterReferenceType.ENVIRONMENT));
    verify(apiService).update(anyString(), any());
}
Also used : UpdatePlanEntity(io.gravitee.rest.api.model.UpdatePlanEntity) Test(org.junit.Test)

Example 4 with UpdatePlanEntity

use of io.gravitee.rest.api.model.UpdatePlanEntity 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 5 with UpdatePlanEntity

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

the class PlanService_UpdateTest method shouldUpdate_withNotPublished_GCUPage_StagingPlan.

@Test
public void shouldUpdate_withNotPublished_GCUPage_StagingPlan() throws TechnicalException {
    final String PAGE_ID = "PAGE_ID_TEST";
    when(plan.getStatus()).thenReturn(Plan.Status.STAGING);
    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);
    when(apiService.findById(API_ID)).thenReturn(apiEntity);
    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());
    planService.update(updatePlan);
    verify(planRepository).update(any());
    verify(parameterService).findAsBoolean(any(), eq(ParameterReferenceType.ENVIRONMENT));
}
Also used : UpdatePlanEntity(io.gravitee.rest.api.model.UpdatePlanEntity) Test(org.junit.Test)

Aggregations

UpdatePlanEntity (io.gravitee.rest.api.model.UpdatePlanEntity)5 Test (org.junit.Test)4 PageEntity (io.gravitee.rest.api.model.PageEntity)2