BAEL-1280: Fixed sample code issues
This commit is contained in:
parent
568198fed9
commit
7ee0ac104d
|
@ -29,6 +29,12 @@
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.12</version>
|
<version>4.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
|
|
|
@ -12,9 +12,9 @@ import org.junit.Test;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class DynamicMappingTest {
|
public class DynamicMappingIntegrationTest {
|
||||||
|
|
||||||
private Session session;
|
private Session session;
|
||||||
|
|
||||||
|
@ -34,21 +34,21 @@ public class DynamicMappingTest {
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
transaction.commit();
|
transaction.rollback();
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenEntity_whenFieldMappedWithFormula_thenFieldIsCalculated() {
|
public void givenEntity_whenFieldMappedWithFormula_thenFieldIsCalculated() {
|
||||||
Employee employee = new Employee(10_000L, 25);
|
Employee employee = new Employee(10_000L, 25);
|
||||||
assertEquals(2_500L, employee.getTaxJavaWay());
|
assertThat(employee.getTaxJavaWay()).isEqualTo(2_500L);
|
||||||
|
|
||||||
session.save(employee);
|
session.save(employee);
|
||||||
session.flush();
|
session.flush();
|
||||||
session.clear();
|
session.clear();
|
||||||
|
|
||||||
employee = session.get(Employee.class, employee.getId());
|
employee = session.get(Employee.class, employee.getId());
|
||||||
assertEquals(2_500L, employee.getTax());
|
assertThat(employee.getTax()).isEqualTo(2_500L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -59,18 +59,18 @@ public class DynamicMappingTest {
|
||||||
session.clear();
|
session.clear();
|
||||||
|
|
||||||
employee = session.find(Employee.class, employee.getId());
|
employee = session.find(Employee.class, employee.getId());
|
||||||
assertNotNull(employee);
|
assertThat(employee).isNotNull();
|
||||||
|
|
||||||
employee.setDeleted(true);
|
employee.setDeleted(true);
|
||||||
session.flush();
|
session.flush();
|
||||||
|
|
||||||
employee = session.find(Employee.class, employee.getId());
|
employee = session.find(Employee.class, employee.getId());
|
||||||
assertNotNull(employee);
|
assertThat(employee).isNotNull();
|
||||||
|
|
||||||
session.clear();
|
session.clear();
|
||||||
|
|
||||||
employee = session.find(Employee.class, employee.getId());
|
employee = session.find(Employee.class, employee.getId());
|
||||||
assertNull(employee);
|
assertThat(employee).isNull();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,17 +89,17 @@ public class DynamicMappingTest {
|
||||||
session.clear();
|
session.clear();
|
||||||
|
|
||||||
employee = session.find(Employee.class, employee.getId());
|
employee = session.find(Employee.class, employee.getId());
|
||||||
assertEquals(employee.getPhones().size(), 2);
|
assertThat(employee.getPhones()).hasSize(2);
|
||||||
|
|
||||||
employee.getPhones().iterator().next().setDeleted(true);
|
employee.getPhones().iterator().next().setDeleted(true);
|
||||||
session.flush();
|
session.flush();
|
||||||
session.clear();
|
session.clear();
|
||||||
|
|
||||||
employee = session.find(Employee.class, employee.getId());
|
employee = session.find(Employee.class, employee.getId());
|
||||||
assertEquals(employee.getPhones().size(), 1);
|
assertThat(employee.getPhones()).hasSize(1);
|
||||||
|
|
||||||
List<Phone> fullPhoneList = session.createQuery("from Phone").getResultList();
|
List<Phone> fullPhoneList = session.createQuery("from Phone").getResultList();
|
||||||
assertEquals(2, fullPhoneList.size());
|
assertThat(fullPhoneList).hasSize(2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,10 +117,10 @@ public class DynamicMappingTest {
|
||||||
|
|
||||||
List<Employee> employees = session.createQuery("from Employee").getResultList();
|
List<Employee> employees = session.createQuery("from Employee").getResultList();
|
||||||
|
|
||||||
assertEquals(2, employees.size());
|
assertThat(employees).hasSize(2);
|
||||||
|
|
||||||
Employee employee = session.get(Employee.class, 1);
|
Employee employee = session.get(Employee.class, 1);
|
||||||
assertEquals(10_000, employee.getGrossIncome());
|
assertThat(employee.getGrossIncome()).isEqualTo(10_000);
|
||||||
|
|
||||||
session.close();
|
session.close();
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ public class DynamicMappingTest {
|
||||||
|
|
||||||
employees = session.createQuery("from Employee").getResultList();
|
employees = session.createQuery("from Employee").getResultList();
|
||||||
|
|
||||||
assertEquals(3, employees.size());
|
assertThat(employees).hasSize(3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,9 +156,9 @@ public class DynamicMappingTest {
|
||||||
|
|
||||||
List<EntityDescription> descriptions = session.createQuery("from EntityDescription").getResultList();
|
List<EntityDescription> descriptions = session.createQuery("from EntityDescription").getResultList();
|
||||||
|
|
||||||
assertTrue(Employee.class.isAssignableFrom(descriptions.get(0).getEntity().getClass()));
|
assertThat(Employee.class.isAssignableFrom(descriptions.get(0).getEntity().getClass())).isTrue();
|
||||||
assertTrue(Phone.class.isAssignableFrom(descriptions.get(1).getEntity().getClass()));
|
assertThat(Phone.class.isAssignableFrom(descriptions.get(1).getEntity().getClass())).isTrue();
|
||||||
assertTrue(Phone.class.isAssignableFrom(descriptions.get(2).getEntity().getClass()));
|
assertThat(Phone.class.isAssignableFrom(descriptions.get(2).getEntity().getClass())).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue