Skip to content

Commit cebd15a

Browse files
committed
add Boolean mapper test cases
1 parent 44ca176 commit cebd15a

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.aerospike.mapper;
2+
3+
import com.aerospike.client.Key;
4+
import com.aerospike.client.Record;
5+
import com.aerospike.client.policy.Policy;
6+
import com.aerospike.mapper.annotations.AerospikeKey;
7+
import com.aerospike.mapper.annotations.AerospikeRecord;
8+
import com.aerospike.mapper.tools.AeroMapper;
9+
import com.fasterxml.jackson.core.JsonProcessingException;
10+
import org.junit.jupiter.api.Test;
11+
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
import static com.aerospike.client.Value.UseBoolBin;
14+
15+
public class BooleanTest extends AeroMapperBaseTest {
16+
@AerospikeRecord(namespace = "test", set = "B")
17+
public static class B {
18+
@AerospikeKey
19+
public int id;
20+
public Boolean boolValue;
21+
}
22+
23+
@Test
24+
public void testNumericEncoding() throws JsonProcessingException {
25+
UseBoolBin = false;
26+
27+
B b = new B();
28+
b.boolValue = true;
29+
b.id = 1;
30+
String config =
31+
"---\n" +
32+
"classes:\n" +
33+
" - class: com.aerospike.mapper.BooleanTest$B\n" +
34+
" namespace: test\n" +
35+
" set: B\n" +
36+
" key:\n" +
37+
" field: id\n";
38+
39+
AeroMapper mapper = new AeroMapper.Builder(client).withConfiguration(config).build();
40+
mapper.save(b);
41+
42+
B b2 = mapper.read(B.class, 1);
43+
44+
assertEquals(b.id, b2.id);
45+
assertEquals(b.boolValue, b2.boolValue);
46+
final Record rec = mapper.getClient().get(new Policy(), new Key("test", "B", 1));
47+
final Object rawRepresentation = rec.bins.get("boolValue");
48+
49+
assertEquals(Long.class, rawRepresentation.getClass());
50+
}
51+
52+
@Test
53+
public void testObjectEncoding() throws JsonProcessingException {
54+
UseBoolBin = true;
55+
56+
B b = new B();
57+
b.boolValue = true;
58+
b.id = 1;
59+
String config =
60+
"---\n" +
61+
"classes:\n" +
62+
" - class: com.aerospike.mapper.BooleanTest$B\n" +
63+
" namespace: test\n" +
64+
" set: B\n" +
65+
" key:\n" +
66+
" field: id\n";
67+
68+
AeroMapper mapper = new AeroMapper.Builder(client).withConfiguration(config).build();
69+
mapper.save(b);
70+
71+
B b2 = mapper.read(B.class, 1);
72+
73+
assertEquals(b.id, b2.id);
74+
assertEquals(b.boolValue, b2.boolValue);
75+
final Record rec = mapper.getClient().get(new Policy(), new Key("test", "B", 1));
76+
final Object rawRepresentation = rec.bins.get("boolValue");
77+
assertEquals(Boolean.class, rawRepresentation.getClass());
78+
}
79+
80+
@Test
81+
public void testObjectByDefault() throws JsonProcessingException {
82+
B b = new B();
83+
b.boolValue = true;
84+
b.id = 1;
85+
String config =
86+
"---\n" +
87+
"classes:\n" +
88+
" - class: com.aerospike.mapper.BooleanTest$B\n" +
89+
" namespace: test\n" +
90+
" set: B\n" +
91+
" key:\n" +
92+
" field: id\n";
93+
94+
AeroMapper mapper = new AeroMapper.Builder(client).withConfiguration(config).build();
95+
mapper.save(b);
96+
97+
B b2 = mapper.read(B.class, 1);
98+
99+
assertEquals(b.id, b2.id);
100+
assertEquals(b.boolValue, b2.boolValue);
101+
final Record rec = mapper.getClient().get(new Policy(), new Key("test", "B", 1));
102+
final Object rawRepresentation = rec.bins.get("boolValue");
103+
assertEquals(Boolean.class, rawRepresentation.getClass());
104+
}
105+
106+
}

0 commit comments

Comments
 (0)