Skip to content

Commit b91947d

Browse files
committed
Add TestDataCheckInspection TestCase
1 parent 881913e commit b91947d

File tree

8 files changed

+168
-0
lines changed

8 files changed

+168
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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.inspection.sql
17+
18+
import org.domaframework.doma.intellij.DomaSqlTest
19+
import org.domaframework.doma.intellij.inspection.sql.inspector.SqlTestDataAfterBlockCommentValidValidInspector
20+
21+
class TestDataCheckTest : DomaSqlTest() {
22+
private val testDaoName = "TestDataCheckDao"
23+
private val packageName = "inspection"
24+
25+
override fun setUp() {
26+
super.setUp()
27+
addDaoJavaFile(
28+
"$packageName/$testDaoName.java",
29+
)
30+
addSqlFile(
31+
"$packageName/$testDaoName/literalDirective.sql",
32+
"$packageName/$testDaoName/bindVariableDirective.sql",
33+
"$packageName/$testDaoName/conditionAndLoopDirective.sql",
34+
"$packageName/$testDaoName/commentBlock.sql",
35+
"$packageName/$testDaoName/populateDirective.sql",
36+
"$packageName/$testDaoName/invalidTestData.sql",
37+
)
38+
myFixture.enableInspections(SqlTestDataAfterBlockCommentValidValidInspector())
39+
}
40+
41+
fun testLiteralDirective() {
42+
val sqlFile = findSqlFile("$packageName/$testDaoName/literalDirective.sql")
43+
assertNotNull("Not Found SQL File", sqlFile)
44+
if (sqlFile == null) return
45+
46+
myFixture.testHighlighting(false, false, false, sqlFile)
47+
}
48+
49+
fun testBindVariableDirective() {
50+
val sqlFile = findSqlFile("$packageName/$testDaoName/bindVariableDirective.sql")
51+
assertNotNull("Not Found SQL File", sqlFile)
52+
if (sqlFile == null) return
53+
54+
myFixture.testHighlighting(false, false, false, sqlFile)
55+
}
56+
57+
fun testConditionAndLoopDirective() {
58+
val sqlFile = findSqlFile("$packageName/$testDaoName/conditionAndLoopDirective.sql")
59+
assertNotNull("Not Found SQL File", sqlFile)
60+
if (sqlFile == null) return
61+
62+
myFixture.testHighlighting(false, false, false, sqlFile)
63+
}
64+
65+
fun testCommentBlock() {
66+
val sqlFile =
67+
findSqlFile("$packageName/$testDaoName/commentBlock.sql")
68+
assertNotNull("Not Found SQL File", sqlFile)
69+
if (sqlFile == null) return
70+
71+
myFixture.testHighlighting(false, false, false, sqlFile)
72+
}
73+
74+
fun testPopulateDirective() {
75+
val sqlFile =
76+
findSqlFile("$packageName/$testDaoName/populateDirective.sql")
77+
assertNotNull("Not Found SQL File", sqlFile)
78+
if (sqlFile == null) return
79+
80+
myFixture.testHighlighting(false, false, false, sqlFile)
81+
}
82+
83+
fun testInvalidTestData() {
84+
val sqlFile =
85+
findSqlFile("$packageName/$testDaoName/invalidTestData.sql")
86+
assertNotNull("Not Found SQL File", sqlFile)
87+
if (sqlFile == null) return
88+
89+
myFixture.testHighlighting(false, false, false, sqlFile)
90+
}
91+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package doma.example.dao.inspection;
2+
3+
import doma.example.entity.*:
4+
import org.seasar.doma.*;
5+
import org.seasar.doma.jdbc.Config;
6+
import org.seasar.doma.jdbc.PreparedSql;
7+
import org.seasar.doma.jdbc.SelectOptions;
8+
9+
import java.util.List;
10+
import java.util.function.BiFunction;
11+
12+
@Dao
13+
interface TestDataCheckDao {
14+
15+
@Select
16+
EmployeeSummary literalDirective(String literalName, Integer literalId, Integer literalAge);
17+
18+
@Insert(sqlFile=true)
19+
int bindVariableDirective(Employee employee);
20+
21+
@Select
22+
List<Employee> conditionAndLoopDirective(List<Project> projects,LocalDate referenceDate);
23+
24+
@Select
25+
Employee commentBlock(Integer id);
26+
27+
@Update(sqlFile=true)
28+
int populateDirective(Employee employee);
29+
30+
@Insert(sqlFile=true)
31+
int invalidTestData(Employee employee);
32+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
INSERT INTO employee
2+
(employee_id
3+
, employee_name
4+
, department_name)
5+
VALUES ( /* employee.employeeId */0
6+
, <error descr="Bind variables must be followed by test data">/* employee.employeeName */</error>
7+
, <error descr="Bind variables must be followed by test data">/* employee.department */</error>)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- This Comment Line
2+
SELECT e.employee_id AS employeeId
3+
, e.employee_name AS employeeName
4+
, e.department_name AS departmentName
5+
/**
6+
This is a comment block
7+
*/
8+
FROM employee e
9+
/*%! This comment will be removed */
10+
WHERE e.employee_id = <error descr="Bind variables must be followed by test data">/*^ id */</error>
11+
AND e.age >= /*^ literalAge */99
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SELECT *
2+
FROM employee
3+
WHERE join_at <= <error descr="Bind variables must be followed by test data">/* referenceDate */</error>
4+
/*%for project : projects */
5+
employee_name LIKE /* project.projectName */'hoge'
6+
/*%if project_has_next */
7+
/*# "or" */
8+
/*%end */
9+
/*%end*/
10+
OR salary > 1000
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
INSERT INTO employee
2+
(employee_id
3+
, employee_name
4+
, department_name)
5+
VALUES ( /* employee.employeeId */0
6+
, /* employee.employeeName */'name'
7+
, <error descr="Bind variables must be followed by test data">/* employee.department */</error>department)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SELECT e.employee_id AS employeeId
2+
, e.employee_name AS employeeName
3+
, e.department_name AS departmentName
4+
FROM employee e
5+
WHERE e.employee_id = <error descr="Bind variables must be followed by test data">/*^ literalId */</error>
6+
AND e.employee_name = <error descr="Bind variables must be followed by test data">/*^ literalName */</error>
7+
AND e.age >= /*^ literalAge */99
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
UPDATE employee
2+
SET /*%populate*/id = id
3+
WHERE rank < <error descr="Bind variables must be followed by test data">/* emplotee.rank */</error>

0 commit comments

Comments
 (0)