Search in sources :

Example 21 with PlanEntity

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

the class AnalyticsServiceImpl method getPlanMetadata.

private Map<String, String> getPlanMetadata(String plan) {
    Map<String, String> metadata = new HashMap<>();
    try {
        if (plan.equals(UNKNOWN_SERVICE) || plan.equals(UNKNOWN_SERVICE_MAPPED)) {
            metadata.put(METADATA_NAME, METADATA_UNKNOWN_PLAN_NAME);
            metadata.put(METADATA_UNKNOWN, Boolean.TRUE.toString());
        } else {
            PlanEntity planEntity = planService.findById(plan);
            metadata.put(METADATA_NAME, planEntity.getName());
        }
    } catch (PlanNotFoundException anfe) {
        metadata.put(METADATA_DELETED, Boolean.TRUE.toString());
        metadata.put(METADATA_NAME, METADATA_DELETED_PLAN_NAME);
    }
    return metadata;
}
Also used : PlanEntity(io.gravitee.rest.api.model.PlanEntity)

Example 22 with PlanEntity

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

the class APIV1toAPIV2ConverterTest method apiWithOnlyPlans.

@Test
public void apiWithOnlyPlans() throws Exception {
    ApiEntity toMigrate = load("/io/gravitee/rest/api/service/migration/api-withOnlyPlans.json", ApiEntity.class);
    ApiEntity expected = load("/io/gravitee/rest/api/service/migration/api-withOnlyPlans-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)

Example 23 with PlanEntity

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

the class PlanService_CreateOrUpdateTest method shouldUpdateAndHaveNoId.

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

Example 24 with PlanEntity

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

the class PlanService_CreateOrUpdateTest method shouldThrowExceptionWhenTooManyResults.

@Test(expected = TechnicalManagementException.class)
public void shouldThrowExceptionWhenTooManyResults() throws TechnicalException {
    final PlanEntity expected = new PlanEntity();
    expected.setId("updated");
    final ArrayList<PlanEntity> searchResult = new ArrayList<>();
    searchResult.add(new PlanEntity());
    searchResult.add(new PlanEntity());
    when(planEntity.getId()).thenReturn(null);
    doReturn(searchResult).when(planService).search(any());
    final PlanEntity actual = planService.createOrUpdatePlan(planEntity, ENVIRONMENT_ID);
    assertThat(actual.getId()).isEqualTo(expected.getId());
    verify(planService, times(1)).search(any());
}
Also used : PlanEntity(io.gravitee.rest.api.model.PlanEntity) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 25 with PlanEntity

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

the class PlanService_CreateOrUpdateTest method shouldCreateAndHaveId.

@Test
public void shouldCreateAndHaveId() throws TechnicalException {
    final PlanEntity expected = new PlanEntity();
    expected.setId("created");
    when(planEntity.getId()).thenReturn(PLAN_ID);
    doThrow(PlanNotFoundException.class).when(planService).findById(PLAN_ID);
    doReturn(expected).when(planService).create(any());
    final PlanEntity actual = planService.createOrUpdatePlan(planEntity, ENVIRONMENT_ID);
    assertThat(actual.getId()).isEqualTo(expected.getId());
    verify(planService, times(1)).findById(PLAN_ID);
    verify(planService, times(1)).create(any());
}
Also used : PlanEntity(io.gravitee.rest.api.model.PlanEntity) 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