Skip to content

Commit

Permalink
[GEOS-11494] WFS GetFeature request with a propertyname parameter fai…
Browse files Browse the repository at this point in the history
…ls when layer attributes are customized (geoserver#7971)

[GEOS-11494]actaully test the csv file header

Co-authored-by: Nikiforos Archakis <nikiforos.archakis@utopiamusic.com>
  • Loading branch information
Arxa and Nikiforos Archakis authored Dec 16, 2024
1 parent 9e3e886 commit 1d03a3b
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.geoserver.data.test.CiteTestData.ROAD_SEGMENTS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import au.com.bytecode.opencsv.CSVReader;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringReader;
Expand All @@ -27,6 +29,7 @@
import java.util.Locale;
import net.opengis.wfs.GetFeatureType;
import net.opengis.wfs.WfsFactory;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.NamespaceInfo;
import org.geoserver.catalog.impl.NamespaceInfoImpl;
import org.geoserver.config.GeoServer;
Expand Down Expand Up @@ -68,6 +71,31 @@
public class CSVOutputFormatTest extends WFSTestSupport {
private static final String CSV = "text/csv";

@Test
public void testWithAttributesRemoved() throws Exception {
String layerId = getLayerId(ROAD_SEGMENTS);
FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(layerId);
fti.getAttributes().addAll(fti.attributes());
fti.getAttributes().remove(1);
getCatalog().save(fti);

GeoServer gs = getGeoServer();
WFSInfo wfs = gs.getService(WFSInfo.class);
wfs.setFeatureBounding(false);
gs.save(wfs);

MockHttpServletResponse response =
getAsServletResponse(
"ows?service=WFS&version=1.0.0&request=GetFeature&typeName=cite:RoadSegments&maxFeatures=50&outputFormat=text%2Fcsv&propertyname=NAME");
assertEquals(
"attachment; filename=RoadSegments.csv", response.getHeader("Content-Disposition"));

assertEquals(CSV, getBaseMimeType(response.getContentType()));
BufferedReader content =
new BufferedReader(new StringReader(new String(response.getContentAsByteArray())));
assertEquals("FID,NAME", content.readLine().strip().replace(" ", ""));
}

@Test
public void testFullRequest() throws Exception {
MockHttpServletResponse resp =
Expand Down

0 comments on commit 1d03a3b

Please sign in to comment.