import org.junit.BeforeClass; import org.junit.Test; import java.sql.SQLException; import java.time.Instant; import java.time.LocalDate; import java.time.LocalTime; import java.util.List; import java.util.Optional; import static org.junit.Assert.*; import static org.junit.Assert.assertTrue; public final class Tests { private static Repository repo = null; private static Operation testOperation = null; private static OperationService opService; private static OPStaff testOPStaff = null; private static OPStaffService opStaffService; private static OperationTeam testOperationTeam = null; private static OperationTeamService operationTeamService; private static TeamMember testTeamMember = null; private static TeamMemberService teamMemberService; @BeforeClass public static void init() throws Exception { System.setProperty("pms.repo.jdbc.url", "jdbc:postgresql:postgres"); System.setProperty("pms.repo.jdbc.user", "postgres"); System.setProperty("pms.repo.jdbc.password", "1234"); repo = JDBCRepository.instance(); testOperation = new Operation( new Id<>("1111"), LocalDate.of(2024, 05, 24), LocalTime.of(13, 35, 00), LocalTime.of(14, 00, 00), Instant.now()); opService = new OperationServiceImpl(repo); testOPStaff = new OPStaff( new Id<>("3333"), Role.SURGEON, Specialty.urology, Instant.now()); opStaffService = new OPStaffServiceImpl(repo); testOperationTeam = new OperationTeam( new Id<>("31313131"), ("NochCooler"), Instant.now() ); operationTeamService = new OperationTeamImpl(repo) { }; testTeamMember = new TeamMember( new Id<>("newTeamMember1"), testOperationTeam.operationTeamId(), testOPStaff.id(), Instant.now() ); } //@Test public void testRepoOperationSave(){ try { repo.save(testOperation); } catch (Exception e){ e.printStackTrace(); } assertTrue( repo.findOperation(testOperation.id()).isPresent() ); } //@Test public void testRepoOperationUpdate() { try { repo.save(testOperation); } catch (Exception e){ e.printStackTrace(); } Operation updatedTestOperation = new Operation( testOperation.id(), LocalDate.of(1999, 01, 01), testOperation.startTime(), testOperation.endTime(), Instant.now() ); try { repo.save(updatedTestOperation); } catch (Exception e){ e.printStackTrace(); } assertNotEquals(repo.findOperation(updatedTestOperation.id()).get().date(), testOperation.date()); assertNotEquals(repo.findOperation(updatedTestOperation.id()).get().lastUpdate(), testOperation.lastUpdate()); } //@Test public void testRepoOperationDelete() { try { repo.save(testOperation); } catch (Exception e){ e.printStackTrace(); } try { repo.deleteOperation(testOperation.id()); } catch (SQLException e) { throw new RuntimeException(e); } } //@Test public void testCreateOperation() throws Exception { Operation.Create createCommand = new Operation.Create( LocalDate.of(2025, 05, 11), LocalTime.of(10, 30, 00), LocalTime.of(11, 00, 00) ); Operation createOperation = opService.process(createCommand); assertTrue( repo.findOperation(createOperation.id()).isPresent() ); } //@Test public void testUpdateOperation() throws Exception { repo.save(testOperation); Operation.Update updateCommand = new Operation.Update( testOperation.id(), Optional.of(LocalDate.of(1999, 01, 01)), Optional.empty(), Optional.empty() ); opService.getOperation(testOperation.id()); Operation updateOperation = opService.process(updateCommand); assertNotEquals( repo.findOperation(updateOperation.id()).get().date(), testOperation.date() ); assertEquals( repo.findOperation(updateOperation.id()).get().startTime(), testOperation.startTime() ); assertEquals( repo.findOperation(updateOperation.id()).get().endTime(), testOperation.endTime() ); assertNotEquals( repo.findOperation(updateOperation.id()).get().lastUpdate(), testOperation.lastUpdate() ); } public void testDeleteOperation() throws Exception { //repo.save(testOperation); var id = new Id<Operation>("ade321ba-53f7-4f72-9748-bf2bbddfd98c"); Operation.Delete deleteCommand = new Operation.Delete( //testOperation.id() id ); Operation deleteOperation = opService.process(deleteCommand); assertFalse( repo.findOperation(deleteOperation.id()).isPresent() ); } //ade321ba-53f7-4f72-9748-bf2bbddfd98c //@Test public void testGetOperations() { LocalDate testDate = LocalDate.of(2024, 05, 24); Operation.Filter filter = new Operation.Filter(Optional.of(testDate)); // Operation.Filter filter = Operation.Filter.NONE; List<Operation> operations = opService.getOperations(filter); for (Operation operation : operations) { System.out.println(operation); assertEquals(operation.date(), testDate); } } //@Test public void testCreateOPStaff_1() { try { repo.saveOPStaff(testOPStaff); } catch (Exception e){ e.printStackTrace(); } } //@Test public void testCreateOPStaff_2() throws Exception { OPStaff.CreateOPStaff createCommand = new OPStaff.CreateOPStaff( Role.SURGEON, Specialty.cardiology ); OPStaff createOPStaff = opStaffService.process(createCommand); } //@Test public void testGetOPStaff() { try{ var id = new Id<OPStaff>("3333"); Optional<OPStaff> opStaff = opStaffService.getOPStaff(id); System.out.println(opStaff); } catch (Exception e){ e.printStackTrace(); } //assertEquals(operation.date(), testDate); } //@Test //getting all the OPStaffs public void testGetOPStaffs() { try{ List<OPStaff> opStaff = opStaffService.getOPStaffs(); for(OPStaff opStaff1 : opStaff){ System.out.println(opStaff1); } } catch (Exception e){ e.printStackTrace(); } //assertEquals(operation.date(), testDate); } //@Test public void testUpdateOPStaff() throws Exception{ OPStaff.UpdateOPStaff updateCommand = new OPStaff.UpdateOPStaff( testOPStaff.id(), Optional.empty(), Optional.of(Specialty.Orthopedics) ); OPStaff updateOPStaff = opStaffService.process(updateCommand); } //@Test public void testDeleteOPStaff() throws Exception{ var id = new Id<OPStaff>("b940de7b-a9a3-40e5-b465-12b018390061"); OPStaff.DeleteOPStaff deleteCommand = new OPStaff.DeleteOPStaff( id ); OPStaff deleteOPStaff = opStaffService.process(deleteCommand); } //@Test public void testCreateOperationTeam() throws Exception{ try { repo.saveOperationTeam(testOperationTeam); } catch (Exception e){ e.printStackTrace(); } } //@Test public void testDeleteOperationTeam() throws Exception{ var id = new Id<OperationTeam>("1212"); OperationTeam.DeleteTeam deleteCommand = new OperationTeam.DeleteTeam( id ); OperationTeam deleteOperationTeam = operationTeamService.process(deleteCommand); } //@Test public void testInsertTeamMember1() throws Exception{ try { repo.saveTeamMember(testTeamMember); } catch (Exception e){ e.printStackTrace(); } } @Test public void testGetOperationTeam() throws Exception{ var id = new Id<OperationTeam>("31313131"); try{ Optional<OperationTeam> operationTeam = operationTeamService.getOperationTeam(id); //for(OPStaff opStaff1 : opStaff){ System.out.println(operationTeam); //} } catch (Exception e){ e.printStackTrace(); } } }