Skip to content

Commit 13974cf

Browse files
committed
feat: Making expected SQL annotations more descriptive and repeatable
- Add new repeated ExpectSelect/ExpectInsert/ExpectUpdate/ExpectDelete annotation variants - Include optional comment in ExpectSelect/ExpectInsert/ExpectUpdate/ExpectDelete - Add and register new verifiers - Add new test cases Resolves #222 Signed-off-by: Esta Nagy <nagyesta@gmail.com>
1 parent f51bb2a commit 13974cf

21 files changed

+730
-9
lines changed

junit4/junit4-sql-test/src/test/java/org/quickperf/sql/DisableQuickPerfFeaturesJUnit4Test.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.quickperf.annotation.FunctionalIteration;
2020
import org.quickperf.junit4.QuickPerfJUnitRunner;
2121
import org.quickperf.sql.annotation.ExpectSelect;
22+
import org.quickperf.sql.annotation.ExpectSelects;
2223

2324
import javax.persistence.EntityManager;
2425
import javax.persistence.Query;
@@ -39,6 +40,18 @@ public void execute_one_select_but_five_select_expected() {
3940
query.getResultList();
4041
}
4142

43+
@DisableQuickPerf
44+
@ExpectSelects({
45+
@ExpectSelect(comment = "Select books"),
46+
@ExpectSelect(comment = "Select related entities", value = 4)
47+
})
48+
@Test
49+
public void execute_one_select_but_five_select_expected_with_repeated_annotations() {
50+
EntityManager em = emf.createEntityManager();
51+
Query query = em.createQuery("FROM " + Book.class.getCanonicalName());
52+
query.getResultList();
53+
}
54+
4255
}
4356

4457
@Test public void
@@ -67,6 +80,18 @@ public void execute_one_select_but_five_select_expected() {
6780
query.getResultList();
6881
}
6982

83+
@FunctionalIteration
84+
@ExpectSelects({
85+
@ExpectSelect(comment = "Select books"),
86+
@ExpectSelect(comment = "Select related entities", value = 4)
87+
})
88+
@Test
89+
public void execute_one_select_but_five_select_expected_with_repeated_annotations() {
90+
EntityManager em = emf.createEntityManager();
91+
Query query = em.createQuery("FROM " + Book.class.getCanonicalName());
92+
query.getResultList();
93+
}
94+
7095
}
7196

7297
@Test public void

junit4/junit4-sql-test/src/test/java/org/quickperf/sql/SqlConcurrencyJUnit4Test.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.junit.runner.RunWith;
2020
import org.quickperf.junit4.QuickPerfJUnitRunner;
2121
import org.quickperf.sql.annotation.ExpectSelect;
22+
import org.quickperf.sql.annotation.ExpectSelects;
2223

2324
import javax.persistence.EntityManager;
2425
import javax.persistence.Query;
@@ -39,9 +40,21 @@ public void execute_one_select() {
3940
query.getResultList();
4041
}
4142

