|
18 | 18 |
|
19 | 19 | import static org.junit.Assert.*; |
20 | 20 |
|
| 21 | +import java.util.Calendar; |
21 | 22 | import java.util.Iterator; |
22 | 23 |
|
23 | 24 | import org.junit.After; |
|
30 | 31 | import com.marklogic.client.DatabaseClientFactory; |
31 | 32 | import com.marklogic.client.DatabaseClientFactory.Authentication; |
32 | 33 | import com.marklogic.client.ResourceNotFoundException; |
| 34 | +import com.marklogic.client.functionaltest.TestPOJOgetDocumentUri.CalendarPOJO; |
| 35 | +import com.marklogic.client.functionaltest.TestPOJOgetDocumentUri.DoublePOJO; |
| 36 | +import com.marklogic.client.functionaltest.TestPOJOgetDocumentUri.IntegerPOJO; |
| 37 | +import com.marklogic.client.functionaltest.TestPOJOgetDocumentUri.StringPOJO; |
33 | 38 | import com.marklogic.client.pojo.PojoPage; |
34 | 39 | import com.marklogic.client.pojo.PojoRepository; |
| 40 | +import com.marklogic.client.pojo.annotation.Id; |
35 | 41 |
|
36 | 42 | public class TestPOJOReadWrite1 extends BasicJavaClientREST { |
37 | 43 | private static String dbName = "TestPOJORWDB"; |
38 | 44 | private static String [] fNames = {"TestPOJORWDB-1"}; |
39 | 45 | private static String restServerName = "REST-Java-Client-API-Server"; |
40 | 46 | private static int restPort = 8011; |
41 | 47 | private DatabaseClient client ; |
| 48 | + /* |
| 49 | + * @Id annotation on String type |
| 50 | + */ |
| 51 | + public static class StringPOJO { |
| 52 | + @Id |
| 53 | + public String name; |
| 54 | + public String getName() { |
| 55 | + return name; |
| 56 | + } |
| 57 | + public StringPOJO setName(String name) { |
| 58 | + this.name = name; |
| 59 | + return this; |
| 60 | + } |
| 61 | + } |
| 62 | + /* |
| 63 | + * @Id annotation on Integer type. |
| 64 | + */ |
| 65 | + public static class IntegerPOJO { |
| 66 | + @Id |
| 67 | + public Integer id; |
| 68 | + public Integer getId() { |
| 69 | + return id; |
| 70 | + } |
| 71 | + public IntegerPOJO setId(Integer id) { |
| 72 | + this.id = id; |
| 73 | + return this; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + /* |
| 78 | + * @Id annotation on Calender type. |
| 79 | + */ |
| 80 | + public static class CalendarPOJO { |
| 81 | + @Id |
| 82 | + public Calendar dateId; |
| 83 | + public Calendar getDateId() { |
| 84 | + return dateId; |
| 85 | + } |
| 86 | + public CalendarPOJO setDateId(Calendar dateId) { |
| 87 | + this.dateId = dateId; |
| 88 | + return this; |
| 89 | + } |
| 90 | + } |
| 91 | + /* |
| 92 | + * @Id annotation on double type. |
| 93 | + */ |
| 94 | + public static class DoublePOJO { |
| 95 | + @Id |
| 96 | + public double doubleId; |
| 97 | + public double getDoubleId() { |
| 98 | + return doubleId; |
| 99 | + } |
| 100 | + public DoublePOJO setDoubleId(double doubleId) { |
| 101 | + this.doubleId = doubleId; |
| 102 | + return this; |
| 103 | + } |
| 104 | + } |
| 105 | + public static class NumberPOJO { |
| 106 | + @Id |
| 107 | + public Number nId; |
| 108 | + public Number getNumberId() { |
| 109 | + return nId; |
| 110 | + } |
| 111 | + public NumberPOJO setNumberId(Number nId) { |
| 112 | + this.nId =nId; |
| 113 | + return this; |
| 114 | + } |
| 115 | + } |
42 | 116 |
|
43 | 117 | @BeforeClass |
44 | 118 | public static void setUpBeforeClass() throws Exception { |
@@ -266,4 +340,47 @@ public void testPOJOWriteWithPojoPageReadAll() { |
266 | 340 |
|
267 | 341 |
|
268 | 342 | } |
| 343 | +@Test |
| 344 | +public void testPOJOgetDocumentUri(){ |
| 345 | + PojoRepository<StringPOJO,String> strPojoRepo = client.newPojoRepository(StringPOJO.class, String.class); |
| 346 | + StringPOJO sobj = new StringPOJO(); |
| 347 | + String uri ="StringUri"; |
| 348 | + sobj.setName("StringUri"); |
| 349 | + strPojoRepo.write(sobj); |
| 350 | + System.out.println(strPojoRepo.getDocumentUri(sobj)); |
| 351 | + assertEquals("Uri mismatch","com.marklogic.client.functionaltest.TestPOJOReadWrite1$StringPOJO/StringUri.json",strPojoRepo.getDocumentUri(sobj)); |
| 352 | + |
| 353 | + PojoRepository<IntegerPOJO,Integer> intPojoRepo = client.newPojoRepository(IntegerPOJO.class, Integer.class); |
| 354 | + IntegerPOJO iobj = new IntegerPOJO(); |
| 355 | + iobj.setId(-12); |
| 356 | + intPojoRepo.write(iobj); |
| 357 | + System.out.println(intPojoRepo.getDocumentUri(iobj)); |
| 358 | + assertEquals("Uri mismatch","com.marklogic.client.functionaltest.TestPOJOReadWrite1$IntegerPOJO/-12.json",intPojoRepo.getDocumentUri(iobj)); |
| 359 | + |
| 360 | + PojoRepository<CalendarPOJO,Calendar> calPojoRepo = client.newPojoRepository(CalendarPOJO.class, Calendar.class); |
| 361 | + CalendarPOJO cobj = new CalendarPOJO(); |
| 362 | + Calendar cal = Calendar.getInstance(); |
| 363 | + cobj.setDateId(cal); |
| 364 | + calPojoRepo.write(cobj); |
| 365 | + System.out.println(calPojoRepo.getDocumentUri(cobj)); |
| 366 | + assertTrue("Uri mismatch",calPojoRepo.getDocumentUri(cobj).contains("com.marklogic.client.functionaltest.TestPOJOReadWrite1$CalendarPOJO")); |
| 367 | + |
| 368 | + PojoRepository<DoublePOJO,Double> dPojoRepo = client.newPojoRepository(DoublePOJO.class, Double.class); |
| 369 | + DoublePOJO dobj = new DoublePOJO(); |
| 370 | + double dvar= 2.015; |
| 371 | + dobj.setDoubleId(dvar); |
| 372 | + dPojoRepo.write(dobj); |
| 373 | + System.out.println(dPojoRepo.getDocumentUri(dobj)); |
| 374 | + assertEquals("Uri mismatch","com.marklogic.client.functionaltest.TestPOJOReadWrite1$DoublePOJO/2.015.json",dPojoRepo.getDocumentUri(dobj)); |
| 375 | + |
| 376 | + PojoRepository<NumberPOJO,Number> nPojoRepo = client.newPojoRepository(NumberPOJO.class, Number.class); |
| 377 | + NumberPOJO nobj = new NumberPOJO(); |
| 378 | + Number nvar =99; |
| 379 | + nvar.intValue(); |
| 380 | + nobj.setNumberId(nvar); |
| 381 | + nPojoRepo.write(nobj); |
| 382 | + System.out.println(nPojoRepo.getDocumentUri(nobj)); |
| 383 | + assertEquals("Uri mismatch","com.marklogic.client.functionaltest.TestPOJOReadWrite1$NumberPOJO/99.json",nPojoRepo.getDocumentUri(nobj)); |
| 384 | + |
| 385 | +} |
269 | 386 | } |
0 commit comments