use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class VectorToolTest method testVectorToolDBDataSource.
@Test
public void testVectorToolDBDataSource() {
TestMissingSLDAttributes testAttribute = new TestMissingSLDAttributes();
List<CheckAttributeInterface> checkList = new ArrayList<CheckAttributeInterface>();
checkList.add(testAttribute);
CheckAttributeFactory.setOverideCheckList(checkList);
String testsldfile = "/polygon/sld/polygon_polygonwithdefaultlabel.sld";
TestSLDEditor testSLDEditor = null;
try {
testSLDEditor = TestSLDEditor.createAndShowGUI2(null, null, true, null);
} catch (Exception e) {
e.printStackTrace();
}
RenderPanelImpl.setUnderTest(true);
InputStream inputStream = VectorToolTest.class.getResourceAsStream(testsldfile);
if (inputStream == null) {
Assert.assertNotNull("Failed to find sld test file : " + testsldfile, inputStream);
} else {
File f = null;
try {
f = stream2file(inputStream);
try {
testSLDEditor.openFile(f.toURI().toURL());
} catch (NullPointerException nullException) {
nullException.printStackTrace();
StackTraceElement[] stackTraceElements = nullException.getStackTrace();
System.out.println(stackTraceElements[0].getMethodName());
}
f.delete();
} catch (IOException e1) {
e1.printStackTrace();
}
}
// Fields extracted from the SLD file
DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
Collection<PropertyDescriptor> propertyList = dataSource.getPropertyDescriptorList();
assertEquals(2, propertyList.size());
Map<String, PropertyDescriptor> map = new HashMap<String, PropertyDescriptor>();
for (PropertyDescriptor property : propertyList) {
map.put(property.getName().getLocalPart(), property);
}
AttributeDescriptor name = (AttributeDescriptor) map.get("name");
assertNotNull(name);
GeometryDescriptor geometry = (GeometryDescriptor) map.get("geom");
assertNotNull(geometry);
File tempFolder = Files.createTempDir();
TestVectorTool vectorTool = new TestVectorTool(testSLDEditor);
try {
InputStream gpkgInputStream = VectorToolTest.class.getResourceAsStream("/test/sld_cookbook_polygon.gpkg");
final File gpkgFile = new File(tempFolder, "sld_cookbook_polygon.gpkg");
try (FileOutputStream out = new FileOutputStream(gpkgFile)) {
IOUtils.copy(gpkgInputStream, out);
}
DatabaseConnection databaseConnection = DatabaseConnectionFactory.getConnection(gpkgFile.getAbsolutePath());
DatabaseFeatureClassNode dbFCTreeNode = new DatabaseFeatureClassNode(null, databaseConnection, "sld_cookbook_polygon");
DatabaseConnectionManager.getInstance().addNewConnection(null, databaseConnection);
vectorTool.testSetDataSource(dbFCTreeNode);
dataSource = DataSourceFactory.createDataSource(null);
propertyList = dataSource.getPropertyDescriptorList();
assertEquals(3, propertyList.size());
map.clear();
for (PropertyDescriptor property : propertyList) {
map.put(property.getName().getLocalPart(), property);
}
name = (AttributeDescriptor) map.get("name");
assertNotNull(name);
geometry = (GeometryDescriptor) map.get("geometry");
assertNotNull(geometry);
AttributeDescriptor pop = (AttributeDescriptor) map.get("pop");
assertNotNull(pop);
// Create SLD from geopackage layer
vectorTool.testImportFeatureClass(dbFCTreeNode);
dataSource = DataSourceFactory.createDataSource(null);
propertyList = dataSource.getPropertyDescriptorList();
assertEquals(3, propertyList.size());
map.clear();
for (PropertyDescriptor property : propertyList) {
map.put(property.getName().getLocalPart(), property);
}
name = (AttributeDescriptor) map.get("name");
assertNotNull(name);
geometry = (GeometryDescriptor) map.get("geometry");
assertNotNull(geometry);
pop = (AttributeDescriptor) map.get("pop");
assertNotNull(pop);
// Release locks
dataSource.reset();
} catch (IOException e) {
e.printStackTrace();
fail();
}
// Tidy up so the remaining unit tests are ok
JFrame frame = testSLDEditor.getApplicationFrame();
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
testSLDEditor = null;
clearDown();
// Delete the shape files we extracted
purgeDirectory(tempFolder);
}
use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class DatabaseConnectionToolTest method testDatabaseConnectionTool.
/**
* Test method for
* {@link com.sldeditor.tool.databaseconnection.DatabaseConnectionTool#DatabaseConnectionTool(com.sldeditor.tool.databaseconnection.DatabaseConnectStateInterface)}.
*/
@Test
public void testDatabaseConnectionTool() {
TestDatabaseConnectState state = new TestDatabaseConnectState();
TestDatabaseConnectionTool testObj = new TestDatabaseConnectionTool(state);
testObj.setSelectedItems(null, null);
List<NodeInterface> nodeTypeList = new ArrayList<NodeInterface>();
DatabaseConnection connection = DatabaseConnectionFactory.createGeoPackage();
nodeTypeList.add(new DatabaseNode(new DatabaseInput(ToolManager.getInstance()), connection));
File parent = new File("");
String filename = "test.gpkg";
FileTreeNode fileTreeNode = null;
try {
fileTreeNode = new FileTreeNode(parent, filename);
fileTreeNode.setFileCategory(FileTreeNodeTypeEnum.DATABASE);
nodeTypeList.add(fileTreeNode);
} catch (SecurityException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
testObj.setSelectedItems(nodeTypeList, null);
testObj.populateComplete(null);
assertNotNull(testObj.getPanel());
List<Class<?>> uniqueNodeTypeList = new ArrayList<Class<?>>();
List<SLDDataInterface> sldDataList = null;
assertFalse(testObj.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
uniqueNodeTypeList.add(String.class);
assertTrue(testObj.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
nodeTypeList.remove(0);
assertTrue(testObj.supports(uniqueNodeTypeList, nodeTypeList, sldDataList));
testObj.testConnect();
testObj.testDisconnect();
}
use of com.sldeditor.common.data.DatabaseConnection in project sldeditor by robward-scisys.
the class DatabaseConnectionFactoryTest method testGetNames.
@Test
public void testGetNames() {
List<String> nameList = DatabaseConnectionFactory.getNames();
assertFalse(nameList.isEmpty());
List<String> externalDrivers = new ArrayList<String>();
externalDrivers.add("Microsoft SQL Server (JNDI)");
externalDrivers.add("DB2 NG (JNDI)");
for (String name : nameList) {
if (!externalDrivers.contains(name)) {
System.out.println(name);
DatabaseConnection databaseConnection = DatabaseConnectionFactory.getNewConnection(name);
assertNotNull(databaseConnection);
databaseConnection.setConnectionDataMap(new HashMap<String, String>());
System.out.println(databaseConnection.getConnectionName());
DatabaseConnection databaseConnection2 = DatabaseConnectionFactory.getNewConnection(databaseConnection);
assertNotNull(databaseConnection2);
}
}
DatabaseConnection databaseConnection3 = DatabaseConnectionFactory.getConnection("test.gpkg");
assertNotNull(databaseConnection3);
}
Aggregations