Search in sources :

Example 6 with EventEntity

use of io.gravitee.management.model.EventEntity in project gravitee-management-rest-api by gravitee-io.

the class EventServiceTest method shouldFindByApi.

@Test
public void shouldFindByApi() throws TechnicalException {
    when(event.getType()).thenReturn(EventType.PUBLISH_API);
    when(event.getPayload()).thenReturn(EVENT_PAYLOAD);
    when(event.getProperties()).thenReturn(EVENT_PROPERTIES);
    when(eventRepository.search(new EventCriteria.Builder().property(Event.EventProperties.API_ID.getValue(), API_ID).build())).thenReturn(Collections.singletonList(event));
    Set<EventEntity> eventEntities = eventService.findByApi(API_ID);
    assertNotNull(eventEntities);
    assertEquals(1, eventEntities.size());
    EventEntity eventEntity = eventEntities.stream().findFirst().get();
    assertEquals(API_ID, eventEntity.getProperties().get(Event.EventProperties.API_ID.getValue()));
}
Also used : EventEntity(io.gravitee.management.model.EventEntity) NewEventEntity(io.gravitee.management.model.NewEventEntity) EventCriteria(io.gravitee.repository.management.api.search.EventCriteria) Test(org.junit.Test)

Example 7 with EventEntity

use of io.gravitee.management.model.EventEntity in project gravitee-management-rest-api by gravitee-io.

the class EventServiceTest method shouldFindByUsername.

@Test
public void shouldFindByUsername() throws TechnicalException {
    when(event.getType()).thenReturn(EventType.PUBLISH_API);
    when(event.getPayload()).thenReturn(EVENT_PAYLOAD);
    when(event.getProperties()).thenReturn(EVENT_PROPERTIES);
    when(eventRepository.search(new EventCriteria.Builder().property(Event.EventProperties.USER.getValue(), EVENT_USERNAME).build())).thenReturn(Collections.singletonList(event));
    Set<EventEntity> eventEntities = eventService.findByUser(EVENT_USERNAME);
    assertNotNull(eventEntities);
    assertEquals(1, eventEntities.size());
    EventEntity eventEntity = eventEntities.stream().findFirst().get();
    assertEquals(EVENT_USERNAME, eventEntity.getProperties().get(Event.EventProperties.USER.getValue()));
}
Also used : EventEntity(io.gravitee.management.model.EventEntity) NewEventEntity(io.gravitee.management.model.NewEventEntity) EventCriteria(io.gravitee.repository.management.api.search.EventCriteria) Test(org.junit.Test)

Example 8 with EventEntity

use of io.gravitee.management.model.EventEntity in project gravitee-management-rest-api by gravitee-io.

the class EventServiceTest method shouldFindByOrigin.

@Test
public void shouldFindByOrigin() throws TechnicalException {
    when(event.getType()).thenReturn(EventType.PUBLISH_API);
    when(event.getPayload()).thenReturn(EVENT_PAYLOAD);
    when(event.getProperties()).thenReturn(EVENT_PROPERTIES);
    when(eventPage.getTotalElements()).thenReturn(1L);
    when(eventPage.getContent()).thenReturn(Collections.singletonList(event));
    when(eventRepository.search(new EventCriteria.Builder().property(Event.EventProperties.ORIGIN.getValue(), EVENT_ORIGIN).build())).thenReturn(Collections.singletonList(event));
    Set<EventEntity> eventEntities = eventService.findByOrigin(EVENT_ORIGIN);
    assertNotNull(eventEntities);
    assertEquals(1, eventEntities.size());
    EventEntity eventEntity = eventEntities.stream().findFirst().get();
    assertEquals(EVENT_ORIGIN, eventEntity.getProperties().get(Event.EventProperties.ORIGIN.getValue()));
}
Also used : EventEntity(io.gravitee.management.model.EventEntity) NewEventEntity(io.gravitee.management.model.NewEventEntity) EventCriteria(io.gravitee.repository.management.api.search.EventCriteria) Test(org.junit.Test)

Example 9 with EventEntity

use of io.gravitee.management.model.EventEntity in project gravitee-management-rest-api by gravitee-io.

the class EventServiceTest method shouldCreateEventWithPublishApiEventType.

@Test
public void shouldCreateEventWithPublishApiEventType() throws TechnicalException {
    when(event.getType()).thenReturn(EventType.PUBLISH_API);
    when(event.getPayload()).thenReturn(EVENT_PAYLOAD);
    when(event.getProperties()).thenReturn(EVENT_PROPERTIES);
    when(eventRepository.findById(EVENT_ID)).thenReturn(Optional.empty());
    when(eventRepository.create(any())).thenReturn(event);
    when(newEvent.getType()).thenReturn(io.gravitee.management.model.EventType.PUBLISH_API);
    when(newEvent.getPayload()).thenReturn(EVENT_PAYLOAD);
    when(newEvent.getProperties()).thenReturn(EVENT_PROPERTIES);
    final EventEntity eventEntity = eventService.create(newEvent);
    assertNotNull(eventEntity);
    assertEquals(EventType.PUBLISH_API.toString(), eventEntity.getType().toString());
    assertEquals(EVENT_PAYLOAD, eventEntity.getPayload());
    assertEquals(EVENT_USERNAME, eventEntity.getProperties().get(Event.EventProperties.USER.getValue()));
}
Also used : EventEntity(io.gravitee.management.model.EventEntity) NewEventEntity(io.gravitee.management.model.NewEventEntity) Test(org.junit.Test)

Example 10 with EventEntity

use of io.gravitee.management.model.EventEntity in project gravitee-management-rest-api by gravitee-io.

the class EventServiceTest method shouldFindById.

@Test
public void shouldFindById() throws TechnicalException {
    when(event.getType()).thenReturn(EventType.PUBLISH_API);
    when(event.getPayload()).thenReturn(EVENT_PAYLOAD);
    when(event.getProperties()).thenReturn(EVENT_PROPERTIES);
    when(eventRepository.findById(EVENT_ID)).thenReturn(Optional.of(event));
    final EventEntity eventEntity = eventService.findById(EVENT_ID);
    assertNotNull(eventEntity);
}
Also used : EventEntity(io.gravitee.management.model.EventEntity) NewEventEntity(io.gravitee.management.model.NewEventEntity) Test(org.junit.Test)

Aggregations

EventEntity (io.gravitee.management.model.EventEntity)11 Test (org.junit.Test)7 NewEventEntity (io.gravitee.management.model.NewEventEntity)6 EventCriteria (io.gravitee.repository.management.api.search.EventCriteria)3 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ApiEntity (io.gravitee.management.model.ApiEntity)1 UserEntity (io.gravitee.management.model.UserEntity)1 Permissions (io.gravitee.management.rest.security.Permissions)1 UserNotFoundException (io.gravitee.management.service.exceptions.UserNotFoundException)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1