Skip to content

Commit 731be3d

Browse files
authored
Merge pull request #102 from gmunozfe/9.104.x-prod-kie-issues#2287
[kie-issues#2287] Add integration test for variables query (apache#2289)
2 parents a191044 + 0227e81 commit 731be3d

File tree

3 files changed

+135
-1
lines changed

3 files changed

+135
-1
lines changed

apps-integration-tests/integration-tests-data-index-service/integration-tests-data-index-service-common/src/test/java/org/kie/kogito/index/AbstractProcessDataIndexIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
public abstract class AbstractProcessDataIndexIT {
5959

60-
private static Duration TIMEOUT = Duration.ofSeconds(30);
60+
protected static Duration TIMEOUT = Duration.ofSeconds(30);
6161

6262
static {
6363
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();

apps-integration-tests/integration-tests-data-index-service/integration-tests-data-index-service-quarkus/src/test/java/org/kie/kogito/index/postgresql/AbstractProcessDataIndexPostgreSqlIT.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@
1818
*/
1919
package org.kie.kogito.index.postgresql;
2020

21+
import org.junit.jupiter.api.Test;
2122
import org.kie.kogito.index.AbstractProcessDataIndexIT;
2223
import org.kie.kogito.test.quarkus.QuarkusTestProperty;
2324

25+
import io.restassured.http.ContentType;
26+
27+
import static io.restassured.RestAssured.given;
28+
import static org.awaitility.Awaitility.await;
29+
import static org.hamcrest.CoreMatchers.containsString;
30+
import static org.hamcrest.CoreMatchers.is;
2431
import static org.kie.kogito.index.test.Constants.KOGITO_DATA_INDEX_SERVICE_URL;
2532

2633
public abstract class AbstractProcessDataIndexPostgreSqlIT extends AbstractProcessDataIndexIT {
@@ -42,4 +49,19 @@ public boolean validateDomainData() {
4249
public boolean validateGetProcessInstanceSource() {
4350
return true;
4451
}
52+
53+
@Test
54+
public void testJsonQueryVariablesAndMetadata() throws Exception {
55+
String pId = createTestProcessInstance();
56+
57+
await().atMost(TIMEOUT).untilAsserted(() -> given().spec(dataIndexSpec())
58+
.contentType(ContentType.JSON)
59+
.body("{ \"query\": \"{ ProcessInstances(where: { id: { equal: \\\"" + pId + "\\\" } }) { id variables state } }\" }")
60+
.when().post("/graphql")
61+
.then().statusCode(200)
62+
.body("data.ProcessInstances[0].id", containsString(pId))
63+
.body("data.ProcessInstances[0].variables.traveller.firstName", containsString("Darth"))
64+
.body("data.ProcessInstances[0].state", is("ACTIVE")));
65+
}
66+
4567
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.kie.kogito.index.postgresql.query;
20+
21+
import java.util.List;
22+
import java.util.Map;
23+
import java.util.Set;
24+
import java.util.UUID;
25+
26+
import org.junit.jupiter.api.Test;
27+
import org.kie.kogito.event.process.ProcessInstanceVariableDataEvent;
28+
import org.kie.kogito.index.jpa.storage.ProcessDefinitionEntityStorage;
29+
import org.kie.kogito.index.model.ProcessDefinition;
30+
import org.kie.kogito.index.model.ProcessDefinitionKey;
31+
import org.kie.kogito.index.model.ProcessInstance;
32+
import org.kie.kogito.index.storage.ProcessInstanceStorage;
33+
import org.kie.kogito.index.test.TestUtils;
34+
import org.kie.kogito.testcontainers.quarkus.PostgreSqlQuarkusTestResource;
35+
36+
import com.fasterxml.jackson.databind.JsonNode;
37+
38+
import io.quarkus.test.common.QuarkusTestResource;
39+
import io.quarkus.test.junit.QuarkusTest;
40+
41+
import jakarta.inject.Inject;
42+
43+
import static org.assertj.core.api.Assertions.assertThat;
44+
45+
@QuarkusTest
46+
@QuarkusTestResource(PostgreSqlQuarkusTestResource.class)
47+
class VariablesAndMetadataJsonIT {
48+
49+
@Inject
50+
ProcessInstanceStorage storage;
51+
52+
@Inject
53+
ProcessDefinitionEntityStorage definitionStorage;
54+
55+
@Test
56+
void shouldStoreAndRetrieveVariablesAndMetadataWithPostgresJson() {
57+
String processId = "json.process";
58+
String processInstanceId = UUID.randomUUID().toString();
59+
60+
final String version = "1.0";
61+
ProcessDefinitionKey key = new ProcessDefinitionKey(processId, version);
62+
ProcessDefinition definitionEvent = TestUtils.createProcessDefinition(processId, version, Set.of());
63+
definitionEvent.setAnnotations(Set.of("TestAnnotation"));
64+
definitionEvent.setMetadata(Map.of(
65+
"name", "TestProcess",
66+
"type", "demo",
67+
"owner", "pepe"));
68+
definitionStorage.put(key, definitionEvent);
69+
70+
ProcessInstanceVariableDataEvent variableEvent =
71+
TestUtils.createProcessInstanceVariableEvent(
72+
processInstanceId,
73+
processId,
74+
"John",
75+
28,
76+
false,
77+
List.of("A", "B"));
78+
variableEvent.setKogitoProcessInstanceVersion(version);
79+
80+
storage.indexVariable(variableEvent);
81+
82+
ProcessInstance result = storage.get(processInstanceId);
83+
assertThat(result).isNotNull();
84+
85+
JsonNode variablesNode = result.getVariables();
86+
assertThat(variablesNode).isNotNull();
87+
assertThat(variablesNode.has("traveller")).isTrue();
88+
89+
JsonNode travellerNode = variablesNode.get("traveller");
90+
assertThat(travellerNode.get("name").asText()).isEqualTo("John");
91+
assertThat(travellerNode.get("age").asInt()).isEqualTo(28);
92+
assertThat(travellerNode.get("isMartian").asBoolean()).isFalse();
93+
94+
JsonNode aliasesNode = travellerNode.get("aliases");
95+
assertThat(aliasesNode.isArray()).isTrue();
96+
assertThat(aliasesNode).hasSize(2);
97+
assertThat(aliasesNode.get(0).asText()).isEqualTo("A");
98+
assertThat(aliasesNode.get(1).asText()).isEqualTo("B");
99+
100+
ProcessDefinition storedDefinition = definitionStorage.get(key);
101+
assertThat(storedDefinition).isNotNull();
102+
103+
Map<String, Object> metadata = storedDefinition.getMetadata();
104+
assertThat(metadata).isNotNull();
105+
assertThat(metadata).containsEntry("name", "TestProcess");
106+
assertThat(metadata).containsEntry("type", "demo");
107+
assertThat(metadata).containsEntry("owner", "pepe");
108+
109+
Set<String> annotations = storedDefinition.getAnnotations();
110+
assertThat(annotations).contains("TestAnnotation");
111+
}
112+
}

0 commit comments

Comments
 (0)