Skip to content

Commit 6f68dea

Browse files
committed
work on unit tests
1 parent 79586cc commit 6f68dea

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

lightblue-ldap-integration-test/src/test/java/com/redhat/lightblue/crud/ldap/ITCaseLdapCRUDControllerTest.java

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,27 @@
1919
package com.redhat.lightblue.crud.ldap;
2020

2121
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.fail;
2223

2324
import java.io.IOException;
24-
import java.lang.reflect.InvocationTargetException;
2525

26+
import org.junit.After;
2627
import org.junit.Before;
2728
import org.junit.Rule;
2829
import org.junit.Test;
2930

31+
import com.redhat.lightblue.DataError;
32+
import com.redhat.lightblue.Response;
3033
import com.redhat.lightblue.config.DataSourcesConfiguration;
34+
import com.redhat.lightblue.config.JsonTranslator;
3135
import com.redhat.lightblue.config.LightblueFactory;
36+
import com.redhat.lightblue.crud.InsertionRequest;
3237
import com.redhat.lightblue.ldap.test.LdapServerExternalResource;
3338
import com.redhat.lightblue.ldap.test.LdapServerExternalResource.InMemoryLdapServer;
34-
import com.redhat.lightblue.mediator.Mediator;
3539
import com.redhat.lightblue.mongo.test.MongoServerExternalResource;
3640
import com.redhat.lightblue.mongo.test.MongoServerExternalResource.InMemoryMongoServer;
41+
import com.redhat.lightblue.util.Error;
42+
import com.redhat.lightblue.util.JsonUtils;
3743
import com.redhat.lightblue.util.test.AbstractJsonNodeTest;
3844

3945
@InMemoryLdapServer
@@ -47,25 +53,58 @@ public class ITCaseLdapCRUDControllerTest{
4753
public MongoServerExternalResource mongoServer = new MongoServerExternalResource();
4854

4955
@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;
5664
}
5765

5866
public ITCaseLdapCRUDControllerTest(){
5967
System.setProperty("ldap.host", "localhost");
6068
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));
6172
}
6273

63-
public Mediator mediator;
74+
public LightblueFactory lightblueFactory;
6475

6576
@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);
6884
}
6985

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+
}
70109

71110
}

0 commit comments

Comments
 (0)