Skip to content

myashchenko/assertsqlcount

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Assert SQL Count

Build Status

The library contains SQL statement validator that helps to verify count of queries generated by Hibernate.

Code Example

There are two options:

  1. Using AssertSqlCount class
@RunWith(SpringRunner.class)
@SpringBootTest(classes = UserQueryServiceApplication.class)
public class UserControllerTest {

    @Before
    public void before() {
        AssertSqlCount.reset();
    }

    @Test
    public void shouldFindUser() throws Exception {
        User user = userRepository.findOne("1");
        user.getOrders().size();
        AssertSqlCount.assertInsertCount(1);
    }
}
  1. Using matcher
@RunWith(SpringRunner.class)
@SpringBootTest(classes = UserQueryServiceApplication.class)
public class UserControllerTest {

    @Before
    public void before() {
        AssertSqlCount.reset();
    }

    @Test
    public void shouldFindUser() throws Exception {
        User user = userRepository.findOne("1");
        user.getOrders().size();
        assertThat(queryCounts(), hasSelectCount(1));
    }
}

Installation

Add following dependency to pom.xml

<dependency>
    <groupId>io.github.yashchenkon</groupId>
    <artifactId>assertsqlcount</artifactId>
    <version>1.0.0</version>
</dependency>

If you are using Spring Boot, insert the following line to application.properties

spring.jpa.properties.hibernate.session_factory.statement_inspector=io.github.yashchenkon.assertsqlcount.inspector.QueryCountsInspector

Tests

Description will be added later.

Contributors

Please, create pull requests in case of any fixes.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages