]> git.somenet.org - pub/jan/dst18.git/blob - ass1-jpa/src/test/java/dst/ass1/jpa/tests/Ass1_1_1_05Test.java
Add template for assignment 1
[pub/jan/dst18.git] / ass1-jpa / src / test / java / dst / ass1 / jpa / tests / Ass1_1_1_05Test.java
1 package dst.ass1.jpa.tests;
2
3 import static org.hamcrest.CoreMatchers.is;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertNotNull;
6 import static org.junit.Assert.assertThat;
7
8 import javax.persistence.metamodel.ManagedType;
9 import javax.persistence.metamodel.Type;
10
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.rules.ExpectedException;
14
15 import dst.ass1.jpa.ORMService;
16 import dst.ass1.jpa.model.IAddress;
17
18 /**
19  * Tests if IAddress is implemented correctly.
20  */
21 public class Ass1_1_1_05Test {
22
23     @Rule
24     public ORMService orm = new ORMService();
25
26     @Rule
27     public ExpectedException expectedException = ExpectedException.none();
28
29     @Test
30     public void addressEntityCannotBePersisted() {
31         IAddress address = orm.getModelFactory().createAddress();
32         assertNotNull(address);
33
34         address.setCity("city1");
35         address.setStreet("street1");
36         address.setZipCode("zip1");
37
38         expectedException.expect(IllegalArgumentException.class);
39         orm.getEntityManager().persist(address);
40     }
41
42     @Test
43     public void addressIsEmbeddableType() {
44         IAddress address = orm.getModelFactory().createAddress();
45         assertNotNull(address);
46
47         ManagedType<?> type = orm.getEntityManager().getMetamodel().managedType(address.getClass());
48         assertNotNull(type);
49         assertThat(type.getPersistenceType(), is(Type.PersistenceType.EMBEDDABLE));
50     }
51
52     @Test
53     public void addressHasNoTable() throws Exception {
54         assertFalse(orm.getDatabaseGateway().isTable("ADDRESS"));
55     }
56
57 }