Skip to content

Commit

Permalink
readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
rmpestano committed Feb 13, 2016
1 parent f58eaf0 commit 1676feb
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 26 deletions.
50 changes: 47 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ Also note that the same can be done using @Rule but pay attention that you must
<dependency>
<groupId>com.github.dbunit-rules</groupId>
<artifactId>core</artifactId>
<version>0.4.2</version>
<version>0.5.0</version>
<scope>test</scope>
</dependency>
----
Expand Down Expand Up @@ -377,7 +377,7 @@ As stated before DBunit needs a jdbc connection, a way to create one is using JP
<dependency>
<groupId>com.github.dbunit-rules</groupId>
<artifactId>jpa</artifactId>
<version>0.4.2</version>
<version>0.5.0</version>
<scope>test</scope>
</dependency>
----
Expand Down Expand Up @@ -490,7 +490,7 @@ If you use CDI in your tests then you should give a try in DBUnit rules https://
<dependency>
<groupId>com.github.dbunit-rules</groupId>
<artifactId>cdi</artifactId>
<version>0.4.2</version>
<version>0.5.0</version>
<scope>test</scope>
</dependency>
----
Expand Down Expand Up @@ -535,5 +535,49 @@ public class DeltaspikeUsingInterceptorIt {
}
----

== Cucumber module

this module brings a Cucumber runner which is CDI aware.

NOTE: If you don't use CDI just use cucumber 'official' runner and you should be ok.


[source,xml]
----
<dependency>
<groupId>com.github.dbunit-rules</groupId>
<artifactId>cucumber</artifactId>
<version>0.5.0</version>
<scope>test</scope>
</dependency>
----

Now you just need to use *CdiCucumberTestRunner*.

=== Examples

.feature file (src/test/resources/features/contacts.feature)
----
include::examples/src/test/resources//features/contacts.feature[]
----

.Cucumber cdi runner
[source,java]
----
include::examples/src/test/java/com/github/dbunit/rules/examples/cucumber/ContactFeature.java[]
----

<1> You can use glues so step definitions and the runner can be in different packages for reuse between features.

.Step definitions
[source,java]
----
include::examples/src/test/java/com/github/dbunit/rules/examples/cucumber/ContactSteps.java[]
----

<1> Step definitions must be in the same package of the runner. To use different package you can use *glues* as commented above.
<2> DBUnit cdi interceptor can be used in any cucumber step to prepare the database.




2 changes: 1 addition & 1 deletion cdi/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A CDI interceptor to configure DBUnit datasets in your tests.
<dependency>
<groupId>com.github.dbunit-rules</groupId>
<artifactId>cdi</artifactId>
<version>0.4.2</version>
<version>0.5.0</version>
<scope>test</scope>
</dependency>
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
import cucumber.api.CucumberOptions;
import org.junit.runner.RunWith;

/**
* Created by pestano on 12/02/16.
*/

@RunWith(CdiCucumberTestRunner.class)
@CucumberOptions(
features = {"src/test/resources/features/contacts.feature"},
plugin = {"json:target/cucumber.json"}
//glue = "com.github.dbunit.rules.examples.glues" //step definitions can be in different packages for reuse
//glue = "com.github.dbunit.rules.examples.glues" <1>
)
public class ContactFeature {
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.github.dbunit.rules.examples.cucumber;
package com.github.dbunit.rules.examples.cucumber; //<1>

import com.github.dbunit.rules.api.dataset.DataSet;
import com.github.dbunit.rules.cdi.api.UsingDataSet;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.apache.deltaspike.data.impl.criteria.selection.SingularAttributeSelection;
import org.example.jpadomain.Contact;
import org.example.jpadomain.Contact_;
import org.example.service.deltaspike.ContactRepository;
Expand All @@ -16,41 +13,38 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
* Created by pestano on 12/02/16.
*/
public class ContactSteps {

@Inject
ContactRepository contactRepository;

Long count;

@Given("^we have contacts in the database$")
@UsingDataSet("datasets/contacts.yml")
public void given() {
assertEquals(contactRepository.count(), new Long(3));
}


@When("^^we search contacts by name \"([^\"]*)\"$")
public void we_search_contacts_by_name_(String name) throws Throwable {
Contact contact = new Contact();
contact.setName(name);
count = contactRepository.countLike(contact, Contact_.name);
}


@Then("^we should find (\\d+) contacts$")
public void we_should_find_result_contacts(Long result) throws Throwable {
assertEquals(result,count);
}

@Given("^we have a list of contacts")
@UsingDataSet("datasets/contacts.yml") //<2>
public void given() {
assertEquals(contactRepository.count(), new Long(3));
}

@When("^we delete contact by id (\\d+)$")
public void we_delete_contact_by_id(long id) throws Throwable {
contactRepository.remove(contactRepository.findBy(id));
}

@Then("^we should not find contacts (\\d+) in database$")
@Then("^we should not find contact (\\d+)$")
public void we_should_not_find_contacts_in_database(long id) throws Throwable {
assertNull(contactRepository.findBy(id));
}
Expand Down
6 changes: 3 additions & 3 deletions examples/src/test/resources/features/contacts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Contacts test


Scenario Outline: search contacts
Given we have contacts in the database
Given we have a list of constacts
When we search contacts by name "<name>"
Then we should find <result> contacts

Expand All @@ -19,6 +19,6 @@ Feature: Contacts test

Scenario: delete a contact

Given we have contacts in the database
Given we have a list of contacts
When we delete contact by id 1
Then we should not find contacts 1 in database
Then we should not find contact 1

0 comments on commit 1676feb

Please sign in to comment.