1 package dst.ass1.jpa.tests;
3 import java.util.Collection;
5 import java.util.function.Function;
6 import java.util.stream.Collectors;
8 import javax.persistence.EntityManager;
10 import org.junit.Before;
11 import org.junit.Rule;
12 import org.junit.rules.ErrorCollector;
13 import org.junit.rules.ExpectedException;
15 import dst.ass1.jpa.DatabaseGateway;
16 import dst.ass1.jpa.ORMService;
17 import dst.ass1.jpa.dao.IDAOFactory;
18 import dst.ass1.jpa.model.IModelFactory;
20 public class Ass1_TestBase {
22 protected final TestData testData = new TestData();
25 public ORMService orm = new ORMService(testData);
28 public ExpectedException expectedException = ExpectedException.none();
31 public ErrorCollector err = new ErrorCollector();
33 // commonly used classes unwrapped from ORMService
34 protected EntityManager em;
35 protected IModelFactory modelFactory;
36 protected IDAOFactory daoFactory;
37 protected DatabaseGateway db;
39 public static <T, R> List<R> map(Collection<T> collection, Function<T, R> fn) {
40 return collection.stream().map(fn).collect(Collectors.toList());
44 public void setUpBase() throws Exception {
45 em = orm.getEntityManager();
46 modelFactory = orm.getModelFactory();
47 daoFactory = orm.getDaoFactory();
48 db = orm.getDatabaseGateway();