|
23 | 23 |
|
24 | 24 | import java.util.ArrayList;
|
25 | 25 | import java.util.Arrays;
|
| 26 | +import java.util.Iterator; |
26 | 27 | import java.util.List;
|
27 | 28 |
|
28 | 29 | import org.json.JSONException;
|
29 | 30 | import org.junit.Test;
|
30 | 31 | import org.skyscreamer.jsonassert.JSONAssert;
|
31 | 32 |
|
| 33 | +import com.fasterxml.jackson.databind.JsonNode; |
32 | 34 | import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
33 | 35 | import com.redhat.lightblue.crud.DocCtx;
|
34 |
| -import com.redhat.lightblue.crud.ldap.translator.ResultTranslator; |
| 36 | +import com.redhat.lightblue.metadata.ArrayElement; |
35 | 37 | import com.redhat.lightblue.metadata.ArrayField;
|
36 | 38 | import com.redhat.lightblue.metadata.EntityMetadata;
|
37 | 39 | import com.redhat.lightblue.metadata.Field;
|
| 40 | +import com.redhat.lightblue.metadata.FieldTreeNode; |
| 41 | +import com.redhat.lightblue.metadata.ObjectField; |
| 42 | +import com.redhat.lightblue.metadata.ReferenceField; |
38 | 43 | import com.redhat.lightblue.metadata.SimpleArrayElement;
|
39 | 44 | import com.redhat.lightblue.metadata.SimpleField;
|
| 45 | +import com.redhat.lightblue.metadata.Type; |
40 | 46 | import com.redhat.lightblue.metadata.types.BooleanType;
|
41 | 47 | import com.redhat.lightblue.metadata.types.DateType;
|
42 | 48 | import com.redhat.lightblue.metadata.types.IntegerType;
|
43 | 49 | import com.redhat.lightblue.metadata.types.StringType;
|
| 50 | +import com.redhat.lightblue.util.Path; |
44 | 51 | import com.unboundid.ldap.sdk.Attribute;
|
45 | 52 | import com.unboundid.ldap.sdk.SearchResult;
|
46 | 53 | import com.unboundid.ldap.sdk.SearchResultEntry;
|
@@ -139,6 +146,55 @@ public void testTranslate_SimpleField_Date() throws JSONException{
|
139 | 146 | true);
|
140 | 147 | }
|
141 | 148 |
|
| 149 | + @Test(expected = UnsupportedOperationException.class) |
| 150 | + public void testTranslate_SimpleField_Unknown() throws JSONException{ |
| 151 | + SearchResult result = fakeSearchResult( |
| 152 | + new SearchResultEntry(-1, "uid=john.doe,dc=example,dc=com", new Attribute[]{ |
| 153 | + new Attribute("uid", "john.doe") |
| 154 | + })); |
| 155 | + |
| 156 | + EntityMetadata md = fakeEntityMetadata("fakeMetadata", |
| 157 | + new SimpleField("uid", new Type(){ |
| 158 | + |
| 159 | + @Override |
| 160 | + public String getName() { |
| 161 | + throw new UnsupportedOperationException("Method should never be called."); |
| 162 | + } |
| 163 | + |
| 164 | + @Override |
| 165 | + public boolean supportsEq() { |
| 166 | + throw new UnsupportedOperationException("Method should never be called."); |
| 167 | + } |
| 168 | + |
| 169 | + @Override |
| 170 | + public boolean supportsOrdering() { |
| 171 | + throw new UnsupportedOperationException("Method should never be called."); |
| 172 | + } |
| 173 | + |
| 174 | + @Override |
| 175 | + public JsonNode toJson(JsonNodeFactory factory, Object value) { |
| 176 | + throw new UnsupportedOperationException("Method should never be called."); |
| 177 | + } |
| 178 | + |
| 179 | + @Override |
| 180 | + public Object fromJson(JsonNode value) { |
| 181 | + throw new UnsupportedOperationException("Method should never be called."); |
| 182 | + } |
| 183 | + |
| 184 | + @Override |
| 185 | + public int compare(Object v1, Object v2) { |
| 186 | + throw new UnsupportedOperationException("Method should never be called."); |
| 187 | + } |
| 188 | + |
| 189 | + @Override |
| 190 | + public Object cast(Object v) { |
| 191 | + throw new UnsupportedOperationException("Method should never be called."); |
| 192 | + } |
| 193 | + })); |
| 194 | + |
| 195 | + new ResultTranslator(factory).translate(result, md); |
| 196 | + } |
| 197 | + |
142 | 198 | @Test
|
143 | 199 | public void testTranslate_ObjectType() throws JSONException{
|
144 | 200 | SearchResult result = fakeSearchResult(
|
@@ -233,6 +289,88 @@ public void testTranslate_SimpleArrayElement_CountAskedFor() throws JSONExceptio
|
233 | 289 | true);
|
234 | 290 | }
|
235 | 291 |
|
| 292 | + @Test(expected = UnsupportedOperationException.class) |
| 293 | + public void testTranslate_UnknownArrayElement() throws JSONException{ |
| 294 | + SearchResult result = fakeSearchResult( |
| 295 | + new SearchResultEntry(-1, "uid=john.doe,dc=example,dc=com", new Attribute[]{ |
| 296 | + new Attribute("fakeArray", Arrays.asList("top", "person", "organizationalPerson", "inetOrgPerson")) |
| 297 | + })); |
| 298 | + |
| 299 | + @SuppressWarnings("serial") |
| 300 | + EntityMetadata md = fakeEntityMetadata("fakeMetadata", |
| 301 | + new ArrayField("fakeArray", new ArrayElement(){ |
| 302 | + |
| 303 | + @Override |
| 304 | + public boolean hasChildren() { |
| 305 | + throw new UnsupportedOperationException("Method should never be called."); |
| 306 | + } |
| 307 | + |
| 308 | + @Override |
| 309 | + public Iterator<? extends FieldTreeNode> getChildren() { |
| 310 | + throw new UnsupportedOperationException("Method should never be called."); |
| 311 | + } |
| 312 | + |
| 313 | + @Override |
| 314 | + public FieldTreeNode resolve(Path p, int level) { |
| 315 | + throw new UnsupportedOperationException("Method should never be called."); |
| 316 | + } |
| 317 | + })); |
| 318 | + |
| 319 | + new ResultTranslator(factory).translate(result, md); |
| 320 | + } |
| 321 | + |
| 322 | + @Test(expected = UnsupportedOperationException.class) |
| 323 | + public void testTranslate_ObjectField() throws JSONException{ |
| 324 | + SearchResult result = fakeSearchResult( |
| 325 | + new SearchResultEntry(-1, "uid=john.doe,dc=example,dc=com", new Attribute[]{new Attribute("fake")})); |
| 326 | + |
| 327 | + EntityMetadata md = fakeEntityMetadata("fakeMetadata", |
| 328 | + new ObjectField("fake") |
| 329 | + ); |
| 330 | + |
| 331 | + new ResultTranslator(factory).translate(result, md); |
| 332 | + } |
| 333 | + |
| 334 | + @Test(expected = UnsupportedOperationException.class) |
| 335 | + public void testTranslate_ReferenceField() throws JSONException{ |
| 336 | + SearchResult result = fakeSearchResult( |
| 337 | + new SearchResultEntry(-1, "uid=john.doe,dc=example,dc=com", new Attribute[]{new Attribute("fake")})); |
| 338 | + |
| 339 | + EntityMetadata md = fakeEntityMetadata("fakeMetadata", |
| 340 | + new ReferenceField("fake") |
| 341 | + ); |
| 342 | + |
| 343 | + new ResultTranslator(factory).translate(result, md); |
| 344 | + } |
| 345 | + |
| 346 | + @Test(expected = UnsupportedOperationException.class) |
| 347 | + public void testTranslate_UnsupportedField() throws JSONException{ |
| 348 | + SearchResult result = fakeSearchResult( |
| 349 | + new SearchResultEntry(-1, "uid=john.doe,dc=example,dc=com", new Attribute[]{new Attribute("fake")})); |
| 350 | + |
| 351 | + @SuppressWarnings("serial") |
| 352 | + EntityMetadata md = fakeEntityMetadata("fakeMetadata", new Field("fake"){ |
| 353 | + |
| 354 | + @Override |
| 355 | + public boolean hasChildren() { |
| 356 | + throw new UnsupportedOperationException("Method should never be called."); |
| 357 | + } |
| 358 | + |
| 359 | + @Override |
| 360 | + public Iterator<? extends FieldTreeNode> getChildren() { |
| 361 | + throw new UnsupportedOperationException("Method should never be called."); |
| 362 | + } |
| 363 | + |
| 364 | + @Override |
| 365 | + public FieldTreeNode resolve(Path p, int level) { |
| 366 | + throw new UnsupportedOperationException("Method should never be called."); |
| 367 | + } |
| 368 | + |
| 369 | + }); |
| 370 | + |
| 371 | + new ResultTranslator(factory).translate(result, md); |
| 372 | + } |
| 373 | + |
236 | 374 | protected SearchResult fakeSearchResult(SearchResultEntry... entries){
|
237 | 375 | return new SearchResult(-1, null, "", "", new String[0], Arrays.asList(entries), new ArrayList<SearchResultReference>(), entries.length, 0, null);
|
238 | 376 | }
|
|
0 commit comments