19
19
package com .redhat .lightblue .crud .ldap ;
20
20
21
21
import static org .junit .Assert .assertNotNull ;
22
+ import static org .junit .Assert .fail ;
22
23
23
24
import java .io .IOException ;
24
- import java .lang .reflect .InvocationTargetException ;
25
25
26
+ import org .junit .After ;
26
27
import org .junit .Before ;
27
28
import org .junit .Rule ;
28
29
import org .junit .Test ;
29
30
31
+ import com .redhat .lightblue .DataError ;
32
+ import com .redhat .lightblue .Response ;
30
33
import com .redhat .lightblue .config .DataSourcesConfiguration ;
34
+ import com .redhat .lightblue .config .JsonTranslator ;
31
35
import com .redhat .lightblue .config .LightblueFactory ;
36
+ import com .redhat .lightblue .crud .InsertionRequest ;
32
37
import com .redhat .lightblue .ldap .test .LdapServerExternalResource ;
33
38
import com .redhat .lightblue .ldap .test .LdapServerExternalResource .InMemoryLdapServer ;
34
- import com .redhat .lightblue .mediator .Mediator ;
35
39
import com .redhat .lightblue .mongo .test .MongoServerExternalResource ;
36
40
import com .redhat .lightblue .mongo .test .MongoServerExternalResource .InMemoryMongoServer ;
41
+ import com .redhat .lightblue .util .Error ;
42
+ import com .redhat .lightblue .util .JsonUtils ;
37
43
import com .redhat .lightblue .util .test .AbstractJsonNodeTest ;
38
44
39
45
@ InMemoryLdapServer
@@ -47,25 +53,58 @@ public class ITCaseLdapCRUDControllerTest{
47
53
public MongoServerExternalResource mongoServer = new MongoServerExternalResource ();
48
54
49
55
@ Before
50
- public void before () throws IOException , ClassNotFoundException , IllegalAccessException , InvocationTargetException , NoSuchMethodException , InstantiationException {
51
- if (mediator == null ){
52
- LightblueFactory factory = new LightblueFactory (
53
- new DataSourcesConfiguration (AbstractJsonNodeTest .loadJsonNode ("./datasources.json" )));
54
- mediator = factory .getMediator ();
55
- }
56
+ public void before () throws IOException {
57
+ lightblueFactory = new LightblueFactory (
58
+ new DataSourcesConfiguration (AbstractJsonNodeTest .loadJsonNode ("./datasources.json" )));
59
+ }
60
+
61
+ @ After
62
+ public void after (){
63
+ lightblueFactory = null ;
56
64
}
57
65
58
66
public ITCaseLdapCRUDControllerTest (){
59
67
System .setProperty ("ldap.host" , "localhost" );
60
68
System .setProperty ("ldap.port" , String .valueOf (LdapServerExternalResource .DEFAULT_PORT ));
69
+
70
+ System .setProperty ("mongo.host" , "localhost" );
71
+ System .setProperty ("mongo.port" , String .valueOf (MongoServerExternalResource .DEFAULT_PORT ));
61
72
}
62
73
63
- public Mediator mediator ;
74
+ public LightblueFactory lightblueFactory ;
64
75
65
76
@ Test
66
- public void test (){
67
- assertNotNull (mediator );
77
+ public void testInsert () throws Exception {
78
+ JsonTranslator tx = lightblueFactory .getJsonTranslator ();
79
+ InsertionRequest insertIequest = tx .parse (InsertionRequest .class , JsonUtils .json ("{}" ));
80
+ Response response = lightblueFactory .getMediator ().insert (insertIequest );
81
+
82
+ assertNotNull (response );
83
+ //assertNoErrors(response);
68
84
}
69
85
86
+ private void assertNoErrors (Response response ){
87
+ if (response .getErrors ().isEmpty () && response .getDataErrors ().isEmpty ()){
88
+ return ;
89
+ }
90
+
91
+ StringBuilder builder = new StringBuilder ();
92
+
93
+ if (!response .getErrors ().isEmpty ()){
94
+ builder .append ("Response has Errors: \n " );
95
+ for (Error error : response .getErrors ()){
96
+ builder .append (error .toJson ()+ "\n " );
97
+ }
98
+ }
99
+
100
+ if (!response .getDataErrors ().isEmpty ()){
101
+ builder .append ("Response has Data Errors: \n " );
102
+ for (DataError error : response .getDataErrors ()){
103
+ builder .append (error .toJson () + "\n " );
104
+ }
105
+ }
106
+
107
+ fail (builder .toString ());
108
+ }
70
109
71
110
}
0 commit comments