Search in sources :

Example 26 with PlanEntity

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

the class PlanService_CreateOrUpdateTest method shouldCreateAndHaveNoId.

@Test
public void shouldCreateAndHaveNoId() throws TechnicalException {
    final PlanEntity expected = new PlanEntity();
    expected.setId("created");
    when(planEntity.getId()).thenReturn(null);
    doReturn(emptyList()).when(planService).search(any());
    doReturn(expected).when(planService).create(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)).create(any());
}
Also used : PlanEntity(io.gravitee.rest.api.model.PlanEntity) Test(org.junit.Test)

Example 27 with PlanEntity

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

the class EmailNotifierServiceTest method shouldHaveATemplateForApplicationHooks.

@Test
public void shouldHaveATemplateForApplicationHooks() {
    GenericNotificationConfig cfg = new GenericNotificationConfig();
    cfg.setConfig("test@mail.com");
    ApiEntity api = new ApiEntity();
    api.setName("api-name");
    PlanEntity plan = new PlanEntity();
    plan.setName("plan-name");
    Map<String, Object> params = new HashMap<>();
    params.put((NotificationParamsBuilder.PARAM_API), api);
    params.put((NotificationParamsBuilder.PARAM_PLAN), plan);
    for (ApplicationHook hook : ApplicationHook.values()) {
        reset(mockEmailService);
        service.trigger(hook, cfg, params);
        verify(mockEmailService, times(1)).sendAsyncEmailNotification(argThat(notification -> notification.getTo() != null && notification.getTo().length == 1 && notification.getTo()[0].equals("test@mail.com")), any());
        verify(mockEmailService, never()).sendEmailNotification(any());
    }
}
Also used : InjectMocks(org.mockito.InjectMocks) CoreMatchers(org.hamcrest.CoreMatchers) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) GenericNotificationConfig(io.gravitee.repository.management.model.GenericNotificationConfig) Mock(org.mockito.Mock) TemplateException(freemarker.template.TemplateException) PlanEntity(io.gravitee.rest.api.model.PlanEntity) io.gravitee.rest.api.service.notification(io.gravitee.rest.api.service.notification) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Test(org.junit.Test) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) List(java.util.List) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) EmailNotifierServiceImpl(io.gravitee.rest.api.service.notifiers.impl.EmailNotifierServiceImpl) PrimaryOwnerEntity(io.gravitee.rest.api.model.PrimaryOwnerEntity) Map(java.util.Map) Assert(org.junit.Assert) Collections(java.util.Collections) UserEntity(io.gravitee.rest.api.model.UserEntity) HashMap(java.util.HashMap) GenericNotificationConfig(io.gravitee.repository.management.model.GenericNotificationConfig) 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