diff --git a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java index e3f01ba..9de1981 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java +++ b/src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java @@ -71,6 +71,22 @@ public class RESTResource { public String getAbstract() { return rootElem.getChildText("abstract"); } + + public List getKeywords(){ + List kwdsList = null; + + final Element keywordsRoot = rootElem.getChild("keywords"); + if(keywordsRoot != null){ + final List keywords = keywordsRoot.getChildren(); + if(keywords != null){ + kwdsList = new ArrayList(keywords.size()); + for(Element keyword : keywords){ + kwdsList.add(keyword.getValue()); + } + } + } + return kwdsList; + } public String getNameSpace() { return rootElem.getChild("namespace").getChildText("name"); diff --git a/src/test/java/it/geosolutions/geoserver/decoder/MetadataDecoderTest.java b/src/test/java/it/geosolutions/geoserver/decoder/MetadataDecoderTest.java index f608866..bf40d27 100644 --- a/src/test/java/it/geosolutions/geoserver/decoder/MetadataDecoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/decoder/MetadataDecoderTest.java @@ -69,23 +69,4 @@ public class MetadataDecoderTest { } } - @Test - public void testMetadataLinkInfo() throws IOException{ - File coverageFile = new ClassPathResource("testdata/coverageExample.xml").getFile(); - String coverageString = FileUtils.readFileToString(coverageFile); - RESTCoverage coverage = RESTCoverage.build(coverageString); - - List list = coverage.getEncodedMetadataLinkInfoList(); - - GSMetadataLinkInfoEncoder metadataLinkInfo1 = list.get(0); - Assert.assertEquals("text/xml", metadataLinkInfo1.getType()); - Assert.assertEquals("ISO19115:2003", metadataLinkInfo1.getMetadataType()); - Assert.assertEquals("http://www.organization.org/metadata1", metadataLinkInfo1.getContent()); - - GSMetadataLinkInfoEncoder metadataLinkInfo2 = list.get(1); - Assert.assertEquals("text/html",metadataLinkInfo2.getType()); - Assert.assertEquals("ISO19115:2003",metadataLinkInfo2.getMetadataType()); - Assert.assertEquals("http://www.organization.org/metadata2",metadataLinkInfo2.getContent()); - - } } diff --git a/src/test/java/it/geosolutions/geoserver/decoder/ResourceDecoderTest.java b/src/test/java/it/geosolutions/geoserver/decoder/ResourceDecoderTest.java new file mode 100644 index 0000000..bc20bc0 --- /dev/null +++ b/src/test/java/it/geosolutions/geoserver/decoder/ResourceDecoderTest.java @@ -0,0 +1,120 @@ +package it.geosolutions.geoserver.decoder; + +import it.geosolutions.geoserver.rest.decoder.RESTCoverage; +import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.core.io.ClassPathResource; + +/** +* ResourceDecoderTest +* +* @author eblondel +* +*/ +public class ResourceDecoderTest { + + + RESTCoverage coverage; + + @Before + public void setup() throws IOException { + File coverageFile = new ClassPathResource( + "testdata/coverageExample.xml").getFile(); + String coverageString = FileUtils.readFileToString(coverageFile); + coverage = RESTCoverage.build(coverageString); + } + + @Test + public void testName() { + Assert.assertEquals(coverage.getName(), "granuleTestMosaic"); + } + + @Test + public void testNativeName() { + Assert.assertEquals(coverage.getNativeName(), "granuleTestMosaic"); + } + + @Test + public void testTitle() { + Assert.assertEquals(coverage.getNativeName(), "granuleTestMosaic"); + } + + @Test + public void testAbstract() { + Assert.assertEquals(coverage.getAbstract(), "this is an abstract"); + } + + @Test + public void testKeywords() { + List keywords = coverage.getKeywords(); + Assert.assertEquals(keywords.get(0), "keyword1"); + Assert.assertEquals(keywords.get(1), "keyword2"); + Assert.assertEquals(keywords.get(2), "keyword3"); + } + + @Test + public void testNameSpace() { + Assert.assertEquals(coverage.getNameSpace(), "topp"); + } + + @Test + public void testStoreName() { + Assert.assertEquals(coverage.getStoreName(), "granuleTestMosaic"); + } + + @Test + public void testStoreType() { + Assert.assertEquals(coverage.getStoreType(), "coverageStore"); + } + + @Test + public void testStoreUrl() { + Assert.assertEquals( + coverage.getStoreUrl(), + "http://localhost:8080/geoserver/rest/workspaces/topp/coveragestores/granuleTestMosaic.xml"); + } + + @Test + public void testCRS() { + Assert.assertEquals(coverage.getCRS(), "EPSG:4326"); + } + + @Test + public void testBoundingBox() { + Assert.assertEquals(coverage.getMinX(), -180.0, 0); + Assert.assertEquals(coverage.getMaxX(), 180.0, 0); + Assert.assertEquals(coverage.getMinY(), -90, 0); + Assert.assertEquals(coverage.getMaxY(), 90, 0); + } + + @Test + public void testMetadataLinkInfo() throws IOException { + + List list = coverage + .getEncodedMetadataLinkInfoList(); + + GSMetadataLinkInfoEncoder metadataLinkInfo1 = list.get(0); + Assert.assertEquals("text/xml", metadataLinkInfo1.getType()); + Assert.assertEquals("ISO19115:2003", + metadataLinkInfo1.getMetadataType()); + Assert.assertEquals("http://www.organization.org/metadata1", + metadataLinkInfo1.getContent()); + + GSMetadataLinkInfoEncoder metadataLinkInfo2 = list.get(1); + Assert.assertEquals("text/html", metadataLinkInfo2.getType()); + Assert.assertEquals("ISO19115:2003", + metadataLinkInfo2.getMetadataType()); + Assert.assertEquals("http://www.organization.org/metadata2", + metadataLinkInfo2.getContent()); + + } + +} \ No newline at end of file diff --git a/src/test/resources/testdata/coverageExample.xml b/src/test/resources/testdata/coverageExample.xml index 4230091..8603547 100644 --- a/src/test/resources/testdata/coverageExample.xml +++ b/src/test/resources/testdata/coverageExample.xml @@ -2,11 +2,17 @@ granuleTestMosaic granuleTestMosaic + this is an abstract topp granuleTestMosaic + + keyword1 + keyword2 + keyword3 + text/xml