Em um projeto spring boot, faço teste de integração simulando as tabelas com H2, mas tenho uma entidade mapeada com JoinTable e por não ter uma classe java nem um repository para um .save, como simulo ela no teste de integração?
No exemplo seria o emp_workstation.
exemplo:
@ Entity
@ Table(name = "employee")
public class Employee {
@ Id
@ GeneratedValue(strategy = GenerationType.AUTO)
@ Column(name = "id")
private Long id;
//...
@ OneToOne(cascade = CascadeType.ALL)
@ JoinTable(name = "emp_workstation",
joinColumns =
{ @ JoinColumn(name = "employee_id", referencedColumnName = "id") },
inverseJoinColumns =
{ @ JoinColumn(name = "workstation_id", referencedColumnName = "id") })
private WorkStation workStation;
//... getters and setters
}
@ IntegrationTest
public class Exemple {
@ Test
public void test() throws Exception {
include();
...
}
private void include() {
Employee employee = new Employee ();
employee.setId(1);
employee.setEname("Test");
employeeRepository.save(employee);
WorkStation workStation = new WorkStation();
workStation.setInt(1);
workStation.setWorkstationNumber(11);
workStation.setFloor("Teste");
workStationRepository.save(workStation);
//Emp_workstation emp_workstation = new Emp_workstation();
//emp_workstation.setEmployee_id(1);
//emp_workstation.setWorkstatio_id(1);
//emp_workstationRepository.save(emp_workstation);
}
}