diff --git a/tdt4140-gr1800/app.core/src/main/java/tdt4140/gr1800/app/core/DocumentStorageImpl.java b/tdt4140-gr1800/app.core/src/main/java/tdt4140/gr1800/app/core/DocumentStorageImpl.java index 4e91dfaf9d49c3a455cf0ab11c469198692b901b..559279c2a795c5b1fa859a9a2c0129736fe71f33 100644 --- a/tdt4140-gr1800/app.core/src/main/java/tdt4140/gr1800/app/core/DocumentStorageImpl.java +++ b/tdt4140-gr1800/app.core/src/main/java/tdt4140/gr1800/app/core/DocumentStorageImpl.java @@ -16,6 +16,11 @@ public abstract class DocumentStorageImpl<D, L> implements IDocumentStorage<L> { this.documentLocation = documentLocation; } + protected void setDocumentAndLocation(D document, L documentLocation) { + setDocument(document); + setDocumentLocation(documentLocation); + } + protected abstract D getDocument(); protected abstract void setDocument(D document); @@ -25,13 +30,12 @@ public abstract class DocumentStorageImpl<D, L> implements IDocumentStorage<L> { @Override public void newDocument() { - setDocument(createDocument()); + setDocumentAndLocation(createDocument(), null); } @Override public void openDocument(L storage) throws IOException { - setDocument(loadDocument(storage)); - setDocumentLocation(storage); + setDocumentAndLocation(loadDocument(storage), storage); } @Override diff --git a/tdt4140-gr1800/app.core/src/test/java/tdt4140/gr1800/app/core/AppTest.java b/tdt4140-gr1800/app.core/src/test/java/tdt4140/gr1800/app/core/AppTest.java index f43ba340d6afe61fdc5ad907a409aba8eba91913..8add30329d13176bfa9a549f2d4defd5304112d8 100644 --- a/tdt4140-gr1800/app.core/src/test/java/tdt4140/gr1800/app/core/AppTest.java +++ b/tdt4140-gr1800/app.core/src/test/java/tdt4140/gr1800/app/core/AppTest.java @@ -18,11 +18,15 @@ public class AppTest { } @Test - public void testLoadDocument() { + public void testNewDocument() { + IDocumentStorage<File> documentStorage = app.getDocumentStorage(); + documentStorage.newDocument(); + Assert.assertFalse(app.getGeoLocationNames().iterator().hasNext()); + Assert.assertNull(documentStorage.getDocumentLocation()); + } + + protected void testLoadDocument(File file) { IDocumentStorage<File> documentStorage = app.getDocumentStorage(); - URL url = getClass().getResource("geoLocations.json"); - Assert.assertEquals("Not file URL", "file", url.getProtocol()); - File file = new File(url.getPath()); try { documentStorage.openDocument(file); } catch (IOException e) { @@ -31,4 +35,27 @@ public class AppTest { Assert.assertEquals(file, documentStorage.getDocumentLocation()); GeoLocationsPersistenceTest.testGeoLocationsDotJson(app.getGeoLocations((String[]) null)); } + + @Test + public void testLoadDocument() { + URL url = getClass().getResource("geoLocations.json"); + Assert.assertEquals("Not file URL", "file", url.getProtocol()); + File file = new File(url.getPath()); + testLoadDocument(file); + } + + @Test + public void testSaveDocument() { + testLoadDocument(); + try { + IDocumentStorage<File> documentStorage = app.getDocumentStorage(); + File tempFile = File.createTempFile("geoLocations", ".json"); + tempFile.deleteOnExit(); + documentStorage.setDocumentLocation(tempFile); + documentStorage.saveDocument(); + testLoadDocument(tempFile); + } catch (IOException e) { + Assert.fail(e.getMessage()); + } + } } diff --git a/tdt4140-gr1800/app.core/src/test/java/tdt4140/gr1800/app/core/GeoLocationsPersistenceTest.java b/tdt4140-gr1800/app.core/src/test/java/tdt4140/gr1800/app/core/GeoLocationsPersistenceTest.java index 4eb7dc5817e158f0f753367c7da9daad9945c19a..73a426f00181d39a7dca1c71e00d64e50d0d89c6 100644 --- a/tdt4140-gr1800/app.core/src/test/java/tdt4140/gr1800/app/core/GeoLocationsPersistenceTest.java +++ b/tdt4140-gr1800/app.core/src/test/java/tdt4140/gr1800/app/core/GeoLocationsPersistenceTest.java @@ -3,6 +3,7 @@ package tdt4140.gr1800.app.core; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Iterator; @@ -31,6 +32,13 @@ public class GeoLocationsPersistenceTest { } } + public static Collection<GeoLocations> createGeoLocationsDotJson() { + return Arrays.asList( + new GeoLocations("1", new LatLong(63, 10), new LatLong(63.1, 10.1)), + new GeoLocations("2", new LatLong(64, 11), new LatLong(64.1, 11.1)) + ); + } + public static void testGeoLocationsDotJson(Collection<GeoLocations> geoLocations) { Assert.assertEquals(2, geoLocations.size()); Iterator<GeoLocations> it = geoLocations.iterator(); @@ -40,9 +48,7 @@ public class GeoLocationsPersistenceTest { @Test public void testSaveLocations() { - Collection<GeoLocations> geoLocations = new ArrayList<GeoLocations>(); - geoLocations.add(new GeoLocations("1", new LatLong(63, 10), new LatLong(63.1, 10.1))); - geoLocations.add(new GeoLocations("2", new LatLong(64, 11), new LatLong(64.1, 11.1))); + Collection<GeoLocations> geoLocations = createGeoLocationsDotJson(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { persistence.saveLocations(geoLocations, outputStream); diff --git a/tdt4140-gr18nn/app.ui/pom.xml b/tdt4140-gr18nn/app.ui/pom.xml index f81bdf8a0cfa2fa57569da527e0cf7b989b26577..a96b8e3133fcca564bdd25fb3ea1963a98d3e3c5 100644 --- a/tdt4140-gr18nn/app.ui/pom.xml +++ b/tdt4140-gr18nn/app.ui/pom.xml @@ -8,6 +8,31 @@ <artifactId>tdt4140-gr18nn</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> + + <profiles> + <profile> + <id>gitlab-ci</id> + <activation> + <property> + <name>gitlab-ci</name> + <value>true</value> + </property> + </activation> + <!-- + <properties> + <skip-ui-tests>true</skip-ui-tests> + </properties> + --> + <dependencies> + <dependency> + <groupId>org.testfx</groupId> + <artifactId>openjfx-monocle</artifactId> + <version>8u76-b04</version> <!-- jdk-9+181 for Java 9 --> + <scope>test</scope> + </dependency> + </dependencies> + </profile> + </profiles> <dependencies> <dependency> diff --git a/tdt4140-gr18nn/app.ui/src/test/java/tdt4140/gr18nn/app/ui/FxAppTest.java b/tdt4140-gr18nn/app.ui/src/test/java/tdt4140/gr18nn/app/ui/FxAppTest.java index e654ea387d79048cbba63e36521ec45e0dbdf492..5c787744fd98e3e84ff154453e3d9616d97e8104 100644 --- a/tdt4140-gr18nn/app.ui/src/test/java/tdt4140/gr18nn/app/ui/FxAppTest.java +++ b/tdt4140-gr18nn/app.ui/src/test/java/tdt4140/gr18nn/app/ui/FxAppTest.java @@ -1,5 +1,6 @@ package tdt4140.gr18nn.app.ui; +import org.junit.BeforeClass; import org.junit.Test; import org.testfx.framework.junit.ApplicationTest; @@ -9,6 +10,21 @@ import javafx.scene.Scene; import javafx.stage.Stage; public class FxAppTest extends ApplicationTest { + + @BeforeClass + public static void headless() { + if (Boolean.valueOf(System.getProperty("gitlab-ci", "false"))) { + System.setProperty("prism.verbose", "true"); // optional + System.setProperty("java.awt.headless", "true"); + System.setProperty("testfx.robot", "glass"); + System.setProperty("testfx.headless", "true"); + System.setProperty("glass.platform", "Monocle"); + System.setProperty("monocle.platform", "Headless"); + System.setProperty("prism.order", "sw"); + System.setProperty("prism.text", "t2k"); + System.setProperty("testfx.setup.timeout", "2500"); + } + } @Override public void start(Stage stage) throws Exception {