Skip to content

Commit da0fcc0

Browse files
authored
Merge pull request #64 from saumya1singh/sync_main
Sync main branch with Apache main branch apache#98
2 parents c043e2b + c023a8a commit da0fcc0

File tree

24 files changed

+192
-75
lines changed

24 files changed

+192
-75
lines changed

data-audit/kogito-addons-data-audit-jpa/data-audit-quarkus-jpa-service/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@
5656
<groupId>io.quarkus</groupId>
5757
<artifactId>quarkus-container-image-jib</artifactId>
5858
</dependency>
59+
<dependency>
60+
<groupId>io.quarkus</groupId>
61+
<artifactId>quarkus-jdbc-h2</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>io.quarkus</groupId>
65+
<artifactId>quarkus-jdbc-postgresql</artifactId>
66+
</dependency>
5967
</dependencies>
6068

6169
<build>

data-audit/kogito-addons-data-audit-jpa/kogito-addons-data-audit-jpa-quarkus/pom.xml

-11
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
<groupId>io.quarkus</groupId>
7373
<artifactId>quarkus-arc</artifactId>
7474
</dependency>
75-
7675
<dependency>
7776
<groupId>io.quarkus</groupId>
7877
<artifactId>quarkus-reactive-routes</artifactId>
@@ -85,21 +84,11 @@
8584
<groupId>io.quarkus</groupId>
8685
<artifactId>quarkus-vertx-graphql</artifactId>
8786
</dependency>
88-
8987
<!-- dependencies -->
9088
<dependency>
9189
<groupId>io.quarkus</groupId>
9290
<artifactId>quarkus-hibernate-orm</artifactId>
9391
</dependency>
94-
95-
<dependency>
96-
<groupId>io.quarkus</groupId>
97-
<artifactId>quarkus-jdbc-h2</artifactId>
98-
</dependency>
99-
<dependency>
100-
<groupId>io.quarkus</groupId>
101-
<artifactId>quarkus-jdbc-postgresql</artifactId>
102-
</dependency>
10392
</dependencies>
10493

10594
</project>

data-audit/kogito-addons-data-audit-quarkus/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@
111111
<artifactId>rest-assured</artifactId>
112112
<scope>test</scope>
113113
</dependency>
114+
<dependency>
115+
<groupId>io.quarkus</groupId>
116+
<artifactId>quarkus-jdbc-h2</artifactId>
117+
<scope>test</scope>
118+
</dependency>
119+
114120

115121
</dependencies>
116122

data-index/data-index-storage/data-index-storage-jpa/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<dependency>
5454
<groupId>io.quarkus</groupId>
5555
<artifactId>quarkus-jdbc-h2</artifactId>
56+
<scope>test</scope>
5657
</dependency>
5758

5859
<dependency>

data-index/data-index-storage/data-index-storage-jpa/src/test/java/org/kie/kogito/index/jdbc/query/H2JobEntityQueryIT.java

-6
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@
1818
*/
1919
package org.kie.kogito.index.jdbc.query;
2020

21-
import org.kie.kogito.index.jdbc.H2QuarkusTestProfile;
2221
import org.kie.kogito.index.jpa.query.AbstractJobEntityQueryIT;
2322

2423
import io.quarkus.test.TestTransaction;
25-
import io.quarkus.test.common.QuarkusTestResource;
26-
import io.quarkus.test.h2.H2DatabaseTestResource;
2724
import io.quarkus.test.junit.QuarkusTest;
28-
import io.quarkus.test.junit.TestProfile;
2925

3026
@QuarkusTest
3127
@TestTransaction
32-
@QuarkusTestResource(value = H2DatabaseTestResource.class, restrictToAnnotatedClass = true)
33-
@TestProfile(H2QuarkusTestProfile.class)
3428
class H2JobEntityQueryIT extends AbstractJobEntityQueryIT {
3529

3630
}

data-index/data-index-storage/data-index-storage-jpa/src/test/java/org/kie/kogito/index/jdbc/query/H2ProcessDefinitionEntityQueryIT.java

-6
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@
1818
*/
1919
package org.kie.kogito.index.jdbc.query;
2020

