use of io.gravitee.rest.api.model.ApiKeyEntity in project gravitee-management-rest-api 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());
doReturn(true).when(permissionService).hasPermission(any(), any(), any());
}
use of io.gravitee.rest.api.model.ApiKeyEntity in project gravitee-management-rest-api by gravitee-io.
the class SubscriptionKeysResourceTest method shouldNotRevokeKey.
@Test
public void shouldNotRevokeKey() {
apiKeyEntity = new ApiKeyEntity();
apiKeyEntity.setKey(KEY);
apiKeyEntity.setSubscription(ANOTHER_SUBSCRIPTION);
doReturn(apiKeyEntity).when(apiKeyService).findByKey(KEY);
final Response response = target(SUBSCRIPTION).path("keys/" + KEY + "/_revoke").request().post(null);
assertEquals(HttpStatusCode.BAD_REQUEST_400, response.getStatus());
assertEquals("'keyId' parameter does not correspond to the subscription", response.readEntity(String.class));
}
use of io.gravitee.rest.api.model.ApiKeyEntity in project gravitee-management-rest-api by gravitee-io.
the class SubscriptionKeysResourceTest method shouldRevokeKeyNoSubscription.
@Test
public void shouldRevokeKeyNoSubscription() {
apiKeyEntity = new ApiKeyEntity();
apiKeyEntity.setKey(KEY);
doReturn(apiKeyEntity).when(apiKeyService).findByKey(KEY);
final Response response = target(SUBSCRIPTION).path("keys/" + KEY + "/_revoke").request().post(null);
assertEquals(HttpStatusCode.NO_CONTENT_204, response.getStatus());
Mockito.verify(apiKeyService).revoke(KEY, true);
assertFalse(response.hasEntity());
}
use of io.gravitee.rest.api.model.ApiKeyEntity in project gravitee-management-rest-api by gravitee-io.
the class SubscriptionsResourceTest method shouldCreateSubscription.
@Test
public void shouldCreateSubscription() {
SubscriptionInput subscriptionInput = new SubscriptionInput().application(APPLICATION).plan(PLAN).request("request");
final ApiKeyEntity apiKeyEntity = new ApiKeyEntity();
final Key key = new Key();
when(apiKeyService.findBySubscription(SUBSCRIPTION)).thenReturn(Collections.singletonList(apiKeyEntity));
when(keyMapper.convert(apiKeyEntity)).thenReturn(key);
final Response response = target().request().post(Entity.json(subscriptionInput));
assertEquals(OK_200, response.getStatus());
ArgumentCaptor<NewSubscriptionEntity> argument = ArgumentCaptor.forClass(NewSubscriptionEntity.class);
Mockito.verify(subscriptionService).create(argument.capture());
assertEquals(APPLICATION, argument.getValue().getApplication());
assertEquals(PLAN, argument.getValue().getPlan());
assertEquals("request", argument.getValue().getRequest());
final Subscription subscriptionResponse = response.readEntity(Subscription.class);
assertNotNull(subscriptionResponse);
assertEquals(SUBSCRIPTION, subscriptionResponse.getId());
assertNotNull(subscriptionResponse.getKeys());
assertEquals(1, subscriptionResponse.getKeys().size());
assertEquals(key, subscriptionResponse.getKeys().get(0));
}
Aggregations