Skip to content

Commit eb577ec

Browse files
committed
test: add tests for API-Version response header
1 parent 632711d commit eb577ec

5 files changed

Lines changed: 185 additions & 0 deletions

File tree

deegree-ogcapi-features/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<artifactId>joda-time</artifactId>
285285
<scope>test</scope>
286286
</dependency>
287+
<dependency>
288+
<groupId>com.github.stefanbirkner</groupId>
289+
<artifactId>system-rules</artifactId>
290+
<scope>test</scope>
291+
</dependency>
287292
</dependencies>
288293

289294
</project>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*-
2+
* #%L
3+
* deegree-ogcapi-features - OGC API Features (OAF) implementation - Querying and modifying of geospatial data objects
4+
* %%
5+
* Copyright (C) 2019 - 2020 lat/lon GmbH, info@lat-lon.de, www.lat-lon.de
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package org.deegree.services.oaf.filter;
23+
24+
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
25+
import static javax.ws.rs.core.MediaType.APPLICATION_XML_TYPE;
26+
import static org.deegree.services.oaf.TestData.mockDataAccess;
27+
import static org.deegree.services.oaf.TestData.mockWorkspaceInitializer;
28+
import static org.hamcrest.CoreMatchers.is;
29+
import static org.hamcrest.CoreMatchers.nullValue;
30+
import static org.hamcrest.MatcherAssert.assertThat;
31+
32+
import javax.ws.rs.core.Application;
33+
import javax.ws.rs.core.Response;
34+
35+
import org.deegree.commons.utils.TunableParameter;
36+
import org.deegree.services.oaf.openapi.OpenApiCreator;
37+
import org.deegree.services.oaf.resource.FeatureCollection;
38+
import org.deegree.services.oaf.workspace.DataAccess;
39+
import org.deegree.services.oaf.workspace.DeegreeWorkspaceInitializer;
40+
import org.glassfish.hk2.utilities.binding.AbstractBinder;
41+
import org.glassfish.jersey.server.ResourceConfig;
42+
import org.glassfish.jersey.test.JerseyTest;
43+
import org.glassfish.jersey.test.TestProperties;
44+
import org.junit.Test;
45+
46+
/**
47+
* Base class for testing if API version response header is present.
48+
*/
49+
public abstract class AbstractApiVersionResponseFilterTest extends JerseyTest {
50+
51+
private final boolean headerExpected;
52+
53+
public AbstractApiVersionResponseFilterTest(boolean headerExpected) {
54+
super();
55+
this.headerExpected = headerExpected;
56+
}
57+
58+
@Override
59+
protected Application configure() {
60+
TunableParameter.resetCache();
61+
62+
enable( TestProperties.LOG_TRAFFIC );
63+
ResourceConfig resourceConfig = new ResourceConfig( FeatureCollection.class );
64+
resourceConfig.register(ApiVersionResponseFilter.class);
65+
resourceConfig.register( new AbstractBinder() {
66+
@Override
67+
protected void configure() {
68+
bind( mockDataAccess() ).to( DataAccess.class );
69+
bind( mockWorkspaceInitializer() ).to( DeegreeWorkspaceInitializer.class );
70+
}
71+
} );
72+
return resourceConfig;
73+
}
74+
75+
private void verifyResponse(Response response) {
76+
if (headerExpected) {
77+
assertThat( response.getHeaderString(ApiVersionResponseFilter.HEADER_API_VERSION), is( OpenApiCreator.VERSION ) );
78+
}
79+
else {
80+
assertThat( response.getHeaderString(ApiVersionResponseFilter.HEADER_API_VERSION), is( nullValue() ) );
81+
}
82+
}
83+
84+
@Test
85+
public void test_Collection() {
86+
Response response = target( "/datasets/oaf/collections/test" ).request( APPLICATION_JSON_TYPE ).get();
87+
verifyResponse(response);
88+
}
89+
90+
@Test
91+
public void test_CollectionXml() {
92+
Response response = target( "/datasets/oaf/collections" ).request( APPLICATION_XML_TYPE ).get();
93+
verifyResponse(response);
94+
}
95+
96+
@Test
97+
public void test_Collections() {
98+
Response response = target( "/datasets/oaf/collections" ).request( APPLICATION_JSON_TYPE ).get();
99+
verifyResponse(response);
100+
}
101+
102+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*-
2+
* #%L
3+
* deegree-ogcapi-features - OGC API Features (OAF) implementation - Querying and modifying of geospatial data objects
4+
* %%
5+
* Copyright (C) 2019 - 2020 lat/lon GmbH, info@lat-lon.de, www.lat-lon.de
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package org.deegree.services.oaf.filter;
23+
24+
/**
25+
* Test if API version response header is not present when disabled (default).
26+
*/
27+
public class ApiVersionResponseFilterDisabledTest extends AbstractApiVersionResponseFilterTest {
28+
29+
public ApiVersionResponseFilterDisabledTest() {
30+
super(false);
31+
}
32+
33+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*-
2+
* #%L
3+
* deegree-ogcapi-features - OGC API Features (OAF) implementation - Querying and modifying of geospatial data objects
4+
* %%
5+
* Copyright (C) 2019 - 2020 lat/lon GmbH, info@lat-lon.de, www.lat-lon.de
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package org.deegree.services.oaf.filter;
23+
24+
import org.junit.Rule;
25+
import org.junit.contrib.java.lang.system.ProvideSystemProperty;
26+
27+
/**
28+
* Test if API version response header is present when enabled.
29+
*/
30+
public class ApiVersionResponseFilterEnabledTest extends AbstractApiVersionResponseFilterTest {
31+
32+
@Rule
33+
public final ProvideSystemProperty providesSystemPropertyRule = new ProvideSystemProperty(ApiVersionResponseFilter.PARAMETER_ENABLE_VERSION_HEADER, "true");
34+
35+
public ApiVersionResponseFilterEnabledTest() {
36+
super(true);
37+
}
38+
39+
}

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,12 @@
844844
<version>${jersey-version}</version>
845845
<scope>test</scope>
846846
</dependency>
847+
<dependency>
848+
<groupId>com.github.stefanbirkner</groupId>
849+
<artifactId>system-rules</artifactId>
850+
<version>1.19.0</version>
851+
<scope>test</scope>
852+
</dependency>
847853
<dependency>
848854
<groupId>io.swagger.parser.v3</groupId>
849855
<artifactId>swagger-parser-v3</artifactId>

0 commit comments

Comments
 (0)