Skip to content

Commit d91678c

Browse files
committed
refactor: use injection by constructor
Signed-off-by: Otavio Santana <[email protected]>
1 parent 4fe9783 commit d91678c

File tree

4 files changed

+248
-9
lines changed

4 files changed

+248
-9
lines changed

jnosql-solr/src/main/java/org/eclipse/jnosql/databases/solr/mapping/DefaultSolrTemplate.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@
4141
@ApplicationScoped
4242
class DefaultSolrTemplate extends AbstractDocumentTemplate implements SolrTemplate {
4343

44-
private Instance<SolrDocumentManager> manager;
44+
private final Instance<SolrDocumentManager> manager;
4545

46-
private DocumentEntityConverter converter;
46+
private final DocumentEntityConverter converter;
4747

48-
private DocumentWorkflow flow;
48+
private final DocumentWorkflow flow;
4949

50-
private DocumentEventPersistManager persistManager;
50+
private final DocumentEventPersistManager persistManager;
5151

52-
private EntitiesMetadata entities;
52+
private final EntitiesMetadata entities;
5353

54-
private Converters converters;
54+
private final Converters converters;
5555

5656
@Inject
5757
DefaultSolrTemplate(Instance<SolrDocumentManager> manager,
@@ -67,9 +67,6 @@ class DefaultSolrTemplate extends AbstractDocumentTemplate implements SolrTempla
6767
this.converters = converters;
6868
}
6969

70-
DefaultSolrTemplate() {
71-
}
72-
7370
@Override
7471
protected DocumentEntityConverter getConverter() {
7572
return converter;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
@Entity
22+
public record Book(@Id String id, @Column("title") String title, @Column("edition") int edition) {
23+
24+
25+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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.solr.integration;
16+
17+
18+
import jakarta.inject.Inject;
19+
import org.eclipse.jnosql.databases.mongodb.communication.MongoDBDocumentConfigurations;
20+
import org.eclipse.jnosql.databases.mongodb.mapping.MongoDBTemplate;
21+
import org.eclipse.jnosql.mapping.Convert;
22+
import org.eclipse.jnosql.mapping.config.MappingConfigurations;
23+
import org.eclipse.jnosql.mapping.document.DocumentEntityConverter;
24+
import org.eclipse.jnosql.mapping.document.spi.DocumentExtension;
25+
import org.eclipse.jnosql.mapping.reflection.EntityMetadataExtension;
26+
import org.jboss.weld.junit5.auto.AddExtensions;
27+
import org.jboss.weld.junit5.auto.AddPackages;
28+
import org.jboss.weld.junit5.auto.EnableAutoWeld;
29+
import org.junit.jupiter.api.Test;
30+
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
31+
32+
import java.util.Optional;
33+
34+
import static java.util.UUID.randomUUID;
35+
import static org.assertj.core.api.Assertions.assertThat;
36+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
37+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
38+
import static org.eclipse.jnosql.databases.mongodb.communication.DocumentDatabase.INSTANCE;
39+
40+
@EnableAutoWeld
41+
@AddPackages(value = {Convert.class, DocumentEntityConverter.class})
42+
@AddPackages(Book.class)
43+
@AddPackages(MongoDBTemplate.class)
44+
@AddExtensions({EntityMetadataExtension.class,
45+
DocumentExtension.class})
46+
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
47+
class MongoDBTemplateIntegrationTest {
48+
49+
@Inject
50+
private MongoDBTemplate template;
51+
52+
static {
53+
INSTANCE.get("library");
54+
System.setProperty(MongoDBDocumentConfigurations.HOST.get() + ".1", INSTANCE.host());
55+
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library");
56+
}
57+
58+
@Test
59+
public void shouldInsert() {
60+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
61+
template.insert(book);
62+
Optional<Book> optional = template.find(Book.class, book.id());
63+
assertThat(optional).isNotNull().isNotEmpty()
64+
.get().isEqualTo(book);
65+
}
66+
67+
@Test
68+
public void shouldUpdate() {
69+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
70+
assertThat(template.insert(book))
71+
.isNotNull()
72+
.isEqualTo(book);
73+
74+
Book updated = new Book(book.id(), book.title() + " updated", 2);
75+
76+
assertThat(template.update(updated))
77+
.isNotNull()
78+
.isNotEqualTo(book);
79+
80+
assertThat(template.find(Book.class, book.id()))
81+
.isNotNull().get().isEqualTo(updated);
82+
83+
}
84+
85+
@Test
86+
public void shouldFindById() {
87+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
88+
assertThat(template.insert(book))
89+
.isNotNull()
90+
.isEqualTo(book);
91+
92+
assertThat(template.find(Book.class, book.id()))
93+
.isNotNull().get().isEqualTo(book);
94+
}
95+
96+
@Test
97+
public void shouldDelete() {
98+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
99+
assertThat(template.insert(book))
100+
.isNotNull()
101+
.isEqualTo(book);
102+
103+
template.delete(Book.class, book.id());
104+
assertThat(template.find(Book.class, book.id()))
105+
.isNotNull().isEmpty();
106+
}
107+
108+
109+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
import jakarta.inject.Inject;
19+
import jakarta.nosql.document.DocumentTemplate;
20+
import org.eclipse.jnosql.databases.mongodb.communication.MongoDBDocumentConfigurations;
21+
import org.eclipse.jnosql.mapping.Convert;
22+
import org.eclipse.jnosql.mapping.config.MappingConfigurations;
23+
import org.eclipse.jnosql.mapping.document.DocumentEntityConverter;
24+
import org.eclipse.jnosql.mapping.document.spi.DocumentExtension;
25+
import org.eclipse.jnosql.mapping.reflection.EntityMetadataExtension;
26+
import org.jboss.weld.junit5.auto.AddExtensions;
27+
import org.jboss.weld.junit5.auto.AddPackages;
28+
import org.jboss.weld.junit5.auto.EnableAutoWeld;
29+
import org.junit.jupiter.api.Test;
30+
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
31+
32+
import java.util.Optional;
33+
34+
import static java.util.UUID.randomUUID;
35+
import static org.assertj.core.api.Assertions.assertThat;
36+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
37+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
38+
import static org.eclipse.jnosql.databases.mongodb.communication.DocumentDatabase.INSTANCE;
39+
40+
@EnableAutoWeld
41+
@AddPackages(value = {Convert.class, DocumentEntityConverter.class})
42+
@AddPackages(Book.class)
43+
@AddExtensions({EntityMetadataExtension.class,
44+
DocumentExtension.class})
45+
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
46+
class TemplateIntegrationTest {
47+
48+
@Inject
49+
private DocumentTemplate template;
50+
51+
static {
52+
INSTANCE.get("library");
53+
System.setProperty(MongoDBDocumentConfigurations.HOST.get() + ".1", INSTANCE.host());
54+
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library");
55+
}
56+
57+
@Test
58+
public void shouldInsert() {
59+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
60+
template.insert(book);
61+
Optional<Book> optional = template.find(Book.class, book.id());
62+
assertThat(optional).isNotNull().isNotEmpty()
63+
.get().isEqualTo(book);
64+
}
65+
66+
@Test
67+
public void shouldUpdate() {
68+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
69+
assertThat(template.insert(book))
70+
.isNotNull()
71+
.isEqualTo(book);
72+
73+
Book updated = new Book(book.id(), book.title() + " updated", 2);
74+
75+
assertThat(template.update(updated))
76+
.isNotNull()
77+
.isNotEqualTo(book);
78+
79+
assertThat(template.find(Book.class, book.id()))
80+
.isNotNull().get().isEqualTo(updated);
81+
82+
}
83+
84+
@Test
85+
public void shouldFindById() {
86+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
87+
assertThat(template.insert(book))
88+
.isNotNull()
89+
.isEqualTo(book);
90+
91+
assertThat(template.find(Book.class, book.id()))
92+
.isNotNull().get().isEqualTo(book);
93+
}
94+
95+
@Test
96+
public void shouldDelete() {
97+
Book book = new Book(randomUUID().toString(), "Effective Java", 1);
98+
assertThat(template.insert(book))
99+
.isNotNull()
100+
.isEqualTo(book);
101+
102+
template.delete(Book.class, book.id());
103+
assertThat(template.find(Book.class, book.id()))
104+
.isNotNull().isEmpty();
105+
}
106+
107+
108+
}

0 commit comments

Comments
 (0)