use of com.terran4j.commons.util.value.KeyedList 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.util.value.KeyedList 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.util.value.KeyedList 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());
}
use of com.terran4j.commons.util.value.KeyedList in project commons by terran4j.
the class ParseListBeanTest method testParseListBean.
@Test
public void testParseListBean() throws Exception {
log.info("testParseListBean");
Method method = ReflectionUtils.findMethod(getClass(), "getListBean");
Assert.assertNotNull(method);
KeyedList<String, ApiResultObject> list = new KeyedList<>();
ApiResultObject results = ApiResultObject.parseResultType(method, list);
Assert.assertNotNull(results);
log.info("results: {}", results);
Assert.assertTrue(list.size() == 2);
ApiResultObject resultTop = list.get(0);
log.info("resultTop: {}", resultTop);
Assert.assertTrue(resultTop.getChildren().size() == 1);
ApiResultObject users = resultTop.getChildren().get(0);
Assert.assertEquals("users", users.getId());
Assert.assertEquals("There are many users!", users.getComment().getValue());
ApiResultObject resultUser = list.get(1);
log.info("resultUser: {}", resultUser);
Assert.assertEquals("users", resultUser.getId());
Assert.assertTrue(resultUser.getChildren().size() == 2);
ApiResultObject userId = resultUser.getChildren().get(0);
Assert.assertEquals("id", userId.getId());
Assert.assertEquals("账号id", userId.getComment().getValue());
}
Aggregations