Skip to content

Commit 14b81e4

Browse files
committed
adding test for the issue 214
1 parent a765687 commit 14b81e4

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

test-complete/src/test/java/com/marklogic/client/functionaltest/TestPOJOReadWrite1.java

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.Assert.*;
2020

21+
import java.util.Calendar;
2122
import java.util.Iterator;
2223

2324
import org.junit.After;
@@ -30,15 +31,88 @@
3031
import com.marklogic.client.DatabaseClientFactory;
3132
import com.marklogic.client.DatabaseClientFactory.Authentication;
3233
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;
3338
import com.marklogic.client.pojo.PojoPage;
3439
import com.marklogic.client.pojo.PojoRepository;
40+
import com.marklogic.client.pojo.annotation.Id;
3541

3642
public class TestPOJOReadWrite1 extends BasicJavaClientREST {
3743
private static String dbName = "TestPOJORWDB";
3844
private static String [] fNames = {"TestPOJORWDB-1"};
3945
private static String restServerName = "REST-Java-Client-API-Server";
4046
private static int restPort = 8011;
4147
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+
}
42116

43117
@BeforeClass
44118
public static void setUpBeforeClass() throws Exception {
@@ -266,4 +340,47 @@ public void testPOJOWriteWithPojoPageReadAll() {
266340

267341

268342
}
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+
}
269386
}

0 commit comments

Comments
 (0)