diff options
| author | Viktoria Pundy <viktoria.pundy@aon.at> | 2018-05-05 20:07:40 +0200 | 
|---|---|---|
| committer | Viktoria Pundy <viktoria.pundy@aon.at> | 2018-05-06 18:12:33 +0200 | 
| commit | 2ba1998d8c1152537e16fcc7f5caf683f20a2574 (patch) | |
| tree | b9fdad88f90738ee6784be02dc7ed49a2bb274a3 /src/test | |
| parent | 160e236d8f1e92b7c59b0bb6dc3a7b5aaefe33ac (diff) | |
| download | sepm-groupproject-2ba1998d8c1152537e16fcc7f5caf683f20a2574.tar.gz sepm-groupproject-2ba1998d8c1152537e16fcc7f5caf683f20a2574.tar.xz sepm-groupproject-2ba1998d8c1152537e16fcc7f5caf683f20a2574.zip  | |
Added some component tests, mocking of database still necessary
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java | 155 | 
1 files changed, 155 insertions, 0 deletions
diff --git a/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java new file mode 100644 index 0000000..fc3ea54 --- /dev/null +++ b/src/test/at/ac/tuwien/sepm/assignment/groupphase/operation/OperationServiceComponentTest.java @@ -0,0 +1,155 @@ +package at.ac.tuwien.sepm.assignment.groupphase.operation; + +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.DBOperationDAO; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; +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.einsatzverwaltung.service.OperationService; +import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.OperationServiceImpl; +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 at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager; +import java.time.Instant; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class OperationServiceComponentTest { + +    private final OperationDAO operationDAO = new DBOperationDAO(new JDBCConnectionManager()); +    private final OperationService operationService = new OperationServiceImpl(operationDAO); + +    @Test +    public void addOperationTest() { +        //TODO: MOCK H2 +        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(List.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(List.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(List.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(List.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(List.of()) +                        .build(); +        try { +            Assert.assertThat(operationService.add(operation), is(1L)); +        } catch (ServiceException e) { +            e.printStackTrace(); +        } +    } + +}  | 
