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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations