Search in sources :

Example 6 with ApiResultObject

use of com.terran4j.commons.api2doc.domain.ApiResultObject in project commons by terran4j.

the class ApiResultObjectTest method testParseResultTypeWithDate.

@Test
public void testParseResultTypeWithDate() throws Exception {
    log.info("testParseResultTypeWithDate");
    Method method = ReflectionUtils.findMethod(getClass(), "getDateBean");
    Assert.assertNotNull(method);
    KeyedList<String, ApiResultObject> totalResults = new KeyedList<>();
    ApiResultObject object = ApiResultObject.parseResultType(method, totalResults);
    Assert.assertNotNull(object);
    ApiResultObject current = object.getChild("current");
    Assert.assertEquals("long", current.getTypeName());
}
Also used : KeyedList(com.terran4j.commons.util.value.KeyedList) Method(java.lang.reflect.Method) ApiResultObject(com.terran4j.commons.api2doc.domain.ApiResultObject) Test(org.junit.Test)

Example 7 with ApiResultObject

use of com.terran4j.commons.api2doc.domain.ApiResultObject in project commons by terran4j.

the class JavaBeanCodeWriterTest method testGetModel.

@Test
public void testGetModel() throws Exception {
    log.info("testGetModel");
    Method method = ReflectionUtils.findMethod(getClass(), "getUser");
    KeyedList<String, ApiResultObject> totalResults = new KeyedList<>();
    ApiResultObject user = ApiResultObject.parseResultType(method, totalResults);
    Map<String, Object> model = javaBeanCodeWriter.getModel(user, "User", null);
    @SuppressWarnings("unchecked") Set<String> imports = (Set<String>) model.get("imports");
    log.info("imports: {}", imports);
    Assert.assertFalse(imports.contains(Date.class.getName()));
    MemoryCodeOutput out = new MemoryCodeOutput();
    javaBeanCodeWriter.writeCode(user, "User", out, null);
    String code = out.getCode("User.java");
    log.info("User.java:\n{}", code);
}
Also used : Set(java.util.Set) MemoryCodeOutput(com.terran4j.commons.api2doc.codewriter.MemoryCodeOutput) KeyedList(com.terran4j.commons.util.value.KeyedList) ApiResultObject(com.terran4j.commons.api2doc.domain.ApiResultObject) Method(java.lang.reflect.Method) ApiResultObject(com.terran4j.commons.api2doc.domain.ApiResultObject) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with ApiResultObject

use of com.terran4j.commons.api2doc.domain.ApiResultObject in project commons by terran4j.

the class ParseApiCommentOnMethod method testParseApiCommentOnMethod.

@Test
public void testParseApiCommentOnMethod() throws Exception {
    log.info("testParseApiCommentOnMethod");
    Method method = ReflectionUtils.findMethod(getClass(), "getUser");
    Assert.assertNotNull(method);
    KeyedList<String, ApiResultObject> list = new KeyedList<>();
    ApiResultObject user = ApiResultObject.parseResultType(method, list);
    Assert.assertNotNull(user);
    log.info("user: {}", user);
    Assert.assertEquals(2, user.getChildren().size());
    ApiResultObject userId = user.getChildren().get(0);
    Assert.assertEquals("id", userId.getId());
    Assert.assertEquals("账号id", userId.getComment().getValue());
    Assert.assertEquals("123", userId.getSample().getValue());
    ApiResultObject userName = user.getChildren().get(1);
    Assert.assertEquals("username", userName.getId());
    Assert.assertEquals("账号用户名", userName.getComment().getValue());
    Assert.assertEquals("terran4j", userName.getSample().getValue());
}
Also used : KeyedList(com.terran4j.commons.util.value.KeyedList) Method(java.lang.reflect.Method) ApiResultObject(com.terran4j.commons.api2doc.domain.ApiResultObject) Test(org.junit.Test)

Example 9 with ApiResultObject

use of com.terran4j.commons.api2doc.domain.ApiResultObject in project commons by terran4j.

the class ParseApiCommentOnSeeClass method testParseApiCommentOnSeeClass.

@Test
public void testParseApiCommentOnSeeClass() throws Exception {
    log.info("testParseApiCommentOnSeeClass");
    Api2DocCollector collector = new Api2DocCollector();
    ApiFolderObject folder = collector.toApiFolder(new ParseApiCommentOnSeeClass.MyController(), "myController");
    ApiDocObject doc = folder.getDoc("updateUser");
    List<ApiParamObject> params = doc.getParams();
    Assert.assertEquals("用户id", params.get(0).getComment().toString());
    Assert.assertEquals("123", params.get(0).getSample().toString());
    Assert.assertEquals("用户名称", params.get(1).getComment().toString());
    Assert.assertEquals("neo", params.get(1).getSample().toString());
    ApiResultObject user = doc.getResults().get(0);
    ApiResultObject userId = user.getChildren().get(0);
    Assert.assertEquals("id", userId.getId());
    Assert.assertEquals("用户id", userId.getComment().getValue());
    Assert.assertEquals("123", userId.getSample().getValue());
    ApiResultObject userName = user.getChildren().get(1);
    Assert.assertEquals("name", userName.getId());
    Assert.assertEquals("用户名称", userName.getComment().getValue());
    Assert.assertEquals("neo", userName.getSample().getValue());
}
Also used : Api2DocCollector(com.terran4j.commons.api2doc.impl.Api2DocCollector) ApiParamObject(com.terran4j.commons.api2doc.domain.ApiParamObject) ApiFolderObject(com.terran4j.commons.api2doc.domain.ApiFolderObject) ApiDocObject(com.terran4j.commons.api2doc.domain.ApiDocObject) ApiResultObject(com.terran4j.commons.api2doc.domain.ApiResultObject) Test(org.junit.Test)

Example 10 with ApiResultObject

use of com.terran4j.commons.api2doc.domain.ApiResultObject in project commons by terran4j.

the class ParseEnumTest method testParseResultTypeWithEnum.

@Test
public void testParseResultTypeWithEnum() throws Exception {
    log.info("testParseResultTypeWithEnum");
    Method method = ReflectionUtils.findMethod(getClass(), "getState");
    Assert.assertNotNull(method);
    KeyedList<String, ApiResultObject> list = new KeyedList<>();
    ApiResultObject result = ApiResultObject.parseResultType(method, list);
    Assert.assertNotNull(result);
    Assert.assertEquals("可选值为:\nopen: 打开; \nclose: 关闭;", result.getComment().getValue().trim());
}
Also used : KeyedList(com.terran4j.commons.util.value.KeyedList) Method(java.lang.reflect.Method) ApiResultObject(com.terran4j.commons.api2doc.domain.ApiResultObject) Test(org.junit.Test)

Aggregations

ApiResultObject (com.terran4j.commons.api2doc.domain.ApiResultObject)12 Test (org.junit.Test)11 Method (java.lang.reflect.Method)9 KeyedList (com.terran4j.commons.util.value.KeyedList)7 ApiDocObject (com.terran4j.commons.api2doc.domain.ApiDocObject)2 ApiFolderObject (com.terran4j.commons.api2doc.domain.ApiFolderObject)2 ApiParamObject (com.terran4j.commons.api2doc.domain.ApiParamObject)2 Api2DocCollector (com.terran4j.commons.api2doc.impl.Api2DocCollector)2 MemoryCodeOutput (com.terran4j.commons.api2doc.codewriter.MemoryCodeOutput)1 Set (java.util.Set)1 HashedMap (org.apache.commons.collections4.map.HashedMap)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1