Search in sources :

Example 1 with ApiKeyCriteria

use of io.gravitee.repository.management.api.search.ApiKeyCriteria in project gravitee-gateway by gravitee-io.

the class ApiKeyRepositoryRefresherTest method shouldRefreshWithRevokedApiKey.

@Test
public void shouldRefreshWithRevokedApiKey() throws TechnicalException {
    Mockito.when(plan.getSecurity()).thenReturn(io.gravitee.repository.management.model.Plan.PlanSecurityType.API_KEY.name());
    List<Plan> plans = Collections.singletonList(plan);
    Mockito.when(api.getPlans()).thenReturn(plans);
    refresher.initialize();
    refresher.run();
    refresher.run();
    InOrder inOrder = Mockito.inOrder(apiKeyRepository, apiKeyRepository);
    inOrder.verify(apiKeyRepository).findByCriteria(Matchers.argThat(new ArgumentMatcher<ApiKeyCriteria>() {

        @Override
        public boolean matches(Object arg) {
            ApiKeyCriteria criteria = (ApiKeyCriteria) arg;
            return !criteria.isIncludeRevoked() && criteria.getFrom() == 0 && criteria.getTo() == 0 && criteria.getPlans().size() == 1;
        }
    }));
    inOrder.verify(apiKeyRepository).findByCriteria(Matchers.argThat(new ArgumentMatcher<ApiKeyCriteria>() {

        @Override
        public boolean matches(Object arg) {
            ApiKeyCriteria criteria = (ApiKeyCriteria) arg;
            return criteria.isIncludeRevoked() && criteria.getFrom() != 0 && criteria.getTo() != 0 && criteria.getPlans().size() == 1;
        }
    }));
}
Also used : ApiKeyCriteria(io.gravitee.repository.management.api.search.ApiKeyCriteria) Plan(io.gravitee.gateway.handlers.api.definition.Plan) Test(org.junit.Test)

Example 2 with ApiKeyCriteria

use of io.gravitee.repository.management.api.search.ApiKeyCriteria in project gravitee-gateway by gravitee-io.

the class ApiKeyRepositoryRefresherTest method shouldRefreshWithRevokedApiKeyAndPutIntoCache.

@Test
public void shouldRefreshWithRevokedApiKeyAndPutIntoCache() throws TechnicalException {
    Mockito.when(plan.getSecurity()).thenReturn(io.gravitee.repository.management.model.Plan.PlanSecurityType.API_KEY.name());
    List<Plan> plans = Collections.singletonList(plan);
    Mockito.when(api.getPlans()).thenReturn(plans);
    ApiKey apiKey1 = Mockito.mock(ApiKey.class);
    Mockito.when(apiKey1.isRevoked()).thenReturn(false);
    Mockito.when(apiKeyRepository.findByCriteria(Mockito.any(ApiKeyCriteria.class))).thenReturn(Collections.singletonList(apiKey1));
    refresher.initialize();
    refresher.run();
    refresher.run();
    InOrder inOrder = Mockito.inOrder(apiKeyRepository, apiKeyRepository);
    inOrder.verify(apiKeyRepository).findByCriteria(Matchers.argThat(new ArgumentMatcher<ApiKeyCriteria>() {

        @Override
        public boolean matches(Object arg) {
            ApiKeyCriteria criteria = (ApiKeyCriteria) arg;
            return !criteria.isIncludeRevoked() && criteria.getFrom() == 0 && criteria.getTo() == 0 && criteria.getPlans().size() == 1;
        }
    }));
    inOrder.verify(apiKeyRepository).findByCriteria(Matchers.argThat(new ArgumentMatcher<ApiKeyCriteria>() {

        @Override
        public boolean matches(Object arg) {
            ApiKeyCriteria criteria = (ApiKeyCriteria) arg;
            return criteria.isIncludeRevoked() && criteria.getFrom() != 0 && criteria.getTo() != 0 && criteria.getPlans().size() == 1;
        }
    }));
    Mockito.verify(cache, Mockito.times(2)).put(Matchers.any(Element.class));
}
Also used : ApiKeyCriteria(io.gravitee.repository.management.api.search.ApiKeyCriteria) ApiKey(io.gravitee.repository.management.model.ApiKey) Element(net.sf.ehcache.Element) Plan(io.gravitee.gateway.handlers.api.definition.Plan) Test(org.junit.Test)

