Search in sources :

Example 16 with Event

use of io.gravitee.repository.management.model.Event in project gravitee-gateway by gravitee-io.

the class SyncManagerTest method test_newApi.

@Test
public void test_newApi() throws Exception {
    io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test").updatedAt(new Date()).definition("test").build();
    final Api mockApi = mockApi(api);
    final Event mockEvent = mockEvent(api, EventType.PUBLISH_API);
    when(eventRepository.search(any(EventCriteria.class), any(Pageable.class))).thenReturn(new Page<>(Collections.singletonList(mockEvent), 0, 0, 1));
    when(apiRepository.findAll()).thenReturn(Collections.singleton(api));
    syncManager.refresh();
    verify(apiManager).deploy(mockApi);
    verify(apiManager, never()).update(any(Api.class));
    verify(apiManager, never()).undeploy(any(String.class));
}
Also used : Pageable(io.gravitee.repository.management.api.search.Pageable) Event(io.gravitee.repository.management.model.Event) RepositoryApiBuilder(io.gravitee.gateway.services.sync.builder.RepositoryApiBuilder) Api(io.gravitee.gateway.handlers.api.definition.Api) EventCriteria(io.gravitee.repository.management.api.search.EventCriteria) Test(org.junit.Test)

Example 17 with Event

use of io.gravitee.repository.management.model.Event in project gravitee-gateway by gravitee-io.

the class SyncManagerTest method shouldDeployApiWithTags.

public void shouldDeployApiWithTags(final String tags, final String[] apiTags) throws Exception {
    io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test").updatedAt(new Date()).definition("test").build();
    final Api mockApi = mockApi(api, apiTags);
    when(gatewayConfiguration.shardingTags()).thenReturn(Optional.of(Arrays.asList(tags.split(","))));
    when(apiRepository.findAll()).thenReturn(Collections.singleton(api));
    when(apiManager.apis()).thenReturn(Collections.singleton(mockApi));
    final Event mockEvent = mockEvent(api, EventType.PUBLISH_API);
    when(eventRepository.search(any(EventCriteria.class), any(Pageable.class))).thenReturn(new Page<>(Collections.singletonList(mockEvent), 0, 0, 1));
    syncManager.refresh();
    verify(apiManager).deploy(mockApi);
    verify(apiManager, never()).update(any(Api.class));
    verify(apiManager, never()).undeploy(any(String.class));
}
Also used : Pageable(io.gravitee.repository.management.api.search.Pageable) Event(io.gravitee.repository.management.model.Event) RepositoryApiBuilder(io.gravitee.gateway.services.sync.builder.RepositoryApiBuilder) Api(io.gravitee.gateway.handlers.api.definition.Api) EventCriteria(io.gravitee.repository.management.api.search.EventCriteria)

Example 18 with Event

use of io.gravitee.repository.management.model.Event in project gravitee-gateway by gravitee-io.

the class SyncManagerTest method test_twiceWithTwoApis_api_noUpdate.

@Test
public void test_twiceWithTwoApis_api_noUpdate() throws Exception {
    io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test").updatedAt(new Date()).definition("test").build();
    io.gravitee.repository.management.model.Api api2 = new RepositoryApiBuilder().id("api-test").updatedAt(api.getUpdatedAt()).definition("test").build();
    final Api mockApi = mockApi(api);
    final Event mockEvent = mockEvent(api, EventType.PUBLISH_API);
    final Event mockEvent2 = mockEvent(api2, EventType.PUBLISH_API);
    List<Event> events = new ArrayList<Event>();
    events.add(mockEvent);
    events.add(mockEvent2);
    when(eventRepository.search(any(EventCriteria.class), any(Pageable.class))).thenReturn(new Page<>(events, 0, 0, 1));
    when(apiRepository.findAll()).thenReturn(Collections.singleton(api));
    syncManager.refresh();
    when(apiRepository.findAll()).thenReturn(Collections.singleton(api2));
    syncManager.refresh();
    verify(apiManager, times(2)).deploy(mockApi);
    verify(apiManager, never()).update(any(Api.class));
    verify(apiManager, never()).undeploy(any(String.class));
}
Also used : RepositoryApiBuilder(io.gravitee.gateway.services.sync.builder.RepositoryApiBuilder) EventCriteria(io.gravitee.repository.management.api.search.EventCriteria) Pageable(io.gravitee.repository.management.api.search.Pageable) Event(io.gravitee.repository.management.model.Event) Api(io.gravitee.gateway.handlers.api.definition.Api) Test(org.junit.Test)

