Skip to content

Commit 93ebd3d

Browse files
committed
Add tests for annotation option parameter inspection with parent class properties
1 parent 7bfaaee commit 93ebd3d

File tree

8 files changed

+306
-188
lines changed

8 files changed

+306
-188
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.dao
17+
18+
import org.domaframework.doma.intellij.DomaSqlTest
19+
import org.domaframework.doma.intellij.inspection.dao.inspector.DaoAnnotationOptionParameterInspection
20+
21+
/**
22+
* Test class for annotation option parameter inspection.
23+
* Tests include/exclude options with parent class properties.
24+
*/
25+
class AnnotationOptionParameterInspectionTest : DomaSqlTest() {
26+
/**
27+
* Since error highlight tags for annotation options cannot be set in the test data, verify manually.
28+
* There are no automated test cases, so perform manual checks using the following as a reference.
29+
*
30+
* Here is an updated summary of the test case coverage based on the revised method documentation. This can be used as a test case overview document.
31+
* Relation: [AnnotationOptionTestInValidDao]
32+
* - Error check when specifying fields not defined in the parameter type with `include` option.
33+
* - Error check when specifying fields not defined in the parameter type with `exclude` option.
34+
* - Error check for specifying fields not defined in immutable Entity with `MultiInsert` (also for fields not defined in parameter type).
35+
* - Error check for specifying fields not defined in mutable Entity with `MultiInsert`.
36+
* - Error check for specifying fields not defined in parameter type with batch annotations.
37+
* - Error when ending with an embedded property.
38+
* - Error when specifying incorrect properties in an embedded class.
39+
* - Error check for invalid field specification in `Returning` option.
40+
* - Error check for invalid field specification in `Returning` option for mutable Entity.
41+
* - Error check for specifying fields not defined in embedded property.
42+
* - Error when specifying further properties from a primitive type.
43+
* - Error check for specifying parent class properties in subclass with `@Entity`.
44+
* - Error check for specifying parent class properties in subclass without `@Entity`.
45+
*/
46+
}

src/test/testData/src/main/java/doma/example/dao/inspection/option/AnnotationOptionTestDao_base.java

Lines changed: 0 additions & 94 deletions
This file was deleted.

src/test/testData/src/main/java/doma/example/dao/inspection/option/AnnotationOptionTestDao_highlight.java

