Skip to content

Commit 1bc780f

Browse files
committed
feat: create insert scenario
Signed-off-by: Otavio Santana <[email protected]>
1 parent ed71e0b commit 1bc780f

File tree

4 files changed

+289
-0
lines changed

4 files changed

+289
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2024 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.oracle.integration;
16+
17+
import jakarta.nosql.Column;
18+
import jakarta.nosql.Entity;
19+
import jakarta.nosql.Id;
20+
21+
import java.util.List;
22+
import java.util.Map;
23+
import java.util.Objects;
24+
25+
@Entity
26+
public class Beer {
27+
28+
@Id
29+
private String id;
30+
31+
@Column
32+
private List<String> comments;
33+
34+
@Column
35+
public List<Crew> crew;
36+
37+
@Column
38+
public Map<String, Object> data;
39+
40+
41+
public String id() {
42+
return id;
43+
}
44+
45+
public List<String> comments() {
46+
return comments;
47+
}
48+
49+
public List<Crew> crew() {
50+
return crew;
51+
}
52+
53+
public Map<String, Object> data() {
54+
return data;
55+
}
56+
57+
Beer() {
58+
}
59+
60+
Beer(String id, List<String> comments, List<Crew> crew, Map<String, Object> data) {
61+
this.id = id;
62+
this.comments = comments;
63+
this.crew = crew;
64+
this.data = data;
65+
}
66+
67+
@Override
68+
public String toString() {
69+
return "Beer{" +
70+
"id='" + id + '\'' +
71+
", comments=" + comments +
72+
", crew=" + crew +
73+
", data=" + data +
74+
'}';
75+
}
76+
77+
@Override
78+
public boolean equals(Object o) {
79+
if (this == o) {
80+
return true;
81+
}
82+
if (o == null || getClass() != o.getClass()) {
83+
return false;
84+
}
85+
Beer beer = (Beer) o;
86+
return Objects.equals(id, beer.id);
87+
}
88+
89+
@Override
90+
public int hashCode() {
91+
return Objects.hashCode(id);
92+
}
93+
94+
public static BeerBuilder builder() {
95+
return new BeerBuilder();
96+
}
97+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2024 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.oracle.integration;
16+
17+
import java.util.List;
18+
import java.util.Map;
19+
20+
public class BeerBuilder {
21+
private String id;
22+
private List<String> comments;
23+
private List<Crew> crew;
24+
private Map<String, Object> data;
25+
26+
public BeerBuilder id(String id) {
27+
this.id = id;
28+
return this;
29+
}
30+
31+
public BeerBuilder comments(List<String> comments) {
32+
this.comments = comments;
33+
return this;
34+
}
35+
36+
public BeerBuilder crew(List<Crew> crew) {
37+
this.crew = crew;
38+
return this;
39+
}
40+
41+
public BeerBuilder data(Map<String, Object> data) {
42+
this.data = data;
43+
return this;
44+
}
45+
46+
public Beer build() {
47+
return new Beer(id, comments, crew, data);
48+
}
49+
}
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.oracle.integration;
16+
17+
18+
import jakarta.inject.Inject;
19+
import org.assertj.core.api.SoftAssertions;
20+
import org.eclipse.jnosql.databases.oracle.communication.Database;
21+
import org.eclipse.jnosql.databases.oracle.communication.OracleNoSQLConfigurations;
22+
import org.eclipse.jnosql.databases.oracle.mapping.OracleNoSQLTemplate;
23+
import org.eclipse.jnosql.mapping.Convert;
24+
import org.eclipse.jnosql.mapping.core.Converters;
25+
import org.eclipse.jnosql.mapping.core.config.MappingConfigurations;
26+
import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension;
27+
import org.eclipse.jnosql.mapping.document.DocumentEntityConverter;
28+
import org.eclipse.jnosql.mapping.document.spi.DocumentExtension;
29+
import org.eclipse.jnosql.mapping.reflection.Reflections;
30+
import org.jboss.weld.junit5.auto.AddExtensions;
31+
import org.jboss.weld.junit5.auto.AddPackages;
32+
import org.jboss.weld.junit5.auto.EnableAutoWeld;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
35+
36+
import java.util.List;
37+
import java.util.Map;
38+
import java.util.Optional;
39+
import java.util.UUID;
40+
41+
import static java.util.UUID.randomUUID;
42+
import static org.assertj.core.api.Assertions.assertThat;
43+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
44+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
45+
46+
@EnableAutoWeld
47+
@AddPackages(value = {Convert.class, DocumentEntityConverter.class})
48+
@AddPackages(Beer.class)
49+
@AddPackages(OracleNoSQLTemplate.class)
50+
@AddExtensions({EntityMetadataExtension.class,
51+
DocumentExtension.class})
52+
@AddPackages(Reflections.class)
53+
@AddPackages(Converters.class)
54+
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
55+
class BeerTemplateIntegrationTest {
56+
57+
@Inject
58+
private OracleNoSQLTemplate template;
59+
60+
static {
61+
System.setProperty(OracleNoSQLConfigurations.HOST.get(), Database.INSTANCE.host());
62+
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library");
63+
}
64+
65+
@Test
66+
void shouldInsert() {
67+
68+
Beer beer = Beer.builder()
69+
.id(UUID.randomUUID().toString())
70+
.data(Map.of("name", "beer"))
71+
.crew(List.of(new Crew("Otavio")))
72+
.build();
73+
74+
}
75+
76+
77+
78+
79+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2024 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.oracle.integration;
16+
17+
18+
import jakarta.nosql.Column;
19+
import jakarta.nosql.Entity;
20+
21+
import java.util.Objects;
22+
23+
@Entity
24+
public class Crew {
25+
26+
@Column
27+
private String name;
28+
29+
public String name() {
30+
return name;
31+
}
32+
33+
34+
Crew() {
35+
}
36+
37+
Crew(String name) {
38+
this.name = name;
39+
}
40+
41+
@Override
42+
public boolean equals(Object o) {
43+
if (this == o) {
44+
return true;
45+
}
46+
if (o == null || getClass() != o.getClass()) {
47+
return false;
48+
}
49+
Crew crew = (Crew) o;
50+
return Objects.equals(name, crew.name);
51+
}
52+
53+
@Override
54+
public int hashCode() {
55+
return Objects.hashCode(name);
56+
}
57+
58+
@Override
59+
public String toString() {
60+
return "Crew{" +
61+
"name='" + name + '\'' +
62+
'}';
63+
}
64+
}

0 commit comments

Comments
 (0)