use of com.sldeditor.tool.dbconnectionlist.DatabaseConnectionName in project sldeditor by robward-scisys.
the class DatabaseConnectionTest method testDatabaseConnection.
/**
* Test method for
* {@link com.sldeditor.common.data.DatabaseConnection#DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)}.
*/
@Test
public void testDatabaseConnection() {
Param param = GeoPkgDataStoreFactory.DBTYPE;
List<DatabaseConnectionField> expectedDetailList = new ArrayList<DatabaseConnectionField>();
expectedDetailList.add(new DatabaseConnectionField(GeoPkgDataStoreFactory.DATABASE));
expectedDetailList.add(new DatabaseConnectionField(GeoPkgDataStoreFactory.USER));
String expectedDatabaseTypeLabel = "GeoPackage";
boolean expectedSupportsDuplication = false;
DatabaseConnection test = new DatabaseConnection(param, expectedDatabaseTypeLabel, expectedSupportsDuplication, expectedDetailList, new DatabaseConnectionName() {
@Override
public String getConnectionName(String duplicatePrefix, int noOfDuplicates, Map<String, String> properties) {
String connectionName = Localisation.getString(DatabaseConnectionTest.class, "common.notSet");
String databaseName = properties.get(GeoPkgDataStoreFactory.DATABASE.key);
if (databaseName != null) {
File f = new File(databaseName);
if (f.isFile()) {
connectionName = f.getName();
}
}
for (int i = 0; i < noOfDuplicates; i++) {
connectionName = duplicatePrefix + connectionName;
}
return connectionName;
}
});
Map<String, String> connectionDataMap = new HashMap<String, String>();
connectionDataMap.put(GeoPkgDataStoreFactory.DATABASE.key, "test datatbase");
test.setConnectionDataMap(connectionDataMap);
assertEquals(test.isSupportsDuplication(), expectedSupportsDuplication);
assertNotNull(test.getConnectionName());
assertNotNull(test.getDatabaseConnectionName());
assertEquals(test.getDetailList(), expectedDetailList);
assertEquals(test.getDatabaseTypeLabel(), expectedDatabaseTypeLabel);
assertTrue(test.hashCode() != 0);
assertEquals(1, test.getExpectedKeys().size());
assertEquals(GeoPkgDataStoreFactory.DATABASE.key, test.getExpectedKeys().get(0));
assertEquals(test.getDatabaseType(), param.sample);
assertEquals(test.getConnectionDataMap().get(GeoPkgDataStoreFactory.DATABASE.key), connectionDataMap.get(GeoPkgDataStoreFactory.DATABASE.key));
assertEquals(test.getConnectionDataMap().get(GeoPkgDataStoreFactory.DBTYPE.key), GeoPkgDataStoreFactory.DBTYPE.sample);
String expectedUserName = "test user";
test.setUserName(expectedUserName);
assertEquals(test.getUserName(), expectedUserName);
assertNotNull(test.getDBConnectionParams());
String expectedPassword = "password123";
test.setPassword(expectedPassword);
assertEquals(test.getPassword(), expectedPassword);
// Duplicate
DatabaseConnection testCopy = test.duplicate();
assertTrue(testCopy.compareTo(test) < 0);
testCopy.update(test);
assertEquals(testCopy, test);
assertEquals(testCopy, testCopy);
testCopy.setUserName("new username");
assertFalse(testCopy.equals(test));
testCopy.update(test);
assertTrue(testCopy.equals(test));
String actualString = test.encodeAsString();
DatabaseConnection newTest = DatabaseConnection.decodeString(actualString);
assertTrue(newTest.equals(test));
}
Aggregations