2323import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
2424
2525import static junit .framework .TestCase .assertEquals ;
26+ import static junit .framework .TestCase .assertTrue ;
2627import static junit .framework .TestCase .fail ;
2728
2829/**
@@ -101,12 +102,11 @@ public void testCompositeEntityWithShardKey() {
101102 public void testCompositeEntityWithNoShardKey () {
102103 Class <?> domainClass = CompositeEntityWithNoShardKey .class ;
103104 try {
104- NosqlEntityInformation <?, ?> entityInformation =
105- template .getNosqlEntityInformation (domainClass );
106- template .createTableIfNotExists (entityInformation );
105+ template .getNosqlEntityInformation (domainClass );
107106 fail ("Expecting IllegalArgumentException but didn't get" );
108- } catch (IllegalArgumentException ignored ) {
109-
107+ } catch (IllegalArgumentException iae ) {
108+ assertTrue (iae .getMessage ().contains (
109+ "At least one of the @NosqlKey must be shard key" ));
110110 }
111111 }
112112
@@ -133,35 +133,36 @@ public void testCompositeEntityWithOrder() {
133133 public void testCompositeEntityWithMultipleKeys () {
134134 Class <?> domainClass = CompositeEntityWithMultipleKeys .class ;
135135 try {
136- NosqlEntityInformation <?, ?> entityInformation =
137- template .getNosqlEntityInformation (domainClass );
136+ template .getNosqlEntityInformation (domainClass );
138137 fail ("Expecting IllegalArgumentException but didn't get" );
139- } catch (IllegalArgumentException ignored ) {
140-
138+ } catch (IllegalArgumentException iae ) {
139+ assertTrue (iae .getMessage ().contains (
140+ "Order of non shard keys must be greater than all the" +
141+ " shard keys" ));
141142 }
142143 }
143144
144145 @ Test
145146 public void testCompositeEntityWithRepeatingOrder () {
146147 Class <?> domainClass = CompositeEntityWithRepeatingOrder .class ;
147148 try {
148- NosqlEntityInformation <?, ?> entityInformation =
149- template .getNosqlEntityInformation (domainClass );
149+ template .getNosqlEntityInformation (domainClass );
150150 fail ("Expecting IllegalArgumentException but didn't get" );
151- } catch (IllegalArgumentException ignored ) {
152-
151+ } catch (IllegalArgumentException iae ) {
152+ assertTrue (iae .getMessage ().contains ("Order of keys must be " +
153+ "unique" ));
153154 }
154155 }
155156
156157 @ Test
157158 public void testCompositeEntityWithMissingOrder () {
158159 Class <?> domainClass = CompositeEntityWithMissingOrder .class ;
159160 try {
160- NosqlEntityInformation <?, ?> entityInformation =
161- template .getNosqlEntityInformation (domainClass );
161+ template .getNosqlEntityInformation (domainClass );
162162 fail ("Expecting IllegalArgumentException but didn't get" );
163- } catch (IllegalArgumentException ignored ) {
164-
163+ } catch (IllegalArgumentException iae ) {
164+ assertTrue (iae .getMessage ().contains (
165+ "If order is specified, it must be specified on all key" ));
165166 }
166167 }
167168
@@ -173,8 +174,9 @@ public void testCompositeEntityWithMissingNonShardOrder() {
173174 template .getNosqlEntityInformation (domainClass );
174175 template .createTableIfNotExists (entityInformation );
175176 fail ("Expecting IllegalArgumentException but didn't get" );
176- } catch (IllegalArgumentException ignored ) {
177-
177+ } catch (IllegalArgumentException iae ) {
178+ assertTrue (iae .getMessage ().contains (
179+ "If order is specified, it must be specified on all key" ));
178180 }
179181 }
180182
@@ -218,24 +220,26 @@ public void testCompositeEntityCaseInsensitive() {
218220
219221 @ Test
220222 public void testCompositeKeyCollision () {
221- //shard and non shard key collision
223+ // shard and non shard key collision
222224 Class <?> domainClass = CompositeEntityFieldCollision .class ;
223225 try {
224226 template .getNosqlEntityInformation (domainClass );
225227 fail ("Expecting IllegalArgumentException but didn't get" );
226- } catch (IllegalArgumentException ignored ) {
227-
228+ } catch (IllegalArgumentException iae ) {
229+ assertTrue ( iae . getMessage (). contains ( "Conflicting name" ));
228230 }
229231 }
230232
231233 @ Test
232234 public void testCompositeEntityKvJsonField () {
233- //shard and non shard key collision
235+ // shard and non shard key collision
234236 Class <?> domainClass = CompositeEntityKvJsonField .class ;
235237 try {
236238 template .getNosqlEntityInformation (domainClass );
237239 fail ("Expecting IllegalArgumentException but didn't get" );
238- } catch (IllegalArgumentException ignored ) {
240+ } catch (IllegalArgumentException iae ) {
241+ assertTrue (iae .getMessage ().contains (
242+ "composite key can not be named 'kv_json_'" ));
239243 }
240244 }
241245
@@ -253,7 +257,9 @@ public void testTableDDLMismatchOrderOfShardKeys() {
253257 template .getNosqlClient ().doTableRequest (tableRequest , 10000 , 2000 );
254258 template .createTableIfNotExists (template .getNosqlEntityInformation (domainClass ));
255259 fail ("Expecting IllegalArgumentException but didn't get" );
256- } catch (IllegalArgumentException ignored ) {
260+ } catch (IllegalArgumentException iae ) {
261+ assertTrue (iae .getMessage ().contains ("Shard primary keys " +
262+ "mismatch" ));
257263 template .dropTableIfExists (domainClass .getSimpleName ());
258264 }
259265 }
@@ -273,7 +279,9 @@ public void testTableDDLMismatchOrderOfNonShardKeys() {
273279 template .getNosqlClient ().doTableRequest (tableRequest , 10000 , 2000 );
274280 template .createTableIfNotExists (template .getNosqlEntityInformation (domainClass ));
275281 fail ("Expecting IllegalArgumentException but didn't get" );
276- } catch (IllegalArgumentException ignored ) {
282+ } catch (IllegalArgumentException iae ) {
283+ assertTrue (iae .getMessage ().contains ("Non-shard primary keys " +
284+ "mismatch" ));
277285 template .dropTableIfExists (domainClass .getSimpleName ());
278286 }
279287 }
@@ -292,7 +300,9 @@ public void testTableDDLMismatchTypeOfShardKey() {
292300 template .getNosqlClient ().doTableRequest (tableRequest , 10000 , 2000 );
293301 template .createTableIfNotExists (template .getNosqlEntityInformation (domainClass ));
294302 fail ("Expecting IllegalArgumentException but didn't get" );
295- } catch (IllegalArgumentException ignored ) {
303+ } catch (IllegalArgumentException iae ) {
304+ assertTrue (iae .getMessage ().contains ("Shard primary keys " +
305+ "mismatch" ));
296306 template .dropTableIfExists (domainClass .getSimpleName ());
297307 }
298308 }
@@ -313,7 +323,9 @@ public void testTableDDLMismatchTypeOfNonShardKey() {
313323 template .getNosqlClient ().doTableRequest (tableRequest , 10000 , 2000 );
314324 template .createTableIfNotExists (template .getNosqlEntityInformation (domainClass ));
315325 fail ("Expecting IllegalArgumentException but didn't get" );
316- } catch (IllegalArgumentException ignored ) {
326+ } catch (IllegalArgumentException iae ) {
327+ assertTrue (iae .getMessage ().contains (
328+ "Non-shard primary keys mismatch" ));
317329 template .dropTableIfExists (domainClass .getSimpleName ());
318330 }
319331 }
@@ -332,7 +344,9 @@ public void testTableMismatchDifferentColumn() {
332344 template .getNosqlClient ().doTableRequest (tableRequest , 10000 , 2000 );
333345 template .createTableIfNotExists (template .getNosqlEntityInformation (domainClass ));
334346 fail ("Expecting IllegalArgumentException but didn't get" );
335- } catch (IllegalArgumentException ignored ) {
347+ } catch (IllegalArgumentException iae ) {
348+ assertTrue (iae .getMessage ().contains ("Shard primary keys " +
349+ "mismatch" ));
336350 template .dropTableIfExists (domainClass .getSimpleName ());
337351 }
338352 }
@@ -350,7 +364,9 @@ public void testTableMismatchMissingColumn() {
350364 template .getNosqlClient ().doTableRequest (tableRequest , 10000 , 2000 );
351365 template .createTableIfNotExists (template .getNosqlEntityInformation (domainClass ));
352366 fail ("Expecting IllegalArgumentException but didn't get" );
353- } catch (IllegalArgumentException ignored ) {
367+ } catch (IllegalArgumentException iae ) {
368+ assertTrue (iae .getMessage ().contains ("Shard primary keys " +
369+ "mismatch" ));
354370 template .dropTableIfExists (domainClass .getSimpleName ());
355371 }
356372 }
@@ -369,7 +385,11 @@ public void testTableMismatchMissingJson() {
369385 template .getNosqlClient ().doTableRequest (tableRequest , 10000 , 2000 );
370386 template .createTableIfNotExists (template .getNosqlEntityInformation (domainClass ));
371387 fail ("Expecting IllegalArgumentException but didn't get" );
372- } catch (IllegalArgumentException ignored ) {
388+ } catch (IllegalArgumentException iae ) {
389+ assertTrue (iae .getMessage ().contains ("Shard primary keys " +
390+ "mismatch" ));
391+ assertTrue (iae .getMessage ().contains ("Non-primary key columns " +
392+ "mismatch" ));
373393 template .dropTableIfExists (domainClass .getSimpleName ());
374394 }
375395 }
@@ -382,13 +402,41 @@ public void testTableMismatchMissingJsonType() {
382402 "KV_json_ LONG, PRIMARY KEY(ID1,ID2))" ,
383403 domainClass .getSimpleName ());
384404 tableRequest .setStatement (ddl );
385- tableRequest .setTableLimits (new TableLimits (100 ,100 ,1 ));
405+ tableRequest .setTableLimits (new TableLimits (100 , 100 , 1 ));
386406 try {
387407 template .dropTableIfExists (domainClass .getSimpleName ());
388408 template .getNosqlClient ().doTableRequest (tableRequest , 10000 , 2000 );
389409 template .createTableIfNotExists (template .getNosqlEntityInformation (domainClass ));
390410 fail ("Expecting IllegalArgumentException but didn't get" );
391- } catch (IllegalArgumentException ignored ) {
411+ } catch (IllegalArgumentException iae ) {
412+ assertTrue (iae .getMessage ().contains ("Non-primary key columns " +
413+ "mismatch" ));
414+ template .dropTableIfExists (domainClass .getSimpleName ());
415+ }
416+ }
417+
418+ @ Test
419+ public void testTableMismatchAll () {
420+ Class <?> domainClass = MismatchEntity .class ;
421+ TableRequest tableRequest = new TableRequest ();
422+ String ddl = String .format ("CREATE TABLE %s (id1 STRING, id2 STRING, " +
423+ "KV_json_ LONG, age integer, PRIMARY KEY(SHARD(ID1)," +
424+ "ID2))" ,
425+ domainClass .getSimpleName ());
426+ tableRequest .setStatement (ddl );
427+ tableRequest .setTableLimits (new TableLimits (100 , 100 , 1 ));
428+ try {
429+ template .dropTableIfExists (domainClass .getSimpleName ());
430+ template .getNosqlClient ().doTableRequest (tableRequest , 10000 , 2000 );
431+ template .createTableIfNotExists (template .getNosqlEntityInformation (domainClass ));
432+ fail ("Expecting IllegalArgumentException but didn't get" );
433+ } catch (IllegalArgumentException iae ) {
434+ assertTrue (iae .getMessage ().contains ("Shard primary keys " +
435+ "mismatch" ));
436+ assertTrue (iae .getMessage ().contains ("Non-shard primary keys " +
437+ "mismatch" ));
438+ assertTrue (iae .getMessage ().contains ("Non-primary key columns " +
439+ "mismatch" ));
392440 template .dropTableIfExists (domainClass .getSimpleName ());
393441 }
394442 }
@@ -408,7 +456,9 @@ public void testTableMismatchIdentity() {
408456 template .getNosqlClient ().doTableRequest (tableRequest , 10000 , 2000 );
409457 template .createTableIfNotExists (template .getNosqlEntityInformation (domainClass ));
410458 fail ("Expecting IllegalArgumentException but didn't get" );
411- } catch (IllegalArgumentException ignored ) {
459+ } catch (IllegalArgumentException iae ) {
460+ assertTrue (iae .getMessage ().contains ("Identity information " +
461+ "mismatch" ));
412462 template .dropTableIfExists (domainClass .getSimpleName ());
413463 }
414464 }
@@ -428,7 +478,9 @@ public void testTableMismatchIdentity1() {
428478 template .getNosqlClient ().doTableRequest (tableRequest , 10000 , 2000 );
429479 template .createTableIfNotExists (template .getNosqlEntityInformation (domainClass ));
430480 fail ("Expecting IllegalArgumentException but didn't get" );
431- } catch (IllegalArgumentException ignored ) {
481+ } catch (IllegalArgumentException iae ) {
482+ assertTrue (iae .getMessage ().contains ("Identity information " +
483+ "mismatch" ));
432484 template .dropTableIfExists (domainClass .getSimpleName ());
433485 }
434486 }
@@ -751,4 +803,19 @@ public static class TTLEntity1 {
751803 @ NosqlId (generated = true )
752804 private int id ;
753805 }
806+
807+ @ NosqlTable
808+ public static class MismatchEntity {
809+ @ NosqlId
810+ private MismatchKey id ;
811+ }
812+
813+ public static class MismatchKey {
814+ @ NosqlKey (shardKey = true , order = 0 )
815+ private int i ;
816+ @ NosqlKey (shardKey = true , order = 1 )
817+ private int j ;
818+ @ NosqlKey (shardKey = false , order = 3 )
819+ private int k ;
820+ }
754821}
0 commit comments