21-
import org.kie.kogito.index.jdbc.H2QuarkusTestProfile;
2221
import org.kie.kogito.index.jpa.query.AbstractProcessDefinitionEntityQueryIT;
2322

2423
import io.quarkus.test.TestTransaction;
25-
import io.quarkus.test.common.QuarkusTestResource;
26-
import io.quarkus.test.h2.H2DatabaseTestResource;
2724
import io.quarkus.test.junit.QuarkusTest;
28-
import io.quarkus.test.junit.TestProfile;
2925

3026
@QuarkusTest
3127
@TestTransaction
32-
@QuarkusTestResource(value = H2DatabaseTestResource.class, restrictToAnnotatedClass = true)
33-
@TestProfile(H2QuarkusTestProfile.class)
3428
class H2ProcessDefinitionEntityQueryIT extends AbstractProcessDefinitionEntityQueryIT {
3529

3630
}

data-index/data-index-storage/data-index-storage-jpa/src/test/java/org/kie/kogito/index/jdbc/query/H2ProcessInstanceEntityQueryIT.java

-6
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@
1818
*/
1919
package org.kie.kogito.index.jdbc.query;
2020

21-
import org.kie.kogito.index.jdbc.H2QuarkusTestProfile;
2221
import org.kie.kogito.index.jpa.query.AbstractProcessInstanceEntityQueryIT;
2322

2423
import io.quarkus.test.TestTransaction;
25-
import io.quarkus.test.common.QuarkusTestResource;
26-
import io.quarkus.test.h2.H2DatabaseTestResource;
2724
import io.quarkus.test.junit.QuarkusTest;
28-
import io.quarkus.test.junit.TestProfile;
2925

