Search in sources :

Example 16 with PlanEntity

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

the class EmailNotifierServiceTest method shouldHaveEmail.

@Test
public void shouldHaveEmail() {
    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);
    List<String> mails = service.getMails(cfg, params);
    assertNotNull(mails);
    assertFalse(mails.isEmpty());
    assertThat(mails, CoreMatchers.hasItem(cfg.getConfig()));
}
Also used : 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)

Example 17 with PlanEntity

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

the class EmailNotifierServiceTest method shouldHaveATemplateForApiHooks.

@Test
public void shouldHaveATemplateForApiHooks() {
    GenericNotificationConfig cfg = new GenericNotificationConfig();
    cfg.setConfig("test@mail.com");
    ApiEntity api = new ApiEntity();
    api.setName("api-name");
    PlanEntity plan = new PlanEntity();
    plan.setId("plan-12345");
    plan.setName("plan-name");
    Map<String, Object> params = new HashMap<>();
    params.put((NotificationParamsBuilder.PARAM_API), api);
    params.put((NotificationParamsBuilder.PARAM_PLAN), plan);
    for (ApiHook hook : ApiHook.values()) {
        if (!ApiHook.MESSAGE.equals(hook)) {
            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)

Example 18 with PlanEntity

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

the class KeyMapperTest method init.

@Before
public void init() {
    // init
    apiKeyEntity = new ApiKeyEntity();
    apiKeyEntity.setApplication(APPLICATION);
    apiKeyEntity.setCreatedAt(nowDate);
    apiKeyEntity.setExpireAt(nowDate);
    apiKeyEntity.setKey(KEY);
    apiKeyEntity.setPaused(false);
    apiKeyEntity.setPlan(PLAN);
    apiKeyEntity.setRevoked(false);
    apiKeyEntity.setRevokedAt(nowDate);
    apiKeyEntity.setSubscription(SUBSCRIPTION);
    apiKeyEntity.setUpdatedAt(nowDate);
    PlanEntity planEntity = new PlanEntity();
    planEntity.setApi(API);
    doReturn(planEntity).when(planService).findById(PLAN);
    doThrow(PlanNotFoundException.class).when(planService).findById(UNKNOWN_PLAN);
}
Also used : ApiKeyEntity(io.gravitee.rest.api.model.ApiKeyEntity) PlanEntity(io.gravitee.rest.api.model.PlanEntity) Before(org.junit.Before)

Example 19 with PlanEntity

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

the class ApplicationSubscriptionsResource method createSubscriptionWithApplication.

@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Subscribe to a plan", notes = "User must have the MANAGE_SUBSCRIPTIONS permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Subscription successfully created", response = Subscription.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_SUBSCRIPTION, acls = RolePermissionAction.CREATE) })
public Response createSubscriptionWithApplication(@ApiParam(name = "plan", required = true) @NotNull @QueryParam("plan") String plan, NewSubscriptionEntity newSubscriptionEntity) {
    // If no request message has been passed, the entity is not created
    if (newSubscriptionEntity == null) {
        newSubscriptionEntity = new NewSubscriptionEntity();
    }
    PlanEntity planEntity = planService.findById(plan);
    if (planEntity.isCommentRequired() && (newSubscriptionEntity.getRequest() == null || newSubscriptionEntity.getRequest().isEmpty())) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Plan requires a consumer comment when subscribing").build();
    }
    newSubscriptionEntity.setApplication(application);
    newSubscriptionEntity.setPlan(plan);
    Subscription subscription = convert(subscriptionService.create(newSubscriptionEntity));
    return Response.created(this.getRequestUriBuilder().path(subscription.getId()).replaceQueryParam("plan", null).build()).entity(subscription).build();
}
Also used : NewSubscriptionEntity(io.gravitee.rest.api.model.NewSubscriptionEntity) PlanEntity(io.gravitee.rest.api.model.PlanEntity) Subscription(io.gravitee.rest.api.management.rest.model.Subscription) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 20 with PlanEntity

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

the class SubscriptionsResource 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.setStatus(subscriptionEntity.getStatus());
    ApplicationEntity application = applicationService.findById(subscriptionEntity.getApplication());
    subscription.setApplication(new Subscription.Application(application.getId(), application.getName(), application.getType(), application.getDescription(), new Subscription.User(application.getPrimaryOwner().getId(), application.getPrimaryOwner().getDisplayName())));
    PlanEntity plan = planService.findById(subscriptionEntity.getPlan());
    subscription.setPlan(new Subscription.Plan(plan.getId(), plan.getName()));
    subscription.setClosedAt(subscriptionEntity.getClosedAt());
    return subscription;
}
Also used : ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) PlanEntity(io.gravitee.rest.api.model.PlanEntity) Subscription(io.gravitee.rest.api.management.rest.model.Subscription)

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