Skip to content

Commit a03befa

Browse files
committed
test: create test scenario to mongodb
Signed-off-by: Otavio Santana <[email protected]>
1 parent c84833a commit a03befa

File tree

8 files changed

+330
-2
lines changed

8 files changed

+330
-2
lines changed

jnosql-arangodb/src/main/java/org/eclipse/jnosql/databases/arangodb/communication/ArangoDBUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private static Object getMap(Object val) {
148148
Map<Object, Object> map = new HashMap<>();
149149
for (Object item : iterable) {
150150
var document = cast(item);
151-
map.put(document.name(), document.value());
151+
map.put(document.name(), document.get());
152152
}
153153
return map;
154154
}

jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/MongoDBUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private static Object getMap(Object val) {
105105
Map<Object, Object> map = new HashMap<>();
106106
for (Object item : iterable) {
107107
var document = cast(item);
108-
map.put(document.name(), document.value());
108+
map.put(document.name(), document.get());
109109
}
110110
return map;
111111
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.mongodb.integration;
16+
17+
public enum MainStepType {
18+
MAIN, ENTRY
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.mongodb.integration;
16+
17+
18+
public enum StepTransitionReason {
19+
REPEAT
20+
}

jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/integration/TemplateIntegrationTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import jakarta.inject.Inject;
1919
import jakarta.nosql.document.DocumentTemplate;
20+
import org.assertj.core.api.SoftAssertions;
2021
import org.eclipse.jnosql.databases.mongodb.communication.MongoDBDocumentConfigurations;
2122
import org.eclipse.jnosql.mapping.Convert;
2223
import org.eclipse.jnosql.mapping.Converters;
@@ -31,13 +32,15 @@
3132
import org.junit.jupiter.api.Test;
3233
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
3334

35+
import java.util.List;
3436
import java.util.Optional;
3537

3638
import static java.util.UUID.randomUUID;
3739
import static org.assertj.core.api.Assertions.assertThat;
3840
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
3941
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
4042
import static org.eclipse.jnosql.databases.mongodb.communication.DocumentDatabase.INSTANCE;
43+
import static org.eclipse.jnosql.databases.mongodb.integration.StepTransitionReason.REPEAT;
4144

4245
@EnableAutoWeld
4346
@AddPackages(value = {Convert.class, DocumentEntityConverter.class})
@@ -120,4 +123,39 @@ void shouldDeleteAll(){
120123
template.delete(Book.class).execute();
121124
assertThat(template.select(Book.class).result()).isEmpty();
122125
}
126+
127+
@Test
128+
void shouldUpdateEmbeddable() {
129+
var workflowStep = WorkflowStep.builder()
130+
.id("id")
131+
.key("key")
132+
.workflowSchemaKey("workflowSchemaKey")
133+
.stepName("stepName")
134+
.mainStepType(MainStepType.MAIN)
135+
.stepNo(1)
136+
.componentConfigurationKey("componentConfigurationKey")
137+
.relationTypeKey("relationTypeKey")
138+
.availableTransitions(List.of(new Transition("TEST_WORKFLOW_STEP_KEY", REPEAT,
139+
null, List.of("ADMIN"))))
140+
.build();
141+
var result = this.template.insert(workflowStep);
142+
143+
SoftAssertions.assertSoftly(soft ->{
144+
soft.assertThat(result).isNotNull();
145+
soft.assertThat(result.id()).isEqualTo("id");
146+
soft.assertThat(result.key()).isEqualTo("key");
147+
soft.assertThat(result.workflowSchemaKey()).isEqualTo("workflowSchemaKey");
148+
soft.assertThat(result.stepName()).isEqualTo("stepName");
149+
soft.assertThat(result.mainStepType()).isEqualTo(MainStepType.MAIN);
150+
soft.assertThat(result.stepNo()).isEqualTo(1);
151+
soft.assertThat(result.componentConfigurationKey()).isEqualTo("componentConfigurationKey");
152+
soft.assertThat(result.relationTypeKey()).isEqualTo("relationTypeKey");
153+
soft.assertThat(result.availableTransitions()).hasSize(1);
154+
soft.assertThat(result.availableTransitions().get(0).targetWorkflowStepKey()).isEqualTo("TEST_WORKFLOW_STEP_KEY");
155+
soft.assertThat(result.availableTransitions().get(0).stepTransitionReason()).isEqualTo(REPEAT);
156+
soft.assertThat(result.availableTransitions().get(0).mailTemplateKey()).isNull();
157+
soft.assertThat(result.availableTransitions().get(0).restrictedRoleGroups()).hasSize(1);
158+
soft.assertThat(result.availableTransitions().get(0).restrictedRoleGroups().get(0)).isEqualTo("ADMIN");
159+
});
160+
}
123161
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.mongodb.integration;
16+
17+
import jakarta.nosql.Column;
18+
import org.eclipse.jnosql.mapping.Embeddable;
19+
20+
import java.util.List;
21+
22+
@Embeddable
23+
public class Transition {
24+
25+
@Column
26+
private String targetWorkflowStepKey;
27+
@Column
28+
private StepTransitionReason stepTransitionReason;
29+
@Column
30+
private String mailTemplateKey;
31+
@Column
32+
private List<String> restrictedRoleGroups;
33+
34+
public Transition(String targetWorkflowStepKey,
35+
StepTransitionReason stepTransitionReason,
36+
String mailTemplateKey,
37+
List<String> restrictedRoleGroups) {
38+
this.targetWorkflowStepKey = targetWorkflowStepKey;
39+
this.stepTransitionReason = stepTransitionReason;
40+
this.mailTemplateKey = mailTemplateKey;
41+
this.restrictedRoleGroups = restrictedRoleGroups;
42+
}
43+
44+
public Transition() {
45+
}
46+
47+
public String targetWorkflowStepKey() {
48+
return targetWorkflowStepKey;
49+
}
50+
51+
public StepTransitionReason stepTransitionReason() {
52+
return stepTransitionReason;
53+
}
54+
55+
public String mailTemplateKey() {
56+
return mailTemplateKey;
57+
}
58+
59+
public List<String> restrictedRoleGroups() {
60+
return restrictedRoleGroups;
61+
}
62+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.mongodb.integration;
16+
17+
import jakarta.nosql.Column;
18+
import jakarta.nosql.Entity;
19+
import jakarta.nosql.Id;
20+
21+
import java.util.List;
22+
23+
@Entity("workflow_step")
24+
public class WorkflowStep {
25+
26+
@Id
27+
private String id;
28+
29+
@Column("_key")
30+
private String key;
31+
32+
@Column
33+
private String workflowSchemaKey;
34+
35+
@Column
36+
private String stepName;
37+
38+
@Column
39+
private MainStepType mainStepType;
40+
41+
@Column
42+
private Integer stepNo;
43+
44+
@Column
45+
private String componentConfigurationKey;
46+
47+
@Column
48+
private String relationTypeKey;
49+
50+
@Column
51+
private List<Transition> availableTransitions;
52+
53+
WorkflowStep(String id, String key, String workflowSchemaKey,
54+
String stepName, MainStepType mainStepType,
55+
Integer stepNo, String componentConfigurationKey,
56+
String relationTypeKey, List<Transition> availableTransitions) {
57+
this.id = id;
58+
this.key = key;
59+
this.workflowSchemaKey = workflowSchemaKey;
60+
this.stepName = stepName;
61+
this.mainStepType = mainStepType;
62+
this.stepNo = stepNo;
63+
this.componentConfigurationKey = componentConfigurationKey;
64+
this.relationTypeKey = relationTypeKey;
65+
this.availableTransitions = availableTransitions;
66+
}
67+
68+
WorkflowStep() {
69+
}
70+
71+
public static WorkflowStepBuilder builder() {
72+
return new WorkflowStepBuilder();
73+
}
74+
75+
public String id() {
76+
return id;
77+
}
78+
79+
public String key() {
80+
return key;
81+
}
82+
83+
public String workflowSchemaKey() {
84+
return workflowSchemaKey;
85+
}
86+
87+
public String stepName() {
88+
return stepName;
89+
}
90+
91+
public MainStepType mainStepType() {
92+
return mainStepType;
93+
}
94+
95+
public Integer stepNo() {
96+
return stepNo;
97+
}
98+
99+
public String componentConfigurationKey() {
100+
return componentConfigurationKey;
101+
}
102+
103+
public String relationTypeKey() {
104+
return relationTypeKey;
105+
}
106+
107+
public List<Transition> availableTransitions() {
108+
return availableTransitions;
109+
}
110+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.mongodb.integration;
16+
17+
import java.util.List;
18+
19+
public class WorkflowStepBuilder {
20+
private String id;
21+
private String key;
22+
private String workflowSchemaKey;
23+
private String stepName;
24+
private MainStepType mainStepType;
25+
private Integer stepNo;
26+
private String componentConfigurationKey;
27+
private String relationTypeKey;
28+
private List<Transition> availableTransitions;
29+
30+
public WorkflowStepBuilder id(String id) {
31+
this.id = id;
32+
return this;
33+
}
34+
35+
public WorkflowStepBuilder key(String key) {
36+
this.key = key;
37+
return this;
38+
}
39+
40+
public WorkflowStepBuilder workflowSchemaKey(String workflowSchemaKey) {
41+
this.workflowSchemaKey = workflowSchemaKey;
42+
return this;
43+
}
44+
45+
public WorkflowStepBuilder stepName(String stepName) {
46+
this.stepName = stepName;
47+
return this;
48+
}
49+
50+
public WorkflowStepBuilder mainStepType(MainStepType mainStepType) {
51+
this.mainStepType = mainStepType;
52+
return this;
53+
}
54+
55+
public WorkflowStepBuilder stepNo(Integer stepNo) {
56+
this.stepNo = stepNo;
57+
return this;
58+
}
59+
60+
public WorkflowStepBuilder componentConfigurationKey(String componentConfigurationKey) {
61+
this.componentConfigurationKey = componentConfigurationKey;
62+
return this;
63+
}
64+
65+
public WorkflowStepBuilder relationTypeKey(String relationTypeKey) {
66+
this.relationTypeKey = relationTypeKey;
67+
return this;
68+
}
69+
70+
public WorkflowStepBuilder availableTransitions(List<Transition> availableTransitions) {
71+
this.availableTransitions = availableTransitions;
72+
return this;
73+
}
74+
75+
public WorkflowStep build() {
76+
return new WorkflowStep(id, key, workflowSchemaKey, stepName, mainStepType,
77+
stepNo, componentConfigurationKey, relationTypeKey, availableTransitions);
78+
}
79+
}

0 commit comments

Comments
 (0)