Skip to content

Commit

Permalink
add a test for reading records written with Aerospike Java client
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Dec 12, 2023
1 parent 25316d6 commit 4738541
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 8 deletions.
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,64 @@
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;

public class AerospikeReadDataIntegrationTest extends BaseBlockingIntegrationTests {

long longId = 10L;
String setName = "testSetName";
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", 20, "zipCode", "ZipCode", "city", "City");

@AllArgsConstructor
@Getter
static class User {
@Id
long id;
String name;
int age;
Map<Integer, String> map;
Address address;
}

@Test
public void readLongId() {
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()) {
// the matching key is calculated if isKeepOriginalKeyTypes == true, otherwise returns null
user = template.findById(longId, User.class);
assertThat(users.get(0).getId() == (user.getId())).isTrue();
assertThat(users.get(0).getName().equals(user.getName())).isTrue();
} else {
user = users.get(0);
}
assertThat(user.getId() == longId).isTrue();
assertThat(user.getName().equals(name)).isTrue();
assertThat(user.getAge() == (age)).isTrue();
assertThat(user.getMap().equals(map)).isTrue();
assertThat(user.getAddress().equals(address)).isTrue();
}
}

0 comments on commit 4738541

Please sign in to comment.