-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #309 from eclipse-jnosql/BUG-573
Enums stopped to be supported as repository method parameters
- Loading branch information
Showing
6 changed files
with
318 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...t/java/org/eclipse/jnosql/databases/arangodb/integration/ArangoDBEnumIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.databases.arangodb.integration; | ||
|
||
|
||
import jakarta.inject.Inject; | ||
import org.assertj.core.api.SoftAssertions; | ||
import org.eclipse.jnosql.databases.arangodb.communication.ArangoDBConfigurations; | ||
import org.eclipse.jnosql.mapping.Database; | ||
import org.eclipse.jnosql.mapping.core.Converters; | ||
import org.eclipse.jnosql.mapping.core.config.MappingConfigurations; | ||
import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension; | ||
import org.eclipse.jnosql.mapping.document.DocumentTemplate; | ||
import org.eclipse.jnosql.mapping.document.spi.DocumentExtension; | ||
import org.eclipse.jnosql.mapping.reflection.Reflections; | ||
import org.eclipse.jnosql.mapping.semistructured.EntityConverter; | ||
import org.jboss.weld.junit5.auto.AddExtensions; | ||
import org.jboss.weld.junit5.auto.AddPackages; | ||
import org.jboss.weld.junit5.auto.EnableAutoWeld; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES; | ||
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED; | ||
import static org.eclipse.jnosql.databases.arangodb.communication.DocumentDatabase.INSTANCE; | ||
|
||
@EnableAutoWeld | ||
@AddPackages(value = {Database.class, EntityConverter.class, DocumentTemplate.class}) | ||
@AddPackages(Magazine.class) | ||
@AddExtensions({EntityMetadataExtension.class, | ||
DocumentExtension.class}) | ||
@AddPackages(Reflections.class) | ||
@AddPackages(Converters.class) | ||
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES) | ||
public class ArangoDBEnumIntegrationTest { | ||
|
||
|
||
static { | ||
INSTANCE.get("library"); | ||
System.setProperty(ArangoDBConfigurations.HOST.get() + ".1", INSTANCE.host()); | ||
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library"); | ||
} | ||
|
||
@Inject | ||
private DocumentTemplate template; | ||
|
||
|
||
@Inject | ||
private MailTemplateRepository repository; | ||
|
||
@Test | ||
void shouldCreateAndQueryByEnumAndDefaultTrue() { | ||
template.insert(MailTemplate.builder() | ||
.category(MailCategory.TIMER) | ||
.from("[email protected]") | ||
.to("[email protected]") | ||
.isDefault(true) | ||
.build()); | ||
|
||
List<MailTemplate> result = template.select(MailTemplate.class) .where("category") | ||
.eq(MailCategory.TIMER).result(); | ||
|
||
SoftAssertions.assertSoftly(soft -> { | ||
Predicate<MailTemplate> isTimer = m -> m.getCategory().equals(MailCategory.TIMER); | ||
Predicate<MailTemplate> isTrue = m -> m.isDefault(); | ||
soft.assertThat(result).allMatch(isTimer.and(isTrue)); | ||
}); | ||
} | ||
|
||
@Test | ||
void shouldCreateAndQueryByEnumAndDefaultFalse() { | ||
var emailTemplate = MailTemplate.builder() | ||
.category(MailCategory.TRANSITION_ALTERNATIVE) | ||
.from("[email protected]") | ||
.to("[email protected]") | ||
.isDefault(false) | ||
.build(); | ||
|
||
template.insert(emailTemplate); | ||
|
||
List<MailTemplate> result = template.select(MailTemplate.class) | ||
.where("category") | ||
.eq(MailCategory.TRANSITION_ALTERNATIVE) | ||
.and("isDefault") | ||
.eq(false).result(); | ||
|
||
SoftAssertions.assertSoftly(soft -> { | ||
Predicate<MailTemplate> isAlternative = m -> m.getCategory().equals(MailCategory.TRANSITION_ALTERNATIVE); | ||
Predicate<MailTemplate> isFalse = m -> !m.isDefault(); | ||
soft.assertThat(result).hasSize(1).allMatch( | ||
isAlternative.and(isFalse)); | ||
}); | ||
} | ||
|
||
@Test | ||
void shouldQueryUsingRepository() { | ||
repository.save(MailTemplate.builder() | ||
.category(MailCategory.TIMER) | ||
.from("[email protected]") | ||
.to("[email protected]") | ||
.isDefault(true) | ||
.build()); | ||
|
||
repository.save(MailTemplate.builder() | ||
.category(MailCategory.TRANSITION_ALTERNATIVE) | ||
.from("[email protected]") | ||
.to("[email protected]") | ||
.isDefault(true) | ||
.build()); | ||
|
||
List<MailTemplate> categoryAndIsDefaultTrue = repository.findByCategoryAndIsDefaultTrue(MailCategory.TIMER); | ||
|
||
SoftAssertions.assertSoftly(soft -> { | ||
Predicate<MailTemplate> isTimer = m -> m.getCategory().equals(MailCategory.TIMER); | ||
Predicate<MailTemplate> isTrue = m -> m.isDefault(); | ||
soft.assertThat(categoryAndIsDefaultTrue).hasSize(1).allMatch( | ||
isTimer.and(isTrue)); | ||
}); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...rangodb/src/test/java/org/eclipse/jnosql/databases/arangodb/integration/MailCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.databases.arangodb.integration; | ||
|
||
public enum MailCategory { | ||
TIMER, | ||
TRANSITION_MAIN, | ||
TRANSITION_ALTERNATIVE, | ||
TRANSITION_FALLBACK | ||
} |
132 changes: 132 additions & 0 deletions
132
...rangodb/src/test/java/org/eclipse/jnosql/databases/arangodb/integration/MailTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.databases.arangodb.integration; | ||
|
||
import jakarta.nosql.Column; | ||
import jakarta.nosql.Entity; | ||
import jakarta.nosql.Id; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
@Entity | ||
public class MailTemplate { | ||
|
||
@Id | ||
private String id; | ||
|
||
@Column | ||
private String to; | ||
|
||
@Column | ||
private String from; | ||
|
||
@Column | ||
private MailCategory category; | ||
|
||
@Column | ||
private boolean isDefault; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getTo() { | ||
return to; | ||
} | ||
|
||
public String getFrom() { | ||
return from; | ||
} | ||
|
||
public MailCategory getCategory() { | ||
return category; | ||
} | ||
|
||
public boolean isDefault() { | ||
return isDefault; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
MailTemplate that = (MailTemplate) o; | ||
return Objects.equals(id, that.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MailTemplate{" + | ||
"id=" + id + | ||
", to='" + to + '\'' + | ||
", from='" + from + '\'' + | ||
", category=" + category + | ||
", isDefault=" + isDefault + | ||
'}'; | ||
} | ||
|
||
public static MailTemplateBuilder builder(){ | ||
return new MailTemplateBuilder(); | ||
} | ||
|
||
|
||
public static class MailTemplateBuilder{ | ||
|
||
private String to; | ||
|
||
private String from; | ||
|
||
private MailCategory category; | ||
|
||
private boolean isDefault; | ||
|
||
public MailTemplateBuilder to(String to) { | ||
this.to = to; | ||
return this; | ||
} | ||
|
||
public MailTemplateBuilder from(String from) { | ||
this.from = from; | ||
return this; | ||
} | ||
|
||
public MailTemplateBuilder category(MailCategory category) { | ||
this.category = category; | ||
return this; | ||
} | ||
|
||
public MailTemplateBuilder isDefault(boolean isDefault) { | ||
this.isDefault = isDefault; | ||
return this; | ||
} | ||
|
||
public MailTemplate build(){ | ||
MailTemplate mailTemplate = new MailTemplate(); | ||
mailTemplate.id = UUID.randomUUID().toString(); | ||
mailTemplate.to = this.to; | ||
mailTemplate.from = this.from; | ||
mailTemplate.category = this.category; | ||
mailTemplate.isDefault = this.isDefault; | ||
return mailTemplate; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...c/test/java/org/eclipse/jnosql/databases/arangodb/integration/MailTemplateRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.databases.arangodb.integration; | ||
|
||
import jakarta.data.repository.Repository; | ||
import org.eclipse.jnosql.mapping.NoSQLRepository; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface MailTemplateRepository extends NoSQLRepository<MailTemplate, String> { | ||
|
||
List<MailTemplate> findByCategoryAndIsDefaultTrue(@NotNull MailCategory mailCategory); | ||
} |