|
| 1 | +package org.jsondoc.core.pojo; |
| 2 | + |
| 3 | +import java.util.HashSet; |
| 4 | +import java.util.List; |
| 5 | +import java.util.Map; |
| 6 | +import java.util.Set; |
| 7 | + |
| 8 | +import org.jsondoc.core.annotation.ApiObject; |
| 9 | +import org.jsondoc.core.annotation.ApiObjectField; |
| 10 | +import org.jsondoc.core.util.JSONDocUtils; |
| 11 | +import org.junit.Assert; |
| 12 | +import org.junit.Test; |
| 13 | + |
| 14 | +public class ApiObjectDocTest { |
| 15 | + |
| 16 | + @ApiObject(name="test-object") |
| 17 | + private class TestObject { |
| 18 | + |
| 19 | + @ApiObjectField(description="the test name") |
| 20 | + private String name; |
| 21 | + |
| 22 | + @ApiObjectField(description="the test age") |
| 23 | + private Integer age; |
| 24 | + |
| 25 | + @ApiObjectField(description="the test avg") |
| 26 | + private Long avg; |
| 27 | + |
| 28 | + @ApiObjectField(description="the test map") |
| 29 | + private Map<String, Integer> map; |
| 30 | + |
| 31 | + @ApiObjectField(description="an unparametrized list to test https://github.com/fabiomaffioletti/jsondoc/issues/5") |
| 32 | + private List unparametrizedList; |
| 33 | + |
| 34 | + @ApiObjectField(description="a parametrized list") |
| 35 | + private List<String> parametrizedList; |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testApiObjectDoc() { |
| 41 | + Set<Class<?>> classes = new HashSet<Class<?>>(); |
| 42 | + classes.add(TestObject.class); |
| 43 | + ApiObjectDoc childDoc = JSONDocUtils.getApiObjectDocs(classes).iterator().next(); |
| 44 | + Assert.assertEquals("test-object", childDoc.getName()); |
| 45 | + Assert.assertEquals(6, childDoc.getFields().size()); |
| 46 | + |
| 47 | + for (ApiObjectFieldDoc fieldDoc : childDoc.getFields()) { |
| 48 | + if(fieldDoc.getName().equals("unparametrizedList")) { |
| 49 | + Assert.assertEquals("undefined", fieldDoc.getType()); |
| 50 | + Assert.assertEquals("true", fieldDoc.getMultiple()); |
| 51 | + } |
| 52 | + |
| 53 | + if(fieldDoc.getName().equals("parametrizedList")) { |
| 54 | + Assert.assertEquals("string", fieldDoc.getType()); |
| 55 | + Assert.assertEquals("true", fieldDoc.getMultiple()); |
| 56 | + } |
| 57 | + |
| 58 | + if(fieldDoc.getName().equals("name")) { |
| 59 | + Assert.assertEquals("string", fieldDoc.getType()); |
| 60 | + Assert.assertEquals("false", fieldDoc.getMultiple()); |
| 61 | + } |
| 62 | + |
| 63 | + if(fieldDoc.getName().equals("age")) { |
| 64 | + Assert.assertEquals("integer", fieldDoc.getType()); |
| 65 | + Assert.assertEquals("false", fieldDoc.getMultiple()); |
| 66 | + } |
| 67 | + |
| 68 | + if(fieldDoc.getName().equals("avg")) { |
| 69 | + Assert.assertEquals("long", fieldDoc.getType()); |
| 70 | + Assert.assertEquals("false", fieldDoc.getMultiple()); |
| 71 | + } |
| 72 | + |
| 73 | + if(fieldDoc.getName().equals("map")) { |
| 74 | + Assert.assertEquals("map", fieldDoc.getType()); |
| 75 | + Assert.assertEquals("string", fieldDoc.getMapKeyObject()); |
| 76 | + Assert.assertEquals("integer", fieldDoc.getMapValueObject()); |
| 77 | + Assert.assertEquals("false", fieldDoc.getMultiple()); |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | +} |
0 commit comments