Skip to content

Commit 62c79fc

Browse files
Ajit GeorgeAjit George
authored andcommitted
New test methods
1 parent 73c5bb2 commit 62c79fc

File tree

1 file changed

+141
-12
lines changed

1 file changed

+141
-12
lines changed

test-complete/src/test/java/com/marklogic/javaclient/TestAutomatedPathRangeIndex.java

Lines changed: 141 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
import org.junit.BeforeClass;
1919
import org.junit.Test;
2020

21+
import com.fasterxml.jackson.core.JsonParser;
2122
import com.fasterxml.jackson.databind.JsonNode;
2223
import com.fasterxml.jackson.databind.ObjectMapper;
2324
import com.marklogic.client.DatabaseClient;
2425
import com.marklogic.client.DatabaseClientFactory;
2526
import com.marklogic.client.DatabaseClientFactory.Authentication;
27+
import com.marklogic.client.pojo.annotation.PathIndexProperty;
28+
import com.marklogic.client.pojo.annotation.PathIndexProperty.ScalarType;
2629
import com.marklogic.client.pojo.util.GenerateIndexConfig;
2730

2831
/*
@@ -33,6 +36,7 @@
3336
* daytimeduration* - This needs Java SE 8. Not tested in this class
3437
* URI
3538
* Numerals as Strings*
39+
*
3640
*/
3741

