Skip to content
This repository was archived by the owner on Sep 22, 2020. It is now read-only.

Commit d9371a8

Browse files
author
clouless
committed
simple cucumber bdd tests for active objects
1 parent 562dd1f commit d9371a8

File tree

5 files changed

+130
-1
lines changed

5 files changed

+130
-1
lines changed

pom.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@
3838
<dependency>
3939
<groupId>junit</groupId>
4040
<artifactId>junit</artifactId>
41-
<version>4.10</version>
41+
<version>4.12</version>
42+
<scope>test</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.slf4j</groupId>
46+
<artifactId>slf4j-jdk14</artifactId>
47+
<version>1.7.25</version>
4248
<scope>test</scope>
4349
</dependency>
4450

@@ -137,6 +143,19 @@
137143
<version>1.3</version>
138144
<scope>test</scope>
139145
</dependency>
146+
147+
<dependency>
148+
<groupId>io.cucumber</groupId>
149+
<artifactId>cucumber-java8</artifactId>
150+
<version>4.0.1</version>
151+
<scope>test</scope>
152+
</dependency>
153+
<dependency>
154+
<groupId>io.cucumber</groupId>
155+
<artifactId>cucumber-junit</artifactId>
156+
<version>4.0.1</version>
157+
<scope>test</scope>
158+
</dependency>
140159
</dependencies>
141160

142161
<build>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ut.com.comsysto.poc.ao.service.features;
2+
3+
import com.comsysto.poc.ao.model.OwnerEntity;
4+
import com.comsysto.poc.ao.service.PetAndOwnerDataAccessServiceImpl;
5+
import cucumber.api.java8.En;
6+
7+
import static org.hamcrest.CoreMatchers.*;
8+
import static org.hamcrest.MatcherAssert.assertThat;
9+
10+
public class Feature_OwnersAndPets_Scenario_FindOwnersWithPets implements En {
11+
12+
// Dependency
13+
private PetAndOwnerDataAccessServiceImpl petAndOwnerDataAccessService;
14+
// Subject
15+
private OwnerEntity[] ownerEntities;
16+
17+
public Feature_OwnersAndPets_Scenario_FindOwnersWithPets() {
18+
Given("PetAndOwnerDataAccessService to query for pets and owners", () -> {
19+
petAndOwnerDataAccessService = Feature_OwnersAndPets_Test.petAndOwnerDataAccessService;
20+
assertThat(this.petAndOwnerDataAccessService, is(notNullValue()));
21+
});
22+
When("we query the database via method getOwnersWhoHavePets", () -> {
23+
ownerEntities = petAndOwnerDataAccessService.getOwnersWhoHavePets();
24+
});
25+
Then("we should only retrieve owners who actually have pets", () -> {
26+
assertThat(ownerEntities, is(notNullValue()));
27+
assertThat(ownerEntities.length, is(1));
28+
assertThat(ownerEntities[0].getName(), is(equalTo("jim")));
29+
});
30+
}
31+
32+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package ut.com.comsysto.poc.ao.service.features;
2+
3+
import com.atlassian.activeobjects.external.ActiveObjects;
4+
import com.atlassian.activeobjects.test.TestActiveObjects;
5+
import com.comsysto.poc.ao.model.OwnerEntity;
6+
import com.comsysto.poc.ao.model.PetEntity;
7+
import com.comsysto.poc.ao.service.PetAndOwnerDataAccessServiceImpl;
8+
import cucumber.api.CucumberOptions;
9+
import cucumber.api.junit.Cucumber;
10+
import net.java.ao.EntityManager;
11+
import net.java.ao.test.converters.NameConverters;
12+
import net.java.ao.test.jdbc.Data;
13+
import net.java.ao.test.jdbc.DatabaseUpdater;
14+
import net.java.ao.test.junit.ActiveObjectsJUnitRunner;
15+
import org.junit.Before;
16+
import org.junit.Test;
17+
import org.junit.runner.JUnitCore;
18+
import org.junit.runner.RunWith;
19+
import ut.com.comsysto.poc.ao.service.seed.DatabaseSeedHelper;
20+
21+
import static org.junit.Assert.assertNotNull;
22+
23+
@RunWith(ActiveObjectsJUnitRunner.class)
24+
@Data(Feature_OwnersAndPets_Test.CucumberRunnerTestDatabaseUpdater.class)
25+
@NameConverters
26+
public class Feature_OwnersAndPets_Test {
27+
28+
private EntityManager entityManager;
29+
private ActiveObjects activeObjects;
30+
// Make available to tests
31+
public static PetAndOwnerDataAccessServiceImpl petAndOwnerDataAccessService;
32+
33+
@Before
34+
public void setUp() throws Exception {
35+
assertNotNull(entityManager);
36+
activeObjects = new TestActiveObjects(entityManager);
37+
petAndOwnerDataAccessService = new PetAndOwnerDataAccessServiceImpl(activeObjects);
38+
}
39+
40+
public static class CucumberRunnerTestDatabaseUpdater implements DatabaseUpdater {
41+
@Override
42+
public void update(EntityManager entityManager) throws Exception {
43+
entityManager.migrate(PetEntity.class, OwnerEntity.class);
44+
DatabaseSeedHelper.seed(entityManager);
45+
}
46+
}
47+
48+
// ------
49+
50+
@Test
51+
public void subRunner() throws Exception {
52+
assert(JUnitCore.runClasses(SubRunner.class).wasSuccessful());
53+
}
54+
55+
@RunWith(Cucumber.class)
56+
@CucumberOptions(
57+
features = "src/test/resources/ut/com/comsysto/poc/ao/service/features",
58+
plugin = {"pretty"})
59+
public static class SubRunner { }
60+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
package ut.com.comsysto.poc.ao.service.seed;
22

33
import com.comsysto.poc.ao.model.OwnerEntity;
4+
import com.comsysto.poc.ao.model.PetEntity;
45
import net.java.ao.EntityManager;
56

67
public class DatabaseSeedHelper {
78
public static void seed(EntityManager entityManager) throws Exception {
89
OwnerEntity owner = entityManager.create(OwnerEntity.class);
910
owner.setName("bob");
1011
owner.save();
12+
13+
OwnerEntity owner2 = entityManager.create(OwnerEntity.class);
14+
owner2.setName("jim");
15+
owner2.save();
16+
17+
PetEntity pet = entityManager.create(PetEntity.class);
18+
pet.setName("snorre");
19+
pet.setType("CAT");
20+
pet.setOwnerId((long) owner2.getID());
21+
pet.save();
1122
}
1223
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Feature: Owners and Pets are stored in he Database
2+
We can query the database for owners and pets
3+
4+
Scenario: find owners with pets
5+
Given PetAndOwnerDataAccessService to query for pets and owners
6+
When we query the database via method getOwnersWhoHavePets
7+
Then we should only retrieve owners who actually have pets

0 commit comments

Comments
 (0)