TsWMSClient.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2017 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-wms/TsWMSClient.cpp
22 
23  \brief A test suit for the WS OGC WMSClient.
24 
25  \author Emerson Moraes
26  */
27 
28  //TerraLib
33 
34  //Boost
35  #include <boost/test/unit_test.hpp>
36 
37 //STL
38 #include <memory>
39 #include <iostream>
40 
41 BOOST_AUTO_TEST_CASE(getcapabilities_test)
42 {
44 
45  // Directory where test WMS test data is stored.
46  std::string dataDir = TERRALIB_DATA_DIR;
47 
48  //WMS GeoSolutions Demo server
49  std::string url = "http://demo.geo-solutions.it/geoserver/ows";
50 
51  //Version that will be used on WMS Requests.
52  std::string version = "1.3.0";
53 
54  te::ws::ogc::WMSClient client (dataDir, url, version);
55 
56  // Makes GetCapabilities Test Request.
57  BOOST_CHECK_NO_THROW(client.updateCapabilities());
58 
60 
61  te::ws::ogc::wms::Capability capability = capabilities.m_capability;
62 
63  std::vector<te::ws::ogc::wms::Layer> layers = capability.m_layer.m_layers;
64 
65  BOOST_CHECK(layers.size() > 0);
66 
67  return;
68 }
69 
70 BOOST_AUTO_TEST_CASE(getcapabilities_exception_test)
71 {
72 
74 
75  // Directory where test WMS test data is stored.
76  std::string dataDir = TERRALIB_DATA_DIR;
77 
78  // A wrong WMS server URL.
79  std::string url = "http://wrongaddress.org/geoserver/ows";
80 
81  // Version that will be used on WMS Requests.
82  std::string version = "1.3.0";
83 
84  te::ws::ogc::WMSClient client (dataDir, url, version);
85 
86  // Makes GetCapabilities Request.
87  BOOST_CHECK_THROW(client.updateCapabilities(), te::ws::core::Exception);
88 
89  return;
90 }
91 
92 
93 BOOST_AUTO_TEST_CASE(not_supported_version_test)
94 {
96 
97  // Directory where test WMS test data is stored.
98  std::string dataDir = TERRALIB_DATA_DIR;
99 
100  // WMS server URL.
101  std::string url = "http://demo.geo-solutions.it/geoserver/ows";
102 
103  // Version not supported yet.
104  std::string version = "1.0.0";
105 
106  te::ws::ogc::WMSClient client (dataDir, url, version);
107 
108  BOOST_CHECK_THROW(client.updateCapabilities(), te::ws::core::Exception);
109 
110  return;
111 }
112 
114 {
116 
117  // Directory where test WMS test data is stored.
118  std::string dataDir = TERRALIB_DATA_DIR;
119 
120  // WMS server URL.
121  std::string url = "http://demo.geo-solutions.it/geoserver/ows";
122 
123  std::string version = "1.3.0";
124 
125  te::ws::ogc::WMSClient client (dataDir, url, version);
126 
127  client.updateCapabilities();
128 
130 
131  te::ws::ogc::wms::Capability capability = capabilities.m_capability;
132 
133  std::vector<te::ws::ogc::wms::Layer> layers = capability.m_layer.m_layers;
134 
136 
137  for(size_t i = 0; i < layers.size(); i++)
138  {
139  if(layers[i].m_name == "tasmania")
140  {
141  request.m_layers.push_back(layers[i].m_name);
142 
143  if(layers[i].m_styles.size() > 0)
144  {
145  request.m_styles.push_back(layers[i].m_styles[0].m_name);
146  }
147 
148  request.m_srs = "EPSG:4326";
149 
151  bbox.m_crs = request.m_srs;
152  bbox.m_maxX = layers[i].m_geoBoundingBox.m_eastBoundLongitude;
153  bbox.m_maxY = layers[i].m_geoBoundingBox.m_northBoundLatitude;
154  bbox.m_minX = layers[i].m_geoBoundingBox.m_westBoundLongitude;
155  bbox.m_minY = layers[i].m_geoBoundingBox.m_southBoundLatitude;
156 
157  request.m_boundingBox = bbox;
158 
159  break;
160  }
161  }
162 
163  BOOST_CHECK(request.m_layers.size() == 1);
164 
165  te::ws::ogc::wms::WMSGetMapResponse response = client.getMap(request);
166 
167  BOOST_CHECK(response.m_buffer.empty() == false);
168  BOOST_CHECK(response.m_size > 0);
169  BOOST_CHECK(response.m_format == "image/png");
170 
171  return;
172 }
173 
174 
175 BOOST_AUTO_TEST_CASE(savegetmap_test)
176 {
178 
179  // Directory where test WMS test data is stored.
180  std::string dataDir = TERRALIB_DATA_DIR;
181 
182  // WMS server URL.
183  std::string url = "http://demo.geo-solutions.it/geoserver/ows";
184 
185  std::string version = "1.3.0";
186 
187  te::ws::ogc::WMSClient client (dataDir, url, version);
188 
189  client.updateCapabilities();
190 
192 
193  te::ws::ogc::wms::Capability capability = capabilities.m_capability;
194 
195  std::vector<te::ws::ogc::wms::Layer> layers = capability.m_layer.m_layers;
196 
198 
199  for(size_t i = 0; i < layers.size(); i++)
200  {
201  if(layers[i].m_name == "tasmania")
202  {
203  request.m_layers.push_back(layers[i].m_name);
204 
205  if(layers[i].m_styles.size() > 0)
206  {
207  request.m_styles.push_back(layers[i].m_styles[0].m_name);
208  }
209 
210  request.m_srs = "EPSG:4326";
211 
213  bbox.m_crs = request.m_srs;
214  bbox.m_maxX = layers[i].m_geoBoundingBox.m_eastBoundLongitude;
215  bbox.m_maxY = layers[i].m_geoBoundingBox.m_northBoundLatitude;
216  bbox.m_minX = layers[i].m_geoBoundingBox.m_westBoundLongitude;
217  bbox.m_minY = layers[i].m_geoBoundingBox.m_southBoundLatitude;
218 
219  request.m_boundingBox = bbox;
220 
221  break;
222  }
223  }
224 
225  BOOST_CHECK(request.m_layers.size() == 1);
226 
227  std::string imageDiskPath = client.saveGetMap(request, "test_image.png");
228 
229  std::string expectedResult = dataDir + std::string("/wms/") + "test_image.png";
230 
231  BOOST_CHECK(imageDiskPath == expectedResult);
232 }
BOOST_AUTO_TEST_CASE(getcapabilities_test)
Definition: TsWMSClient.cpp:41
const te::ws::ogc::wms::WMSGetMapResponse getMap(const te::ws::ogc::wms::WMSGetMapRequest &request) const
Return the WMSGetMapResponse member.
Definition: WMSClient.cpp:118
const te::ws::ogc::wms::WMSCapabilities & getCapabilities() const
Return the WMSCapabilities member.
Definition: WMSClient.cpp:108
The Capability WMS 1.3.0 struct.
The Capability WMS 1.3.0 struct.
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
te::da::DataSourceCapabilities capabilities
The WMSGetMapResponse WMS 1.3.0 struct.
const std::string saveGetMap(const te::ws::ogc::wms::WMSGetMapRequest &request, const std::string &filename)
It execute a WMS GetMap and save the result image on disk. The request will be based on WMSGetMapRequ...
Definition: WMSClient.cpp:137
Base exception class for WS Core Runtime Library.
Exception classes for the WS Core Runtime Library.
void updateCapabilities()
Method to get the capabilities from a WMS server and store in m_capabilities member.
Definition: WMSClient.cpp:67
Specifies containers for WMS data types.
A class to retrieve information and data from a Web Map Service.
Definition: WMSClient.h:57
The base API for controllers of TerraLib applications.
The WMSGetMapRequest WMS 1.3.0 struct.
The BoundingBox WMS 1.3.0 struct.