use of com.terran4j.commons.api2doc.impl.Api2DocCollector in project commons by terran4j.
the class ApiCommentUtilsTest method testSee.
@Test
public void testSee() throws Exception {
Api2DocCollector collector = new Api2DocCollector();
ApiFolderObject folder = collector.toApiFolder(new 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("terran4j", params.get(1).getSample().toString());
}
use of com.terran4j.commons.api2doc.impl.Api2DocCollector in project commons by terran4j.
the class ParseApiCommentOnParam method testParseApiCommentOnParam.
@Test
public void testParseApiCommentOnParam() throws Exception {
log.info("testParseApiCommentOnParam");
Method method = ReflectionUtils.findMethod(getClass(), "setUser", new Class<?>[] { String.class, boolean.class, User.class });
Assert.assertNotNull(method);
Api2DocCollector collector = new Api2DocCollector();
List<ApiParamObject> params = collector.toApiParams(method, null);
Assert.assertEquals(4, params.size());
ApiParamObject type = params.get(0);
Assert.assertEquals("type", type.getId());
Assert.assertEquals("用户类型", type.getComment().getValue());
Assert.assertEquals("root", type.getSample().getValue());
ApiParamObject asRoot = params.get(1);
Assert.assertEquals("asRoot", asRoot.getId());
Assert.assertEquals(ApiParamLocation.RequestParam, asRoot.getLocation());
ApiParamObject id = params.get(2);
Assert.assertEquals("id", id.getId());
Assert.assertEquals("账号id", id.getComment().getValue());
Assert.assertEquals("123", id.getSample().getValue());
ApiParamObject name = params.get(3);
Assert.assertEquals("name", name.getId());
Assert.assertEquals("账号用户名", name.getComment().getValue());
Assert.assertEquals("neo", name.getSample().getValue());
}
use of com.terran4j.commons.api2doc.impl.Api2DocCollector in project commons by terran4j.
the class ParseApiCommentOnSeeClassLoop method testParseApiCommentOnSeeClassLoop.
@Test
public void testParseApiCommentOnSeeClassLoop() throws Exception {
log.info("testParseApiCommentOnSeeClass");
Api2DocCollector collector = new Api2DocCollector();
ApiFolderObject folder = collector.toApiFolder(new ParseApiCommentOnSeeClassLoop.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.impl.Api2DocCollector in project commons by terran4j.
the class Api2DocCollectorTest method testToApiFolder.
@Test
public void testToApiFolder() throws Exception {
log.info("testToApiFolder");
Api2DocCollector collector = new Api2DocCollector();
ApiFolderObject folder = collector.toApiFolder(new UserController(), "userController");
Assert.assertNotNull(folder);
Assert.assertEquals(4, folder.getDocs().size());
// 按 order 及 方法中排序。
Assert.assertEquals("delete", folder.getDocs().get(0).getId());
Assert.assertEquals("getUser", folder.getDocs().get(1).getId());
Assert.assertEquals("getUsers", folder.getDocs().get(2).getId());
Assert.assertEquals("insert", folder.getDocs().get(3).getId());
}
use of com.terran4j.commons.api2doc.impl.Api2DocCollector in project commons by terran4j.
the class Api2DocUtilsTest method testToURL.
@Test
public void testToURL() throws Exception {
log.info("testToURL");
Api2DocCollector collector = new Api2DocCollector();
ApiFolderObject folder = collector.toApiFolder(new Api2DocUtilsTestController(), "userController");
ApiDocObject doc = folder.getDoc("getUser");
String url = Api2DocUtils.toURL(doc, serverURL);
Assert.assertEquals("http://localhost:8080/api/v1/user/123", url);
doc = folder.getDoc("getUser2");
url = Api2DocUtils.toURL(doc, serverURL);
Assert.assertEquals("http://localhost:8080/api/v1/user2/0", url);
doc = folder.getDoc("getUsers");
url = Api2DocUtils.toURL(doc, serverURL);
Assert.assertEquals("http://localhost:8080/api/v1/group/3/users?" + "age=30&city=%E5%8C%97%E4%BA%AC", url);
}
Aggregations