|
| 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 | +} |
0 commit comments