Skip to content

Commit

Permalink
444 database feature classes (#445)
Browse files Browse the repository at this point in the history
* Fixed tools that are displayed for databases

* Fixed unit tests

* Updated travis to use openjdk8

* Start xvfb as a service on Travis
  • Loading branch information
Robert Ward committed Oct 3, 2019
1 parent 2824639 commit fb827e0
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 53 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Expand Up @@ -5,8 +5,10 @@ addons:
secure: "$SONAR_TOKEN"

jdk :
- oraclejdk8
- openjdk8
language : java
services:
- xvfb
cache:
directories:
- $HOME/.m2
Expand All @@ -18,9 +20,7 @@ script :
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar

before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
- export DISPLAY=:99.0
after_success:
- cd modules/application
- mvn org.eluder.coveralls:coveralls-maven-plugin:report
Expand Down
6 changes: 6 additions & 0 deletions modules/application/pom.xml
Expand Up @@ -239,6 +239,12 @@
<version>4.5.6</version>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>

<!-- Using the GeoServer legend generation code causes a CRS factory -->
<!-- to be loaded which results in no CRS codes when the user is asked -->
<!-- in the JCRSChooser dialog. -->
Expand Down
Expand Up @@ -223,6 +223,8 @@ public boolean supports(
if (fileNode.getFileCategory() == FileTreeNodeTypeEnum.DATABASE) {
supported = true;
}
} else if (node instanceof DatabaseNode) {
supported = true;
}
}
}
Expand Down
Expand Up @@ -24,7 +24,6 @@
import com.sldeditor.common.data.DatabaseConnection;
import com.sldeditor.common.localisation.Localisation;
import com.sldeditor.datasource.extension.filesystem.DatabaseConnectUpdateInterface;
import com.sldeditor.datasource.extension.filesystem.node.database.DatabaseNode;
import com.sldeditor.datasource.extension.filesystem.node.database.DatabaseOverallNode;
import com.sldeditor.tool.ToolButton;
import com.sldeditor.tool.ToolInterface;
Expand Down Expand Up @@ -189,17 +188,7 @@ public void setSelectedItems(

if (nodeTypeList != null) {
for (NodeInterface nodeType : nodeTypeList) {
if (nodeType instanceof DatabaseNode) {
DatabaseNode databaseNode = (DatabaseNode) nodeType;

DatabaseConnection connection = databaseNode.getConnection();
connectionList.add(connection);
databaseNodesSelected = true;

if (!connection.isSupportsDuplication()) {
canDuplicate = false;
}
} else if (nodeType instanceof DatabaseOverallNode) {
if (nodeType instanceof DatabaseOverallNode) {
DatabaseOverallNode databaseOverallNode = (DatabaseOverallNode) nodeType;
selectedDatabaseType = databaseOverallNode.toString();
canDuplicate = false;
Expand Down
Expand Up @@ -148,12 +148,24 @@ public SLDTestRunner() {
/**
* Writes an InputStream to a temporary file.
*
* @param in the in
* @return the file
* @param in the input stream
* @return the file object represent the stream
* @throws IOException Signals that an I/O exception has occurred.
*/
public static File stream2file(InputStream in) throws IOException {
final File tempFile = File.createTempFile(PREFIX, SUFFIX);
return stream2file(in, SUFFIX);
}

/**
* Writes an InputStream to a temporary file with supplied file suffix
*
* @param in the input stream
* @param suffix the filename suffix of the generated file
* @return the file object represent the stream
* @throws IOException Signals that an I/O exception has occurred.
*/
public static File stream2file(InputStream in, String suffix) throws IOException {
final File tempFile = File.createTempFile(PREFIX, suffix);
try (FileOutputStream out = new FileOutputStream(tempFile)) {
IOUtils.copy(in, out);
}
Expand Down
Expand Up @@ -19,13 +19,16 @@

package com.sldeditor.test.unit.datasource.chooseraster;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.sldeditor.datasource.chooseraster.ChooseRasterFormatInterface;
import com.sldeditor.datasource.chooseraster.DetermineRasterFormat;
import com.sldeditor.test.SLDTestRunner;
import com.sldeditor.test.unit.ui.tree.SLDTreeTest;
import java.io.File;
import java.net.URL;
import java.io.IOException;
import java.io.InputStream;
import java.util.Set;
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.coverage.grid.io.UnknownFormat;
Expand All @@ -51,28 +54,41 @@ public void testChoose() {
AbstractGridFormat gridFormat = DetermineRasterFormat.choose(null, null);
assertTrue(UnknownFormat.class == gridFormat.getClass());

URL url = SLDTreeTest.class.getResource("/raster/sld/sld_cookbook_raster.tif");
String testRasterFile = "/raster/sld/sld_cookbook_raster.tif";
InputStream inputStream = SLDTreeTest.class.getResourceAsStream(testRasterFile);
File f = null;

File f = new File(url.getFile());
gridFormat = DetermineRasterFormat.choose(f, null);
if (inputStream == null) {
assertNotNull(inputStream, "Failed to find raster test file : " + testRasterFile);
} else {
try {
f = SLDTestRunner.stream2file(inputStream, ".tif");

assertTrue(gridFormat != null);
gridFormat = DetermineRasterFormat.choose(f, null);

// Force to WorldImageFormat
gridFormat =
DetermineRasterFormat.choose(
f,
new ChooseRasterFormatInterface() {
assertTrue(gridFormat != null);

@Override
public AbstractGridFormat showPanel(
Set<AbstractGridFormat> formatList) {
WorldImageFormat wif = new WorldImageFormat();
// Force to WorldImageFormat
gridFormat =
DetermineRasterFormat.choose(
f,
new ChooseRasterFormatInterface() {

return wif;
}
});
@Override
public AbstractGridFormat showPanel(
Set<AbstractGridFormat> formatList) {
WorldImageFormat wif = new WorldImageFormat();

assertTrue(WorldImageFormat.class == gridFormat.getClass());
return wif;
}
});

assertTrue(WorldImageFormat.class == gridFormat.getClass());
} catch (IOException e1) {
e1.printStackTrace();
} finally {
f.delete();
}
}
}
}
Expand Up @@ -196,18 +196,18 @@ void testSetSelectedItems() {
DatabaseConnection dbConnection = DatabaseConnectionFactory.createPostgres();
nodeTypeList.add(new DatabaseNode(null, dbConnection));
testTool.setSelectedItems(nodeTypeList, sldDataList);
assertTrue(testTool.isEditButtonEnabled());
assertTrue(testTool.isDuplicateButtonEnabled());
assertTrue(testTool.isDeleteButtonEnabled());
assertFalse(testTool.isEditButtonEnabled());
assertFalse(testTool.isDuplicateButtonEnabled());
assertFalse(testTool.isDeleteButtonEnabled());

// Try a DatabaseNode -- does not support duplication
nodeTypeList.clear();
dbConnection = DatabaseConnectionFactory.createH2();
nodeTypeList.add(new DatabaseNode(null, dbConnection));
testTool.setSelectedItems(nodeTypeList, sldDataList);
assertTrue(testTool.isEditButtonEnabled());
assertFalse(testTool.isEditButtonEnabled());
assertFalse(testTool.isDuplicateButtonEnabled());
assertTrue(testTool.isDeleteButtonEnabled());
assertFalse(testTool.isDeleteButtonEnabled());

// Try multiple DatabaseNodes
nodeTypeList.clear();
Expand All @@ -216,7 +216,7 @@ void testSetSelectedItems() {
testTool.setSelectedItems(nodeTypeList, sldDataList);
assertFalse(testTool.isEditButtonEnabled());
assertFalse(testTool.isDuplicateButtonEnabled());
assertTrue(testTool.isDeleteButtonEnabled());
assertFalse(testTool.isDeleteButtonEnabled());
}

/**
Expand Down Expand Up @@ -274,23 +274,21 @@ void testButtons() {
testTool.setSelectedItems(nodeTypeList, sldDataList);

testTool.duplicateButtonPressed();
assertEquals(2, receiver.dbList.size());
assertEquals(1, receiver.dbList.size());

// Edit
nodeTypeList.clear();
assertEquals(1, receiver.dbList.size());
nodeTypeList.add(new DatabaseNode(null, receiver.dbList.get(0)));
nodeTypeList.add(new DatabaseNode(null, receiver.dbList.get(1)));
testTool.setSelectedItems(nodeTypeList, sldDataList);
testTool.editButtonPressed();
assertEquals(2, receiver.dbList.size());

// Delete
nodeTypeList.clear();
nodeTypeList.add(new DatabaseNode(null, receiver.dbList.get(0)));
nodeTypeList.add(new DatabaseNode(null, receiver.dbList.get(1)));
testTool.setSelectedItems(nodeTypeList, sldDataList);
testTool.deleteButtonPressed();
assertEquals(0, receiver.dbList.size());
assertEquals(1, receiver.dbList.size());
DBConnectorDetailsPanel.setInTestMode(false);
}
}
Expand Up @@ -31,6 +31,7 @@
import com.sldeditor.common.data.SelectedSymbol;
import com.sldeditor.datasource.RenderSymbolInterface;
import com.sldeditor.datasource.impl.GeometryTypeEnum;
import com.sldeditor.test.SLDTestRunner;
import com.sldeditor.ui.detail.EmptyPanel;
import com.sldeditor.ui.detail.FeatureTypeStyleDetails;
import com.sldeditor.ui.detail.LineSymbolizerDetails;
Expand All @@ -54,7 +55,7 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.io.InputStream;
import java.util.List;
import org.geotools.styling.StyledLayerDescriptor;
import org.junit.jupiter.api.Test;
Expand All @@ -80,9 +81,24 @@ public void testSLDTreeNull() {
// Select top level node
tree1.selectFirstSymbol();

URL url = SLDTreeTest.class.getResource("/polygon/sld/polygon_attributebasedpolygon.sld");
String testsldfile = "/polygon/sld/polygon_attributebasedpolygon.sld";
InputStream inputStream = SLDTreeTest.class.getResourceAsStream(testsldfile);
String sldContents = "";

String sldContents = readFile(new File(url.getFile()).getAbsolutePath());
if (inputStream == null) {
assertNotNull(inputStream, "Failed to find sld test file : " + testsldfile);
} else {
File f = null;
try {
f = SLDTestRunner.stream2file(inputStream);

sldContents = readFile(f.getAbsolutePath());

f.delete();
} catch (IOException e1) {
e1.printStackTrace();
}
}

SLDData sldData = new SLDData(null, sldContents);

Expand Down Expand Up @@ -121,9 +137,24 @@ public void testSLDTree() {
SLDTreeTools treeTools = new SLDTreeTools();
SLDTree tree1 = new SLDTree(renderList, treeTools);

URL url = SLDTreeTest.class.getResource("/test/polygon_line_point.sld");
String testsldfile = "/test/polygon_line_point.sld";
InputStream inputStream = SLDTreeTest.class.getResourceAsStream(testsldfile);
String sldContents = "";

String sldContents = readFile(new File(url.getFile()).getAbsolutePath());
if (inputStream == null) {
assertNotNull(inputStream, "Failed to find sld test file : " + testsldfile);
} else {
File f = null;
try {
f = SLDTestRunner.stream2file(inputStream);

sldContents = readFile(f.getAbsolutePath());

f.delete();
} catch (IOException e1) {
e1.printStackTrace();
}
}

SLDData sldData = new SLDData(null, sldContents);

Expand Down

0 comments on commit fb827e0

Please sign in to comment.