43+
@ExpectSelects({
44+
@ExpectSelect(comment = "Select books.")
45+
})
46+
@Test
47+
public void execute_one_select_with_repeatable_annotation() {
48+
EntityManager em = emf.createEntityManager();
49+
Query query = em.createQuery("FROM " + Book.class.getCanonicalName());
50+
query.getResultList();
51+
}
52+
4253
}
43-
44-
@ThreadCount(100) @Test public void
54+
55+
@ThreadCount(100)
56+
@Test
57+
public void
4558
sql_performance_property_is_ok() {
4659

4760
Class<?> testClass = AClassHavingAMethodWithoutSqlPerformanceIssue.class;

sql/sql-annotations/src/main/java/org/quickperf/sql/annotation/ExpectDelete.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@
4040
*/
4141
int value() default 1;
4242

43+
/**
44+
* To comment on the reason why we expect the specified amount of queries of this type.
45+
* @return comment message
46+
*/
47+
String comment() default "";
48+
4349
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2019-2022 the original author or authors.
12+
*/
13+
package org.quickperf.sql.annotation;
14+
15+
import java.lang.annotation.ElementType;
16+
import java.lang.annotation.Retention;
17+
import java.lang.annotation.RetentionPolicy;
18+
import java.lang.annotation.Target;
19+
20+
/**
21+
* The <code>ExpectDeletes</code> annotation verifies the number of executed delete statements corresponds to the
22+
* specified values.
23+
*
24+
* <br><br>
25+
* <h3>Example:</h3>
26+
* <pre>
27+
* <b>&#064;ExpectDeletes({</b>
28+
* <b>&#064;ExpectDelete(comment="Delete user"),</b>
29+
* <b>&#064;ExpectDelete(comment="Delete posts",value=2)</b>
30+
* <b>})</b>
31+
* public void execute_three_delete() {
32+
* <code>..</code>
33+
* }
34+
* </pre>
35+
*/
36+
@Retention(RetentionPolicy.RUNTIME)
37+
@Target({ElementType.METHOD})
38+
public @interface ExpectDeletes {
39+
40+
/**
41+
* Specifies an array of expected queries.
42+
*/
43+
ExpectDelete[] value();
44+
45+
}

sql/sql-annotations/src/main/java/org/quickperf/sql/annotation/ExpectInsert.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,10 @@
4141

4242
int value() default 1;
4343

44+
/**
45+
* To comment on the reason why we expect the specified amount of queries of this type.
46+
* @return comment message
47+
*/
48+
String comment() default "";
49+
4450
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2019-2022 the original author or authors.
12+
*/
13+
package org.quickperf.sql.annotation;
14+
15+
import java.lang.annotation.ElementType;
16+
import java.lang.annotation.Retention;
17+
import java.lang.annotation.RetentionPolicy;
18+
import java.lang.annotation.Target;
19+
20+
/**
21+
* The <code>ExpectInserts</code> annotation verifies the number of executed insert statements corresponds to the
22+
* specified values.
23+
*
24+
* <br><br>
25+
* <h3>Example:</h3>
26+
* <pre>
27+
* <b>&#064;ExpectInserts({</b>
28+
* <b>&#064;ExpectInsert(comment="Insert user"),</b>
29+
* <b>&#064;ExpectInsert(comment="Insert posts",value=2),</b>
30+
* <b>&#064;ExpectInsert(comment="Insert comments",value=3)</b>
31+
* <b>})</b>
32+
* public void execute_six_insert() {
33+
* <code>..</code>
34+
* }
35+
* </pre>
36+
*/
37+
@Retention(RetentionPolicy.RUNTIME)
38+
@Target({ElementType.METHOD})
39+
public @interface ExpectInserts {
40+
41+
/**
42+
* Specifies an array of expected queries.
43+
*/
44+
ExpectInsert[] value();
45+
46+
}

sql/sql-annotations/src/main/java/org/quickperf/sql/annotation/ExpectSelect.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@
4040
*/
4141
int value() default 1;
4242

43+
/**
44+
* To comment on the reason why we expect the specified amount of queries of this type.
45+
* @return comment message
46+
*/
47+
String comment() default "";
48+
4349
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2019-2022 the original author or authors.
12+
*/
13+
package org.quickperf.sql.annotation;
14+
15+
import java.lang.annotation.ElementType;
16+
import java.lang.annotation.Retention;
17+
import java.lang.annotation.RetentionPolicy;
18+
import java.lang.annotation.Target;
19+
20+
/**
21+
* The <code>ExpectSelects</code> annotation verifies the number of executed select statements corresponds to the
22+
* specified values.
23+
*
24+
* <br><br>
25+
* <h3>Example:</h3>
26+
* <pre>
27+
* <b>&#064;ExpectSelects({</b>
28+
* <b>&#064;ExpectSelect(comment="Load post"),</b>
29+
* <b>&#064;ExpectSelect(comment="Load comments",value=2)</b>
30+
* <b>})</b>
31+
* public void execute_three_selects() {
32+
* <code>..</code>
33+
* }
34+
* </pre>
35+
*/
36+
@Retention(RetentionPolicy.RUNTIME)
37+
@Target({ElementType.METHOD, ElementType.TYPE})
38+
public @interface ExpectSelects {
39+
40+
/**
41+
* Specifies an array of expected queries.
42+
*/
43+
ExpectSelect[] value();
44+
45+
}

sql/sql-annotations/src/main/java/org/quickperf/sql/annotation/ExpectUpdate.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@
4040
*/
4141
int value() default 1;
4242

43+
/**
44+
* To comment on the reason why we expect the specified amount of queries of this type.
45+
* @return comment message
46+
*/
47+
String comment() default "";
48+
4349
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2019-2022 the original author or authors.
12+
*/
13+
package org.quickperf.sql.annotation;
14+
15+
import java.lang.annotation.ElementType;
16+
import java.lang.annotation.Retention;
17+
import java.lang.annotation.RetentionPolicy;
18+
import java.lang.annotation.Target;
19+
20+
/**
21+
* The <code>ExpectUpdates</code> annotation verifies the number of executed update statements corresponds to the
22+
* specified values.
23+
*
24+
* <br><br>
25+
* <h3>Example:</h3>
26+
* <pre>
27+
* <b>&#064;ExpectUpdates({</b>
28+
* <b>&#064;ExpectUpdate(comment="Update post"),</b>
29+
* <b>&#064;ExpectUpdate(comment="Update comments",value=2)</b>
30+
* <b>})</b>
31+
* public void execute_three_update() {
32+
* <code>..</code>
33+
* }
34+
* </pre>
35+
*/
36+
@Retention(RetentionPolicy.RUNTIME)
37+
@Target({ElementType.METHOD})
38+
public @interface ExpectUpdates {
39+
40+
/**
41+
* Specifies an array of expected queries.
42+
*/
43+
ExpectUpdate[] value();
44+
45+
}

0 commit comments

Comments
 (0)