Lines changed: 0 additions & 94 deletions
This file was deleted.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package doma.example.dao.inspection.option;
2+
3+
import doma.example.entity.Department;
4+
import doma.example.entity.NonSubEntity;
5+
import doma.example.entity.Pckt;
6+
import doma.example.entity.SubEntity;
7+
import org.seasar.doma.*;
8+
import org.seasar.doma.jdbc.MultiResult;
9+
10+
import java.util.List;
11+
12+
/**
13+
* When using this test data with [LightJavaCodeInsightFixtureTestCase],
14+
* the highlighted elements are not parsed correctly, resulting in errors.
15+
* Compare the highlights in this test data with the actual highlights in IDEA,
16+
* and visually confirm that the highlights and errors occur as expected based on the test data.
17+
*/
18+
@Dao
19+
public interface AnnotationOptionTestInValidDao {
20+
21+
/**
22+
* include: Error highlight when specifying fields not defined in the parameter type
23+
* Error: Field [invalidField] specified in [include] option does not exist in "Department". Available fields: [id, name, location, managerCount, subId, embeddableEntity, embeddableEntity2]
24+
* @param department
25+
* @return
26+
*/
27+
@Update(include = {"name", "invalidField"})
28+
int updateWithInvalidInclude(Department department);
29+
30+
/**
31+
* exclude: Error highlight when specifying fields not defined in the parameter type
32+
* Error: Field [salary] specified in [exclude] option does not exist in "Department". Available fields: [id, name, location, managerCount, subId, embeddableEntity, embeddableEntity2]
33+
* @param department
34+
* @return
35+
*/
36+
@Insert(exclude = {"salary", "location"})
37+
int insertWithInvalidExclude(Department department);
38+
39+
/**
40+
* MultiInsert: Error highlight when specifying fields not defined in immutable Entity
41+
* Also error highlight when specifying fields not defined in the parameter type
42+
* Error: Field [salary] specified in [include] option does not exist in "Department". Available fields: [id, name, location, managerCount, subId, embeddableEntity, embeddableEntity2]
43+
* Field [bonus] specified in [exclude] option does not exist in "Department". Available fields: [id, name, location, managerCount, subId, embeddableEntity, embeddableEntity2]
44+
* @param departments
45+
* @return
46+
*/
47+
@MultiInsert(include = {"salary"}, exclude = {"bonus"})
48+
int multiInsert(List<Department> departments);
49+
50+
/**
51+
* MultiInsert: Error highlight when specifying fields not defined in mutable Entity in include/exclude
52+
* Error: Field [salary] specified in [include] option does not exist in "Pckt". Available fields: [id, name]
53+
* Field [bonus] specified in [exclude] option does not exist in "Pckt". Available fields: [id, name]
54+
* @param pckts
55+
* @return
56+
*/
57+
@MultiInsert(include = {"salary"}, exclude = {"bonus"})
58+
MultiResult<Pckt> multiInsertImpairmentEntity(List<Pckt> pckts);
59+
60+
/**
61+
* Batch annotations: Error highlight when specifying fields not defined in the parameter type
62+
* Error: Field [email] specified in [include] option does not exist in "Department". Available fields: [id, name, location, managerCount, subId, embeddableEntity, embeddableEntity2]
63+
* @param departments
64+
* @return
65+
*/
66+
@BatchUpdate(include = {"email"})
67+
int[] batchUpdateWithInvalidInclude(List<Department> departments);
68+
69+
/**
70+
* Error when ending with an Embedded property
71+
* Error: Field [embeddableEntity] specified in [include] option is an Embeddable type "ClientUser". Must specify its properties. Available properties: [id, name, number]
72+
*/
73+
@Update(include = {"embeddableEntity"})
74+
int updateEmbedded(Department department);
75+
76+
/**
77+
* Error when there is a mistake in Embedded class properties
78+
* Error: Field [age] specified in [include] option does not exist in "ClientUser". Available fields: [id, name, number, childEmbedded, childEmbedded2]
79+
*/
80+
@Insert(include = {"embeddableEntity.age", "embeddableEntity.id"})
81+
int insertEmbeddedWithProperties(Department department);
82+
83+
/**
84+
* Same check applies when using Returning
85+
* Error: Field [age] specified in [include] option does not exist in "ClientUser". Available fields: [id, name, number, childEmbedded, childEmbedded2]
86+
*/
87+
@Update(returning = @Returning(include = {"embeddableEntity.age"}))
88+
Department updateReturning(Department department);
89+
90+
/**
91+
* Error highlight when specifying invalid fields in Returning option
92+
* Error: Field [embeddableEntity] specified in [exclude] option is an Embeddable type "ClientUser". Must specify its properties. Available properties: [id, name, number]
93+
* @param department
94+
* @return
95+
*/
96+
@Insert(returning = @Returning(exclude = {"embeddableEntity"}))
97+
Department insertReturning(Department department);
98+
99+
/**
100+
* MultiInsert Returning option: Error highlight in both include/exclude when specifying invalid fields
101+
* Error: Field [email] specified in [include] option does not exist in "Department". Available fields: [id, name, location, managerCount, subId, embeddableEntity, embeddableEntity2]
102+
* @param departments
103+
* @return
104+
*/
105+
@MultiInsert(returning = @Returning(include = {"email"}, exclude = {"embeddableEntity.salary"}))
106+
List<Department> multiInsertReturning(List<Department> departments);
107+
108+
/**
109+
* Error highlight when specifying fields not defined in mutable Entity within Returning option
110+
* Error: Field [embeddableEntity] specified in [include] option does not exist in "Pckt". Available fields: [id, name]
111+
*/
112+
@Update(returning = @Returning(include = {"embeddableEntity.age"}))
113+
Pckt updateReturning(Pckt pckt);
114+
115+
/**
116+
* Error highlight when specifying fields not defined in Embedded property
117+
* Error: Field [age] specified in [include] option does not exist in "ClientUser". Available fields: [id, name, number, childEmbedded, childEmbedded2]
118+
*/
119+
@Update(returning = @Returning(include = "embeddableEntity.age"))
120+
Department updateSingleInclude(Department department);
121+
122+
/**
123+
* Error highlight when specifying further properties from a Primitive type
124+
* Error: Field path [subId.get] specified in [exclude] option is invalid. Field [get] is a primitive type and does not have nested properties
125+
*/
126+
@Insert(exclude = "subId.get")
127+
int insertPrimitiveProperty(Department department);
128+
}

0 commit comments

Comments
 (0)