use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders in project kogito-apps by kiegroup.
the class ExecutionsApiV1IT method givenARequestWhenExecutionEndpointIsCalledThenTheExecutionHeaderIsReturned.
@Test
void givenARequestWhenExecutionEndpointIsCalledThenTheExecutionHeaderIsReturned() throws ParseException {
Execution execution = new Decision("test1", "http://localhost:8081/model/service", "http://localhost:8081", OffsetDateTime.parse("2020-01-01T00:00:00Z", DateTimeFormatter.ISO_OFFSET_DATE_TIME).toInstant().toEpochMilli(), true, "name", "model", "namespace", Collections.emptyList(), Collections.emptyList());
Mockito.when(executionService.getExecutionHeaders(any(OffsetDateTime.class), any(OffsetDateTime.class), any(Integer.class), any(Integer.class), any(String.class))).thenReturn(new MatchedExecutionHeaders(List.of(execution), 1));
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(1, response.getHeaders().size());
}
use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders in project kogito-apps by kiegroup.
the class ExecutionsApiV1IT method givenARequestWithoutTimeRangeParametersWhenExecutionEndpointIsCalledThenTheDefaultValuesAreUsed.
@Test
void givenARequestWithoutTimeRangeParametersWhenExecutionEndpointIsCalledThenTheDefaultValuesAreUsed() {
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));
given().when().get("/executions").then().statusCode(200);
given().when().get("/executions?from=2000-01-01").then().statusCode(200);
given().when().get("/executions?to=2000-01-01").then().statusCode(200);
given().when().get("/executions?from=2000-01-01T00:00:00Z").then().statusCode(200);
given().when().get("/executions?to=2000-01-01T00:00:00Z").then().statusCode(200);
}
use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders in project kogito-apps by kiegroup.
the class KeycloakTrustyServiceIT method shouldReturnOkWhenValidUser.
@Test
void shouldReturnOkWhenValidUser() {
when(trustyService.getExecutionHeaders(any(OffsetDateTime.class), any(OffsetDateTime.class), anyInt(), anyInt(), anyString())).thenReturn(new MatchedExecutionHeaders(new ArrayList<>(), 0));
given().auth().oauth2(getAccessToken(VALID_USER)).get(TRUSTY_ENDPOINT).then().statusCode(HttpStatus.SC_OK);
}
use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders in project kogito-apps by kiegroup.
the class TrustyServiceTest method givenManyExecutionsThenPaginationWorksProperly.
@Test
@SuppressWarnings("unchecked")
void givenManyExecutionsThenPaginationWorksProperly() {
List<Decision> decisions = new ArrayList<>();
IntStream.range(0, 10).forEach(x -> {
Decision d = new Decision();
d.setExecutionId(String.valueOf(x));
decisions.add(d);
});
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(decisions);
Storage storageMock = mock(Storage.class);
decisions.forEach(x -> {
when(storageMock.put(eq(x.getExecutionId()), any(Object.class))).thenReturn(x);
when(storageMock.containsKey(eq(x.getExecutionId()))).thenReturn(false);
});
when(storageMock.query()).thenReturn(queryMock);
when(trustyStorageServiceMock.getDecisionsStorage()).thenReturn(storageMock);
decisions.forEach(x -> trustyService.storeDecision(x.getExecutionId(), x));
MatchedExecutionHeaders result = trustyService.getExecutionHeaders(OffsetDateTime.now().minusDays(1), OffsetDateTime.now(), 3, 5, "");
assertEquals(3, result.getExecutions().size());
assertEquals(decisions.size(), result.getAvailableResults());
result = trustyService.getExecutionHeaders(OffsetDateTime.now().minusDays(1), OffsetDateTime.now(), 100, 5, "");
assertEquals(5, result.getExecutions().size());
assertEquals(decisions.size(), result.getAvailableResults());
}
use of org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders in project kogito-apps by kiegroup.
the class AbstractTrustyServiceIT method givenTwoExecutionsWhenTheQueryExcludesOneExecutionThenOnlyOneExecutionIsReturned.
@Test
public void givenTwoExecutionsWhenTheQueryExcludesOneExecutionThenOnlyOneExecutionIsReturned() {
storeExecution("myExecution", 1591692950000L);
storeExecution("executionId2", 1591692958000L);
OffsetDateTime from = OffsetDateTime.ofInstant(Instant.ofEpochMilli(1591692940000L), ZoneOffset.UTC);
OffsetDateTime to = OffsetDateTime.ofInstant(Instant.ofEpochMilli(1591692955000L), ZoneOffset.UTC);
MatchedExecutionHeaders result = trustyService.getExecutionHeaders(from, to, 100, 0, "");
Assertions.assertEquals(1, result.getExecutions().size());
Assertions.assertEquals("myExecution", result.getExecutions().get(0).getExecutionId());
}
Aggregations