Skip to content

Commit 2570e4d

Browse files
committed
Add error push/pop to TranslatorFromJson
1 parent 1c75553 commit 2570e4d

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

lightblue-ldap-crud/src/main/java/com/redhat/lightblue/crud/ldap/EntryBuilder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.redhat.lightblue.metadata.Type;
3434
import com.redhat.lightblue.metadata.types.BinaryType;
3535
import com.redhat.lightblue.metadata.types.DateType;
36+
import com.redhat.lightblue.util.Error;
3637
import com.redhat.lightblue.util.JsonDoc;
3738
import com.redhat.lightblue.util.JsonNodeCursor;
3839
import com.unboundid.ldap.sdk.Entry;
@@ -53,8 +54,10 @@ public EntryBuilder(EntityMetadata md, LdapFieldNameTranslator fieldNameTranslat
5354
}
5455

5556
public Entry build(String dn, JsonDoc document){
57+
Error.push(LdapConstant.ATTRIBUTE_DN + "=" + dn);
5658
Entry entry = new Entry(dn);
5759
translate(document, entry);
60+
Error.pop();
5861
return entry;
5962
}
6063

@@ -123,7 +126,7 @@ protected void translateSimpleArray(ArrayField field, List<Object> items, Entry
123126

124127
@Override
125128
protected void translateObjectArray(ArrayField field, JsonNodeCursor cursor, Entry target) {
126-
throw new UnsupportedOperationException("Object ArrayField type is not currently supported.");
129+
throw Error.get("Unsupported Feature: object array", field.getFullPath().toString());
127130
}
128131

129132
}

lightblue-ldap-crud/src/main/java/com/redhat/lightblue/crud/ldap/TranslatorFromJson.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.redhat.lightblue.metadata.SimpleArrayElement;
3434
import com.redhat.lightblue.metadata.SimpleField;
3535
import com.redhat.lightblue.metadata.Type;
36+
import com.redhat.lightblue.util.Error;
3637
import com.redhat.lightblue.util.JsonDoc;
3738
import com.redhat.lightblue.util.JsonNodeCursor;
3839
import com.redhat.lightblue.util.Path;
@@ -102,6 +103,8 @@ protected void translate(JsonNodeCursor cursor, T target){
102103
throw new NullPointerException("No Metadata field found for: " + path.toString());
103104
}
104105

106+
Error.push(fieldNode.getFullPath().getLast());
107+
105108
if (fieldNode instanceof SimpleField) {
106109
translate((SimpleField) fieldNode, node, target);
107110
}
@@ -117,6 +120,8 @@ else if (fieldNode instanceof ReferenceField) {
117120
else{
118121
throw new UnsupportedOperationException("Field type is not supported: " + fieldNode.getClass().getName());
119122
}
123+
124+
Error.pop();
120125
}
121126

122127
private void translate(ArrayField field, JsonNodeCursor cursor, T target){
@@ -149,6 +154,7 @@ protected void translate(ObjectField field, JsonNodeCursor cursor, T target){
149154
//TODO: throw exception?
150155
return;
151156
}
157+
152158
do {
153159
translate(cursor, target);
154160
} while (cursor.nextSibling());

lightblue-ldap-crud/src/test/java/com/redhat/lightblue/crud/ldap/EntryBuilderTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232

3333
import javax.xml.bind.DatatypeConverter;
3434

35+
import org.junit.Rule;
3536
import org.junit.Test;
37+
import org.junit.rules.ExpectedException;
3638
import org.junit.runner.RunWith;
3739
import org.junit.runners.Parameterized;
3840
import org.junit.runners.Parameterized.Parameters;
@@ -76,6 +78,9 @@ protected static String quote(String text){
7678

7779
public static class SpecializedTests {
7880

81+
@Rule
82+
public ExpectedException expectedEx = ExpectedException.none();
83+
7984
@Test
8085
public void testFieldIsObjectType() throws Exception{
8186
Entry entry = buildEntry(LightblueUtil.FIELD_OBJECT_TYPE, "{\"type\": \"string\"}", quote("someEntity"));
@@ -115,17 +120,18 @@ public void testFieldIsArrayFieldWithoutMatchArray() throws Exception{
115120
* it requires two fields.
116121
* ObjectFields are not currently supported in LDAP, an exception should be thrown indicating as such.
117122
*/
118-
@Test(expected = UnsupportedOperationException.class)
123+
@Test
119124
public void testObjectArrayField_ThrowsException() throws Exception{
120125
String arrayFieldName = "someObjectArray";
121126
String arrayCountFieldName = LightblueUtil.createArrayCountFieldName(arrayFieldName);
122-
Entry entry = buildEntry(
127+
128+
expectedEx.expect(com.redhat.lightblue.util.Error.class);
129+
expectedEx.expectMessage("{\"objectType\":\"error\",\"context\":\"dn=uid=someuid,dc=example,dc=com/" + arrayFieldName + "\",\"errorCode\":\"Unsupported Feature: object array\",\"msg\":\"" + arrayFieldName + "\"}");
130+
131+
buildEntry(
123132
arrayCountFieldName,
124133
"{\"type\": \"integer\"}, " + quote(arrayFieldName) + ": {\"type\": \"array\", \"items\": {\"type\": \"object\",\"fields\": {\"someField\": {\"type\": \"string\"}}}}",
125134
"1," + quote(arrayFieldName) + ":[{\"someField\":\"hello\"}]");
126-
127-
assertNotNull(entry);
128-
assertNull(entry.getAttribute(arrayFieldName));
129135
}
130136

131137
@Test(expected = IllegalArgumentException.class)

0 commit comments

Comments
 (0)