Search in sources :

Example 6 with PlanEntity

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

the class PageService_DeleteTest method shouldNotDeletePage_UsedBy_DEPRECATED_Plan.

@Test(expected = PageUsedAsGeneralConditionsException.class)
public void shouldNotDeletePage_UsedBy_DEPRECATED_Plan() throws TechnicalException {
    Page page = mock(Page.class);
    when(page.getId()).thenReturn(PAGE_ID);
    when(page.getReferenceType()).thenReturn(PageReferenceType.API);
    when(page.getReferenceId()).thenReturn(API_ID);
    PlanEntity plan = mock(PlanEntity.class);
    when(plan.getGeneralConditions()).thenReturn(PAGE_ID);
    when(plan.getStatus()).thenReturn(PlanStatus.DEPRECATED);
    when(pageRepository.findById(PAGE_ID)).thenReturn(Optional.of(page));
    when(planService.findByApi(API_ID)).thenReturn(Sets.newHashSet(plan));
    pageService.delete(PAGE_ID);
}
Also used : PlanEntity(io.gravitee.rest.api.model.PlanEntity) Page(io.gravitee.repository.management.model.Page) Test(org.junit.Test)

Example 7 with PlanEntity

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

the class PlanService_CreateOrUpdateTest method shouldUpdateAndHaveId.

@Test
public void shouldUpdateAndHaveId() throws TechnicalException {
    final PlanEntity expected = new PlanEntity();
    expected.setId("updated");
    when(this.planEntity.getId()).thenReturn(PLAN_ID);
    doReturn(new PlanEntity()).when(planService).findById(PLAN_ID);
    doReturn(expected).when(planService).update(any());
    final PlanEntity actual = planService.createOrUpdatePlan(this.planEntity, ENVIRONMENT_ID);
    assertThat(actual.getId()).isEqualTo(expected.getId());
    verify(planService, times(1)).findById(PLAN_ID);
    verify(planService, times(1)).update(any());
}
Also used : PlanEntity(io.gravitee.rest.api.model.PlanEntity) Test(org.junit.Test)

Example 8 with PlanEntity

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

the class PlanService_FindByIdTest method shouldFindById.

@Test
public void shouldFindById() throws TechnicalException {
    when(plan.getType()).thenReturn(Plan.PlanType.API);
    when(plan.getValidation()).thenReturn(Plan.PlanValidationType.AUTO);
    when(plan.getApi()).thenReturn(API_ID);
    when(apiService.findById(API_ID)).thenReturn(api);
    when(planRepository.findById(PLAN_ID)).thenReturn(Optional.of(plan));
    final PlanEntity planEntity = planService.findById(PLAN_ID);
    assertNotNull(planEntity);
}
Also used : PlanEntity(io.gravitee.rest.api.model.PlanEntity) Test(org.junit.Test)

Example 9 with PlanEntity

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

the class PlanSynchronizationProcessor method processCheckSynchronization.

public boolean processCheckSynchronization(PlanEntity deployedPlan, PlanEntity planToDeploy) {
    Class<PlanEntity> cl = PlanEntity.class;
    List<Object> requiredFieldsDeployedPlan = new ArrayList<>();
    List<Object> requiredFieldsPlanToDeploy = new ArrayList<>();
    for (Field f : cl.getDeclaredFields()) {
        if (f.getAnnotation(DeploymentRequired.class) != null) {
            boolean previousAccessibleState = f.isAccessible();
            f.setAccessible(true);
            try {
                requiredFieldsDeployedPlan.add(f.get(deployedPlan));
                requiredFieldsPlanToDeploy.add(f.get(planToDeploy));
            } catch (Exception e) {
                LOGGER.error("Error access Plan required deployment fields", e);
            } finally {
                f.setAccessible(previousAccessibleState);
            }
        }
    }
    try {
        String requiredFieldsDeployedPlanDefinition = objectMapper.writeValueAsString(requiredFieldsDeployedPlan);
        String requiredFieldsPlanToDeployDefinition = objectMapper.writeValueAsString(requiredFieldsPlanToDeploy);
        return requiredFieldsDeployedPlanDefinition.equals(requiredFieldsPlanToDeployDefinition);
    } catch (Exception e) {
        LOGGER.error("Unexpected error while generating Plan deployment required fields definition", e);
        return false;
    }
}
Also used : Field(java.lang.reflect.Field) PlanEntity(io.gravitee.rest.api.model.PlanEntity) ArrayList(java.util.ArrayList) DeploymentRequired(io.gravitee.rest.api.model.DeploymentRequired)

Example 10 with PlanEntity

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

the class APIV1toAPIV2ConverterTest method apiWithPathsAndPlans.

@Test
public void apiWithPathsAndPlans() throws Exception {
    ApiEntity toMigrate = load("/io/gravitee/rest/api/service/migration/api-withPathsAndPlans.json", ApiEntity.class);
    ApiEntity expected = load("/io/gravitee/rest/api/service/migration/api-withPathsAndPlans-migrated.json", ApiEntity.class);
    Set<PlanEntity> planEntities = loadSet("/io/gravitee/rest/api/service/migration/plans.json", PlanEntity.class);
    ApiEntity actual = cut.migrateToV2(toMigrate, policies, planEntities);
    assertEqualsApiEntity(expected, actual);
}
Also used : PlanEntity(io.gravitee.rest.api.model.PlanEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Test(org.junit.Test)

Aggregations

PlanEntity (io.gravitee.rest.api.model.PlanEntity)27 Test (org.junit.Test)17 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)9 Page (io.gravitee.repository.management.model.Page)5 GenericNotificationConfig (io.gravitee.repository.management.model.GenericNotificationConfig)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 List (java.util.List)4 TemplateException (freemarker.template.TemplateException)3 Subscription (io.gravitee.rest.api.management.rest.model.Subscription)3 PrimaryOwnerEntity (io.gravitee.rest.api.model.PrimaryOwnerEntity)3 UserEntity (io.gravitee.rest.api.model.UserEntity)3 io.gravitee.rest.api.service.notification (io.gravitee.rest.api.service.notification)3 EmailNotifierServiceImpl (io.gravitee.rest.api.service.notifiers.impl.EmailNotifierServiceImpl)3 Map (java.util.Map)3 CoreMatchers (org.hamcrest.CoreMatchers)3 Assert (org.junit.Assert)3 Before (org.junit.Before)3 RunWith (org.junit.runner.RunWith)3 InjectMocks (org.mockito.InjectMocks)3