Search in sources :

Example 6 with KeyedList

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);
}
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 7 with KeyedList

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());
}
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 8 with KeyedList

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

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

KeyedList (com.terran4j.commons.util.value.KeyedList)9 Method (java.lang.reflect.Method)8 ApiResultObject (com.terran4j.commons.api2doc.domain.ApiResultObject)7 Test (org.junit.Test)7 Api2Doc (com.terran4j.commons.api2doc.annotations.Api2Doc)1 ApiComment (com.terran4j.commons.api2doc.annotations.ApiComment)1 ApiError (com.terran4j.commons.api2doc.annotations.ApiError)1 ApiErrors (com.terran4j.commons.api2doc.annotations.ApiErrors)1 MemoryCodeOutput (com.terran4j.commons.api2doc.codewriter.MemoryCodeOutput)1 ApiParamObject (com.terran4j.commons.api2doc.domain.ApiParamObject)1 ValueSource (com.terran4j.commons.util.value.ValueSource)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)1