This repository was archived by the owner on Sep 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simple cucumber bdd tests for active objects
- Loading branch information
clouless
committed
Oct 13, 2018
1 parent
562dd1f
commit d9371a8
Showing
5 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...m/comsysto/poc/ao/service/features/Feature_OwnersAndPets_Scenario_FindOwnersWithPets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ut.com.comsysto.poc.ao.service.features; | ||
|
||
import com.comsysto.poc.ao.model.OwnerEntity; | ||
import com.comsysto.poc.ao.service.PetAndOwnerDataAccessServiceImpl; | ||
import cucumber.api.java8.En; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class Feature_OwnersAndPets_Scenario_FindOwnersWithPets implements En { | ||
|
||
// Dependency | ||
private PetAndOwnerDataAccessServiceImpl petAndOwnerDataAccessService; | ||
// Subject | ||
private OwnerEntity[] ownerEntities; | ||
|
||
public Feature_OwnersAndPets_Scenario_FindOwnersWithPets() { | ||
Given("PetAndOwnerDataAccessService to query for pets and owners", () -> { | ||
petAndOwnerDataAccessService = Feature_OwnersAndPets_Test.petAndOwnerDataAccessService; | ||
assertThat(this.petAndOwnerDataAccessService, is(notNullValue())); | ||
}); | ||
When("we query the database via method getOwnersWhoHavePets", () -> { | ||
ownerEntities = petAndOwnerDataAccessService.getOwnersWhoHavePets(); | ||
}); | ||
Then("we should only retrieve owners who actually have pets", () -> { | ||
assertThat(ownerEntities, is(notNullValue())); | ||
assertThat(ownerEntities.length, is(1)); | ||
assertThat(ownerEntities[0].getName(), is(equalTo("jim"))); | ||
}); | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
src/test/java/ut/com/comsysto/poc/ao/service/features/Feature_OwnersAndPets_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package ut.com.comsysto.poc.ao.service.features; | ||
|
||
import com.atlassian.activeobjects.external.ActiveObjects; | ||
import com.atlassian.activeobjects.test.TestActiveObjects; | ||
import com.comsysto.poc.ao.model.OwnerEntity; | ||
import com.comsysto.poc.ao.model.PetEntity; | ||
import com.comsysto.poc.ao.service.PetAndOwnerDataAccessServiceImpl; | ||
import cucumber.api.CucumberOptions; | ||
import cucumber.api.junit.Cucumber; | ||
import net.java.ao.EntityManager; | ||
import net.java.ao.test.converters.NameConverters; | ||
import net.java.ao.test.jdbc.Data; | ||
import net.java.ao.test.jdbc.DatabaseUpdater; | ||
import net.java.ao.test.junit.ActiveObjectsJUnitRunner; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.JUnitCore; | ||
import org.junit.runner.RunWith; | ||
import ut.com.comsysto.poc.ao.service.seed.DatabaseSeedHelper; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
@RunWith(ActiveObjectsJUnitRunner.class) | ||
@Data(Feature_OwnersAndPets_Test.CucumberRunnerTestDatabaseUpdater.class) | ||
@NameConverters | ||
public class Feature_OwnersAndPets_Test { | ||
|
||
private EntityManager entityManager; | ||
private ActiveObjects activeObjects; | ||
// Make available to tests | ||
public static PetAndOwnerDataAccessServiceImpl petAndOwnerDataAccessService; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
assertNotNull(entityManager); | ||
activeObjects = new TestActiveObjects(entityManager); | ||
petAndOwnerDataAccessService = new PetAndOwnerDataAccessServiceImpl(activeObjects); | ||
} | ||
|
||
public static class CucumberRunnerTestDatabaseUpdater implements DatabaseUpdater { | ||
@Override | ||
public void update(EntityManager entityManager) throws Exception { | ||
entityManager.migrate(PetEntity.class, OwnerEntity.class); | ||
DatabaseSeedHelper.seed(entityManager); | ||
} | ||
} | ||
|
||
// ------ | ||
|
||
@Test | ||
public void subRunner() throws Exception { | ||
assert(JUnitCore.runClasses(SubRunner.class).wasSuccessful()); | ||
} | ||
|
||
@RunWith(Cucumber.class) | ||
@CucumberOptions( | ||
features = "src/test/resources/ut/com/comsysto/poc/ao/service/features", | ||
plugin = {"pretty"}) | ||
public static class SubRunner { } | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/java/ut/com/comsysto/poc/ao/service/seed/DatabaseSeedHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
package ut.com.comsysto.poc.ao.service.seed; | ||
|
||
import com.comsysto.poc.ao.model.OwnerEntity; | ||
import com.comsysto.poc.ao.model.PetEntity; | ||
import net.java.ao.EntityManager; | ||
|
||
public class DatabaseSeedHelper { | ||
public static void seed(EntityManager entityManager) throws Exception { | ||
OwnerEntity owner = entityManager.create(OwnerEntity.class); | ||
owner.setName("bob"); | ||
owner.save(); | ||
|
||
OwnerEntity owner2 = entityManager.create(OwnerEntity.class); | ||
owner2.setName("jim"); | ||
owner2.save(); | ||
|
||
PetEntity pet = entityManager.create(PetEntity.class); | ||
pet.setName("snorre"); | ||
pet.setType("CAT"); | ||
pet.setOwnerId((long) owner2.getID()); | ||
pet.save(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/test/resources/ut/com/comsysto/poc/ao/service/features/OwnersAndPets.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Feature: Owners and Pets are stored in he Database | ||
We can query the database for owners and pets | ||
|
||
Scenario: find owners with pets | ||
Given PetAndOwnerDataAccessService to query for pets and owners | ||
When we query the database via method getOwnersWhoHavePets | ||
Then we should only retrieve owners who actually have pets |