Skip to content

Latest commit

 

History

History
74 lines (56 loc) · 1.7 KB

README.md

File metadata and controls

74 lines (56 loc) · 1.7 KB

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.