Search in sources :

Example 1 with PlanEntity

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

the class ApplicationSubscriptionsResource method convert.

private Subscription convert(SubscriptionEntity subscriptionEntity) {
    Subscription subscription = new Subscription();
    subscription.setId(subscriptionEntity.getId());
    subscription.setCreatedAt(subscriptionEntity.getCreatedAt());
    subscription.setUpdatedAt(subscriptionEntity.getUpdatedAt());
    subscription.setStartingAt(subscriptionEntity.getStartingAt());
    subscription.setEndingAt(subscriptionEntity.getEndingAt());
    subscription.setProcessedAt(subscriptionEntity.getProcessedAt());
    subscription.setProcessedBy(subscriptionEntity.getProcessedBy());
    subscription.setReason(subscriptionEntity.getReason());
    subscription.setRequest(subscriptionEntity.getRequest());
    subscription.setStatus(subscriptionEntity.getStatus());
    subscription.setSubscribedBy(new Subscription.User(subscriptionEntity.getSubscribedBy(), userService.findById(subscriptionEntity.getSubscribedBy(), true).getDisplayName()));
    PlanEntity plan = planService.findById(subscriptionEntity.getPlan());
    subscription.setPlan(new Subscription.Plan(plan.getId(), plan.getName()));
    subscription.getPlan().setSecurity(plan.getSecurity());
    ApiEntity api = apiService.findById(subscriptionEntity.getApi());
    subscription.setApi(new Subscription.Api(api.getId(), api.getName(), api.getVersion(), new Subscription.User(api.getPrimaryOwner().getId(), api.getPrimaryOwner().getDisplayName())));
    subscription.setClosedAt(subscriptionEntity.getClosedAt());
    subscription.setPausedAt(subscriptionEntity.getPausedAt());
    return subscription;
}
Also used : PlanEntity(io.gravitee.rest.api.model.PlanEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Subscription(io.gravitee.rest.api.management.rest.model.Subscription)

Example 2 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_PUBLISHED_Plan.

@Test(expected = PageUsedAsGeneralConditionsException.class)
public void shouldNotDeletePage_UsedBy_PUBLISHED_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.PUBLISHED);
    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 3 with PlanEntity

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

the class PageService_DeleteTest method shouldDeletePage_UsedBy_CLOSED_Plan.

@Test
public void shouldDeletePage_UsedBy_CLOSED_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);
    when(page.getVisibility()).thenReturn("PUBLIC");
    PlanEntity plan = mock(PlanEntity.class);
    when(plan.getGeneralConditions()).thenReturn(PAGE_ID);
    when(plan.getStatus()).thenReturn(PlanStatus.CLOSED);
    when(pageRepository.findById(PAGE_ID)).thenReturn(Optional.of(page));
    when(planService.findByApi(API_ID)).thenReturn(Sets.newHashSet(plan));
    pageService.delete(PAGE_ID);
    verify(pageRepository).delete(PAGE_ID);
}
Also used : PlanEntity(io.gravitee.rest.api.model.PlanEntity) Page(io.gravitee.repository.management.model.Page) Test(org.junit.Test)

Example 4 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_STAGING_Plan.

@Test(expected = PageUsedAsGeneralConditionsException.class)
public void shouldNotDeletePage_UsedBy_STAGING_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.STAGING);
    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 5 with PlanEntity

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

the class PageService_DeleteTest method shouldNotDeleteTranslationPage_UsedBy_PUBLISHED_Plan.

@Test(expected = PageUsedAsGeneralConditionsException.class)
public void shouldNotDeleteTranslationPage_UsedBy_PUBLISHED_Plan() throws TechnicalException {
    Page translationPage = mock(Page.class);
    when(translationPage.getType()).thenReturn(PageType.TRANSLATION.name());
    when(translationPage.getParentId()).thenReturn(PAGE_ID);
    when(translationPage.getReferenceType()).thenReturn(PageReferenceType.API);
    when(translationPage.getReferenceId()).thenReturn(API_ID);
    PlanEntity plan = mock(PlanEntity.class);
    when(plan.getGeneralConditions()).thenReturn(PAGE_ID);
    when(plan.getStatus()).thenReturn(PlanStatus.PUBLISHED);
    when(pageRepository.findById(TRANSLATE_PAGE_ID)).thenReturn(Optional.of(translationPage));
    when(planService.findByApi(API_ID)).thenReturn(Sets.newHashSet(plan));
    pageService.delete(TRANSLATE_PAGE_ID);
}
Also used : PlanEntity(io.gravitee.rest.api.model.PlanEntity) Page(io.gravitee.repository.management.model.Page) 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