Skip to content

Commit 6ee9cc7

Browse files
committed
Add Documentation TestCase
1 parent 90cb937 commit 6ee9cc7

File tree

10 files changed

+265
-2
lines changed

10 files changed

+265
-2
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright Doma Tools Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.domaframework.doma.intellij.document
17+
18+
import com.intellij.psi.PsiElement
19+
import org.domaframework.doma.intellij.DomaSqlTest
20+
import org.domaframework.doma.intellij.psi.SqlElIdExpr
21+
22+
class SqlSymbolDocumentTestCase : DomaSqlTest() {
23+
val testPackage = "document"
24+
val testDaoName = "DocumentTestDao"
25+
val myDocumentationProvider: ForItemElementDocumentationProvider = ForItemElementDocumentationProvider()
26+
27+
override fun setUp() {
28+
super.setUp()
29+
addDaoJavaFile("$testPackage/$testDaoName.java")
30+
addSqlFile("$testPackage/$testDaoName/documentForItemDaoParam.sql")
31+
addSqlFile("$testPackage/$testDaoName/documentForItemDeclaration.sql")
32+
addSqlFile("$testPackage/$testDaoName/documentForItemElement.sql")
33+
addSqlFile("$testPackage/$testDaoName/documentForItemElementInBindVariable.sql")
34+
addSqlFile("$testPackage/$testDaoName/documentForItemElementInIfDirective.sql")
35+
addSqlFile("$testPackage/$testDaoName/documentForItemElementByFieldAccess.sql")
36+
}
37+
38+
fun testDocumentForItemDaoParam() {
39+
val sqlName = "documentForItemDaoParam"
40+
val result: String? = null
41+
42+
documentationTest(sqlName, result)
43+
}
44+
45+
fun testDocumentForItemDeclaration() {
46+
val sqlName = "documentForItemDeclaration"
47+
val result =
48+
"<a href=\"psi_element://java.util.List\">List</a><<a href=\"psi_element://java.util.List\">" +
49+
"List</a><<a href=\"psi_element://java.lang.Integer\">Integer</a>>> employeeIds"
50+
51+
documentationTest(sqlName, result)
52+
}
53+
54+
fun testDocumentForItemElement() {
55+
val sqlName = "documentForItemElement"
56+
val result =
57+
"<a href=\"psi_element://java.util.List\">List</a><<a href=\"psi_element://java.util.List\">" +
58+
"List</a><<a href=\"psi_element://java.lang.Integer\">Integer</a>>> employeeIds"
59+
60+
documentationFindTextTest(sqlName, "employeeIds", result)
61+
}
62+
63+
fun testDocumentForItemElementInBindVariable() {
64+
val sqlName = "documentForItemElementInBindVariable"
65+
val result =
66+
"<a href=\"psi_element://java.util.List\">List</a><" +
67+
"<a href=\"psi_element://java.lang.Integer\">Integer</a>> ids"
68+
69+
documentationTest(sqlName, result)
70+
}
71+
72+
fun testDocumentForItemElementInIfDirective() {
73+
val sqlName = "documentForItemElementInIfDirective"
74+
val result =
75+
"<a href=\"psi_element://java.util.List\">List</a><" +
76+
"<a href=\"psi_element://java.lang.Integer\">Integer</a>> ids"
77+
78+
documentationTest(sqlName, result)
79+
}
80+
81+
fun testDocumentForItemElementByFieldAccess() {
82+
val sqlName = "documentForItemElementByFieldAccess"
83+
val result =
84+
"<a href=\"psi_element://doma.example.entity.Project\">Project</a> project"
85+
86+
documentationTest(sqlName, result)
87+
}
88+
89+
private fun documentationTest(
90+
sqlName: String,
91+
result: String?,
92+
) {
93+
val sqlFile = findSqlFile("$testPackage/$testDaoName/$sqlName.sql")
94+
assertNotNull("Not Found SQL File", sqlFile)
95+
if (sqlFile == null) return
96+
97+
myFixture.configureFromExistingVirtualFile(sqlFile)
98+
var originalElement: PsiElement = myFixture.elementAtCaret
99+
println("originalElement: ${originalElement.text}")
100+
101+
val resultDocument = myDocumentationProvider.generateDoc(originalElement, originalElement)
102+
assertEquals("Documentation should contain expected text", result, resultDocument)
103+
}
104+
105+
private fun documentationFindTextTest(
106+
sqlName: String,
107+
originalElementName: String,
108+
result: String?,
109+
) {
110+
val sqlFile = findSqlFile("$testPackage/$testDaoName/$sqlName.sql")
111+
assertNotNull("Not Found SQL File", sqlFile)
112+
if (sqlFile == null) return
113+
114+
myFixture.configureFromExistingVirtualFile(sqlFile)
115+
var originalElement: PsiElement = myFixture.findElementByText(originalElementName, SqlElIdExpr::class.java)
116+
println("originalElement: ${originalElement.text}")
117+
118+
val resultDocument = myDocumentationProvider.generateDoc(originalElement, originalElement)
119+
assertEquals("Documentation should contain expected text", result, resultDocument)
120+
}
121+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package doma.example.dao.document;
2+
3+
import java.util.List;
4+
import java.util.HashSet;
5+
import doma.example.entity.*;
6+
import org.seasar.doma.*;
7+
8+
@Dao
9+
public interface DocumentTestDao {
10+
11+
@Select
12+
List<Employee> documentForItemDaoParam(HashSet<List<List<Integer>>> employeeIdsList);
13+
14+
@Select
15+
List<Employee> documentForItemDeclaration(HashSet<List<List<Integer>>> employeeIdsList);
16+
17+
@Select
18+
List<Employee> documentForItemElement(HashSet<List<List<Integer>>> employeeIdsList);
19+
20+
@Select
21+
List<Employee> documentForItemElementInBindVariable(HashSet<List<List<Integer>>> employeeIdsList);
22+
23+
@Select
24+
List<Employee> documentForItemElementInIfDirective(HashSet<List<List<Integer>>> employeeIdsList);
25+
26+
@Select
27+
List<Employee> documentForItemElementByFieldAccess(List<List<Employee>> employeesList);
28+
29+
}

src/test/testData/src/main/java/doma/example/dao/reference/ReferenceTestDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public interface ReferenceTestDao {
2020
List<Employee> referenceListFieldMethod(List<Employee> employeesList);
2121

2222
@Select
23-
List<Employee> referenceForItem(List<List<List<Employee>>> employeesList);
23+
List<Employee> referenceForItem(List<List<Employee>> employeesList);
2424

2525
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SELECT *
2+
FROM employees
3+
WHERE 1=1
4+
-- employeeIdsList -> HashSet<List<List<Integer>>>
5+
/*%for employeeIds : employee<caret>IdsList */
6+
-- employeeIds -> List<List<Integer>>
7+
/*%for ids : employeeIds */
8+
-- ids -> List<Integer>
9+
/*%if ids.size < 100 */
10+
-- id -> Integer
11+
/*%for id : ids */
12+
AND department = /* id */
13+
/*%end */
14+
/*%else*/
15+
AND departments = /* ids */(1,2,3)
16+
/*%end */
17+
/*%end */
18+
/*%end */
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SELECT *
2+
FROM employees
3+
WHERE 1=1
4+
-- employeeIdsList -> HashSet<List<List<Integer>>>
5+
/*%for employeeIds : employeeIdsList */
6+
-- employeeIds -> List<List<Integer>>
7+
/*%for ids : <caret>employeeIds */
8+
-- ids -> List<Integer>
9+
/*%if ids.size < 100 */
10+
-- id -> Integer
11+
/*%for id : ids */
12+
AND department = /* id */
13+
/*%end */
14+
/*%else*/
15+
AND departments = /* ids */(1,2,3)
16+
/*%end */
17+
/*%end */
18+
/*%end */
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SELECT *
2+
FROM employees
3+
WHERE 1=1
4+
/*%for employ<caret>eeIds : employeeIdsList */
5+
-- employeeIds -> List<List<Integer>>
6+
/*%for ids : employeeIds */
7+
-- ids -> List<Integer>
8+
/*%if ids.size < 100 */
9+
-- id -> Integer
10+
/*%for id : ids */
11+
OR department = /* id */
12+
/*%end */
13+
/*%else*/
14+
OR departments = /* ids */(1,2,3)
15+
/*%end */
16+
/*%end */
17+
/*%end */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
SELECT id
2+
FROM project_detail
3+
WHERE category = 'category'
4+
-- employeesList -> List<List<Employee>>
5+
/*%for employees : employeesList */
6+
-- employees_has_next -> -> List<Employee>
7+
/*%if employees_has_next */
8+
/*# "OR" */
9+
/*%end */
10+
-- employees -> -> List<Employee>
11+
/*%for employee : employees */
12+
/*%for project : employee.projects */
13+
-- project -> Project
14+
project_id = /* pr<caret>oject.projectId */
15+
/*%end */
16+
number >= /* employee.projects.get(0).projectNumber */9999
17+
/*%if employee_has_next */
18+
/*# "AND" */
19+
/*%end */
20+
/*%end */
21+
/*%end */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SELECT *
2+
FROM employees
3+
WHERE 1=1
4+
-- employeeIdsList -> HashSet<List<List<Integer>>>
5+
/*%for employeeIds : employeeIdsList */
6+
-- employeeIds -> List<List<Integer>>
7+
/*%for ids : employeeIds */
8+
-- ids -> List<Integer>
9+
/*%if ids.size < 100 */
10+
-- id -> Integer
11+
/*%for id : ids */
12+
AND department = /* id */
13+
/*%end */
14+
/*%else*/
15+
AND departments = /* id<caret>s */(1,2,3)
16+
/*%end */
17+
/*%end */
18+
/*%end */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SELECT *
2+
FROM employees
3+
WHERE 1=1
4+
-- employeeIdsList -> HashSet<List<List<Integer>>>
5+
/*%for employeeIds : employeeIdsList */
6+
-- employeeIds -> List<List<Integer>>
7+
/*%for ids : employeeIds */
8+
-- ids -> List<Integer>
9+
/*%if id<caret>s.size < 100 */
10+
-- id -> Integer
11+
/*%for id : ids */
12+
AND department = /* id */
13+
/*%end */
14+
/*%else*/
15+
AND departments = /* ids */(1,2,3)
16+
/*%end */
17+
/*%end */
18+
/*%end */

src/test/testData/src/main/resources/META-INF/doma/example/dao/reference/ReferenceTestDao/referenceForItem.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
SELECT id
22
FROM project_detail
3-
WHERE category = /* employeesList.get(0).get(0).get(0).projects.get(0).projectCategory */'category'
3+
-- List<List<Employee>> employeesList
4+
WHERE category = /* employeesList.get(0).get(0).projects.get(0).projectCategory */'category'
45
/*%for employees : employeesList */
56
/*%if employees_has_next */
67
/*# "OR" */
78
/*%end */
9+
-- List<Employee> employees
810
/*%for employee : employees */
11+
-- Employee employee
912
/*%for project : employee.projects */
1013
project_id = /* project.projectId */
1114
/*%end */

0 commit comments

Comments
 (0)