TsWCSClient.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/unittest/ogc-wcs/TsWCSClient.cpp
22 
23  \brief A test suit for the WS OGC WCSClient.
24 
25  \author Emerson Moraes
26  */
27 
28 // TerraLib
34 #include "MockCurlWrapper.h"
35 
36 // Boost
37 #include <boost/test/unit_test.hpp>
38 
39 // LibCurl
40 #include <curl/curl.h>
41 
42 #include <memory>
43 #include <utility>
44 
45 
46 BOOST_AUTO_TEST_CASE(getcapabilities_test)
47 {
49 
50  // Directory where test WCS test data is stored.
51  std::string dataDir = TERRALIB_DATA_DIR;
52 
53  // WCS server URL.
54  std::string url = "http://demo.geo-solutions.it/geoserver/ows";
55 
56  // Version that will be used on WCS Requests.
57  std::string version = "2.0.1";
58 
59  te::ws::ogc::WCSClient client (dataDir, url, version);
60 
61  // Makes GetCapabilities Test Request.
62  BOOST_CHECK_NO_THROW(client.updateCapabilities());
63 
65 
66  std::vector<std::string> coverages = capabilities.coverages;
67 
68  BOOST_CHECK(coverages.size() > 0);
69 
70  return;
71 }
72 
73 BOOST_AUTO_TEST_CASE(getcapabilities_exception_test)
74 {
75 
77 
78  // Directory where test WCS test data is stored.
79  std::string dataDir = TERRALIB_DATA_DIR;
80 
81  // A wrong WCS server URL.
82  std::string url = "http://wrongaddress.org/geoserver/ows";
83 
84  // Version that will be used on WCS Requests.
85  std::string version = "2.0.1";
86 
87  te::ws::ogc::WCSClient client (dataDir, url, version);
88 
89  // Makes GetCapabilities Request.
90  BOOST_CHECK_THROW(client.updateCapabilities(), te::ws::core::Exception);
91 
92  return;
93 }
94 
95 BOOST_AUTO_TEST_CASE(not_supported_version_test)
96 {
98 
99  // Directory where test WCS test data is stored.
100  std::string dataDir = TERRALIB_DATA_DIR;
101 
102  // WCS server URL.
103  std::string url = "http://demo.geo-solutions.it/geoserver/ows";
104 
105  // Version not supported yet.
106  std::string version = "1.0.0";
107 
108  te::ws::ogc::WCSClient client (dataDir, url, version);
109 
110  BOOST_CHECK_THROW(client.updateCapabilities(), te::common::Exception);
111 
112  // Version not supported yet.
113  version = "1.1.0";
114 
115  client = te::ws::ogc::WCSClient (dataDir, url, version);
116 
117  BOOST_CHECK_THROW(client.updateCapabilities(), te::common::Exception);
118 
119  return;
120 }
121 
122 BOOST_AUTO_TEST_CASE(describecoverage_test)
123 {
125 
126  // Directory where test WCS test data is stored.
127  std::string dataDir = TERRALIB_DATA_DIR;
128 
129  // WCS server URL.
130  std::string url = "http://demo.geo-solutions.it/geoserver/ows";
131 
132  // Version that will be used on WCS Requests.
133  std::string version = "2.0.1";
134 
135  te::ws::ogc::WCSClient client (dataDir, url, version);
136 
137  std::string coverageName = "nurc__mosaic";
138 
139  BOOST_CHECK_NO_THROW(client.describeCoverage(coverageName));
140 
141  te::ws::ogc::wcs::CoverageDescription description = client.describeCoverage(coverageName);
142 
143  te::ws::ogc::wcs::EnvelopeWithTimePeriod envelope = description.envelope;
144 
145  BOOST_CHECK(description.coverageId == coverageName);
146  BOOST_CHECK(envelope.srsName == "EPSG:4326");
147  BOOST_CHECK(envelope.srsDimension == "2");
148 
149  return;
150 }
151 
152 BOOST_AUTO_TEST_CASE(getcoverage_test)
153 {
155 
156  // Directory where test WCS test data is stored.
157  std::string dataDir = TERRALIB_DATA_DIR;
158 
159  // WCS server URL.
160  std::string url = "http://demo.geo-solutions.it/geoserver/ows";
161 
162  // Version that will be used on WCS Requests.
163  std::string version = "2.0.1";
164 
165  te::ws::ogc::WCSClient client (dataDir, url, version);
166 
167  // Coverage ID that could be retrieved on DescribeCoverage.
168  std::string coverageId = "nurc__mosaic";
169 
170  // Simple image request by id.
172  request.coverageID = coverageId;
173  request.format = "image/tiff";
174 
175  std::string coverageDiskPath = client.getCoverage(request);
176 
177  std::string expectedResult = dataDir + std::string("/wcs/") + coverageId + ".tif";
178 
179  BOOST_CHECK(coverageDiskPath == expectedResult);
180 
181  return;
182 }
WS Client for OGC WCS.
te::ws::ogc::wcs::CoverageDescription describeCoverage(const std::string coverage)
Method to get the information about a coverage in the WCS server.
Definition: WCSClient.cpp:122
A Wrapper for Lib Curl.
void updateCapabilities()
Method to get the capabilities from a WCS server and store in m_capabilities member.
Definition: WCSClient.cpp:92
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
te::da::DataSourceCapabilities capabilities
A struct to set the parameters of requested coverage.
A class to retrieve information and data from a Web Coverage Service.
Definition: WCSClient.h:58
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Base exception class for WS Core Runtime Library.
std::string getCoverage(const te::ws::ogc::wcs::CoverageRequest coverageRequest, te::common::TaskProgress *taskProgress=0) const
Method to get the coverage from the WCS server.
Definition: WCSClient.cpp:178
Exception classes for the WS Core Runtime Library.
BOOST_AUTO_TEST_CASE(getcapabilities_test)
Definition: TsWCSClient.cpp:46
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
const te::ws::ogc::wcs::Capabilities & getCapabilities() const
Return the m_capabilities member.
Definition: WCSClient.cpp:263
The base API for controllers of TerraLib applications.