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