use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders in project kogito-apps by kiegroup.
the class AbstractTrustyServiceIT method testStoreAndRetrieveExecution.
@Test
public void testStoreAndRetrieveExecution() {
storeExecution("myExecution", 1591692958000L);
OffsetDateTime from = OffsetDateTime.ofInstant(Instant.ofEpochMilli(1591692957000L), ZoneOffset.UTC);
OffsetDateTime to = OffsetDateTime.ofInstant(Instant.ofEpochMilli(1591692959000L), ZoneOffset.UTC);
MatchedExecutionHeaders result = trustyService.getExecutionHeaders(from, to, 100, 0, "");
Assertions.assertEquals(1, result.getExecutions().size());
Assertions.assertEquals("myExecution", result.getExecutions().get(0).getExecutionId());
}
use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders in project kogito-apps by kiegroup.
the class TrustyServiceImpl method getExecutionHeaders.
@Override
public MatchedExecutionHeaders getExecutionHeaders(OffsetDateTime from, OffsetDateTime to, int limit, int offset, String prefix) {
Storage<String, Decision> storage = storageService.getDecisionsStorage();
List<AttributeFilter<?>> filters = new ArrayList<>();
filters.add(QueryFilterFactory.like(Execution.EXECUTION_ID_FIELD, prefix + "*"));
filters.add(QueryFilterFactory.greaterThanEqual(Execution.EXECUTION_TIMESTAMP_FIELD, from.toInstant().toEpochMilli()));
filters.add(QueryFilterFactory.lessThanEqual(Execution.EXECUTION_TIMESTAMP_FIELD, to.toInstant().toEpochMilli()));
ArrayList result = new ArrayList<>(storage.query().sort(asList(orderBy(Execution.EXECUTION_TIMESTAMP_FIELD, DESC))).filter(filters).execute());
if (result.size() < offset) {
throw new IllegalArgumentException("Out of bound start offset in result");
}
return new MatchedExecutionHeaders(result.subList(offset, Math.min(offset + limit, result.size())), result.size());
}
use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders in project kogito-apps by kiegroup.
the class ExecutionsApiV1IT method givenRequestWithoutLimitAndOffsetParametersWhenExecutionEndpointIsCalledThenTheDefaultValuesAreCorrect.
@Test
void givenRequestWithoutLimitAndOffsetParametersWhenExecutionEndpointIsCalledThenTheDefaultValuesAreCorrect() {
Mockito.when(executionService.getExecutionHeaders(any(OffsetDateTime.class), any(OffsetDateTime.class), any(Integer.class), any(Integer.class), any(String.class))).thenReturn(new MatchedExecutionHeaders(new ArrayList<>(), 0));
ExecutionsResponse response = given().contentType(ContentType.JSON).when().get("/executions?from=2000-01-01T00:00:00Z&to=2021-01-01T00:00:00Z").as(ExecutionsResponse.class);
Assertions.assertEquals(100, response.getLimit());
Assertions.assertEquals(0, response.getOffset());
Assertions.assertEquals(0, response.getHeaders().size());
}
use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders in project kogito-apps by kiegroup.
the class TrustyServiceTest method givenADecisionWhenADecisionIsStoredAndRetrievedThenTheOriginalObjectIsReturned.
@Test
@SuppressWarnings("unchecked")
void givenADecisionWhenADecisionIsStoredAndRetrievedThenTheOriginalObjectIsReturned() {
Decision decision = new Decision();
decision.setExecutionId(TEST_EXECUTION_ID);
Query queryMock = mock(Query.class);
when(queryMock.filter(any(List.class))).thenReturn(queryMock);
when(queryMock.offset(any(Integer.class))).thenReturn(queryMock);
when(queryMock.sort(any(List.class))).thenReturn(queryMock);
when(queryMock.execute()).thenReturn(List.of(decision));
Storage storageMock = mock(Storage.class);
when(storageMock.put(eq(TEST_EXECUTION_ID), any(Object.class))).thenReturn(decision);
when(storageMock.containsKey(eq(TEST_EXECUTION_ID))).thenReturn(false);
when(storageMock.query()).thenReturn(queryMock);
when(trustyStorageServiceMock.getDecisionsStorage()).thenReturn(storageMock);
trustyService.storeDecision(TEST_EXECUTION_ID, decision);
MatchedExecutionHeaders result = trustyService.getExecutionHeaders(OffsetDateTime.now().minusDays(1), OffsetDateTime.now(), 100, 0, "");
assertEquals(1, result.getExecutions().size());
assertEquals(decision.getExecutionId(), result.getExecutions().get(0).getExecutionId());
}
use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders in project kogito-apps by kiegroup.
the class TrustyServiceTest method givenNoExecutionsNoExceptionsAreRaised.
@Test
@SuppressWarnings("unchecked")
void givenNoExecutionsNoExceptionsAreRaised() {
Query queryMock = mock(Query.class);
when(queryMock.filter(any(List.class))).thenReturn(queryMock);
when(queryMock.sort(any(List.class))).thenReturn(queryMock);
when(queryMock.execute()).thenReturn(new ArrayList<>());
Storage storageMock = mock(Storage.class);
when(storageMock.query()).thenReturn(queryMock);
when(trustyStorageServiceMock.getDecisionsStorage()).thenReturn(storageMock);
MatchedExecutionHeaders result = trustyService.getExecutionHeaders(OffsetDateTime.now().minusDays(1), OffsetDateTime.now(), 100, 0, "");
assertEquals(0, result.getExecutions().size());
assertEquals(0, result.getAvailableResults());
}
Aggregations