Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions lib-gdal/src/test/java/org/esa/lib/gdal/AbstractGDALTest.java

This file was deleted.

42 changes: 42 additions & 0 deletions lib-gdal/src/test/java/org/esa/lib/gdal/GDALTestUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.esa.lib.gdal;

import org.esa.snap.core.util.SystemUtils;
import org.esa.snap.dataio.gdal.OSCategory;

import java.nio.file.Path;

import static org.apache.commons.lang3.SystemUtils.*;
import static org.esa.snap.dataio.gdal.GDALVersion.GDAL_NATIVE_LIBRARIES_ROOT;

public class GDALTestUtils {

public static String getExpectedDirectory() {
final OSCategory osCategory = getExpectedOSCategory();
return osCategory.getOperatingSystemName() + "/" + osCategory.getArchitecture();
}

public static OSCategory getExpectedOSCategory() {
final String sysArch = System.getProperty("os.arch").toLowerCase();
if (IS_OS_LINUX && sysArch.contains("amd64")) {
return OSCategory.LINUX_64;
} else if (IS_OS_MAC_OSX) {
if (sysArch.contains("amd64") || sysArch.contains("x86_64")) {
return OSCategory.MAC_OS_X;
} else if (sysArch.contains("aarch64")) {
return OSCategory.MAC_OS_X_AARCH64;
}
} else if (IS_OS_WINDOWS) {
if (sysArch.contains("amd64") || sysArch.contains("x86_x64")) {
return OSCategory.WIN_64;
} else {
return OSCategory.WIN_32;
}
}
return OSCategory.UNSUPPORTED;
}

public static Path getExpectedNativeLibrariesRootFolderPath() {
return SystemUtils.getAuxDataPath().resolve(GDAL_NATIVE_LIBRARIES_ROOT);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.esa.snap.dataio.gdal;

import com.bc.ceres.annotation.STTM;
import org.esa.lib.gdal.AbstractGDALTest;
import org.esa.lib.gdal.GDALTestUtils;
import org.esa.snap.jni.EnvironmentVariables;
import org.junit.Test;

Expand All @@ -23,15 +23,15 @@ private static URL getExpectedEnvironmentVariablesFilePathFromSources() {
}

private static String getExpectedEnvironmentVariablesDirectory() {
return GDAL_NATIVE_LIBRARIES_SRC + "/" + AbstractGDALTest.getExpectedDirectory() + "/" + getExpectedEnvironmentVariablesFileName();
return GDAL_NATIVE_LIBRARIES_SRC + "/" + GDALTestUtils.getExpectedDirectory() + "/" + getExpectedEnvironmentVariablesFileName();
}

static String getExpectedEnvironmentVariablesFileName() {
return AbstractGDALTest.getExpectedOSCategory().getOSSpecificEnvironmentVariablesFileName();
return GDALTestUtils.getExpectedOSCategory().getOSSpecificEnvironmentVariablesFileName();
}

static Path getExpectedEnvironmentVariablesFilePath() {
return AbstractGDALTest.getExpectedNativeLibrariesRootFolderPath().resolve(getExpectedEnvironmentVariablesFileName());
return GDALTestUtils.getExpectedNativeLibrariesRootFolderPath().resolve(getExpectedEnvironmentVariablesFileName());
}


Expand All @@ -40,7 +40,7 @@ static Path getExpectedEnvironmentVariablesFilePath() {
public void testInitEnvironmentVariablesNativeLibrary() {
EnvironmentVariablesNativeLoader.ensureEnvironmentVariablesNativeInitialised();
assertTrue(Files.exists(EnvironmentVariablesNativeLoaderTest.getExpectedEnvironmentVariablesFilePath()));
assertTrue(Files.exists(AbstractGDALTest.getExpectedNativeLibrariesRootFolderPath()));
assertTrue(Files.exists(GDALTestUtils.getExpectedNativeLibrariesRootFolderPath()));
assertFalse(EnvironmentVariables.getEnvironmentVariable("PATH").isEmpty());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.esa.snap.dataio.gdal;

import com.bc.ceres.annotation.STTM;
import org.esa.lib.gdal.AbstractGDALTest;
import org.esa.lib.gdal.GDALTestUtils;
import org.junit.Test;

import java.io.IOException;
Expand All @@ -16,7 +16,7 @@ private void testInstallBundleDistribution() {
try {
final GDALVersion gdalVersion = GDALVersion.GDAL_372_FULL;
GDALDistributionInstaller.setupDistribution(gdalVersion);
assertTrue(Files.exists(AbstractGDALTest.getExpectedNativeLibrariesRootFolderPath()));
assertTrue(Files.exists(GDALTestUtils.getExpectedNativeLibrariesRootFolderPath()));
assertTrue(Files.exists(GDALVersionTest.getExpectedGDALVersionLocation(gdalVersion)));
} catch (IOException e) {
fail("Error on testSetupDistribution(): " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.esa.snap.dataio.gdal;

import com.bc.ceres.annotation.STTM;
import org.esa.lib.gdal.AbstractGDALTest;
import org.esa.lib.gdal.GDALTestUtils;
import org.junit.Test;

import java.io.IOException;
Expand All @@ -20,7 +20,7 @@ public void testCopyDistribution() {
final GDALVersion gdalVersion = GDALVersion.getInternalVersion();
assertEquals(GDALVersionTest.getExpectedGDALVersionLocation(gdalVersion), gdalVersion.getNativeLibrariesFolderPath());
GDALInstaller.copyDistribution(gdalVersion);
assertTrue(Files.exists(AbstractGDALTest.getExpectedNativeLibrariesRootFolderPath()));
assertTrue(Files.exists(GDALTestUtils.getExpectedNativeLibrariesRootFolderPath()));
} catch (IOException e) {
fail("Error on testCopyDistribution(): " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.bc.ceres.annotation.STTM;
import eu.esa.snap.core.lib.NativeLibraryTools;
import org.esa.lib.gdal.AbstractGDALTest;
import org.esa.lib.gdal.GDALTestUtils;
import org.esa.lib.gdal.activator.GDALInstallInfo;
import org.esa.snap.core.datamodel.ProductData;
import org.esa.snap.core.util.ThreadExecutor;
Expand All @@ -11,13 +11,13 @@
import org.esa.snap.dataio.gdal.drivers.GDAL;
import org.esa.snap.dataio.gdal.drivers.GDALConst;
import org.esa.snap.dataio.gdal.drivers.GDALConstConstants;
import org.junit.Before;
import org.junit.Test;

import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
Expand All @@ -26,13 +26,18 @@
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;

public class GDALLoaderTest extends AbstractGDALTest {
public class GDALLoaderTest {

private static final String TEST_FILE = "U_1005A.NTF";

private static final GDALLoader TEST_GDAL_LOADER = GDALLoader.getInstance();
private static final GDALVersion TEST_GDAL_VERSION = GDALVersion.getGDALVersion();

public static final String PROPERTY_NAME_DATA_DIR = "snap.reader.tests.data.dir";
private static final String TEST_FOLDER_NAME = "_gdal";

protected Path libGDALTestsFolderPath;

private Path testFilePath;

private static URLClassLoader getExpectedGDALVersionLoader() throws Exception {
Expand Down Expand Up @@ -82,8 +87,23 @@ private static int getExpectedBandDataType(int gdalDataType) {
}
}

@Before
public void setUpLocal() {
private static boolean testDataAvailable() {
final String testDataDir = System.getProperty(PROPERTY_NAME_DATA_DIR);
return (testDataDir != null) && !testDataDir.isEmpty() && Files.exists(Paths.get(testDataDir));
}

private void checkTestDirectoryExists() {
final String testDirectoryPathProperty = System.getProperty(PROPERTY_NAME_DATA_DIR);
assertNotNull("The system property '" + PROPERTY_NAME_DATA_DIR + "' representing the test directory is not set.", testDirectoryPathProperty);
final Path testFolderPath = Paths.get(testDirectoryPathProperty);
assertTrue("The test directory path " + testDirectoryPathProperty + " is not valid.", Files.exists(testFolderPath));
this.libGDALTestsFolderPath = testFolderPath.resolve(TEST_FOLDER_NAME);
assumeTrue("The lib_gdal test directory path (" + this.libGDALTestsFolderPath + ") is not valid.", Files.exists(this.libGDALTestsFolderPath));
}

public final void setUp() {
assumeTrue(testDataAvailable());
checkTestDirectoryExists();
testFilePath = this.libGDALTestsFolderPath.resolve(TEST_FILE);
assumeTrue(Files.exists(testFilePath));
}
Expand All @@ -97,6 +117,7 @@ public void testGetInstance() {
@Test
@STTM("SNAP-3567")
public void testInitGDAL() {
setUp();
try {
assertNotNull(TEST_GDAL_LOADER);
checkGDALInitialised();
Expand All @@ -108,9 +129,11 @@ public void testInitGDAL() {
@Test
@STTM("SNAP-3637")
public void testSyncGDALInitialisation(){
setUp();
assertNotNull(TEST_GDAL_LOADER);
assumeTrue(TEST_GDAL_LOADER.isNotInitialised());
try {
Path gdalRootFolderPath = getExpectedNativeLibrariesRootFolderPath();
Path gdalRootFolderPath = GDALTestUtils.getExpectedNativeLibrariesRootFolderPath();
//remove gdal folder
if(Files.exists(gdalRootFolderPath)){
FileUtils.deleteTree(gdalRootFolderPath.toFile());
Expand Down Expand Up @@ -142,7 +165,7 @@ public void process() {

private void checkGDALInitialised() {
GDALLoader.ensureGDALInitialised();
assertTrue(Files.exists(getExpectedNativeLibrariesRootFolderPath()));
assertTrue(Files.exists(GDALTestUtils.getExpectedNativeLibrariesRootFolderPath()));
assertTrue(GDALInstallInfo.INSTANCE.isPresent());
assertNotNull(GDAL.open(testFilePath.toString(), GDALConst.gaReadonly()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.bc.ceres.annotation.STTM;
import eu.esa.snap.core.lib.NativeLibraryTools;
import org.esa.lib.gdal.AbstractGDALTest;
import org.esa.lib.gdal.GDALTestUtils;
import org.junit.Test;

import java.io.File;
Expand Down Expand Up @@ -35,15 +35,15 @@ private static String getExpectedZipName(String name) {
}

static Path getExpectedGDALVersionLocation(GDALVersion gdalVersion) {
return AbstractGDALTest.getExpectedNativeLibrariesRootFolderPath().resolve(getExpectedDirName(gdalVersion.name));
return GDALTestUtils.getExpectedNativeLibrariesRootFolderPath().resolve(getExpectedDirName(gdalVersion.name));
}

private static String getExpectedLocation() {
return getExpectedGDALVersionLocation(TEST_VERSION).toString();
}

private static URL getExpectedZipFileURLFromSources() {
return GDALVersion.class.getClassLoader().getResource(GDAL_NATIVE_LIBRARIES_SRC + "/" + AbstractGDALTest.getExpectedDirectory() + "/" + getExpectedZipName(TEST_VERSION.name).replace(File.separator, "/"));
return GDALVersion.class.getClassLoader().getResource(GDAL_NATIVE_LIBRARIES_SRC + "/" + GDALTestUtils.getExpectedDirectory() + "/" + getExpectedZipName(TEST_VERSION.name).replace(File.separator, "/"));
}

private static Path getExpectedZipFilePath() {
Expand Down Expand Up @@ -114,7 +114,7 @@ public void testGetZipFilePath() {
@STTM("SNAP-3523")
public void testGetNativeLibrariesRootFolderPath() {
String libraryRoot = NativeLibraryTools.GDAL_NATIVE_LIBRARIES_ROOT;
assertEquals(AbstractGDALTest.getExpectedNativeLibrariesRootFolderPath(), NativeLibraryTools.getNativeLibrariesRootFolderPath(libraryRoot));
assertEquals(GDALTestUtils.getExpectedNativeLibrariesRootFolderPath(), NativeLibraryTools.getNativeLibrariesRootFolderPath(libraryRoot));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testReadProduct() throws IOException {
assertNotNull(coordinateReferenceSystem.getName());
assertEquals("WGS84(DD)", coordinateReferenceSystem.getName().getCode());

assertEquals(2, product.getMaskGroup().getNodeCount());
assertEquals(1, product.getMaskGroup().getNodeCount());

assertEquals(1, product.getBands().length);

Expand Down Expand Up @@ -104,7 +104,7 @@ public void testReadProductPixelSubset() throws IOException {
assertNotNull(coordinateReferenceSystem.getName());
assertEquals("WGS84(DD)", coordinateReferenceSystem.getName().getCode());

assertEquals(1, product.getMaskGroup().getNodeCount());
assertEquals(0, product.getMaskGroup().getNodeCount());

assertEquals(1, product.getBands().length);

Expand Down