// Employee class properties
mechanic.setPosition("Senior mechanic");
mechanic.setSalary(400);
// Create
MechanicEntity mechanicEntity = DozerHelper.map(mechanic,
MechanicEntity.class);
Long id = mechanicRepository.save(mechanicEntity);
SubsidiaryEntity subsidiaryEntity = null;
subsidiaryEntity = subsidiaryRepository.findByName("ARS JUnit Test")
.get(0);
Subsidiary subsidiary = DozerHelper.map(subsidiaryEntity,
Subsidiary.class);
try {
subsidiary.addEmployee(mechanic);
} catch (EmployeeAlreadyExistsException e) {
e.printStackTrace();
}
subsidiaryEntity = DozerHelper.map(subsidiary, SubsidiaryEntity.class);
subsidiaryRepository.merge(subsidiaryEntity);
// Read
List<MechanicEntity> result = mechanicRepository.findBySubsidiary(
subsidiaryEntity, null, null);
Assert.assertEquals(1, result.size());
Assert.assertEquals("mechanic@junit-test.com", result.iterator().next()
.getEmail());
Assert.assertEquals("Senior mechanic", result.iterator().next()
.getPosition());
Assert.assertEquals("1003010054", result.iterator().next()
.getPliRegNo());
// Update
mechanicEntity = mechanicRepository.findById(id);
mechanicEntity.setEmail("junit@test.com");
mechanicRepository.update(mechanicEntity);
result = mechanicRepository.findBySubsidiary(subsidiaryEntity, null,
null);