3842
public class TestAutomatedPathRangeIndex extends BasicJavaClientREST {
@@ -42,7 +46,7 @@ public class TestAutomatedPathRangeIndex extends BasicJavaClientREST {
4246

4347
private static int restPort = 8011;
4448
private DatabaseClient client;
45-
49+
4650
/*
4751
* This class is similar to the Artifact class. It is used to test path
4852
* range index using the name field which has been annotated with @Id also.
@@ -57,8 +61,8 @@ public static void setUpBeforeClass() throws Exception {
5761

5862
@AfterClass
5963
public static void tearDownAfterClass() throws Exception {
60-
System.out.println("In tear down");
61-
//tearDownJavaRESTServer(dbName, fNames, restServerName);
64+
System.out.println("In tear down");
65+
tearDownJavaRESTServer(dbName, fNames, restServerName);
6266
}
6367

6468
@Before
@@ -72,13 +76,13 @@ public void tearDown() throws Exception {
7276
//release client
7377
client.release();
7478
}
75-
79+
7680
/*
7781
* This Method takes the property name and value strings and verifies if
7882
* propName exist and then extracts it from the response.
7983
* The propValue string needs to be available in the extracted JsonNode's path-expression property.
8084
*/
81-
public static void validateRangePathIndexInDatabase(String dbName, String propName, String propValue) throws IOException {
85+
public static void validateRangePathIndexInDatabase(String propName, String propValue) throws IOException {
8286
InputStream jsonstream = null;
8387
boolean propFound = false;
8488
String propertyAvailable = null;
@@ -123,7 +127,7 @@ public static void validateRangePathIndexInDatabase(String dbName, String propNa
123127
* propName exist and then extracts it from the response.
124128
* The propValue string needs to be available in the extracted JsonNode's path-expression property.
125129
*/
126-
public static void validateMultipleRangePathIndexInDatabase(String dbName, String propName, String[] propValue) throws IOException {
130+
public static void validateMultipleRangePathIndexInDatabase(String propName, String[] propValue) throws IOException {
127131
InputStream jsonstream = null;
128132
boolean propFound = false;
129133
String propertyAvailable1 = null;
@@ -188,7 +192,7 @@ public void testArtifactIndexedOnInt() throws Exception {
188192
if (!jnode.isNull()) {
189193
setPathRangeIndexInDatabase(dbName, jnode);
190194
succeeded = true;
191-
validateRangePathIndexInDatabase(dbName, "range-path-index", "com.marklogic.javaclient.ArtifactIndexedOnInt/inventory");
195+
validateRangePathIndexInDatabase("range-path-index", "com.marklogic.javaclient.ArtifactIndexedOnInt/inventory");
192196
} else {
193197
assertTrue(
194198
"testArtifactIndexedOnInt - No Json node available to insert into database",
@@ -222,7 +226,7 @@ public void testArtifactIndexedOnString() throws Exception {
222226
if (!jnode.isNull()) {
223227
setPathRangeIndexInDatabase(dbName, jnode);
224228
succeeded = true;
225-
validateRangePathIndexInDatabase(dbName, "range-path-index", "com.marklogic.javaclient.ArtifactIndexedOnString/name");
229+
validateRangePathIndexInDatabase("range-path-index", "com.marklogic.javaclient.ArtifactIndexedOnString/name");
226230
} else {
227231
assertTrue(
228232
"testArtifactIndexedOnString - No Json node available to insert into database",
@@ -256,7 +260,7 @@ public void testArtifactIndexedOnDateTime() throws Exception {
256260
if (!jnode.isNull()) {
257261
setPathRangeIndexInDatabase(dbName, jnode);
258262
succeeded = true;
259-
validateRangePathIndexInDatabase(dbName, "range-path-index", "com.marklogic.javaclient.ArtifactIndexedOnDateTime/expiryDate");
263+
validateRangePathIndexInDatabase("range-path-index", "com.marklogic.javaclient.ArtifactIndexedOnDateTime/expiryDate");
260264
} else {
261265
assertTrue(
262266
"testArtifactIndexedOnDateTime - No Json node available to insert into database",
@@ -290,7 +294,7 @@ public void testArtifactIndexedOnAnyURI() throws Exception {
290294
if (!jnode.isNull()) {
291295
setPathRangeIndexInDatabase(dbName, jnode);
292296
succeeded = true;
293-
validateRangePathIndexInDatabase(dbName, "range-path-index", "com.marklogic.javaclient.ArtifactIndexedOnUri/artifactUri");
297+
validateRangePathIndexInDatabase("range-path-index", "com.marklogic.javaclient.ArtifactIndexedOnUri/artifactUri");
294298
} else {
295299
assertTrue(
296300
"testArtifactIndexedOnUri - No Json node available to insert into database",
@@ -324,7 +328,7 @@ public void testArtifactIndexedOnIntAsString() throws Exception {
324328
if (!jnode.isNull()) {
325329
setPathRangeIndexInDatabase(dbName, jnode);
326330
succeeded = true;
327-
validateRangePathIndexInDatabase(dbName, "range-path-index", "com.marklogic.javaclient.ArtifactIndexedOnIntAsString/inventory");
331+
validateRangePathIndexInDatabase("range-path-index", "com.marklogic.javaclient.ArtifactIndexedOnIntAsString/inventory");
328332
} else {
329333
assertTrue(
330334
"testArtifactIndexedOnIntAsString - No Json node available to insert into database",
@@ -361,7 +365,7 @@ public void testArtifactIndexedOnMultipleFields() throws Exception {
361365
if (!jnode.isNull()) {
362366
setPathRangeIndexInDatabase(dbName, jnode);
363367
succeeded = true;
364-
validateMultipleRangePathIndexInDatabase(dbName, "range-path-index", propValueStrArray);
368+
validateMultipleRangePathIndexInDatabase("range-path-index", propValueStrArray);
365369
} else {
366370
assertTrue(
367371
"testArtifactIndexedOnIntAsString - No Json node available to insert into database",
@@ -378,4 +382,129 @@ public void testArtifactIndexedOnMultipleFields() throws Exception {
378382
}
379383
}
380384
}
385+
386+
@Test
387+
public void testArtifactIndexedOnStringInSuperClass() throws Exception {
388+
boolean succeeded = false;
389+
File jsonFile = null;
390+
try {
391+
GenerateIndexConfig.main(new String[] { "-classes",
392+
"com.marklogic.javaclient.ArtifactIndexedOnStringSub",
393+
"-file", "TestAutomatedPathRangeIndexStringInSuperClass.json" });
394+
395+
jsonFile = new File("TestAutomatedPathRangeIndexStringInSuperClass.json");
396+
//Array to hold the range path index values. Refer to the class for the annotated class members.
397+
String[] propValueStrArray = {"com.marklogic.javaclient.ArtifactIndexedOnStringSub/name",
398+
"com.marklogic.javaclient.ArtifactIndexedOnStringSub/artifactWeight"};
399+
ObjectMapper mapper = new ObjectMapper();
400+
JsonNode jnode = mapper.readValue(jsonFile, JsonNode.class);
401+
402+
if (!jnode.isNull()) {
403+
setPathRangeIndexInDatabase(dbName, jnode);
404+
succeeded = true;
405+
validateMultipleRangePathIndexInDatabase("range-path-index", propValueStrArray);
406+
} else {
407+
assertTrue(
408+
"testArtifactIndexedOnStringInSuperClass - No Json node available to insert into database",
409+
succeeded);
410+
}
411+
412+
} catch (IOException e) {
413+
e.printStackTrace();
414+
} finally {
415+
try {
416+
jsonFile.delete();
417+
} catch (Exception e) {
418+
e.printStackTrace();
419+
}
420+
}
421+
}
422+
423+
@Test
424+
public void testArtifactMultipleIndexedOnInt() throws Exception {
425+
boolean succeeded = false;
426+
File jsonFile = null;
427+
try {
428+
GenerateIndexConfig.main(new String[] { "-classes",
429+
"com.marklogic.javaclient.ArtifactMultipleIndexedOnInt",
430+
"-file", "TestAutomatedPathRangeMultipleIndexOnInt.json" });
431+
432+
jsonFile = new File("TestAutomatedPathRangeMultipleIndexOnInt.json");
433+
ObjectMapper mapper = new ObjectMapper();
434+
JsonNode jnode = mapper.readValue(jsonFile, JsonNode.class);
435+
436+
if (!jnode.isNull()) {
437+
setPathRangeIndexInDatabase(dbName, jnode);
438+
succeeded = true;
439+
validateRangePathIndexInDatabase("range-path-index", "com.marklogic.javaclient.ArtifactMultipleIndexedOnInt/inventory");
440+
} else {
441+
assertTrue(
442+
"testArtifactMultipleIndexedOnInt - No Json node available to insert into database",
443+
succeeded);
444+
}
445+
446+
} catch (IOException e) {
447+
e.printStackTrace();
448+
} finally {
449+
try {
450+
jsonFile.delete();
451+
} catch (Exception e) {
452+
e.printStackTrace();
453+
}
454+
}
455+
}
456+
457+
458+
/*
459+
* Test for unsupported data type: This was meant as a negative test case.
460+
* The annotation declared on user defined data type will ONLY accept types
461+
* from scalarType class. Assigning a scalarType.Company to the class member
462+
* in the annotation like below, WILL NOT COMPILE:
463+
*
464+
* @PathIndexProperty(scalarType = ScalarType.Company) public Company
465+
* manufacture;
466+
*
467+
* However, for the following, we can declare for example for class property
468+
* Company (which is user defined type), the scalarType.STRING in the class.
469+
*
470+
* @PathIndexProperty(scalarType = ScalarType.STRING) public Company
471+
* manufacture;
472+
*
473+
* MarkLogic server accepts this range path index and this was verified
474+
* manually through the MarkLogic administration GUI on the database also.
475+
*/
476+
477+
@Test
478+
public void testArtifactIndexedOnUnSupportedAsString() throws Exception {
479+
boolean succeeded = false;
480+
File jsonFile = null;
481+
try {
482+
GenerateIndexConfig.main(new String[] { "-classes",
483+
"com.marklogic.javaclient.ArtifactIndexedUnSupportedDataType",
484+
"-file", "TestArtifactIndexedOnUnSupportedAsString.json" });
485+
486+
jsonFile = new File("TestArtifactIndexedOnUnSupportedAsString.json");
487+
ObjectMapper mapper = new ObjectMapper();
488+
JsonNode jnode = mapper.readValue(jsonFile, JsonNode.class);
489+
490+
if (!jnode.isNull()) {
491+
setPathRangeIndexInDatabase(dbName, jnode);
492+
succeeded = true;
493+
validateRangePathIndexInDatabase("range-path-index", "com.marklogic.javaclient.ArtifactIndexedUnSupportedDataType/manufacturer");
494+
} else {
495+
assertTrue(
496+
"testArtifactIndexedOnUnSupportedAsString - No Json node available to insert into database",
497+
succeeded);
498+
}
499+
500+
} catch (IOException e) {
501+
e.printStackTrace();
502+
} finally {
503+
try {
504+
jsonFile.delete();
505+
} catch (Exception e) {
506+
e.printStackTrace();
507+
}
508+
}
509+
}
381510
}

0 commit comments

Comments
 (0)