|
| 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