TsWCSDataAccess.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/TsWCSDataAccess.cpp
22 
23  \brief A test suit for the WS OGC WCS DataAccess.
24 
25  \author Emerson Moraes
26  */
27 
28 // TerraLib
39 
40 // Boost
41 #include <boost/test/unit_test.hpp>
42 
43 // STL
44 #include <map>
45 
46 BOOST_AUTO_TEST_CASE(datasource_open_test)
47 {
49 
51 
52  // Directory where temporary WCS data will be stored.
53  std::string usrDataDir = te::qt::af::AppCtrlSingleton::getInstance().getUserDataDir().toUtf8().data();
54 
55  // WCS server URL.
56  std::string url = "http://demo.geo-solutions.it/geoserver/ows";
57 
58  // Version that will be used on WCS Requests.
59  std::string version = "2.0.1";
60 
61  std::string encodedURL = te::core::URIEncode(url);
62 
63  std::string connInfo("wcs://?URI=" + encodedURL + "&VERSION=" + version + "&USERDATADIR=" + usrDataDir);
64 
65  // Perform connection
66  std::unique_ptr<te::da::DataSource> ds = te::da::DataSourceFactory::make("WCS2", connInfo);
67  ds->open();
68 
69  BOOST_CHECK(ds->isOpened());
70 
71  return;
72 }
73 
74 BOOST_AUTO_TEST_CASE(datasource_open_exception_test)
75 {
77 
78  // Directory where temporary WCS data will be stored.
79  std::string usrDataDir = te::qt::af::AppCtrlSingleton::getInstance().getUserDataDir().toUtf8().data();
80 
81  // WCS server URL.
82  std::string url = "http://demo.geo-solutions.it/geoserver/ows";
83 
84  std::string encodedURL = te::core::URIEncode(url);
85 
86  // Version that will be used on WCS Requests.
87  std::string version = "2.0.1";
88 
89  std::string connInfo;
90 
91  // Perform connection
92  std::unique_ptr<te::da::DataSource> ds = te::da::DataSourceFactory::make("WCS2", connInfo);
93 
94  // Test without any correct connection parameter
95  BOOST_CHECK(ds.get() == nullptr);
96 
97  connInfo = "wcs://?URI=" + encodedURL;
98  ds.reset(te::da::DataSourceFactory::make("WCS2", connInfo).release());
99 
100  // Test with URI correct connection parameter
101  BOOST_CHECK_THROW(ds->open(), te::ws::ogc::wcs::da::Exception);
102 
103  connInfo = "wcs://?VERSION=" + version;
104  ds.reset(te::da::DataSourceFactory::make("WCS2", connInfo).release());
105 
106  // Test with VERSION correct connection parameter
107  BOOST_CHECK_THROW(ds->open(), te::ws::ogc::wcs::da::Exception);
108 
109  connInfo = "wcs://?USERDATADIR=" + usrDataDir;
110  ds.reset(te::da::DataSourceFactory::make("WCS2", connInfo).release());
111 
112  // Test with USERDATADIR correct connection parameter
113  BOOST_CHECK_THROW(ds->open(), te::ws::ogc::wcs::da::Exception);
114 
115  connInfo = "wcs://?URI=" + encodedURL + "&VERSION=" + version;
116  ds.reset(te::da::DataSourceFactory::make("WCS2", connInfo).release());
117 
118  // Test with URI and VERSION correct connection parameters
119  BOOST_CHECK_THROW(ds->open(), te::ws::ogc::wcs::da::Exception);
120 
121  connInfo = "wcs://?URI=" + encodedURL + "&USERDATADIR=" + usrDataDir;
122  ds.reset(te::da::DataSourceFactory::make("WCS2", connInfo).release());
123 
124  // Test with URI and USERDATADIR correct connection parameters
125  BOOST_CHECK_THROW(ds->open(), te::ws::ogc::wcs::da::Exception);
126 
127  connInfo = "wcs://?VERSION=" + version + "&USERDATADIR=" + usrDataDir;
128  ds.reset(te::da::DataSourceFactory::make("WCS2", connInfo).release());
129 
130  // Test with VERSION and USERDATADIR correct connection parameters
131  BOOST_CHECK_THROW(ds->open(), te::ws::ogc::wcs::da::Exception);
132 
133  return;
134 }
WS Client for OGC WCS.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
TECOREEXPORT std::string URIEncode(const std::string &srcUri)
Encodes an decoded URI. The algorithm implementation is based on http://www.codeguru.com/cpp/cpp/algorithms/strings/article.php/c12759/URI-Encoding-and-Decoding.htm.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
#define TE_OGC_WCS_DRIVER_IDENTIFIER
The OGC WCS driver identifier string.
This is a singleton for managing all data source instances available in the system.
This is the factory for WCS data sources.
static te::dt::Date ds(2010, 01, 01)
BOOST_AUTO_TEST_CASE(datasource_open_test)
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
A factory for data sources.
Configuration flags for the Terrralib WS OGC WCS DATA ACCESS module.
TEOGCWCSDATAACCESSEXPORT te::da::DataSource * Build(const te::core::URI &uri)
This file contains utility functions used to manipulate data from a URI.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
static void add(const std::string &dsType, FactoryFnctType f)
The base API for controllers of TerraLib applications.