Search in sources :

Example 1 with MatchedExecutionHeaders

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());
}
Also used : Execution(org.kie.kogito.trusty.storage.api.model.Execution) MatchedExecutionHeaders(org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders) OffsetDateTime(java.time.OffsetDateTime) ExecutionsResponse(org.kie.kogito.trusty.service.common.responses.ExecutionsResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Decision(org.kie.kogito.trusty.storage.api.model.decision.Decision) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 2 with MatchedExecutionHeaders

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);
}
Also used : MatchedExecutionHeaders(org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders) OffsetDateTime(java.time.OffsetDateTime) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 3 with MatchedExecutionHeaders

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);
}
Also used : MatchedExecutionHeaders(org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders) OffsetDateTime(java.time.OffsetDateTime) ArrayList(java.util.ArrayList) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 4 with MatchedExecutionHeaders

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());
}
Also used : Storage(org.kie.kogito.persistence.api.Storage) MatchedExecutionHeaders(org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders) Query(org.kie.kogito.persistence.api.query.Query) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Decision(org.kie.kogito.trusty.storage.api.model.decision.Decision) Test(org.junit.jupiter.api.Test)

Example 5 with MatchedExecutionHeaders

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());
}
Also used : MatchedExecutionHeaders(org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders) OffsetDateTime(java.time.OffsetDateTime) Test(org.junit.jupiter.api.Test)

Aggregations

MatchedExecutionHeaders (org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders)13 Test (org.junit.jupiter.api.Test)11 OffsetDateTime (java.time.OffsetDateTime)8 ArrayList (java.util.ArrayList)8 QuarkusTest (io.quarkus.test.junit.QuarkusTest)4 Decision (org.kie.kogito.trusty.storage.api.model.decision.Decision)4 List (java.util.List)3 Storage (org.kie.kogito.persistence.api.Storage)3 Query (org.kie.kogito.persistence.api.query.Query)3 ExecutionsResponse (org.kie.kogito.trusty.service.common.responses.ExecutionsResponse)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Instant (java.time.Instant)1 DateTimeParseException (java.time.format.DateTimeParseException)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Operation (org.eclipse.microprofile.openapi.annotations.Operation)1 APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)1 AttributeFilter (org.kie.kogito.persistence.api.query.AttributeFilter)1 ExecutionHeaderResponse (org.kie.kogito.trusty.service.common.responses.ExecutionHeaderResponse)1 Execution (org.kie.kogito.trusty.storage.api.model.Execution)1