Skip to content

Commit b09bf7a

Browse files
authored
Merge pull request #309 from eclipse-jnosql/BUG-573
Enums stopped to be supported as repository method parameters
2 parents b67e17c + 234f454 commit b09bf7a

File tree

6 files changed

+318
-1
lines changed

6 files changed

+318
-1
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version
1717
- Update OrientDB driver to 3.2.36
1818
- Update Couchbase client 3.7.6
1919
- Update DynamoDB driver 2.29.45
20+
- Update ArangoDb driver to 7.17.0
2021

2122
=== Fixed
2223

jnosql-arangodb/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<description>The Eclipse JNoSQL layer to ArangoDB</description>
2929

3030
<properties>
31-
<arango.driver>7.16.0</arango.driver>
31+
<arango.driver>7.17.0</arango.driver>
3232

3333
</properties>
3434

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright (c) 2025 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.arangodb.integration;
16+
17+
18+
import jakarta.inject.Inject;
19+
import org.assertj.core.api.SoftAssertions;
20+
import org.eclipse.jnosql.databases.arangodb.communication.ArangoDBConfigurations;
21+
import org.eclipse.jnosql.mapping.Database;
22+
import org.eclipse.jnosql.mapping.core.Converters;
23+
import org.eclipse.jnosql.mapping.core.config.MappingConfigurations;
24+
import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension;
25+
import org.eclipse.jnosql.mapping.document.DocumentTemplate;
26+
import org.eclipse.jnosql.mapping.document.spi.DocumentExtension;
27+
import org.eclipse.jnosql.mapping.reflection.Reflections;
28+
import org.eclipse.jnosql.mapping.semistructured.EntityConverter;
29+
import org.jboss.weld.junit5.auto.AddExtensions;
30+
import org.jboss.weld.junit5.auto.AddPackages;
31+
import org.jboss.weld.junit5.auto.EnableAutoWeld;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
34+
35+
import java.util.List;
36+
import java.util.function.Predicate;
37+
38+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
39+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
40+
import static org.eclipse.jnosql.databases.arangodb.communication.DocumentDatabase.INSTANCE;
41+
42+
@EnableAutoWeld
43+
@AddPackages(value = {Database.class, EntityConverter.class, DocumentTemplate.class})
44+
@AddPackages(Magazine.class)
45+
@AddExtensions({EntityMetadataExtension.class,
46+
DocumentExtension.class})
47+
@AddPackages(Reflections.class)
48+
@AddPackages(Converters.class)
49+
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
50+
public class ArangoDBEnumIntegrationTest {
51+
52+
53+
static {
54+
INSTANCE.get("library");
55+
System.setProperty(ArangoDBConfigurations.HOST.get() + ".1", INSTANCE.host());
56+
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library");
57+
}
58+
59+
@Inject
60+
private DocumentTemplate template;
61+
62+
63+
@Inject
64+
private MailTemplateRepository repository;
65+
66+
@Test
67+
void shouldCreateAndQueryByEnumAndDefaultTrue() {
68+
template.insert(MailTemplate.builder()
69+
.category(MailCategory.TIMER)
70+
.from("otavio@email.com")
71+
.to("mateusz@email.com")
72+
.isDefault(true)
73+
.build());
74+
75+
List<MailTemplate> result = template.select(MailTemplate.class) .where("category")
76+
.eq(MailCategory.TIMER).result();
77+
78+
SoftAssertions.assertSoftly(soft -> {
79+
Predicate<MailTemplate> isTimer = m -> m.getCategory().equals(MailCategory.TIMER);
80+
Predicate<MailTemplate> isTrue = m -> m.isDefault();
81+
soft.assertThat(result).allMatch(isTimer.and(isTrue));
82+
});
83+
}
84+
85+
@Test
86+
void shouldCreateAndQueryByEnumAndDefaultFalse() {
87+
var emailTemplate = MailTemplate.builder()
88+
.category(MailCategory.TRANSITION_ALTERNATIVE)
89+
.from("otavio@email.com")
90+
.to("mateusz@email.com")
91+
.isDefault(false)
92+
.build();
93+
94+
template.insert(emailTemplate);
95+
96+
List<MailTemplate> result = template.select(MailTemplate.class)
97+
.where("category")
98+
.eq(MailCategory.TRANSITION_ALTERNATIVE)
99+
.and("isDefault")
100+
.eq(false).result();
101+
102+
SoftAssertions.assertSoftly(soft -> {
103+
Predicate<MailTemplate> isAlternative = m -> m.getCategory().equals(MailCategory.TRANSITION_ALTERNATIVE);
104+
Predicate<MailTemplate> isFalse = m -> !m.isDefault();
105+
soft.assertThat(result).hasSize(1).allMatch(
106+
isAlternative.and(isFalse));
107+
});
108+
}
109+
110+
@Test
111+
void shouldQueryUsingRepository() {
112+
repository.save(MailTemplate.builder()
113+
.category(MailCategory.TIMER)
114+
.from("otavio@email.com")
115+
.to("mateusz@email.com")
116+
.isDefault(true)
117+
.build());
118+
119+
repository.save(MailTemplate.builder()
120+
.category(MailCategory.TRANSITION_ALTERNATIVE)
121+
.from("otavio@email.com")
122+
.to("mateusz@email.com")
123+
.isDefault(true)
124+
.build());
125+
126+
List<MailTemplate> categoryAndIsDefaultTrue = repository.findByCategoryAndIsDefaultTrue(MailCategory.TIMER);
127+
128+
SoftAssertions.assertSoftly(soft -> {
129+
Predicate<MailTemplate> isTimer = m -> m.getCategory().equals(MailCategory.TIMER);
130+
Predicate<MailTemplate> isTrue = m -> m.isDefault();
131+
soft.assertThat(categoryAndIsDefaultTrue).hasSize(1).allMatch(
132+
isTimer.and(isTrue));
133+
});
134+
}
135+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2025 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.arangodb.integration;
16+
17+
public enum MailCategory {
18+
TIMER,
19+
TRANSITION_MAIN,
20+
TRANSITION_ALTERNATIVE,
21+
TRANSITION_FALLBACK
22+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright (c) 2025 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.arangodb.integration;
16+
17+
import jakarta.nosql.Column;
18+
import jakarta.nosql.Entity;
19+
import jakarta.nosql.Id;
20+
21+
import java.util.Objects;
22+
import java.util.UUID;
23+
24+
@Entity
25+
public class MailTemplate {
26+
27+
@Id
28+
private String id;
29+
30+
@Column
31+
private String to;
32+
33+
@Column
34+
private String from;
35+
36+
@Column
37+
private MailCategory category;
38+
39+
@Column
40+
private boolean isDefault;
41+
42+
public String getId() {
43+
return id;
44+
}
45+
46+
public String getTo() {
47+
return to;
48+
}
49+
50+
public String getFrom() {
51+
return from;
52+
}
53+
54+
public MailCategory getCategory() {
55+
return category;
56+
}
57+
58+
public boolean isDefault() {
59+
return isDefault;
60+
}
61+
62+
@Override
63+
public boolean equals(Object o) {
64+
if (o == null || getClass() != o.getClass()) {
65+
return false;
66+
}
67+
MailTemplate that = (MailTemplate) o;
68+
return Objects.equals(id, that.id);
69+
}
70+
71+
@Override
72+
public int hashCode() {
73+
return Objects.hashCode(id);
74+
}
75+
76+
@Override
77+
public String toString() {
78+
return "MailTemplate{" +
79+
"id=" + id +
80+
", to='" + to + '\'' +
81+
", from='" + from + '\'' +
82+
", category=" + category +
83+
", isDefault=" + isDefault +
84+
'}';
85+
}
86+
87+
public static MailTemplateBuilder builder(){
88+
return new MailTemplateBuilder();
89+
}
90+
91+
92+
public static class MailTemplateBuilder{
93+
94+
private String to;
95+
96+
private String from;
97+
98+
private MailCategory category;
99+
100+
private boolean isDefault;
101+
102+
public MailTemplateBuilder to(String to) {
103+
this.to = to;
104+
return this;
105+
}
106+
107+
public MailTemplateBuilder from(String from) {
108+
this.from = from;
109+
return this;
110+
}
111+
112+
public MailTemplateBuilder category(MailCategory category) {
113+
this.category = category;
114+
return this;
115+
}
116+
117+
public MailTemplateBuilder isDefault(boolean isDefault) {
118+
this.isDefault = isDefault;
119+
return this;
120+
}
121+
122+
public MailTemplate build(){
123+
MailTemplate mailTemplate = new MailTemplate();
124+
mailTemplate.id = UUID.randomUUID().toString();
125+
mailTemplate.to = this.to;
126+
mailTemplate.from = this.from;
127+
mailTemplate.category = this.category;
128+
mailTemplate.isDefault = this.isDefault;
129+
return mailTemplate;
130+
}
131+
}
132+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2025 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.arangodb.integration;
16+
17+
import jakarta.data.repository.Repository;
18+
import org.eclipse.jnosql.mapping.NoSQLRepository;
19+
import org.jetbrains.annotations.NotNull;
20+
21+
import java.util.List;
22+
23+
@Repository
24+
public interface MailTemplateRepository extends NoSQLRepository<MailTemplate, String> {
25+
26+
List<MailTemplate> findByCategoryAndIsDefaultTrue(@NotNull MailCategory mailCategory);
27+
}

0 commit comments

Comments
 (0)