3026
@QuarkusTest
3127
@TestTransaction
32-
@QuarkusTestResource(value = H2DatabaseTestResource.class, restrictToAnnotatedClass = true)
33-
@TestProfile(H2QuarkusTestProfile.class)
3428
class H2ProcessInstanceEntityQueryIT extends AbstractProcessInstanceEntityQueryIT {
3529

3630
@Override

data-index/data-index-storage/data-index-storage-jpa/src/test/java/org/kie/kogito/index/jdbc/query/H2UserTaskInstanceEntityQueryIT.java

-6
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@
1818
*/
1919
package org.kie.kogito.index.jdbc.query;
2020

21-
import org.kie.kogito.index.jdbc.H2QuarkusTestProfile;
2221
import org.kie.kogito.index.jpa.query.AbstractUserTaskInstanceEntityQueryIT;
2322

2423
import io.quarkus.test.TestTransaction;
25-
import io.quarkus.test.common.QuarkusTestResource;
26-
import io.quarkus.test.h2.H2DatabaseTestResource;
2724
import io.quarkus.test.junit.QuarkusTest;
28-
import io.quarkus.test.junit.TestProfile;
2925

3026
@QuarkusTest
3127
@TestTransaction
32-
@QuarkusTestResource(value = H2DatabaseTestResource.class, restrictToAnnotatedClass = true)
33-
@TestProfile(H2QuarkusTestProfile.class)
3428
class H2UserTaskInstanceEntityQueryIT extends AbstractUserTaskInstanceEntityQueryIT {
3529

3630
}

data-index/data-index-storage/data-index-storage-jpa/src/test/java/org/kie/kogito/index/jdbc/storage/H2JobStorageIT.java

-3
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818
*/
1919
package org.kie.kogito.index.jdbc.storage;
2020

21-
import org.kie.kogito.index.jdbc.H2QuarkusTestProfile;
2221
import org.kie.kogito.index.jpa.storage.AbstractJobStorageIT;
2322

2423
import io.quarkus.test.TestTransaction;
2524
import io.quarkus.test.junit.QuarkusTest;
26-
import io.quarkus.test.junit.TestProfile;
2725

2826
@QuarkusTest
2927
@TestTransaction
30-
@TestProfile(H2QuarkusTestProfile.class)
3128
public class H2JobStorageIT extends AbstractJobStorageIT {
3229

3330
}

data-index/data-index-storage/data-index-storage-jpa/src/test/java/org/kie/kogito/index/jdbc/storage/H2ProcessDefinitionStorageIT.java

-3
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818
*/
1919
package org.kie.kogito.index.jdbc.storage;
2020

21-
import org.kie.kogito.index.jdbc.H2QuarkusTestProfile;
2221
import org.kie.kogito.index.jpa.storage.AbstractProcessDefinitionStorageIT;
2322

2423
import io.quarkus.test.TestTransaction;
2524
import io.quarkus.test.junit.QuarkusTest;
26-
import io.quarkus.test.junit.TestProfile;
2725

2826
@QuarkusTest
2927
@TestTransaction
30-
@TestProfile(H2QuarkusTestProfile.class)
3128
class H2ProcessDefinitionStorageIT extends AbstractProcessDefinitionStorageIT {
3229

3330
}

data-index/data-index-storage/data-index-storage-jpa/src/test/java/org/kie/kogito/index/jdbc/storage/H2ProcessInstanceStorageIT.java

-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@
1818
*/
1919
package org.kie.kogito.index.jdbc.storage;
2020

21-
import org.kie.kogito.index.jdbc.H2QuarkusTestProfile;
2221
import org.kie.kogito.index.jpa.storage.AbstractProcessInstanceStorageIT;
2322

2423
import io.quarkus.test.TestTransaction;
2524
import io.quarkus.test.junit.QuarkusTest;
26-
import io.quarkus.test.junit.TestProfile;
2725

2826
@QuarkusTest
2927
@TestTransaction
30-
@TestProfile(H2QuarkusTestProfile.class)
3128
public class H2ProcessInstanceStorageIT extends AbstractProcessInstanceStorageIT {
3229
}

data-index/data-index-storage/data-index-storage-jpa/src/test/java/org/kie/kogito/index/jdbc/storage/H2UserTaskInstanceStorageIT.java

-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@
1818
*/
1919
package org.kie.kogito.index.jdbc.storage;
2020

21-
import org.kie.kogito.index.jdbc.H2QuarkusTestProfile;
2221
import org.kie.kogito.index.jpa.storage.AbstractUserTaskInstanceStorageIT;
2322

2423
import io.quarkus.test.TestTransaction;
2524
import io.quarkus.test.junit.QuarkusTest;
26-
import io.quarkus.test.junit.TestProfile;
2725

2826
@QuarkusTest
2927
@TestTransaction
30-
@TestProfile(H2QuarkusTestProfile.class)
3128
public class H2UserTaskInstanceStorageIT extends AbstractUserTaskInstanceStorageIT {
3229
}

data-index/data-index-storage/data-index-storage-jpa/src/test/resources/application.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ kie.flyway.enabled=true
2424
# Data sources
2525
%test-postgresql.quarkus.datasource.db-kind=postgresql
2626
%test-postgresql.quarkus.datasource.devservices.enabled=false
27-
%test-h2.quarkus.datasource.db-kind=h2
28-
%test-h2.quarkus.datasource.username=kogito
29-
%test-h2.quarkus.datasource.jdbc.url=jdbc:h2:mem:default;NON_KEYWORDS=VALUE,KEY
27+
quarkus.datasource.db-kind=h2
28+
quarkus.datasource.username=kogito
29+
quarkus.datasource.jdbc.url=jdbc:h2:mem:default;NON_KEYWORDS=VALUE,KEY
3030

3131
# Hibernate
3232
quarkus.hibernate-orm.physical-naming-strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
@@ -39,4 +39,4 @@ quarkus.hibernate-orm.flush.mode=always
3939
quarkus.oidc.enabled=false
4040
quarkus.oidc.tenant-enabled=false
4141
quarkus.oidc.auth-server-url=none
42-
quarkus.keycloak.devservices.enabled=false
42+
quarkus.keycloak.devservices.enabled=false

data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/main/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImpl.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import jakarta.inject.Inject;
5656

5757
import static java.util.stream.Collectors.toMap;
58+
import static org.kie.kogito.jackson.utils.JsonObjectUtils.*;
5859

5960
@ApplicationScoped
6061
public class KogitoAddonRuntimeClientImpl extends KogitoRuntimeCommonClient implements KogitoRuntimeClient {
@@ -128,7 +129,21 @@ public CompletableFuture<String> skipProcessInstance(String serviceURL, ProcessI
128129

129130
@Override
130131
public CompletableFuture<String> updateProcessInstanceVariables(String serviceURL, ProcessInstance processInstance, String variables) {
131-
return throwUnsupportedException();
132+
return CompletableFuture.completedFuture(executeOnProcessInstance(processInstance.getProcessId(), processInstance.getId(), pInstance -> {
133+
try {
134+
Model model = (Model) convertValue(fromString(variables), pInstance.variables().getClass());
135+
136+
Model toReturn = (Model) pInstance.updateVariables(convertInstanceOfObject(model));
137+
138+
return JsonObjectUtils.toString(fromValue(toReturn.toMap()));
139+
} catch (Exception ex) {
140+
throw new DataIndexServiceException("Failure to update the variables for the process instance " + pInstance.id(), ex);
141+
}
142+
}));
143+
}
144+
145+
private <T> T convertInstanceOfObject(Object value) {
146+
return value == null ? null : (T) value;
132147
}
133148

134149
@Override
@@ -287,9 +302,9 @@ public CompletableFuture<JsonNode> executeProcessInstance(ProcessDefinition defi
287302
throw new DataIndexServiceException(String.format("Unable to find Process with id %s to perform the operation requested", definition.getId()));
288303
}
289304
Model m = (Model) process.createModel();
290-
m.update(JsonObjectUtils.convertValue(args.input(), Map.class));
305+
m.update(convertValue(args.input(), Map.class));
291306
org.kie.kogito.process.ProcessInstance<? extends Model> pi = process.createInstance(m);
292307
pi.start();
293-
return CompletableFuture.completedFuture(JsonObjectUtils.fromValue(pi.variables().toMap()));
308+
return CompletableFuture.completedFuture(fromValue(pi.variables().toMap()));
294309
}
295310
}

data-index/kogito-addons-quarkus-data-index-persistence/kogito-addons-quarkus-data-index-persistence-common/runtime/src/test/java/org/kie/kogito/index/addon/api/KogitoAddonRuntimeClientImplTest.java

+45-7
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121
import java.nio.Buffer;
2222
import java.util.Map;
2323
import java.util.Optional;
24+
import java.util.concurrent.CompletableFuture;
2425

2526
import org.junit.jupiter.api.BeforeEach;
2627
import org.junit.jupiter.api.Test;
2728
import org.junit.jupiter.api.extension.ExtendWith;
2829
import org.kie.kogito.Application;
29-
import org.kie.kogito.Model;
30+
import org.kie.kogito.index.addon.api.models.TestModel;
3031
import org.kie.kogito.index.api.ExecuteArgs;
3132
import org.kie.kogito.index.api.KogitoRuntimeCommonClient;
32-
import org.kie.kogito.index.model.Job;
33-
import org.kie.kogito.index.model.ProcessDefinition;
34-
import org.kie.kogito.index.model.ProcessInstance;
33+
import org.kie.kogito.index.model.*;
34+
import org.kie.kogito.index.service.DataIndexServiceException;
3535
import org.kie.kogito.index.test.TestUtils;
3636
import org.kie.kogito.jackson.utils.ObjectMapperFactory;
3737
import org.kie.kogito.process.ProcessError;
@@ -43,11 +43,13 @@
4343
import org.kie.kogito.services.uow.DefaultUnitOfWorkManager;
4444
import org.kie.kogito.source.files.SourceFilesProvider;
4545
import org.kie.kogito.svg.ProcessSvgService;
46+
import org.mockito.AdditionalAnswers;
4647
import org.mockito.ArgumentCaptor;
4748
import org.mockito.Mock;
4849
import org.mockito.junit.jupiter.MockitoExtension;
4950

5051
import com.fasterxml.jackson.databind.JsonNode;
52+
import com.fasterxml.jackson.databind.ObjectMapper;
5153

5254
import io.quarkus.security.credential.TokenCredential;
5355
import io.quarkus.security.identity.SecurityIdentity;
@@ -64,6 +66,7 @@
6466

6567
import static java.lang.String.format;
6668
import static org.assertj.core.api.Assertions.assertThat;
69+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
6770
import static org.junit.jupiter.api.Assertions.*;
6871
import static org.mockito.Mockito.*;
6972

@@ -127,14 +130,14 @@ public class KogitoAddonRuntimeClientImplTest {
127130
@Mock
128131
Instance<Application> applicationInstance;
129132

130-
@Mock
131-
Model model;
133+
TestModel model;
132134

133135
@Mock
134136
private Application application;
135137

136138
@BeforeEach
137139
public void setup() {
140+
model = spy(new TestModel());
138141
lenient().when(processSvgServiceInstance.isResolvable()).thenReturn(true);
139142
lenient().when(processSvgServiceInstance.get()).thenReturn(processSvgService);
140143
lenient().when(processesInstance.isResolvable()).thenReturn(true);
@@ -148,12 +151,13 @@ public void setup() {
148151
lenient().when(processInstance.variables()).thenReturn(model);
149152
lenient().when(processInstance.id()).thenReturn(PROCESS_INSTANCE_ID);
150153
lenient().when(processInstance.status()).thenReturn(org.kie.kogito.process.ProcessInstance.STATE_ERROR);
154+
lenient().when(processInstance.updateVariables(any())).then(AdditionalAnswers.returnsFirstArg());
151155
lenient().when(error.failedNodeId()).thenReturn(NODE_ID_ERROR);
152156
lenient().when(error.errorMessage()).thenReturn("Test error message");
153157
lenient().when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
154158
lenient().when(applicationInstance.isResolvable()).thenReturn(true);
155159
lenient().when(applicationInstance.get()).thenReturn(application);
156-
lenient().when(model.toMap()).thenReturn(Map.of("name", "javierito"));
160+
//lenient().when(model.toMap()).thenReturn(Map.of("name", "javierito"));
157161

158162
client = spy(new KogitoAddonRuntimeClientImpl(processSvgServiceInstance, sourceFilesProvider, processesInstance, applicationInstance));
159163
client.setGatewayTargetUrl(Optional.empty());
@@ -355,6 +359,40 @@ public void testGetAuthHeader() {
355359
assertThat(token).isEqualTo("");
356360
}
357361

362+
@Test
363+
void testUpdateProcessInstanceVariables_exception() throws Exception {
364+
365+
ObjectMapper mapper = ObjectMapperFactory.get();
366+
JsonNode originalVariables = mapper.createObjectNode()
367+
.put("key", "value");
368+
369+
ProcessInstance pI = createProcessInstance(PROCESS_INSTANCE_ID, ACTIVE);
370+
371+
assertThatThrownBy(() -> {
372+
client.updateProcessInstanceVariables("http://example.com", pI, mapper.writeValueAsString(originalVariables));
373+
}).isInstanceOf(DataIndexServiceException.class).hasMessageContaining("Failure to update the variables");
374+
}
375+
376+
@Test
377+
void testUpdateProcessInstanceVariablesSuccess() throws Exception {
378+
ObjectMapper mapper = ObjectMapperFactory.get();
379+
JsonNode originalVariables = mapper.createObjectNode()
380+
.put("name", "jdoe")
381+
.put("age", 20)
382+
.put("adult", true);
383+
384+
ProcessInstance pI = createProcessInstance(PROCESS_INSTANCE_ID, ACTIVE);
385+
386+
CompletableFuture<String> result = client.updateProcessInstanceVariables("http://service.url", pI, mapper.writeValueAsString(originalVariables));
387+
388+
assertNotNull(result);
389+
verify(processInstance).updateVariables(any());
390+
391+
String updatedVariablesString = result.get();
392+
JsonNode updatedVariables = mapper.readTree(updatedVariablesString);
393+
assertThat(updatedVariables).isEqualTo(originalVariables);
394+
}
395+
358396
private ProcessInstance createProcessInstance(String processInstanceId, int status) {
359397
return TestUtils.getProcessInstance("travels", processInstanceId, status, null, null);
360398
}

0 commit comments

Comments
 (0)