Search in sources :

Example 6 with ApiKeyEntity

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());
}
Also used : ApiKeyEntity(io.gravitee.rest.api.model.ApiKeyEntity) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) Subscription(io.gravitee.rest.api.portal.rest.model.Subscription) Key(io.gravitee.rest.api.portal.rest.model.Key) Before(org.junit.Before)

Example 7 with ApiKeyEntity

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));
}
Also used : Response(javax.ws.rs.core.Response) ApiKeyEntity(io.gravitee.rest.api.model.ApiKeyEntity) Test(org.junit.Test)

Example 8 with ApiKeyEntity

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());
}
Also used : Response(javax.ws.rs.core.Response) ApiKeyEntity(io.gravitee.rest.api.model.ApiKeyEntity) Test(org.junit.Test)

Example 9 with ApiKeyEntity

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));
}
Also used : Response(javax.ws.rs.core.Response) NewSubscriptionEntity(io.gravitee.rest.api.model.NewSubscriptionEntity) ApiKeyEntity(io.gravitee.rest.api.model.ApiKeyEntity) Test(org.junit.Test)

Aggregations

ApiKeyEntity (io.gravitee.rest.api.model.ApiKeyEntity)9 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)3 Response (javax.ws.rs.core.Response)3 Before (org.junit.Before)3 Test (org.junit.Test)3 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)2 Key (io.gravitee.rest.api.portal.rest.model.Key)2 NewSubscriptionEntity (io.gravitee.rest.api.model.NewSubscriptionEntity)1 PlanEntity (io.gravitee.rest.api.model.PlanEntity)1 Subscription (io.gravitee.rest.api.portal.rest.model.Subscription)1 ForbiddenAccessException (io.gravitee.rest.api.service.exceptions.ForbiddenAccessException)1