use of io.gravitee.rest.api.model.SubscriptionEntity in project gravitee-api-management by gravitee-io.
the class ApplicationSubscriptionApiKeysResource method renewApiKeyForApplicationSubscription.
@POST
@Path("/_renew")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Renew an API key", notes = "User must have the MANAGE_API_KEYS permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "A new API Key", response = ApiKeyEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_SUBSCRIPTION, acls = RolePermissionAction.UPDATE) })
public Response renewApiKeyForApplicationSubscription() {
checkApplicationApiKeyModeAllowed(application);
SubscriptionEntity subscriptionEntity = subscriptionService.findById(subscription);
ApiKeyEntity apiKeyEntity = apiKeyService.renew(subscriptionEntity);
URI location = URI.create(uriInfo.getPath().replace("_renew", apiKeyEntity.getId()));
return Response.created(location).entity(apiKeyEntity).build();
}
use of io.gravitee.rest.api.model.SubscriptionEntity in project gravitee-api-management by gravitee-io.
the class SubscriptionKeysResourceTest method shouldRevokeKeyNoSubscription.
@Test
public void shouldRevokeKeyNoSubscription() {
SubscriptionEntity subscription = new SubscriptionEntity();
subscription.setApi(API);
subscription.setId(SUBSCRIPTION);
apiKeyEntity = new ApiKeyEntity();
apiKeyEntity.setKey(KEY);
apiKeyEntity.setSubscriptions(Set.of(subscription));
doReturn(subscription).when(subscriptionService).findById(SUBSCRIPTION);
doReturn(apiKeyEntity).when(apiKeyService).findByKeyAndApi(KEY, API);
final Response response = target(SUBSCRIPTION).path("keys/" + KEY + "/_revoke").request().post(null);
assertEquals(HttpStatusCode.NO_CONTENT_204, response.getStatus());
Mockito.verify(apiKeyService).revoke(apiKeyEntity, true);
assertFalse(response.hasEntity());
}
use of io.gravitee.rest.api.model.SubscriptionEntity in project gravitee-api-management by gravitee-io.
the class SubscriptionKeysResourceTest method init.
@Before
public void init() {
resetAllMocks();
SubscriptionEntity subscription = new SubscriptionEntity();
subscription.setId(SUBSCRIPTION);
apiKeyEntity = new ApiKeyEntity();
apiKeyEntity.setKey(KEY);
apiKeyEntity.setSubscriptions(Set.of(subscription));
apiKeyEntity.setCreatedAt(new Date());
doReturn(apiKeyEntity).when(apiKeyService).renew(subscription);
doReturn(apiKeyEntity).when(apiKeyService).findByKeyAndApi(KEY, API);
doReturn(new Key().key(KEY)).when(keyMapper).convert(apiKeyEntity);
SubscriptionEntity subscriptionEntity = new SubscriptionEntity();
subscriptionEntity.setApi(API);
subscriptionEntity.setApplication(APPLICATION);
doReturn(subscriptionEntity).when(subscriptionService).findById(eq(SUBSCRIPTION));
doReturn(true).when(permissionService).hasPermission(any(), any(), any());
}
use of io.gravitee.rest.api.model.SubscriptionEntity in project gravitee-api-management by gravitee-io.
the class SubscriptionResourceTest method init.
@Before
public void init() {
resetAllMocks();
subscriptionEntity = new SubscriptionEntity();
subscriptionEntity.setId(SUBSCRIPTION);
subscriptionEntity.setApi(API);
subscriptionEntity.setApplication(APPLICATION);
doReturn(subscriptionEntity).when(subscriptionService).findById(SUBSCRIPTION);
doThrow(SubscriptionNotFoundException.class).when(subscriptionService).findById(UNKNOWN_SUBSCRIPTION);
doReturn(Arrays.asList(new ApiKeyEntity())).when(apiKeyService).findBySubscription(SUBSCRIPTION);
doReturn(new Subscription()).when(subscriptionMapper).convert(any());
doReturn(new Key()).when(keyMapper).convert(any(ApiKeyEntity.class));
doReturn(true).when(permissionService).hasPermission(any(), any(), any());
}
use of io.gravitee.rest.api.model.SubscriptionEntity in project gravitee-api-management by gravitee-io.
the class ApiSubscriptionApikeyResourceTest method mockExistingSubscriptionWithApplication.
private void mockExistingSubscriptionWithApplication(ApiKeyMode apiKeyMode) {
SubscriptionEntity subscription = new SubscriptionEntity();
subscription.setApplication(APPLICATION_ID);
when(subscriptionService.findById(SUBSCRIPTION_ID)).thenReturn(subscription);
ApplicationEntity application = new ApplicationEntity();
application.setApiKeyMode(apiKeyMode);
when(applicationService.findById(GraviteeContext.getCurrentEnvironment(), APPLICATION_ID)).thenReturn(application);
}
Aggregations