Example 3 with ApiKeyCriteria

use of io.gravitee.repository.management.api.search.ApiKeyCriteria in project gravitee-gateway by gravitee-io.

the class ApiKeyRepositoryWrapperTest method shouldFindByCriteria.

@Test
public void shouldFindByCriteria() throws TechnicalException {
    ApiKeyCriteria apiKeyCriteria = Mockito.mock(ApiKeyCriteria.class);
    List<ApiKey> mockApiKeys = Arrays.asList(Mockito.mock(ApiKey.class), Mockito.mock(ApiKey.class));
    Mockito.when(wrappedRepository.findByCriteria(apiKeyCriteria)).thenReturn(mockApiKeys);
    List<ApiKey> apiKeys = repository.findByCriteria(apiKeyCriteria);
    Assert.assertEquals(mockApiKeys, apiKeys);
}
Also used : ApiKeyCriteria(io.gravitee.repository.management.api.search.ApiKeyCriteria) ApiKey(io.gravitee.repository.management.model.ApiKey) Test(org.junit.Test)

Example 4 with ApiKeyCriteria

use of io.gravitee.repository.management.api.search.ApiKeyCriteria in project gravitee-gateway by gravitee-io.

the class ApiKeyRepositoryRefresherTest method shouldInitWithNonRevokedApiKey_lowerCase.

@Test
public void shouldInitWithNonRevokedApiKey_lowerCase() throws TechnicalException {
    Mockito.when(plan.getSecurity()).thenReturn(io.gravitee.repository.management.model.Plan.PlanSecurityType.API_KEY.name().toLowerCase());
    List<Plan> plans = Collections.singletonList(plan);
    Mockito.when(api.getPlans()).thenReturn(plans);
    refresher.initialize();
    refresher.run();
    Mockito.verify(apiKeyRepository).findByCriteria(Matchers.argThat(new ArgumentMatcher<ApiKeyCriteria>() {

        @Override
        public boolean matches(Object arg) {
            ApiKeyCriteria criteria = (ApiKeyCriteria) arg;
            return !criteria.isIncludeRevoked() && criteria.getFrom() == 0 && criteria.getTo() == 0 && criteria.getPlans().size() == 1;
        }
    }));
}
Also used : ApiKeyCriteria(io.gravitee.repository.management.api.search.ApiKeyCriteria) Plan(io.gravitee.gateway.handlers.api.definition.Plan) Test(org.junit.Test)

Example 5 with ApiKeyCriteria

use of io.gravitee.repository.management.api.search.ApiKeyCriteria in project gravitee-gateway by gravitee-io.

the class ApiKeyRepositoryRefresherTest method shouldInitWithNonRevokedApiKey.

@Test
public void shouldInitWithNonRevokedApiKey() throws TechnicalException {
    Mockito.when(plan.getSecurity()).thenReturn(io.gravitee.repository.management.model.Plan.PlanSecurityType.API_KEY.name());
    List<Plan> plans = Collections.singletonList(plan);
    Mockito.when(api.getPlans()).thenReturn(plans);
    refresher.initialize();
    refresher.run();
    Mockito.verify(apiKeyRepository).findByCriteria(Matchers.argThat(new ArgumentMatcher<ApiKeyCriteria>() {

        @Override
        public boolean matches(Object arg) {
            ApiKeyCriteria criteria = (ApiKeyCriteria) arg;
            return !criteria.isIncludeRevoked() && criteria.getFrom() == 0 && criteria.getTo() == 0 && criteria.getPlans().size() == 1;
        }
    }));
}
Also used : ApiKeyCriteria(io.gravitee.repository.management.api.search.ApiKeyCriteria) Plan(io.gravitee.gateway.handlers.api.definition.Plan) Test(org.junit.Test)

Aggregations

ApiKeyCriteria (io.gravitee.repository.management.api.search.ApiKeyCriteria)6 Test (org.junit.Test)6 Plan (io.gravitee.gateway.handlers.api.definition.Plan)5 ApiKey (io.gravitee.repository.management.model.ApiKey)3 Element (net.sf.ehcache.Element)2