Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMWK-284 Integration test for reading data written with Aerospike Java client #676

Merged
merged 9 commits into from
Dec 18, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public interface AerospikeOperations {
/**
* Find a record by id, set name will be determined by the given entityClass.
* <p>
* The resulting The record will be mapped to the given entityClass.
* The matching record will be mapped to the given entityClass.
*
* @param id The id of the record to find. Must not be {@literal null}.
* @param entityClass The class to extract set name from and to map the record to. Must not be
Expand All @@ -593,7 +593,7 @@ public interface AerospikeOperations {
/**
* Find a record by id within the given set.
* <p>
* The record will be mapped to the given entityClass.
* The matching record will be mapped to the given entityClass.
*
* @param id The id of the record to find. Must not be {@literal null}.
* @param entityClass The class to map the record to and to get entity properties from (such as expiration). Must not
Expand All @@ -606,7 +606,7 @@ public interface AerospikeOperations {
/**
* Find a record by id, set name will be determined by the given entityClass.
* <p>
* The record will be mapped to the given entityClass.
* The matching record will be mapped to the given entityClass.
*
* @param id The id of the record to find. Must not be {@literal null}.
* @param entityClass The class to extract set name from. Must not be {@literal null}.
Expand All @@ -619,7 +619,7 @@ public interface AerospikeOperations {
/**
* Find a record by id within the given set.
* <p>
* The record will be mapped to the given entityClass.
* The matching record will be mapped to the given entityClass.
*
* @param id The id of the record to find. Must not be {@literal null}.
* @param entityClass The class to get entity properties from (such as expiration). Must not be {@literal null}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public interface ReactiveAerospikeOperations {
/**
* Reactively find a record by id, set name will be determined by the given entityClass.
* <p>
* The record will be mapped to the given entityClass.
* The matching record will be mapped to the given entityClass.
*
* @param id The id of the record to find. Must not be {@literal null}.
* @param entityClass The class to extract set name from and to map the document to. Must not be
Expand All @@ -574,7 +574,7 @@ public interface ReactiveAerospikeOperations {
/**
* Reactively find a record by id within the given set.
* <p>
* The record will be mapped to the given entityClass.
* The matching record will be mapped to the given entityClass.
*
* @param id The id of the record to find. Must not be {@literal null}.
* @param entityClass The class to map the record to and to get entity properties from (such expiration). Must not
Expand All @@ -587,7 +587,7 @@ public interface ReactiveAerospikeOperations {
/**
* Reactively find a record by id, set name will be determined by the given entityClass.
* <p>
* The record will be mapped to the given targetClass.
* The matching record will be mapped to the given targetClass.
*
* @param id The id of the record to find. Must not be {@literal null}.
* @param entityClass The class to extract set name from. Must not be {@literal null}.
Expand All @@ -599,7 +599,7 @@ public interface ReactiveAerospikeOperations {
/**
* Reactively find a record by id within the given set.
* <p>
* The record will be mapped to the given targetClass.
* The matching record will be mapped to the given targetClass.
*
* @param id The id of the record to find. Must not be {@literal null}.
* @param entityClass The class to map the record to and to get entity properties from (such expiration). Must not
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.springframework.data.aerospike.convert;

import com.aerospike.client.Bin;
import com.aerospike.client.Key;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.BaseBlockingIntegrationTests;
import org.springframework.data.aerospike.sample.Address;
import org.springframework.data.annotation.Id;

import java.util.List;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

class AerospikeReadDataIntegrationTests extends BaseBlockingIntegrationTests {

long longId = 10L;
String name = "John";
int age = 74;
Map<Integer, String> map = Map.of(10, "100");
Address address = new Address("Street", 20, "ZipCode", "City");
Map<String, Object> addressMap = Map.of(
"street", address.getStreet(),
"apartment", address.getApartment(),
"zipCode", address.getZipCode(),
"city", address.getCity());

@AllArgsConstructor
@Getter
static class User {

@Id
long id;
String name;
int age;
Map<Integer, String> map;
Address address;
}

@Test
void readDocumentWithLongId() {
template.getAerospikeClient().put(null,
new Key(namespace, template.getSetName(User.class), longId),
new Bin("name", name),
new Bin("age", 74),
new Bin("map", map),
new Bin("address", addressMap)
);
// we can read the record into a User document because its class is given
List<User> users = template.findAll(User.class).toList();
User user;
if (template.getAerospikeConverter().getAerospikeDataSettings().isKeepOriginalKeyTypes()) {
// we need isKeepOriginalKeyTypes == true because id is of type long, otherwise findById() returns null
// isKeepOriginalKeyTypes parameter would be unimportant if id were of type String
user = template.findById(longId, User.class);
assertThat(users.get(0).getId()).isEqualTo(user.getId());
assertThat(users.get(0).getName()).isEqualTo(user.getName());
} else {
user = users.get(0);
}
assertThat(user.getId()).isEqualTo(longId);
assertThat(user.getName()).isEqualTo(name);
assertThat(user.getAge()).isEqualTo(age);
assertThat(user.getMap()).isEqualTo(map);
assertThat(user.getAddress()).isEqualTo(address);
}

@AllArgsConstructor
@Getter
static class Document {

@Id
String id;
int number;
}

@Test
void readLongIdAsString() {
template.getAerospikeClient().put(null,
new Key(namespace, template.getSetName(Document.class), longId),
new Bin("number", age)
);
// we can read the record into a Document because its class is given
List<Document> users = template.findAll(Document.class).toList();
Document document;
if (template.getAerospikeConverter().getAerospikeDataSettings().isKeepOriginalKeyTypes()) {
// original id has type long
document = template.findById(longId, Document.class);
assertThat(users.get(0).getId()).isEqualTo(document.getId());
assertThat(users.get(0).getNumber()).isEqualTo(document.getNumber());
} else {
document = users.get(0);
}
assertThat(document.getId()).isEqualTo(String.valueOf(longId));
assertThat(document.getNumber()).isEqualTo(age);
}
}
Loading