Commit 46eacae1 authored by Kevin Smith's avatar Kevin Smith
Browse files

GEOS-7116, Add unit tests for ImportTaskTable

parent c0ab37cf
......@@ -36,6 +36,18 @@
<artifactId>prettytime</artifactId>
<version>1.0.8.Final</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geoserver.web</groupId>
<artifactId>gs-web-core</artifactId>
<scope>test</scope>
<classifier>tests</classifier>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
/* (c) 2014-2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.importer.web;
import java.io.File;
import java.io.InputStream;
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.util.tester.TestPanelSource;
import org.geoserver.data.util.IOUtils;
import org.geoserver.importer.Archive;
import org.geoserver.importer.ImportContext;
import org.geoserver.importer.ImportData;
import org.geoserver.importer.ImportTask;
import org.geoserver.web.GeoServerWicketTestSupport;
import org.geoserver.web.wicket.GeoServerDataProvider;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
/**
*
* @author Kevin Smith, Boundless
*/
public class ImportTaskTableTest extends GeoServerWicketTestSupport {
private ImportData data;
private ImportContext context;
private GeoServerDataProvider<ImportTask> provider;
private FeedbackPanel feedback;
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Before
public void setUp() throws Exception {
// Create a test file.
File file = temp.newFile("twoShapefilesNoPrj.zip");
try (InputStream rin = ImportTaskTableTest.class.getResourceAsStream("twoShapefilesNoPrj.zip");){
IOUtils.copy(rin, file);
}
feedback = new FeedbackPanel("feedback");
feedback.setOutputMarkupId(true);
data = new Archive(file);
context = ImporterWebUtils.importer().createContext(data);
provider = new ImportTaskProvider(context);
tester.startPanel(new TestPanelSource(){
/** serialVersionUID */
private static final long serialVersionUID = 1L;
@Override
public Panel getTestPanel(String panelId) {
ImportTaskTable table = new ImportTaskTable(panelId, provider, true);
table.setFeedbackPanel(feedback);
table.setOutputMarkupId(true);
return table;
}
});
}
@Test
public void testTwoCRSSetByFindThenApply() {
tester.assertComponent("panel", ImportTaskTable.class);
// Click the Find CRS button for the first layer to import
tester.clickLink("panel:listContainer:items:1:itemProperties:2:component:form:crs:find", true);
// Select the first CRS
tester.clickLink("panel:listContainer:items:1:itemProperties:2:component:form:crs:popup:content:table:listContainer:items:1:itemProperties:0:component:link", true);
// Click the Find CRS button for the second layer to import
tester.clickLink("panel:listContainer:items:2:itemProperties:2:component:form:crs:find", true);
// Select the first CRS
tester.clickLink("panel:listContainer:items:2:itemProperties:2:component:form:crs:popup:content:table:listContainer:items:2:itemProperties:0:component:link", true);
// The EPSG codes should be set
tester.assertModelValue("panel:listContainer:items:1:itemProperties:2:component:form:crs:srs", "EPSG:2000");
tester.assertModelValue("panel:listContainer:items:2:itemProperties:2:component:form:crs:srs", "EPSG:2001");
// Check that the WKT links set
tester.assertModelValue("panel:listContainer:items:1:itemProperties:2:component:form:crs:wkt:wktLabel", "EPSG:Anguilla 1957 / British West Indies Grid");
tester.assertModelValue("panel:listContainer:items:2:itemProperties:2:component:form:crs:wkt:wktLabel", "EPSG:Antigua 1943 / British West Indies Grid");
// Apply the first
tester.clickLink("panel:listContainer:items:1:itemProperties:2:component:form:apply", true);
// The first entry should be replaced with an "Advanced" link, the numbering continues from those used before so the second item is 3
tester.assertComponent("panel:listContainer:items:3:itemProperties:2:component", ImportTaskTable.AdvancedOptionPanel.class);
// The second (4) should still be set
tester.assertModelValue("panel:listContainer:items:4:itemProperties:2:component:form:crs:srs", "EPSG:2001");
}
void fill(String formPath, String fieldPath, String value) {
FormTester form = tester.newFormTester(formPath);
form.setValue(fieldPath, value);
tester.executeAjaxEvent(String.format("%s:%s", formPath, fieldPath), "onblur");
}
@Test
public void testTwoCRSSetManuallyThenApply() {
tester.assertComponent("panel", ImportTaskTable.class);
// "Type" in the EPSG codes
fill("panel:listContainer:items:1:itemProperties:2:component:form", "crs:srs", "EPSG:3857");
fill("panel:listContainer:items:2:itemProperties:2:component:form", "crs:srs", "EPSG:4326");
// Check that the WKT links set
tester.assertModelValue("panel:listContainer:items:1:itemProperties:2:component:form:crs:wkt:wktLabel", "EPSG:WGS 84 / Pseudo-Mercator");
tester.assertModelValue("panel:listContainer:items:2:itemProperties:2:component:form:crs:wkt:wktLabel", "EPSG:WGS 84");
// Apply the first
tester.clickLink("panel:listContainer:items:1:itemProperties:2:component:form:apply", true);
// The first entry should be replaced with an "Advanced" link, the numbering continues from those used before so the second item is 3
tester.assertComponent("panel:listContainer:items:3:itemProperties:2:component", ImportTaskTable.AdvancedOptionPanel.class);
// The second (4) should still be set
tester.assertModelValue("panel:listContainer:items:4:itemProperties:2:component:form:crs:srs", "EPSG:4326");
}
}
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