diff --git a/tests/org.eclipse.emfcloud.modelserver.emf.tests/.gitignore b/tests/org.eclipse.emfcloud.modelserver.emf.tests/.gitignore new file mode 100644 index 0000000..e050804 --- /dev/null +++ b/tests/org.eclipse.emfcloud.modelserver.emf.tests/.gitignore @@ -0,0 +1 @@ +/.temp/ \ No newline at end of file diff --git a/tests/org.eclipse.emfcloud.modelserver.emf.tests/src/org/eclipse/emfcloud/modelserver/emf/AbstractResourceTest.java b/tests/org.eclipse.emfcloud.modelserver.emf.tests/src/org/eclipse/emfcloud/modelserver/emf/AbstractResourceTest.java index c6fcb95..9551576 100644 --- a/tests/org.eclipse.emfcloud.modelserver.emf.tests/src/org/eclipse/emfcloud/modelserver/emf/AbstractResourceTest.java +++ b/tests/org.eclipse.emfcloud.modelserver.emf.tests/src/org/eclipse/emfcloud/modelserver/emf/AbstractResourceTest.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2019 EclipseSource and others. + * Copyright (c) 2019-2023 EclipseSource and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -10,7 +10,12 @@ ********************************************************************************/ package org.eclipse.emfcloud.modelserver.emf; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.Collections; import org.eclipse.emf.common.util.URI; @@ -21,12 +26,23 @@ import org.eclipse.emfcloud.modelserver.common.codecs.EMFJsonConverter; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; public abstract class AbstractResourceTest { - public static final String RESOURCE_PATH = "resources/"; + public static final String TEST_RESOURCES_PATH = "resources/"; + public static final String RESOURCE_PATH = ".temp/"; @SuppressWarnings({ "checkstyle:VisibilityModifier" }) protected ResourceSetImpl resourceSet; // needed in ResourceManagerTest.java + @BeforeClass + public static void setupTestResources() throws IOException { + // copy test resources to a temporary resource location to avoid + // git changes if executing tests due to saving resources + File sourceDirectory = new File(TEST_RESOURCES_PATH); + File destinationDirectory = new File(RESOURCE_PATH); + copyDirectoryFiles(sourceDirectory, destinationDirectory); + } + @Before public void initializeResourceSet() { resourceSet = new ResourceSetImpl(); @@ -35,6 +51,33 @@ public void initializeResourceSet() { resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()); } + private static void copyDirectoryFiles(final File sourceDirectory, final File destinationDirectory) + throws IOException { + if (!destinationDirectory.exists()) { + destinationDirectory.mkdir(); + } + for (String f : sourceDirectory.list()) { + File source = new File(sourceDirectory, f); + File destination = new File(destinationDirectory, f); + // our src directory only contains files + if (source.isFile()) { + copyFile(source, destination); + } + } + } + + private static void copyFile(final File sourceFile, final File destinationFile) + throws IOException { + try (InputStream in = new FileInputStream(sourceFile); + OutputStream out = new FileOutputStream(destinationFile)) { + byte[] buf = new byte[1024]; + int length; + while ((length = in.read(buf)) > 0) { + out.write(buf, 0, length); + } + } + } + protected Resource loadResource(final String file) throws IOException { Resource resource = resourceSet.createResource(URI.createFileURI(toFullPath(file))); resource.load(Collections.EMPTY_MAP); diff --git a/tests/pom.xml b/tests/pom.xml index 6d7ac65..ac7bc87 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -15,6 +15,7 @@ org.eclipse.emfcloud.modelserver.client.tests org.eclipse.emfcloud.modelserver.common.tests org.eclipse.emfcloud.modelserver.edit.tests + org.eclipse.emfcloud.modelserver.emf.tests org.eclipse.emfcloud.modelserver.tests @@ -22,11 +23,6 @@ m2 - - - org.eclipse.emfcloud.modelserver.emf.tests - -