Skip to content

Commit 990f6ec

Browse files
committed
Update test cases for custom function definition class reference method change
1 parent 520305e commit 990f6ec

File tree

18 files changed

+79
-48
lines changed

18 files changed

+79
-48
lines changed

src/test/kotlin/org/domaframework/doma/intellij/DomaSqlTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ import com.intellij.openapi.vfs.VirtualFile
2828
import com.intellij.psi.PsiClass
2929
import com.intellij.testFramework.PsiTestUtil
3030
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
31+
import org.domaframework.doma.intellij.common.CommonPathParameterUtil
3132
import org.domaframework.doma.intellij.common.RESOURCES_META_INF_PATH
3233
import org.domaframework.doma.intellij.extension.getResourcesSQLFile
33-
import org.domaframework.doma.intellij.setting.SettingComponent
34-
import org.domaframework.doma.intellij.setting.state.DomaToolsCustomFunctionSettings
3534
import org.jetbrains.jps.model.java.JavaResourceRootType
3635
import org.jetbrains.jps.model.java.JavaSourceRootType
3736
import org.junit.Ignore
@@ -68,6 +67,7 @@ open class DomaSqlTest : LightJavaCodeInsightFixtureTestCase() {
6867
override fun tearDown() {
6968
try {
7069
deleteSdk()
70+
CommonPathParameterUtil.clearCache()
7171
} finally {
7272
super.tearDown()
7373
}
@@ -169,7 +169,7 @@ open class DomaSqlTest : LightJavaCodeInsightFixtureTestCase() {
169169
)
170170
}
171171

172-
fun addResourceEmptyFile(vararg sqlFileNames: String) {
172+
fun addResourceEmptySqlFile(vararg sqlFileNames: String) {
173173
for (sqlFileName in sqlFileNames) {
174174
myFixture.addFileToProject(
175175
"main/$resourceRoot/$RESOURCES_META_INF_PATH/$packagePath/dao/$sqlFileName",
@@ -178,6 +178,14 @@ open class DomaSqlTest : LightJavaCodeInsightFixtureTestCase() {
178178
}
179179
}
180180

181+
fun addResourceCompileFile(readFileName: String) {
182+
val file = File("$testDataPath/$resourceRoot/$readFileName")
183+
myFixture.addFileToProject(
184+
"main/$resourceRoot/doma.compile.config",
185+
file.readText(),
186+
)
187+
}
188+
181189
fun addSqlFile(vararg sqlNames: String) {
182190
for (sqlName in sqlNames) {
183191
val file = File("$testDataPath/$resourceRoot/$RESOURCES_META_INF_PATH/$packagePath/dao/$sqlName")
@@ -209,12 +217,4 @@ open class DomaSqlTest : LightJavaCodeInsightFixtureTestCase() {
209217
file.readText(),
210218
)
211219
}
212-
213-
protected fun settingCustomFunctions(newClassNames: MutableList<String>) {
214-
val settings = DomaToolsCustomFunctionSettings.getInstance(project)
215-
val component = SettingComponent()
216-
component.customFunctionClassNames = newClassNames.toMutableList()
217-
settings.apply(component)
218-
assertEquals(newClassNames, settings.getState().customFunctionClassNames)
219-
}
220220
}

src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlCompleteTest.kt

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.domaframework.doma.intellij.complate.sql
1717

1818
import org.domaframework.doma.intellij.DomaSqlTest
19-
import org.domaframework.doma.intellij.inspection.sql.inspector.SqlBindVariableValidInspector
2019

2120
/**
2221
* Code completion testing in SQL
@@ -60,8 +59,8 @@ class SqlCompleteTest : DomaSqlTest() {
6059
"$testDapName/completeOptionalBatchAnnotation.sql",
6160
"$testDapName/completeForDirectiveItem.sql",
6261
"$testDapName/completeImplementCustomFunction.sql",
62+
"$testDapName/completeNotImplementCustomFunction.sql",
6363
)
64-
myFixture.enableInspections(SqlBindVariableValidInspector())
6564
}
6665

6766
fun testCompleteDaoArgument() {
@@ -266,12 +265,16 @@ class SqlCompleteTest : DomaSqlTest() {
266265
"isNotBlank()",
267266
),
268267
listOf(
269-
"escape()",
270-
"prefix()",
271-
"infix()",
272-
"suffix()",
273-
"roundDownTimePart()",
274-
"roundUpTimePart()",
268+
"userId()",
269+
"userName()",
270+
"userAge()",
271+
"langCode()",
272+
"isGest()",
273+
"getId()",
274+
"getName()",
275+
"getAge()",
276+
"getLangCode()",
277+
"isManager()",
275278
),
276279
)
277280
}
@@ -402,9 +405,7 @@ class SqlCompleteTest : DomaSqlTest() {
402405
}
403406

404407
fun testCompleteImplementCustomFunction() {
405-
settingCustomFunctions(
406-
mutableListOf("doma.example.expression.TestExpressionFunctions", "doma.example.expression.TestNotExpressionFunctions"),
407-
)
408+
addResourceCompileFile("doma.compile.config")
408409
innerDirectiveCompleteTest(
409410
"$testDapName/completeImplementCustomFunction.sql",
410411
listOf("userId()", "userName()", "userAge()", "langCode()", "isGest()", "isBlank()", "isNotBlank()"),
@@ -413,9 +414,15 @@ class SqlCompleteTest : DomaSqlTest() {
413414
}
414415

415416
fun testCompleteNotImplementCustomFunction() {
417+
addResourceCompileFile("invalid.doma.compile.config")
416418
innerDirectiveCompleteTest(
417-
"$testDapName/completeImplementCustomFunction.sql",
418-
listOf("isEmpty()", "roundDownTimePart()", "isBlank()", "isNotBlank()"),
419+
"$testDapName/completeNotImplementCustomFunction.sql",
420+
listOf(
421+
"isEmpty()",
422+
"isNotEmpty()",
423+
"isBlank()",
424+
"isNotBlank()",
425+
),
419426
listOf(
420427
"userId()",
421428
"userName()",

src/test/kotlin/org/domaframework/doma/intellij/gutteraction/dao/DaoGenerateSqlActionTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class DaoGenerateSqlActionTest : DomaSqlTest() {
6060
"gutteraction/SqlProcessorGutterTestDao.java",
6161
)
6262

63-
addResourceEmptyFile(
63+
addResourceEmptySqlFile(
6464
"quickfix/SelectQuickFixTestDao/existsSQLFile.sql",
6565
"quickfix/InsertQuickFixTestDao/existsSQLFile.sql",
6666
"quickfix/UpdateQuickFixTestDao/existsSQLFile.sql",
@@ -71,7 +71,7 @@ class DaoGenerateSqlActionTest : DomaSqlTest() {
7171
"quickfix/ScriptQuickFixTestDao/existsSQLFile.script",
7272
"quickfix/SqlProcessorQuickFixTestDao/existsSQLFile.sql",
7373
)
74-
addResourceEmptyFile(
74+
addResourceEmptySqlFile(
7575
"gutteraction/SelectGutterTestDao/existsSQLFile1.sql",
7676
"gutteraction/InsertGutterTestDao/existsSQLFile2.sql",
7777
"gutteraction/UpdateGutterTestDao/existsSQLFile1.sql",

src/test/kotlin/org/domaframework/doma/intellij/gutteraction/dao/DaoGutterActionTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class DaoGutterActionTest : DomaSqlTest() {
4545
"$packageName/ScriptGutterTestDao.java",
4646
"$packageName/SqlProcessorGutterTestDao.java",
4747
)
48-
addResourceEmptyFile(
48+
addResourceEmptySqlFile(
4949
"$packageName/SelectGutterTestDao/existsSQLFile1.sql",
5050
"$packageName/InsertGutterTestDao/existsSQLFile1.sql",
5151
"$packageName/UpdateGutterTestDao/existsSQLFile1.sql",
@@ -56,7 +56,7 @@ class DaoGutterActionTest : DomaSqlTest() {
5656
"$packageName/ScriptGutterTestDao/existsSQLFile1.script",
5757
"$packageName/SqlProcessorGutterTestDao/existsSQLFile1.sql",
5858
)
59-
addResourceEmptyFile(
59+
addResourceEmptySqlFile(
6060
"$packageName/SelectGutterTestDao/existsSQLFile2.sql",
6161
"$packageName/InsertGutterTestDao/existsSQLFile2.sql",
6262
"$packageName/UpdateGutterTestDao/existsSQLFile2.sql",
@@ -67,7 +67,7 @@ class DaoGutterActionTest : DomaSqlTest() {
6767
"$packageName/ScriptGutterTestDao/existsSQLFile2.script",
6868
"$packageName/SqlProcessorGutterTestDao/existsSQLFile2.sql",
6969
)
70-
addResourceEmptyFile(
70+
addResourceEmptySqlFile(
7171
"$packageName/BatchInsertGutterTestDao/existsSQLFile3.sql",
7272
"$packageName/BatchUpdateGutterTestDao/existsSQLFile3.sql",
7373
"$packageName/BatchDeleteGutterTestDao/existsSQLFile3.sql",

src/test/kotlin/org/domaframework/doma/intellij/gutteraction/dao/DaoJumpActionTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DaoJumpActionTest : DomaSqlTest() {
6161
"$packageName/$notDisplayedPackage/SqlProcessorInvalidCaretTestDao.java",
6262
"$packageName/$notDisplayedPackage/InvalidCaretTestDao.java",
6363
)
64-
addResourceEmptyFile(
64+
addResourceEmptySqlFile(
6565
"$packageName/SelectGutterTestDao/existsSQLFile1.sql",
6666
"$packageName/InsertGutterTestDao/existsSQLFile1.sql",
6767
"$packageName/UpdateGutterTestDao/existsSQLFile1.sql",
@@ -72,7 +72,7 @@ class DaoJumpActionTest : DomaSqlTest() {
7272
"$packageName/ScriptGutterTestDao/existsSQLFile1.script",
7373
"$packageName/SqlProcessorGutterTestDao/existsSQLFile1.sql",
7474
)
75-
addResourceEmptyFile(
75+
addResourceEmptySqlFile(
7676
"$packageName/SelectGutterTestDao/existsSQLFile2.sql",
7777
"$packageName/InsertGutterTestDao/existsSQLFile2.sql",
7878
"$packageName/UpdateGutterTestDao/existsSQLFile2.sql",

src/test/kotlin/org/domaframework/doma/intellij/inspection/dao/DomaSqlExistTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class DomaSqlExistTest : DomaSqlTest() {
3232
"ScriptTestDao.java",
3333
"SqlProcessorTestDao.java",
3434
)
35-
addResourceEmptyFile(
35+
addResourceEmptySqlFile(
3636
"SelectTestDao/existsSQLFile.sql",
3737
"InsertTestDao/existsSQLFile.sql",
3838
"UpdateTestDao/existsSQLFile.sql",

src/test/kotlin/org/domaframework/doma/intellij/inspection/dao/DomaSqlQuickFixTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DomaSqlQuickFixTest : DomaSqlTest() {
3737
"quickfix/SqlProcessorQuickFixTestDao.java",
3838
)
3939

40-
addResourceEmptyFile(
40+
addResourceEmptySqlFile(
4141
"quickfix/SelectQuickFixTestDao/existsSQLFile.sql",
4242
"quickfix/InsertQuickFixTestDao/existsSQLFile.sql",
4343
"quickfix/UpdateQuickFixTestDao/existsSQLFile.sql",

src/test/kotlin/org/domaframework/doma/intellij/inspection/sql/ParameterDefinedTest.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.domaframework.doma.intellij.inspection.sql
1717

1818
import org.domaframework.doma.intellij.DomaSqlTest
19-
import org.domaframework.doma.intellij.common.helper.ActiveProjectHelper
2019
import org.domaframework.doma.intellij.inspection.sql.inspector.SqlBindVariableValidInspector
2120

2221
/**
@@ -41,6 +40,7 @@ class ParameterDefinedTest : DomaSqlTest() {
4140
"$testDaoName/bindVariableForItemHasNextAndIndex.sql",
4241
"$testDaoName/optionalDaoParameterFieldAccess.sql",
4342
"$testDaoName/implementCustomFunctions.sql",
43+
"$testDaoName/invalidImplementCustomFunctions.sql",
4444
)
4545
myFixture.enableInspections(SqlBindVariableValidInspector())
4646
}
@@ -126,18 +126,22 @@ class ParameterDefinedTest : DomaSqlTest() {
126126
}
127127

128128
fun testImplementCustomFunctions() {
129-
if (project != null) {
130-
ActiveProjectHelper.setCurrentActiveProject(project)
131-
}
132-
settingCustomFunctions(
133-
mutableListOf("doma.example.expression.TestExpressionFunctions", "doma.example.expression.TestNotExpressionFunctions"),
134-
)
135-
129+
addResourceCompileFile("doma.compile.config")
136130
val sqlFile =
137131
findSqlFile("$testDaoName/implementCustomFunctions.sql")
138132
assertNotNull("Not Found SQL File", sqlFile)
139133
if (sqlFile == null) return
140134

141135
myFixture.testHighlighting(false, false, false, sqlFile)
142136
}
137+
138+
fun testInvalidImplementCustomFunctions() {
139+
addResourceCompileFile("invalid.doma.compile.config")
140+
val sqlFile =
141+
findSqlFile("$testDaoName/invalidImplementCustomFunctions.sql")
142+
assertNotNull("Not Found SQL File", sqlFile)
143+
if (sqlFile == null) return
144+
145+
myFixture.testHighlighting(false, false, false, sqlFile)
146+
}
143147
}

src/test/kotlin/org/domaframework/doma/intellij/refactor/DaoMethodRenameTestCase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DaoMethodRenameTestCase : DomaSqlTest() {
2929
"RenameDaoMethodWithoutSql.java",
3030
"RenameDaoMethodNotExistSql.java",
3131
)
32-
addResourceEmptyFile(
32+
addResourceEmptySqlFile(
3333
"RenameDaoMethod/renameDaoMethodName.sql",
3434
"RenameDao/renameDaoClassName.sql",
3535
)

src/test/kotlin/org/domaframework/doma/intellij/reference/SqlReferenceTestCase.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ class SqlReferenceTestCase : DomaSqlTest() {
128128
}
129129

130130
fun testReferenceCustomFunction() {
131-
settingCustomFunctions(
132-
mutableListOf("doma.example.expression.TestExpressionFunctions", "doma.example.expression.TestNotExpressionFunctions"),
133-
)
131+
addResourceCompileFile("doma.compile.config")
134132
referenceTest(
135133
"referenceCustomFunction",
136134
mapOf(

0 commit comments

Comments
 (0)