Commit aed7b6a4 authored by Andrea Aime's avatar Andrea Aime
Browse files

[GEOS-9140] Import Data unable to connect to and create PostGIS DataStore

parent 2cfcc0c4
......@@ -84,52 +84,11 @@ public abstract class AbstractDbPanel extends ImportSourcePanel {
}
public ImportData createImportSource() {
// try {
// build up the store connection param map
Map<String, Serializable> params = new HashMap<String, Serializable>();
Map<String, Serializable> params = new HashMap<>();
fillStoreParams(params);
return new Database(params);
// // ok, check we can connect
// DataAccess store = null;
// try {
// store = DataAccessFinder.getDataStore(params);
// // force the store to open a connection
// store.getNames();
// store.dispose();
// } catch (Throwable e) {
// LOGGER.log(Level.INFO, "Could not connect to the datastore", e);
// error(new ParamResourceModel("ImporterError.databaseConnectionError",
// AbstractDBMSPage.this, e.getMessage()).getString());
// return;
// } finally {
// if (store != null)
// store.dispose();
// }
//
// // build the store
// CatalogBuilder builder = new CatalogBuilder(getCatalog());
// builder.setWorkspace(workspace);
// StoreInfo si = builder.buildDataStore(generalParams.name);
// si.setDescription(generalParams.description);
// si.getConnectionParameters().putAll(params);
// si.setEnabled(true);
// si.setType(factory.getDisplayName());
// getCatalog().add(si);
//
// // redirect to the layer chooser
// PageParameters pp = new PageParameters();
// pp.put("store", si.getName());
// pp.put("workspace", workspace.getName());
// pp.put("storeNew", true);
// pp.put("workspaceNew", false);
// pp.put("skipGeometryless", isGeometrylessExcluded());
// setResponsePage(VectorLayerChooserPage.class, pp);
// } catch (Exception e) {
// LOGGER.log(Level.SEVERE, "Error while setting up mass import", e);
// }
// return new DataStoreSource()
}
/** Switches between the types of param panels */
......
/* (c) 2019 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.importer.web;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasEntry;
import java.io.Serializable;
import java.util.Map;
import org.apache.wicket.util.tester.FormTester;
import org.geoserver.importer.Database;
import org.geoserver.web.ComponentBuilder;
import org.geoserver.web.FormTestPage;
import org.geoserver.web.GeoServerWicketUnitTestSupport;
import org.junit.Test;
public class AbstractDBPanelTest extends GeoServerWicketUnitTestSupport {
@Test
public void testSubmitParameters() {
FormTestPage testPage = new FormTestPage((ComponentBuilder) id -> new PostGISPanel(id));
tester.startPage(testPage);
// set the username
FormTester formTester = this.tester.newFormTester(FormTestPage.FORM);
formTester.setValue("panel:form:paramPanelContainer:paramPanels:01:username", "testUser");
formTester.submit();
PostGISPanel postgisPanel = (PostGISPanel) testPage.get("form:panel");
Database database = (Database) postgisPanel.createImportSource();
Map<String, Serializable> parameters = database.getParameters();
assertThat(parameters, hasEntry("user", "testUser"));
}
}
/* (c) 2019 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.web;
import java.util.List;
import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.resource.loader.ClassStringResourceLoader;
import org.apache.wicket.resource.loader.IStringResourceLoader;
import org.apache.wicket.settings.ResourceSettings;
import org.apache.wicket.util.tester.WicketTester;
import org.geoserver.test.GeoServerBaseTestSupport;
import org.geoserver.web.wicket.WicketHierarchyPrinter;
import org.junit.Before;
/**
* Base class for testing GeoServer Wicket components in isolation (not full Spring context init, no
* data dir). Useful for quick testing of components that do not interact with other GeoServer core
* components.
*/
public class GeoServerWicketUnitTestSupport {
protected WicketTester tester;
@Before
public void setUp() {
tester = new WicketTester(new TestWebApplication(), true);
}
/**
* Prints the specified component/page containment hierarchy to the standard output
*
* <p>Each line in the dump looks like: <componentId>(class) 'value'
*
* @param c the component to be printed
* @param dumpClass if enabled, the component classes are printed as well
* @param dumpValue if enabled, the component values are printed as well
*/
public void print(Component c, boolean dumpClass, boolean dumpValue) {
if (GeoServerBaseTestSupport.isQuietTests()) {
return;
}
WicketHierarchyPrinter.print(c, dumpClass, dumpValue);
}
/**
* A {@link WebApplication} with just enough initialization to test components meant to run in
* GeoServer, but not really depending on a application context
*/
protected static class TestWebApplication extends WebApplication {
@Override
public Class<? extends Page> getHomePage() {
return null;
}
@Override
protected void init() {
super.init();
// this setup allows the GeoServer i18n to work in unit tests
ResourceSettings resourceSettings = getResourceSettings();
resourceSettings.setUseMinifiedResources(false);
resourceSettings.setResourceStreamLocator(new GeoServerResourceStreamLocator());
List<IStringResourceLoader> stringResourceLoaders =
resourceSettings.getStringResourceLoaders();
stringResourceLoaders.add(0, new GeoServerStringResourceLoader());
stringResourceLoaders.add(0, new ClassStringResourceLoader(GeoServerApplication.class));
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment