Skip to content

Commit 2378d5f

Browse files
authored
Merge pull request #321 from eclipse-jnosql/BUG-586
Fixes: Byte arrays cannot (always) be decoded from the database
2 parents 529131a + 013766e commit 2378d5f

File tree

7 files changed

+227
-4
lines changed

7 files changed

+227
-4
lines changed

CHANGELOG.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version
88

99
== [Unreleased]
1010

11+
=== Fixed
12+
13+
- Fixes delete all at CouchDB
14+
1115
== [1.1.6] - 2025-03-24
1216

1317
== [1.1.5] - 2025-03-23

jnosql-couchdb/src/main/java/org/eclipse/jnosql/databases/couchdb/communication/CouchdbDeleteQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class CouchdbDeleteQuery implements SelectQuery {
3838

3939
@Override
4040
public long limit() {
41-
return 10;
41+
return 0;
4242
}
4343

4444
@Override

jnosql-couchdb/src/test/java/org/eclipse/jnosql/databases/couchdb/communication/DefaultCouchDBDocumentManagerTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,19 @@ void shouldUpdateNull(){
295295
});
296296
}
297297

298+
@Test
299+
void shouldInsertByteArray() {
300+
CommunicationEntity entity = CommunicationEntity.of("Failure");
301+
entity.add(CouchDBConstant.ID, "id");
302+
entity.add("data", new byte[]{'a','b','c','d'});
303+
var communication = entityManager.insert(entity);
304+
305+
SoftAssertions.assertSoftly(soft -> {
306+
soft.assertThat(communication).isNotNull();
307+
soft.assertThat(communication.find("data").get().get()).isInstanceOf(byte[].class);
308+
});
309+
}
310+
298311
private CommunicationEntity createDocumentList() {
299312
CommunicationEntity entity = CommunicationEntity.of("AppointmentBook");
300313
List<List<Element>> documents = new ArrayList<>();

jnosql-couchdb/src/test/java/org/eclipse/jnosql/databases/couchdb/communication/configuration/DocumentDatabase.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.eclipse.jnosql.databases.couchdb.communication.CouchDBConfigurations;
2222
import org.eclipse.jnosql.databases.couchdb.communication.CouchDBDocumentConfiguration;
2323
import org.eclipse.jnosql.databases.couchdb.communication.CouchDBDocumentManagerFactory;
24+
import org.jetbrains.annotations.NotNull;
2425
import org.testcontainers.containers.GenericContainer;
2526

2627
import java.util.function.Supplier;
@@ -40,10 +41,22 @@ public enum DocumentDatabase implements Supplier<CouchDBDocumentManagerFactory>
4041
public CouchDBDocumentManagerFactory get() {
4142
CouchDBDocumentConfiguration configuration = new CouchDBDocumentConfiguration();
4243
SettingsBuilder builder = Settings.builder();
43-
builder.put(CouchDBConfigurations.PORT, couchDB.getFirstMappedPort());
44-
builder.put(CouchDBConfigurations.USER, "admin");
45-
builder.put(CouchDBConfigurations.PASSWORD, "password");
44+
builder.put(CouchDBConfigurations.PORT, getPort());
45+
builder.put(CouchDBConfigurations.USER, getUser());
46+
builder.put(CouchDBConfigurations.PASSWORD, getPassword());
4647
return configuration.apply(builder.build());
4748
}
4849

50+
public String getPassword() {
51+
return "password";
52+
}
53+
54+
public String getUser() {
55+
return "admin";
56+
}
57+
58+
public Integer getPort() {
59+
return couchDB.getFirstMappedPort();
60+
}
61+
4962
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.couchdb.communication.integration;
16+
17+
import jakarta.nosql.Column;
18+
import jakarta.nosql.Entity;
19+
import jakarta.nosql.Id;
20+
21+
@Entity
22+
public record Failure(
23+
@Id String id,
24+
@Column byte[] data) {
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.couchdb.communication.integration;
16+
17+
import jakarta.nosql.Column;
18+
import jakarta.nosql.Entity;
19+
import jakarta.nosql.Id;
20+
21+
@Entity
22+
public record Magazine(@Id String id, @Column("title") String title, @Column("edition") int edition) {
23+
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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.couchdb.communication.integration;
16+
17+
18+
import jakarta.inject.Inject;
19+
import org.assertj.core.api.SoftAssertions;
20+
import org.eclipse.jnosql.databases.couchdb.communication.CouchDBConfigurations;
21+
import org.eclipse.jnosql.databases.couchdb.communication.configuration.DocumentDatabase;
22+
import org.eclipse.jnosql.mapping.Database;
23+
import org.eclipse.jnosql.mapping.core.Converters;
24+
import org.eclipse.jnosql.mapping.core.config.MappingConfigurations;
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.reflection.spi.ReflectionEntityMetadataExtension;
29+
import org.eclipse.jnosql.mapping.semistructured.EntityConverter;
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.Optional;
38+
39+
import static java.util.UUID.randomUUID;
40+
import static org.assertj.core.api.Assertions.assertThat;
41+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
42+
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
43+
44+
@EnableAutoWeld
45+
@AddPackages(value = {Database.class, EntityConverter.class, DocumentTemplate.class})
46+
@AddPackages(Magazine.class)
47+
@AddPackages(Reflections.class)
48+
@AddPackages(Converters.class)
49+
@AddExtensions({ReflectionEntityMetadataExtension.class,
50+
DocumentExtension.class})
51+
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
52+
class TemplateIntegrationTest {
53+
54+
static {
55+
DocumentDatabase database = DocumentDatabase.INSTANCE;
56+
System.setProperty(CouchDBConfigurations.PORT.get(), database.getPort().toString());
57+
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library");
58+
System.setProperty(CouchDBConfigurations.USER.get(), database.getUser());
59+
System.setProperty(CouchDBConfigurations.PASSWORD.get(), database.getPassword());
60+
}
61+
62+
@Inject
63+
private DocumentTemplate template;
64+
65+
@Test
66+
void shouldFindById() {
67+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1);
68+
assertThat(template.insert(magazine))
69+
.isNotNull()
70+
.isEqualTo(magazine);
71+
72+
assertThat(template.find(Magazine.class, magazine.id()))
73+
.isNotNull().get().isEqualTo(magazine);
74+
}
75+
76+
@Test
77+
void shouldInsert() {
78+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1);
79+
template.insert(magazine);
80+
Optional<Magazine> optional = template.find(Magazine.class, magazine.id());
81+
assertThat(optional).isNotNull().isNotEmpty()
82+
.get().isEqualTo(magazine);
83+
}
84+
85+
@Test
86+
void shouldUpdate() {
87+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1);
88+
assertThat(template.insert(magazine))
89+
.isNotNull()
90+
.isEqualTo(magazine);
91+
92+
Magazine updated = new Magazine(magazine.id(), magazine.title() + " updated", 2);
93+
94+
assertThat(template.update(updated))
95+
.isNotNull()
96+
.isNotEqualTo(magazine);
97+
98+
assertThat(template.find(Magazine.class, magazine.id()))
99+
.isNotNull().get().isEqualTo(updated);
100+
101+
}
102+
103+
@Test
104+
void shouldDeleteById() {
105+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", 1);
106+
assertThat(template.insert(magazine))
107+
.isNotNull()
108+
.isEqualTo(magazine);
109+
110+
template.delete(Magazine.class, magazine.id());
111+
assertThat(template.find(Magazine.class, magazine.id()))
112+
.isNotNull().isEmpty();
113+
}
114+
115+
@Test
116+
void shouldDeleteAll(){
117+
for (int index = 0; index < 20; index++) {
118+
Magazine magazine = new Magazine(randomUUID().toString(), "Effective Java", index);
119+
assertThat(template.insert(magazine))
120+
.isNotNull()
121+
.isEqualTo(magazine);
122+
}
123+
124+
template.delete(Magazine.class).execute();
125+
var magazines = template.select(Magazine.class).result();
126+
assertThat(magazines).isNotNull().isEmpty();
127+
}
128+
129+
@Test
130+
void shouldInsertByteArray() {
131+
var failure = new Failure("test", new byte[]{'a','b','c','d'});
132+
template.insert(failure);
133+
Optional<Failure> entity = template.find(Failure.class, "test");
134+
SoftAssertions.assertSoftly(softly -> {
135+
softly.assertThat(entity).isNotNull().isNotEmpty();
136+
softly.assertThat(entity).map(Failure::id).get().isEqualTo("test");
137+
softly.assertThat(entity).map(Failure::data).get().isEqualTo(failure.data());
138+
});
139+
}
140+
141+
}
142+

0 commit comments

Comments
 (0)