diff options
Diffstat (limited to 'src/test/java/at/ac/tuwien/sepm/assignment')
5 files changed, 108 insertions, 578 deletions
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java index e62554c..da20030 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java @@ -4,9 +4,13 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation;  import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity;  import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status;  import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType;  import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; +import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException;  import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase;  import java.time.Instant; +import java.util.Arrays;  import java.util.Collections;  import java.util.EnumSet;  import java.util.Set; @@ -19,12 +23,13 @@ public class OperationDAOTest extends JdbcTestCase {      private static final String[] COMPARE_TABLES =              new String[] {"VehicleOperation", "Operation", "Vehicle", "VehicleVersion"}; -    private OperationDAO operationDAO; +    private final OperationDAO operationDAO;      private final Operation o;      public OperationDAOTest() { -        this.operationDAO = new DBOperationDAO(getJdbcConnectionManager()); +        VehicleDAO vehicleDAO = new VehicleDatabaseDao(getJdbcConnectionManager()); +        this.operationDAO = new DBOperationDAO(getJdbcConnectionManager(), vehicleDAO);          Vehicle v1 =                  Vehicle.builder() @@ -87,4 +92,61 @@ public class OperationDAOTest extends JdbcTestCase {          // TODO: operations.list() currently doesn't set the vehicles set          // assertEquals(Set.of(o), operationSet);      } + +    @Test +    public void testAddOperation() throws Exception { +        operationDAO.add(o); + +        // TODO: won't work because id won't match +        // compareWith("operationDAOUpdateNormal.xml", COMPARE_TABLES); +    } + +    @Test(expected = PersistenceException.class) +    public void testAddFaultyOperation() throws PersistenceException { +        Vehicle vehicle = +                Vehicle.builder() +                        .status(Vehicle.Status.FREI_FUNK) +                        .constructionType(ConstructionType.HOCHDACH) +                        .name("BKTW_123") +                        .hasNef(true) +                        .type(VehicleType.BKTW) +                        .build(); + +        Operation operation = +                Operation.builder() +                        .status(Status.ACTIVE) +                        .opCode(String.valueOf(Arrays.stream(new int[200]).map(i -> 'a'))) +                        .created(Instant.now()) +                        .destination("Wiedner Hauptstraße 35, Wien") +                        .additionalInfo("HTU Wien") +                        .severity(Severity.B) +                        .vehicles(Set.of(vehicle)) +                        .build(); +        operationDAO.add(operation); +    } + +    @Test(expected = PersistenceException.class) +    public void testAddFaultyOperation2() throws PersistenceException { +        Vehicle vehicle = +                Vehicle.builder() +                        .status(Vehicle.Status.FREI_FUNK) +                        .constructionType(ConstructionType.HOCHDACH) +                        .name("BKTW_123") +                        .hasNef(true) +                        .type(VehicleType.BKTW) +                        .build(); + +        Operation operation = +                Operation.builder() +                        .status(Status.ACTIVE) +                        .opCode("ALP-95E7") +                        .created(Instant.now()) +                        .destination( +                                "Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien ") +                        .additionalInfo("HTU Wien") +                        .severity(Severity.B) +                        .vehicles(Set.of(vehicle)) +                        .build(); +        operationDAO.add(operation); +    }  } diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationPersistenceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationPersistenceTest.java deleted file mode 100644 index a5e4993..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationPersistenceTest.java +++ /dev/null @@ -1,127 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao; - -import static junit.framework.TestCase.fail; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; -import java.nio.charset.Charset; -import java.sql.SQLException; -import java.time.Instant; -import java.util.Arrays; -import java.util.Set; -import org.h2.tools.RunScript; -import org.junit.BeforeClass; -import org.junit.Test; - -public class OperationPersistenceTest { - -    private final OperationDAO operationDAO = -            new DBOperationDAO(new JDBCConnectionManager("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1")); - -    @BeforeClass -    public static void createSchema() throws SQLException { -        RunScript.execute( -                "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", -                "", -                "", -                "classpath:sql/database.sql", -                Charset.forName("UTF8"), -                false); -    } - -    @Test -    public void addOperationTest() { -        Vehicle vehicle = -                Vehicle.builder() -                        .status(Vehicle.Status.FREI_FUNK) -                        .constructionType(ConstructionType.HOCHDACH) -                        .name("BKTW_123") -                        .hasNef(true) -                        .type(VehicleType.BKTW) -                        .build(); - -        Operation operation = -                Operation.builder() -                        .status(Status.ACTIVE) -                        .opCode("ALP-95E7") -                        .created(Instant.now()) -                        .destination("Wiedner Hauptstraße 35, Wien") -                        .additionalInfo("HTU Wien") -                        .severity(Severity.B) -                        .vehicles(Set.of(vehicle)) -                        .build(); -        try { -            operationDAO.add(operation); -        } catch (PersistenceException e) { -            fail(); -        } -    } - -    @Test(expected = PersistenceException.class) -    public void addFaultyOperationTest() throws PersistenceException { -        Vehicle vehicle = -                Vehicle.builder() -                        .status(Vehicle.Status.FREI_FUNK) -                        .constructionType(ConstructionType.HOCHDACH) -                        .name("BKTW_123") -                        .hasNef(true) -                        .type(VehicleType.BKTW) -                        .build(); - -        Operation operation = -                Operation.builder() -                        .status(Status.ACTIVE) -                        .opCode(String.valueOf(Arrays.stream(new int[200]).map(i -> 'a'))) -                        .created(Instant.now()) -                        .destination("Wiedner Hauptstraße 35, Wien") -                        .additionalInfo("HTU Wien") -                        .severity(Severity.B) -                        .vehicles(Set.of(vehicle)) -                        .build(); -        operationDAO.add(operation); -    } - -    @Test(expected = PersistenceException.class) -    public void addFaultyOperation1Test() throws PersistenceException { -        operationDAO.add(null); -    } - -    @Test(expected = PersistenceException.class) -    public void addFaultyOperation2Test() throws PersistenceException { -        Vehicle vehicle = -                Vehicle.builder() -                        .status(Vehicle.Status.FREI_FUNK) -                        .constructionType(ConstructionType.HOCHDACH) -                        .name("BKTW_123") -                        .hasNef(true) -                        .type(VehicleType.BKTW) -                        .build(); - -        Operation operation = -                Operation.builder() -                        .status(Status.ACTIVE) -                        .opCode("ALP-95E7") -                        .created(Instant.now()) -                        .destination( -                                "Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien ") -                        .additionalInfo("HTU Wien") -                        .severity(Severity.B) -                        .vehicles(Set.of(vehicle)) -                        .build(); -        operationDAO.add(operation); -    } - -    @Test(expected = PersistenceException.class) -    public void addConnectionTest() throws PersistenceException { -        operationDAO.connectVehicleToOperation(-1, 0); -    } - -    // TODO: ADD CONNECTION TESTS -    // KOMMT ID ZURÜCK?*/ -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/CarAddTestService.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/CarAddTestService.java deleted file mode 100644 index fd8b43f..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/CarAddTestService.java +++ /dev/null @@ -1,281 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import static junit.framework.TestCase.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDatabaseDao; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import org.junit.Test; - -public class CarAddTestService { -    private final VehicleDAO vehicleP = mock(VehicleDatabaseDao.class); -    private final VehicleService vehicleService = new VehicleServiceImpl(vehicleP); - -    public CarAddTestService() throws PersistenceException { -        when(vehicleP.add(any())).thenReturn(1L); -    } - -    @Test -    public void testValidVehicleH() { -        Vehicle vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.HOCHDACH) -                        .type(Vehicle.VehicleType.RTW) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (InvalidVehicleException | ServiceException e) { -            fail(); -        } -        vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.HOCHDACH) -                        .type(Vehicle.VehicleType.KTW) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (InvalidVehicleException | ServiceException e) { -            fail(); -        } -        vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.HOCHDACH) -                        .type(Vehicle.VehicleType.KTW_B) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (InvalidVehicleException | ServiceException e) { -            fail(); -        } -        vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.HOCHDACH) -                        .type(Vehicle.VehicleType.BKTW) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (InvalidVehicleException | ServiceException e) { -            fail(); -        } -    } - -    @Test -    public void testValidVehicleM() { -        Vehicle vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) -                        .type(Vehicle.VehicleType.KTW) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (InvalidVehicleException | ServiceException e) { -            fail(); -        } -        vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) -                        .type(Vehicle.VehicleType.KTW_B) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (InvalidVehicleException | ServiceException e) { -            fail(); -        } -        vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) -                        .type(Vehicle.VehicleType.BKTW) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (InvalidVehicleException | ServiceException e) { -            fail(); -        } -    } - -    @Test -    public void testValidVehicleN() { -        Vehicle vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.NORMAL) -                        .type(Vehicle.VehicleType.BKTW) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (InvalidVehicleException | ServiceException e) { -            fail(); -        } -        vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.NORMAL) -                        .type(Vehicle.VehicleType.NEF) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (InvalidVehicleException | ServiceException e) { -            fail(); -        } -        vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.NORMAL) -                        .type(Vehicle.VehicleType.NAH) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (InvalidVehicleException | ServiceException e) { -            fail(); -        } -    } - -    @Test(expected = InvalidVehicleException.class) -    public void testInvalidVehicleH() throws InvalidVehicleException { -        Vehicle vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.HOCHDACH) -                        .type(Vehicle.VehicleType.NEF) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (ServiceException e) { -            fail(); -        } -        vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.HOCHDACH) -                        .type(Vehicle.VehicleType.NAH) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (ServiceException e) { -            fail(); -        } -    } - -    @Test(expected = InvalidVehicleException.class) -    public void testInvalidVehicleM() throws InvalidVehicleException { -        Vehicle vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) -                        .type(Vehicle.VehicleType.NEF) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (ServiceException e) { -            fail(); -        } -        vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) -                        .type(Vehicle.VehicleType.NAH) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (ServiceException e) { -            fail(); -        } -        vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) -                        .type(Vehicle.VehicleType.RTW) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (ServiceException e) { -            fail(); -        } -    } - -    @Test(expected = InvalidVehicleException.class) -    public void testInvalidVehicleN() throws InvalidVehicleException { -        Vehicle vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.NORMAL) -                        .type(Vehicle.VehicleType.RTW) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (ServiceException e) { -            fail(); -        } -        vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.NORMAL) -                        .type(Vehicle.VehicleType.KTW_B) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (ServiceException e) { -            fail(); -        } -        vehicle = -                Vehicle.builder() -                        .constructionType(Vehicle.ConstructionType.NORMAL) -                        .type(Vehicle.VehicleType.KTW) -                        .hasNef(true) -                        .status(Vehicle.Status.ABGEMELDET) -                        .name("") -                        .build(); -        try { -            vehicleService.add(vehicle); -        } catch (ServiceException e) { -            fail(); -        } -    } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java index 70185d3..f9ec287 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java @@ -1,5 +1,6 @@  package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; +import static org.mockito.ArgumentMatchers.any;  import static org.mockito.ArgumentMatchers.anyLong;  import static org.mockito.Mockito.times;  import static org.mockito.Mockito.verify; @@ -11,10 +12,10 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation;  import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity;  import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status;  import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType;  import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException;  import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException;  import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException;  import java.time.Instant;  import java.util.Collections;  import java.util.Set; @@ -36,14 +37,15 @@ public class OperationServiceTest {      private Set<Vehicle> vehicles;      private Vehicle v1, v2, v3, v4, v5; +    private Operation baseOp, o1, o2;      @Before -    public void setUp() throws ElementNotFoundException, PersistenceException { +    public void setUp() throws Exception {          v1 =                  Vehicle.builder()                          .id(1)                          .name("RTW-1") -                        .constructionType(Vehicle.ConstructionType.HOCHDACH) +                        .constructionType(ConstructionType.HOCHDACH)                          .type(Vehicle.VehicleType.RTW)                          .status(Vehicle.Status.FREI_FUNK)                          .hasNef(true) @@ -53,7 +55,7 @@ public class OperationServiceTest {                  Vehicle.builder()                          .id(2)                          .name("KTW-1") -                        .constructionType(Vehicle.ConstructionType.HOCHDACH) +                        .constructionType(ConstructionType.HOCHDACH)                          .type(Vehicle.VehicleType.KTW)                          .status(Vehicle.Status.FREI_WACHE)                          .hasNef(true) @@ -63,7 +65,7 @@ public class OperationServiceTest {                  Vehicle.builder()                          .id(3)                          .name("KTW-2") -                        .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) +                        .constructionType(ConstructionType.MITTELHOCHDACH)                          .type(Vehicle.VehicleType.KTW_B)                          .status(Vehicle.Status.FREI_FUNK)                          .hasNef(false) @@ -73,7 +75,7 @@ public class OperationServiceTest {                  Vehicle.builder()                          .id(4)                          .name("BKTW-2") -                        .constructionType(Vehicle.ConstructionType.HOCHDACH) +                        .constructionType(ConstructionType.HOCHDACH)                          .type(Vehicle.VehicleType.BKTW)                          .status(Vehicle.Status.FREI_FUNK)                          .hasNef(false) @@ -83,7 +85,7 @@ public class OperationServiceTest {                  Vehicle.builder()                          .id(5)                          .name("NEF-1") -                        .constructionType(Vehicle.ConstructionType.NORMAL) +                        .constructionType(ConstructionType.NORMAL)                          .type(Vehicle.VehicleType.NEF)                          .status(Vehicle.Status.FREI_WACHE)                          .hasNef(true) @@ -93,7 +95,7 @@ public class OperationServiceTest {                  Vehicle.builder()                          .id(6)                          .name("NAH-1") -                        .constructionType(Vehicle.ConstructionType.MITTELHOCHDACH) +                        .constructionType(ConstructionType.MITTELHOCHDACH)                          .type(Vehicle.VehicleType.NAH)                          .status(Vehicle.Status.ABGEMELDET)                          .hasNef(true) @@ -101,24 +103,24 @@ public class OperationServiceTest {          vehicles = Set.of(v1, v2, v3, v4, v5, v6); -        Operation o = +        baseOp =                  Operation.builder()                          .id(1)                          .opCode("ALP-95E7")                          .severity(Severity.E)                          .status(Status.ACTIVE)                          .vehicles(Collections.singleton(v1)) -                        .created(Instant.now())                          .destination("Wiedner Hauptstraße 35, Wien")                          .build(); -        Operation o2 = o.toBuilder().status(Status.CANCELLED).build(); +        o1 = baseOp.toBuilder().created(Instant.now()).build(); +        o2 = o1.toBuilder().id(5).status(Status.CANCELLED).build();          when(operationDAO.get(anyLong()))                  .thenAnswer(                          ans -> {                              long arg = ans.getArgument(0); -                            if (arg == 1L) return o; +                            if (arg == 1L) return o1;                              else if (arg == 5L) return o2;                              else throw new ElementNotFoundException("");                          }); @@ -172,4 +174,34 @@ public class OperationServiceTest {      public void requestInactiveOperation() throws Exception {          operationService.requestVehicles(5, Set.of(1L));      } + +    @Test +    public void addOperation() throws Exception { +        operationService.add(baseOp); + +        // Operation result = +        verify(operationDAO, times(1)) +                .add(baseOp.toBuilder().created(any()).status(Status.ACTIVE).build()); +        verify(vehicleDAO, times(1)).get(v1.id()); +    } + +    @Test(expected = InvalidOperationException.class) +    public void addInvalidSeverity() throws Exception { +        operationService.add(baseOp.toBuilder().severity(Severity.B).build()); +    } + +    @Test(expected = InvalidOperationException.class) +    public void addWithoutVehicles() throws Exception { +        operationService.add(baseOp.toBuilder().vehicles(Set.of()).build()); +    } + +    @Test(expected = InvalidOperationException.class) +    public void addInvalidOpcode() throws Exception { +        operationService.add(baseOp.toBuilder().opCode("ABC").build()); +    } + +    @Test(expected = InvalidOperationException.class) +    public void addWithSetCreated() throws Exception { +        operationService.add(baseOp.toBuilder().created(Instant.now()).build()); +    }  } diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceUnitTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceUnitTest.java deleted file mode 100644 index 7b574a1..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceUnitTest.java +++ /dev/null @@ -1,156 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import static junit.framework.TestCase.fail; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.time.Instant; -import java.util.Set; -import org.junit.Assert; -import org.junit.Test; - -public class OperationServiceUnitTest { -    private final OperationDAO operationDAO = mock(OperationDAO.class); -    private final VehicleDAO vehicleDAO = mock(VehicleDAO.class); -    private final OperationService operationService = -            new OperationServiceImpl(operationDAO, vehicleDAO); - -    @Test -    public void addOperationTest() { -        try { -            when(operationDAO.add(any())).thenReturn(1L); -        } catch (PersistenceException e) { -            fail(); -        } -        Vehicle vehicle = -                Vehicle.builder() -                        .status(Vehicle.Status.FREI_FUNK) -                        .constructionType(ConstructionType.HOCHDACH) -                        .name("BKTW_123") -                        .hasNef(true) -                        .type(VehicleType.BKTW) -                        .build(); - -        Operation operation = -                Operation.builder() -                        .status(Status.ACTIVE) -                        .opCode("ALP-95E7") -                        .created(Instant.now()) -                        .destination("Wiedner Hauptstraße 35, Wien") -                        .additionalInfo("HTU Wien") -                        .severity(Severity.B) -                        .vehicles(Set.of(vehicle)) -                        .build(); -        try { -            Assert.assertThat(operationService.add(operation), is(1L)); -        } catch (InvalidOperationException | ServiceException e) { -            fail(); -        } -    } - -    @Test(expected = InvalidOperationException.class) -    public void addFaultyOperationTest() throws InvalidOperationException { -        Vehicle vehicle = -                Vehicle.builder() -                        .status(Vehicle.Status.FREI_FUNK) -                        .constructionType(ConstructionType.HOCHDACH) -                        .name("BKTW_123") -                        .hasNef(true) -                        .type(VehicleType.BKTW) -                        .build(); -        Vehicle vehicle1 = -                Vehicle.builder() -                        .status(Vehicle.Status.ABGEMELDET) -                        .constructionType(ConstructionType.HOCHDACH) -                        .name("BKTW_123") -                        .hasNef(true) -                        .type(VehicleType.BKTW) -                        .build(); - -        Operation operation = -                Operation.builder() -                        .status(Status.ACTIVE) -                        .opCode("ALP-95E7") -                        .created(Instant.now()) -                        .destination("Wiedner Hauptstraße 35, Wien") -                        .additionalInfo("HTU Wien") -                        .severity(Severity.B) -                        .vehicles(Set.of(vehicle, vehicle1)) -                        .build(); -        try { -            Assert.assertThat(operationService.add(operation), is(1L)); -        } catch (ServiceException e) { -            fail(); -        } -    } - -    @Test(expected = InvalidOperationException.class) -    public void addFaultyOperation2Test() throws InvalidOperationException { -        Operation operation = -                Operation.builder() -                        .status(Status.ACTIVE) -                        .opCode("ALP-95E7") -                        .created(Instant.now()) -                        .destination("Wiedner Hauptstraße 35, Wien") -                        .additionalInfo("HTU Wien") -                        .severity(Severity.B) -                        .vehicles(Set.of()) -                        .build(); -        try { -            Assert.assertThat(operationService.add(operation), is(1L)); -        } catch (ServiceException e) { -            e.printStackTrace(); -        } -    } - -    @Test(expected = InvalidOperationException.class) -    public void addFaultyOperation3Test() throws InvalidOperationException { -        Operation operation = -                Operation.builder() -                        .status(Status.ACTIVE) -                        .opCode("ALP-95E7") -                        .created(Instant.now()) -                        .destination("") -                        .additionalInfo("HTU Wien") -                        .severity(Severity.B) -                        .vehicles(Set.of()) -                        .build(); -        try { -            Assert.assertThat(operationService.add(operation), is(1L)); -        } catch (ServiceException e) { -            e.printStackTrace(); -        } -    } - -    @Test(expected = InvalidOperationException.class) -    public void addFaultyOperation4Test() throws InvalidOperationException { -        Operation operation = -                Operation.builder() -                        .status(Status.ACTIVE) -                        .opCode("") -                        .created(Instant.now()) -                        .destination("Römergasse 7, 2500 Baden") -                        .additionalInfo("HTU Wien") -                        .severity(Severity.B) -                        .vehicles(Set.of()) -                        .build(); -        try { -            Assert.assertThat(operationService.add(operation), is(1L)); -        } catch (ServiceException e) { -            e.printStackTrace(); -        } -    } -}  | 
