Skip to content

Commit dc47bef

Browse files
Tests: remove hard to maintain external annotation tests
These are a time waste. Rather spend time on adding tests to the Gradle plugin and the integration tests.
1 parent 3952194 commit dc47bef

File tree

11 files changed

+15
-150
lines changed

11 files changed

+15
-150
lines changed

tests/objectbox-java-test/src/main/java/io/objectbox/TestEntity.java

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@
2424
import javax.annotation.Nullable;
2525

2626
import io.objectbox.annotation.Entity;
27-
import io.objectbox.annotation.ExternalPropertyType;
28-
import io.objectbox.annotation.ExternalType;
2927
import io.objectbox.annotation.Id;
3028
import io.objectbox.annotation.Unsigned;
3129

3230
/**
33-
* The annotations in this class have no effect as the Gradle plugin is not configured in this project. However, test
34-
* code builds a model like if the annotations were processed.
31+
* The annotations in this class have no effect as the Gradle plugin is not configured in this project. They are
32+
* informational to help maintain the test code that builds a model for this entity (see AbstractObjectBoxTest).
3533
* <p>
36-
* There is a matching test in the internal integration test project where this is tested and model builder code can be
37-
* "stolen" from.
34+
* To test annotations and correct code generation, add a test in the Gradle plugin project. To test related features
35+
* with a database at runtime, add a test in the internal integration test project.
3836
*/
3937
@Entity
4038
public class TestEntity {
@@ -76,13 +74,6 @@ public class TestEntity {
7674
private float[] floatArray;
7775
private double[] doubleArray;
7876
private Date date;
79-
// Just smoke testing this property type (tests do not use Sync).
80-
// Also use UUID instead of the default MONGO_ID.
81-
@ExternalType(ExternalPropertyType.UUID)
82-
private byte[] externalId;
83-
// Just smoke testing this property type (tests do not use Sync).
84-
@ExternalType(ExternalPropertyType.JSON_TO_NATIVE)
85-
private String externalJsonToNative;
8677

8778
transient boolean noArgsConstructorCalled;
8879

@@ -118,9 +109,7 @@ public TestEntity(long id,
118109
long[] longArray,
119110
float[] floatArray,
120111
double[] doubleArray,
121-
Date date,
122-
byte[] externalId,
123-
String externalJsonToNative
112+
Date date
124113
) {
125114
this.id = id;
126115
this.simpleBoolean = simpleBoolean;
@@ -147,8 +136,6 @@ public TestEntity(long id,
147136
this.floatArray = floatArray;
148137
this.doubleArray = doubleArray;
149138
this.date = date;
150-
this.externalId = externalId;
151-
this.externalJsonToNative = externalJsonToNative;
152139
if (STRING_VALUE_THROW_IN_CONSTRUCTOR.equals(simpleString)) {
153140
throw new RuntimeException(EXCEPTION_IN_CONSTRUCTOR_MESSAGE);
154141
}
@@ -367,24 +354,6 @@ public void setDate(Date date) {
367354
this.date = date;
368355
}
369356

370-
@Nullable
371-
public byte[] getExternalId() {
372-
return externalId;
373-
}
374-
375-
public void setExternalId(@Nullable byte[] externalId) {
376-
this.externalId = externalId;
377-
}
378-
379-
@Nullable
380-
public String getExternalJsonToNative() {
381-
return externalJsonToNative;
382-
}
383-
384-
public void setExternalJsonToNative(@Nullable String externalJsonToNative) {
385-
this.externalJsonToNative = externalJsonToNative;
386-
}
387-
388357
@Override
389358
public String toString() {
390359
return "TestEntity{" +
@@ -413,8 +382,6 @@ public String toString() {
413382
", floatArray=" + Arrays.toString(floatArray) +
414383
", doubleArray=" + Arrays.toString(doubleArray) +
415384
", date=" + date +
416-
", externalId=" + Arrays.toString(externalId) +
417-
", externalJsonToString='" + externalJsonToNative + '\'' +
418385
", noArgsConstructorCalled=" + noArgsConstructorCalled +
419386
'}';
420387
}

tests/objectbox-java-test/src/main/java/io/objectbox/TestEntityCursor.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ public Cursor<TestEntity> createCursor(io.objectbox.Transaction tx, long cursorH
7474
private final static int __ID_floatArray = TestEntity_.floatArray.id;
7575
private final static int __ID_doubleArray = TestEntity_.doubleArray.id;
7676
private final static int __ID_date = TestEntity_.date.id;
77-
private final static int __ID_externalId = TestEntity_.externalId.id;
78-
private final static int __ID_externalJsonToNative = TestEntity_.externalJsonToNative.id;
7977

8078
public TestEntityCursor(io.objectbox.Transaction tx, long cursor, BoxStore boxStore) {
8179
super(tx, cursor, TestEntity_.__INSTANCE, boxStore);
@@ -150,29 +148,25 @@ public long put(TestEntity entity) {
150148

151149
String simpleString = entity.getSimpleString();
152150
int __id8 = simpleString != null ? __ID_simpleString : 0;
153-
String externalJsonToNative = entity.getExternalJsonToNative();
154-
int __id26 = externalJsonToNative != null ? __ID_externalJsonToNative : 0;
155151
byte[] simpleByteArray = entity.getSimpleByteArray();
156152
int __id9 = simpleByteArray != null ? __ID_simpleByteArray : 0;
157-
byte[] externalId = entity.getExternalId();
158-
int __id25 = externalId != null ? __ID_externalId : 0;
159153
Map stringObjectMap = entity.getStringObjectMap();
160154
int __id15 = stringObjectMap != null ? __ID_stringObjectMap : 0;
155+
Object flexProperty = entity.getFlexProperty();
156+
int __id16 = flexProperty != null ? __ID_flexProperty : 0;
161157

162158
collect430000(cursor, 0, 0,
163-
__id8, simpleString, __id26, externalJsonToNative,
159+
__id8, simpleString, 0, null,
164160
0, null, 0, null,
165-
__id9, simpleByteArray, __id25, externalId,
166-
__id15, __id15 != 0 ? stringObjectMapConverter.convertToDatabaseValue(stringObjectMap) : null);
161+
__id9, simpleByteArray, __id15, __id15 != 0 ? stringObjectMapConverter.convertToDatabaseValue(stringObjectMap) : null,
162+
__id16, __id16 != 0 ? flexPropertyConverter.convertToDatabaseValue(flexProperty) : null);
167163

168-
Object flexProperty = entity.getFlexProperty();
169-
int __id16 = flexProperty != null ? __ID_flexProperty : 0;
170164
java.util.Date date = entity.getDate();
171165
int __id24 = date != null ? __ID_date : 0;
172166

173167
collect313311(cursor, 0, 0,
174168
0, null, 0, null,
175-
0, null, __id16, __id16 != 0 ? flexPropertyConverter.convertToDatabaseValue(flexProperty) : null,
169+
0, null, 0, null,
176170
__ID_simpleLong, entity.getSimpleLong(), __ID_simpleLongU, entity.getSimpleLongU(),
177171
__id24, __id24 != 0 ? date.getTime() : 0, INT_NULL_HACK ? 0 : __ID_simpleInt, entity.getSimpleInt(),
178172
__ID_simpleIntU, entity.getSimpleIntU(), __ID_simpleShort, entity.getSimpleShort(),

tests/objectbox-java-test/src/main/java/io/objectbox/TestEntity_.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@ public final class TestEntity_ implements EntityInfo<TestEntity> {
127127
public final static io.objectbox.Property<TestEntity> date =
128128
new io.objectbox.Property<>(__INSTANCE, 24, 24, java.util.Date.class, "date");
129129

130-
public final static io.objectbox.Property<TestEntity> externalId =
131-
new io.objectbox.Property<>(__INSTANCE, 25, 25, byte[].class, "externalId");
132-
133-
public final static io.objectbox.Property<TestEntity> externalJsonToNative =
134-
new io.objectbox.Property<>(__INSTANCE, 26, 27, String.class, "externalJsonToNative");
135-
136130
@SuppressWarnings("unchecked")
137131
public final static io.objectbox.Property<TestEntity>[] __ALL_PROPERTIES = new io.objectbox.Property[]{
138132
id,
@@ -159,9 +153,7 @@ public final class TestEntity_ implements EntityInfo<TestEntity> {
159153
longArray,
160154
floatArray,
161155
doubleArray,
162-
date,
163-
externalId,
164-
externalJsonToNative
156+
date
165157
};
166158

167159
public final static io.objectbox.Property<TestEntity> __ID_PROPERTY = id;

tests/objectbox-java-test/src/main/java/io/objectbox/relation/Customer.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import io.objectbox.BoxStore;
2323
import io.objectbox.annotation.Backlink;
2424
import io.objectbox.annotation.Entity;
25-
import io.objectbox.annotation.ExternalPropertyType;
26-
import io.objectbox.annotation.ExternalType;
2725
import io.objectbox.annotation.Id;
2826
import io.objectbox.annotation.Index;
2927

@@ -53,10 +51,6 @@ public class Customer implements Serializable {
5351

5452
ToMany<Order> ordersStandalone = new ToMany<>(this, Customer_.ordersStandalone);
5553

56-
// Just smoke testing, also use UUID instead of the default Mongo ID
57-
@ExternalType(ExternalPropertyType.UUID_VECTOR)
58-
private ToMany<Order> toManyExternalId = new ToMany<>(this, Customer_.toManyExternalId);
59-
6054
// Note: in a typical project the BoxStore field is added by the ObjectBox byte code transformer
6155
// https://docs.objectbox.io/relations#initialization-magic
6256
transient BoxStore __boxStore;
@@ -93,7 +87,4 @@ public ToMany<Order> getOrdersStandalone() {
9387
return ordersStandalone;
9488
}
9589

96-
public ToMany<Order> getToManyExternalId() {
97-
return toManyExternalId;
98-
}
9990
}

tests/objectbox-java-test/src/main/java/io/objectbox/relation/CustomerCursor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public long put(Customer entity) {
7171

7272
checkApplyToManyToDb(entity.getOrders(), Order.class);
7373
checkApplyToManyToDb(entity.getOrdersStandalone(), Order.class);
74-
checkApplyToManyToDb(entity.getToManyExternalId(), Order.class);
7574

7675
return __assignedId;
7776
}

tests/objectbox-java-test/src/main/java/io/objectbox/relation/Customer_.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,4 @@ public List<Order> getToMany(Customer customer) {
129129
}
130130
}, 1);
131131

132-
/** To-many relation "toManyExternalId" to target entity "Order". */
133-
public static final RelationInfo<Customer, Order> toManyExternalId = new RelationInfo<>(Customer_.__INSTANCE, Order_.__INSTANCE,
134-
new ToManyGetter<Customer, Order>() {
135-
@Override
136-
public List<Order> getToMany(Customer entity) {
137-
return entity.getToManyExternalId();
138-
}
139-
},
140-
2);
141-
142132
}

tests/objectbox-java-test/src/main/java/io/objectbox/relation/MyObjectBox.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import io.objectbox.BoxStoreBuilder;
2121
import io.objectbox.ModelBuilder;
2222
import io.objectbox.ModelBuilder.EntityBuilder;
23-
import io.objectbox.model.ExternalPropertyType;
2423
import io.objectbox.model.PropertyFlags;
2524
import io.objectbox.model.PropertyType;
2625

@@ -46,7 +45,7 @@ private static byte[] getModel() {
4645
ModelBuilder modelBuilder = new ModelBuilder();
4746
modelBuilder.lastEntityId(4, 5318696586219463633L);
4847
modelBuilder.lastIndexId(2, 8919874872236271392L);
49-
modelBuilder.lastRelationId(2, 297832184913930702L);
48+
modelBuilder.lastRelationId(1, 8943758920347589435L);
5049

5150
EntityBuilder entityBuilder = modelBuilder.entity("Customer");
5251
entityBuilder.id(1, 8247662514375611729L).lastPropertyId(2, 7412962174183812632L);
@@ -57,11 +56,6 @@ private static byte[] getModel() {
5756

5857
entityBuilder.relation("ordersStandalone", 1, 8943758920347589435L, 3, 6367118380491771428L);
5958

60-
// Note: there is no way to test external type mapping works here. Instead, verify passing a model with
61-
// externalType(int) works.
62-
entityBuilder.relation("toManyExternalId", 2, 297832184913930702L, 3, 6367118380491771428L)
63-
.externalType(ExternalPropertyType.UuidVector);
64-
6559
entityBuilder.entityDone();
6660

6761

tests/objectbox-java-test/src/test/java/io/objectbox/AbstractObjectBoxTest.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import io.objectbox.ModelBuilder.PropertyBuilder;
4343
import io.objectbox.annotation.IndexType;
4444
import io.objectbox.config.DebugFlags;
45-
import io.objectbox.model.ExternalPropertyType;
4645
import io.objectbox.model.PropertyFlags;
4746
import io.objectbox.model.PropertyType;
4847
import io.objectbox.query.InternalAccess;
@@ -307,15 +306,7 @@ private void addTestEntity(ModelBuilder modelBuilder, @Nullable IndexType simple
307306

308307
// Date property
309308
entityBuilder.property("date", PropertyType.Date).id(TestEntity_.date.id, ++lastUid);
310-
311-
// External type property
312-
// Note: there is no way to test external type mapping works here. Instead, verify passing a model with
313-
// externalType(int) works.
314-
entityBuilder.property("externalId", PropertyType.ByteVector).id(TestEntity_.externalId.id, ++lastUid)
315-
.externalType(ExternalPropertyType.Uuid);
316-
int lastId = TestEntity_.externalJsonToNative.id;
317-
entityBuilder.property("externalJsonToNative", PropertyType.String).id(lastId, ++lastUid)
318-
.externalType(ExternalPropertyType.JsonToNative);
309+
int lastId = TestEntity_.date.id;
319310

320311
entityBuilder.lastPropertyId(lastId, lastUid);
321312
addOptionalFlagsToTestEntity(entityBuilder);
@@ -378,10 +369,6 @@ protected TestEntity createTestEntity(@Nullable String simpleString, int nr) {
378369
entity.setFloatArray(new float[]{-simpleFloat, simpleFloat});
379370
entity.setDoubleArray(new double[]{-simpleDouble, simpleDouble});
380371
entity.setDate(new Date(simpleLong));
381-
// Note: there is no way to test external type mapping works here. Instead, verify that
382-
// there are no side effects for put and get.
383-
entity.setExternalId(simpleByteArray);
384-
entity.setExternalJsonToNative("{\"simpleString\":\"" + simpleString + "\"}");
385372
return entity;
386373
}
387374

tests/objectbox-java-test/src/test/java/io/objectbox/BoxStoreBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public void maxDataSize() {
302302
DbMaxDataSizeExceededException.class,
303303
() -> getTestEntityBox().put(testEntity2)
304304
);
305-
assertEquals("Exceeded user-set maximum by [bytes]: 768", maxDataExc.getMessage());
305+
assertEquals("Exceeded user-set maximum by [bytes]: 560", maxDataExc.getMessage());
306306

307307
// Remove to get below max data size, then put again.
308308
getTestEntityBox().remove(testEntity1);

tests/objectbox-java-test/src/test/java/io/objectbox/BoxTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ public void testPutAndGet() {
8989
assertArrayEquals(new float[]{-valFloat, valFloat}, entityRead.getFloatArray(), 0);
9090
assertArrayEquals(new double[]{-valDouble, valDouble}, entity.getDoubleArray(), 0);
9191
assertEquals(new Date(1000 + simpleInt), entity.getDate());
92-
assertArrayEquals(valByteArray, entity.getExternalId());
93-
assertEquals("{\"simpleString\":\"" + simpleString + "\"}", entity.getExternalJsonToNative());
9492
}
9593

9694
@Test
@@ -122,8 +120,6 @@ public void testPutAndGet_defaultOrNullValues() {
122120
assertNull(defaultEntity.getFloatArray());
123121
assertNull(defaultEntity.getDoubleArray());
124122
assertNull(defaultEntity.getDate());
125-
assertNull(defaultEntity.getExternalId());
126-
assertNull(defaultEntity.getExternalJsonToNative());
127123
}
128124

129125
// Note: There is a similar test using the Cursor API directly (which is deprecated) in CursorTest.

0 commit comments

Comments
 (0)