Skip to content

feat: Making expected SQL annotations more descriptive and repeatable #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.quickperf.annotation.FunctionalIteration;
import org.quickperf.junit4.QuickPerfJUnitRunner;
import org.quickperf.sql.annotation.ExpectSelect;
import org.quickperf.sql.annotation.ExpectSelects;

import javax.persistence.EntityManager;
import javax.persistence.Query;
Expand All @@ -39,6 +40,18 @@ public void execute_one_select_but_five_select_expected() {
query.getResultList();
}

@DisableQuickPerf
@ExpectSelects({
@ExpectSelect(comment = "Select books"),
@ExpectSelect(comment = "Select related entities", value = 4)
})
@Test
public void execute_one_select_but_five_select_expected_with_repeated_annotations() {
EntityManager em = emf.createEntityManager();
Query query = em.createQuery("FROM " + Book.class.getCanonicalName());
query.getResultList();
}

}

@Test public void
Expand Down Expand Up @@ -67,6 +80,18 @@ public void execute_one_select_but_five_select_expected() {
query.getResultList();
}

@FunctionalIteration
@ExpectSelects({
@ExpectSelect(comment = "Select books"),
@ExpectSelect(comment = "Select related entities", value = 4)
})
@Test
public void execute_one_select_but_five_select_expected_with_repeated_annotations() {
EntityManager em = emf.createEntityManager();
Query query = em.createQuery("FROM " + Book.class.getCanonicalName());
query.getResultList();
}

}

@Test public void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.runner.RunWith;
import org.quickperf.junit4.QuickPerfJUnitRunner;
import org.quickperf.sql.annotation.ExpectSelect;
import org.quickperf.sql.annotation.ExpectSelects;

import javax.persistence.EntityManager;
import javax.persistence.Query;
Expand All @@ -39,9 +40,21 @@ public void execute_one_select() {
query.getResultList();
}

@ExpectSelects({
@ExpectSelect(comment = "Select books.")
})
@Test
public void execute_one_select_with_repeatable_annotation() {
EntityManager em = emf.createEntityManager();
Query query = em.createQuery("FROM " + Book.class.getCanonicalName());
query.getResultList();
}

}

@ThreadCount(100) @Test public void

@ThreadCount(100)
@Test
public void
sql_performance_property_is_ok() {

Class<?> testClass = AClassHavingAMethodWithoutSqlPerformanceIssue.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@
*/
int value() default 1;

/**
* To comment on the reason why we expect the specified amount of queries of this type.
* @return comment message
*/
String comment() default "";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2019-2022 the original author or authors.
*/
package org.quickperf.sql.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* The <code>ExpectDeletes</code> annotation verifies the number of executed delete statements corresponds to the
* specified values.
*
* <br><br>
* <h3>Example:</h3>
* <pre>
* <b>&#064;ExpectDeletes({</b>
* <b>&#064;ExpectDelete(comment="Delete user"),</b>
* <b>&#064;ExpectDelete(comment="Delete posts",value=2)</b>
* <b>})</b>
* public void execute_three_delete() {
* <code>..</code>
* }
* </pre>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface ExpectDeletes {

/**
* Specifies an array of expected queries.
*/
ExpectDelete[] value();

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@

int value() default 1;

/**
* To comment on the reason why we expect the specified amount of queries of this type.
* @return comment message
*/
String comment() default "";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2019-2022 the original author or authors.
*/
package org.quickperf.sql.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* The <code>ExpectInserts</code> annotation verifies the number of executed insert statements corresponds to the
* specified values.
*
* <br><br>
* <h3>Example:</h3>
* <pre>
* <b>&#064;ExpectInserts({</b>
* <b>&#064;ExpectInsert(comment="Insert user"),</b>
* <b>&#064;ExpectInsert(comment="Insert posts",value=2),</b>
* <b>&#064;ExpectInsert(comment="Insert comments",value=3)</b>
* <b>})</b>
* public void execute_six_insert() {
* <code>..</code>
* }
* </pre>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface ExpectInserts {

/**
* Specifies an array of expected queries.
*/
ExpectInsert[] value();

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@
*/
int value() default 1;

/**
* To comment on the reason why we expect the specified amount of queries of this type.
* @return comment message
*/
String comment() default "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@
*/
int value() default 1;

/**
* To comment on the reason why we expect the specified amount of queries of this type.
* @return comment message
*/
String comment() default "";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2019-2022 the original author or authors.
*/
package org.quickperf.sql.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* The <code>ExpectSelects</code> annotation verifies the number of executed select statements corresponds to the
* specified values.
*
* <br><br>
* <h3>Example:</h3>
* <pre>
* <b>&#064;ExpectSelects({</b>
* <b>&#064;ExpectSelect(comment="Load post"),</b>
* <b>&#064;ExpectSelect(comment="Load comments",value=2)</b>
* <b>})</b>
* public void execute_three_selects() {
* <code>..</code>
* }
* </pre>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface ExpectSelects {

/**
* Specifies an array of expected queries.
*/
ExpectSelect[] value();

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@
*/
int value() default 1;

/**
* To comment on the reason why we expect the specified amount of queries of this type.
* @return comment message
*/
String comment() default "";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2019-2022 the original author or authors.
*/
package org.quickperf.sql.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* The <code>ExpectUpdates</code> annotation verifies the number of executed update statements corresponds to the
* specified values.
*
* <br><br>
* <h3>Example:</h3>
* <pre>
* <b>&#064;ExpectUpdates({</b>
* <b>&#064;ExpectUpdate(comment="Update post"),</b>
* <b>&#064;ExpectUpdate(comment="Update comments",value=2)</b>
* <b>})</b>
* public void execute_three_update() {
* <code>..</code>
* }
* </pre>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface ExpectUpdates {

/**
* Specifies an array of expected queries.
*/
ExpectUpdate[] value();

}
Loading