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);
}
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());
}
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);
}
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;
}
}
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);
}
Aggregations