Example 19 with Event

use of io.gravitee.repository.management.model.Event in project gravitee-gateway by gravitee-io.

the class SyncManagerTest method shouldNotDeployBecauseWrongConfiguration.

@Test(expected = IllegalArgumentException.class)
public void shouldNotDeployBecauseWrongConfiguration() throws Exception {
    io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test").updatedAt(new Date()).definition("test").build();
    final Api mockApi = mockApi(api);
    when(gatewayConfiguration.shardingTags()).thenReturn(Optional.of(Arrays.asList("test", "!test")));
    when(apiRepository.findAll()).thenReturn(Collections.singleton(api));
    when(apiManager.apis()).thenReturn(Collections.singleton(mockApi));
    final Event mockEvent = mockEvent(api, EventType.PUBLISH_API);
    when(eventRepository.search(eq(new EventCriteria.Builder().types(EventType.PUBLISH_API, EventType.UNPUBLISH_API, EventType.START_API, EventType.STOP_API).property(Event.EventProperties.API_ID.getValue(), api.getId()).build()), any())).thenReturn((new Page(Collections.singletonList(mockEvent), 0, 0, 0)));
    syncManager.refresh();
}
Also used : Event(io.gravitee.repository.management.model.Event) Page(io.gravitee.common.data.domain.Page) RepositoryApiBuilder(io.gravitee.gateway.services.sync.builder.RepositoryApiBuilder) Api(io.gravitee.gateway.handlers.api.definition.Api) EventCriteria(io.gravitee.repository.management.api.search.EventCriteria) Test(org.junit.Test)

Example 20 with Event

use of io.gravitee.repository.management.model.Event in project gravitee-gateway by gravitee-io.

the class SyncManagerTest method test_twiceWithSameApi.

@Test
public void test_twiceWithSameApi() throws Exception {
    io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test").updatedAt(new Date()).definition("test").build();
    final Api mockApi = mockApi(api);
    final Event mockEvent = mockEvent(api, EventType.PUBLISH_API);
    when(eventRepository.search(any(EventCriteria.class), any(Pageable.class))).thenReturn(new Page<>(Collections.singletonList(mockEvent), 0, 0, 1));
    when(apiRepository.findAll()).thenReturn(Collections.singleton(api));
    when(apiManager.get(api.getId())).thenReturn(null);
    syncManager.refresh();
    when(apiManager.get(api.getId())).thenReturn(mockApi);
    syncManager.refresh();
    verify(apiManager).deploy(mockApi);
    verify(apiManager, never()).update(any(Api.class));
    verify(apiManager, never()).undeploy(any(String.class));
}
Also used : Pageable(io.gravitee.repository.management.api.search.Pageable) Event(io.gravitee.repository.management.model.Event) RepositoryApiBuilder(io.gravitee.gateway.services.sync.builder.RepositoryApiBuilder) Api(io.gravitee.gateway.handlers.api.definition.Api) EventCriteria(io.gravitee.repository.management.api.search.EventCriteria) Test(org.junit.Test)

Aggregations

Event (io.gravitee.repository.management.model.Event)25 EventCriteria (io.gravitee.repository.management.api.search.EventCriteria)19 Api (io.gravitee.gateway.handlers.api.definition.Api)16 RepositoryApiBuilder (io.gravitee.gateway.services.sync.builder.RepositoryApiBuilder)15 Pageable (io.gravitee.repository.management.api.search.Pageable)14 Test (org.junit.Test)14 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)4 PageableBuilder (io.gravitee.repository.management.api.search.builder.PageableBuilder)4 Instant (java.time.Instant)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 EventRepository (io.gravitee.repository.management.api.EventRepository)3 EventType (io.gravitee.repository.management.model.EventType)3 Collectors (java.util.stream.Collectors)3 ArgumentMatcher (org.mockito.ArgumentMatcher)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 GatewayConfiguration (io.gravitee.gateway.env.GatewayConfiguration)2 InstanceEventPayload (io.gravitee.gateway.services.monitoring.event.InstanceEventPayload)2