Coder Social home page Coder Social logo

ammachado / datasource-assert Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ttddyy/datasource-assert

0.0 1.0 0.0 2.24 MB

Provides assertion APIs for query executions with assertEquals and assertThat(AssertJ and Hamcrest)

License: Apache License 2.0

Shell 1.63% Java 97.40% HTML 0.06% Batchfile 0.91%

datasource-assert's Introduction

datasource-assert

Maven Central

datasource-assert provides assertion API for DataSource to validate query executions.

The assertion API is used for assertion methods such as assertEquals in JUnit and TestNG. Also, it comes with support for assertThat in AssertJ and Hamcrest.

Artifacts

Released Version

<dependency>
  <groupId>net.ttddyy</groupId>
  <artifactId>datasource-assert</artifactId>
  <version>[LATEST_VERSION]</version>
</dependency>

Documentation

How to use

Wrap your datasource with ProxyTestDataSource.

@Test
public void myTest() {
  ProxyTestDataSource ds = new ProxyTestDataSource(actualDataSource);
  // rest of test 
}

If you want to reuse the same ProxyTestDataSource instance, you could reset() it between tests.

@After  // @AfterEach, @AfterMethod
public void tearDown() {
   this.ds.reset();
}

Regular assertions

For normal assertions such as JUnit/TestNG assertEquals, use methods from ProxyTestDataSource.

assertEquals(3, ds.getQueryExecutions().size());
PreparedExecution pe = ds.getFirstPrepared();
assertTrue(pe.isSuccess());

See more details on "Usage examples".

AssertJ

Static import assertThat from DataSourceAssertAssertions.

import static net.ttddyy.dsproxy.asserts.assertj.DataSourceAssertAssertions.assertThat;
assertThat(ds.getQueryExecutions()).hasSize(1);
assertThat(ds.getQueryExecutions().get(0)).isStatement().asStatement().query().isEqualTo("SELECT id FROM emp");
assertThat(ds.getFirstPrepared()).containsParam(1, "foo");

See more details on "Usage examples".

Hamcrest

Use matchers from DataSourceAssertMatchers.

assertThat(ds, statementCount(3));
assertThat(ds, executions(1, is(statement())));
assertThat((StatementExecution) statements.get(0), query(is("SELECT id FROM emp")));
assertThat(ds.getFirstPrepared(), paramAsInteger(1, is(100)));

See more details on "Usage examples".

Usage examples

Regular assertions(assertEquals, etc)

With AssertJ

With Hamcrest


datasource-assert's People

Contributors

ttddyy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.