@@ -73,9 +73,9 @@ void TestQgsStac::cleanupTestCase()
73
73
74
74
void TestQgsStac::testParseLocalCatalog ()
75
75
{
76
- const QString fileName = mDataDir + QStringLiteral ( " catalog.json" );
76
+ const QUrl url ( QStringLiteral ( " file://%1%2 " ). arg ( mDataDir , QStringLiteral ( " catalog.json" ) ) );
77
77
QgsStacController c;
78
- QgsStacObject *obj = c.fetchStacObject ( QStringLiteral ( " file://%1 " ). arg ( fileName ) );
78
+ QgsStacObject *obj = c.fetchStacObject ( url. toString ( ) );
79
79
QVERIFY ( obj );
80
80
QCOMPARE ( obj->type (), QgsStacObject::Type::Catalog );
81
81
QgsStacCatalog *cat = dynamic_cast < QgsStacCatalog * >( obj );
@@ -85,17 +85,27 @@ void TestQgsStac::testParseLocalCatalog()
85
85
QCOMPARE ( cat->stacVersion (), QLatin1String ( " 1.0.0" ) );
86
86
QCOMPARE ( cat->title (), QLatin1String ( " Example Catalog" ) );
87
87
QCOMPARE ( cat->description (), QLatin1String ( " This catalog is a simple demonstration of an example catalog that is used to organize a hierarchy of collections and their items." ) );
88
- QCOMPARE ( cat->links ().size (), 6 );
89
88
QVERIFY ( cat->stacExtensions ().isEmpty () );
90
89
90
+ // check that relative links are correctly resolved into absolute links
91
+ const QVector<QgsStacLink> links = cat->links ();
92
+ QCOMPARE ( links.size (), 6 );
93
+ const QString basePath = url.adjusted ( QUrl::RemoveFilename ).toString ();
94
+ QCOMPARE ( links.at ( 0 ).href (), QStringLiteral ( " %1catalog.json" ).arg ( basePath ) );
95
+ QCOMPARE ( links.at ( 1 ).href (), QStringLiteral ( " %1extensions-collection/collection.json" ).arg ( basePath ) );
96
+ QCOMPARE ( links.at ( 2 ).href (), QStringLiteral ( " %1collection-only/collection.json" ).arg ( basePath ) );
97
+ QCOMPARE ( links.at ( 3 ).href (), QStringLiteral ( " %1collection-only/collection-with-schemas.json" ).arg ( basePath ) );
98
+ QCOMPARE ( links.at ( 4 ).href (), QStringLiteral ( " %1collectionless-item.json" ).arg ( basePath ) );
99
+ QCOMPARE ( links.at ( 5 ).href (), QStringLiteral ( " https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/catalog.json" ) );
100
+
91
101
delete cat;
92
102
}
93
103
94
104
void TestQgsStac::testParseLocalCollection ()
95
105
{
96
- const QString fileName = mDataDir + QStringLiteral ( " collection.json" );
106
+ const QUrl url ( QStringLiteral ( " file://%1%2 " ). arg ( mDataDir , QStringLiteral ( " collection.json" ) ) );
97
107
QgsStacController c;
98
- QgsStacObject *obj = c.fetchStacObject ( QStringLiteral ( " file://%1 " ). arg ( fileName ) );
108
+ QgsStacObject *obj = c.fetchStacObject ( url. toString ( ) );
99
109
QVERIFY ( obj );
100
110
QCOMPARE ( obj->type (), QgsStacObject::Type::Collection );
101
111
QgsStacCollection *col = dynamic_cast < QgsStacCollection * >( obj );
@@ -105,7 +115,17 @@ void TestQgsStac::testParseLocalCollection()
105
115
QCOMPARE ( col->stacVersion (), QLatin1String ( " 1.0.0" ) );
106
116
QCOMPARE ( col->title (), QLatin1String ( " Simple Example Collection" ) );
107
117
QCOMPARE ( col->description (), QLatin1String ( " A simple collection demonstrating core catalog fields with links to a couple of items" ) );
108
- QCOMPARE ( col->links ().size (), 5 );
118
+
119
+ // check that relative links are correctly resolved into absolute links
120
+ const QVector<QgsStacLink> links = col->links ();
121
+ QCOMPARE ( links.size (), 5 );
122
+ const QString basePath = url.adjusted ( QUrl::RemoveFilename ).toString ();
123
+ QCOMPARE ( links.at ( 0 ).href (), QStringLiteral ( " %1collection.json" ).arg ( basePath ) );
124
+ QCOMPARE ( links.at ( 1 ).href (), QStringLiteral ( " %1simple-item.json" ).arg ( basePath ) );
125
+ QCOMPARE ( links.at ( 2 ).href (), QStringLiteral ( " %1core-item.json" ).arg ( basePath ) );
126
+ QCOMPARE ( links.at ( 3 ).href (), QStringLiteral ( " %1extended-item.json" ).arg ( basePath ) );
127
+ QCOMPARE ( links.at ( 4 ).href (), QStringLiteral ( " https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/collection.json" ) );
128
+
109
129
QCOMPARE ( col->providers ().size (), 1 );
110
130
QCOMPARE ( col->stacExtensions ().size (), 3 );
111
131
QCOMPARE ( col->license (), QLatin1String ( " CC-BY-4.0" ) );
@@ -133,19 +153,33 @@ void TestQgsStac::testParseLocalCollection()
133
153
134
154
void TestQgsStac::testParseLocalItem ()
135
155
{
136
- const QString fileName = mDataDir + QStringLiteral ( " core-item.json" );
156
+ const QUrl url ( QStringLiteral ( " file://%1%2 " ). arg ( mDataDir , QStringLiteral ( " core-item.json" ) ) );
137
157
QgsStacController c;
138
- QgsStacObject *obj = c.fetchStacObject ( QStringLiteral ( " file://%1 " ). arg ( fileName ) );
158
+ QgsStacObject *obj = c.fetchStacObject ( url. toString ( ) );
139
159
QVERIFY ( obj );
140
160
QCOMPARE ( obj->type (), QgsStacObject::Type::Item );
141
161
QgsStacItem *item = dynamic_cast <QgsStacItem *>( obj );
142
162
143
163
QVERIFY ( item );
144
164
QCOMPARE ( item->id (), QLatin1String ( " 20201211_223832_CS2" ) );
145
165
QCOMPARE ( item->stacVersion (), QLatin1String ( " 1.0.0" ) );
146
- QCOMPARE ( item->links ().size (), 4 );
147
166
QCOMPARE ( item->stacExtensions ().size (), 0 );
167
+
168
+ // check that relative links are correctly resolved into absolute links
169
+ const QVector<QgsStacLink> links = item->links ();
170
+ QCOMPARE ( links.size (), 4 );
171
+ const QString basePath = url.adjusted ( QUrl::RemoveFilename ).toString ();
172
+ QCOMPARE ( links.at ( 0 ).href (), QStringLiteral ( " %1collection.json" ).arg ( basePath ) );
173
+ QCOMPARE ( links.at ( 1 ).href (), QStringLiteral ( " %1collection.json" ).arg ( basePath ) );
174
+ QCOMPARE ( links.at ( 2 ).href (), QStringLiteral ( " %1collection.json" ).arg ( basePath ) );
175
+ QCOMPARE ( links.at ( 3 ).href (), QStringLiteral ( " http://remotedata.io/catalog/20201211_223832_CS2/index.html" ) );
176
+
148
177
QCOMPARE ( item->assets ().size (), 6 );
178
+ QgsStacAsset asset = item->assets ().value ( QStringLiteral ( " analytic" ), QgsStacAsset ( {}, {}, {}, {}, {} ) );
179
+ QCOMPARE ( asset.href (), basePath + QStringLiteral ( " 20201211_223832_CS2_analytic.tif" ) );
180
+
181
+ asset = item->assets ().value ( QStringLiteral ( " thumbnail" ), QgsStacAsset ( {}, {}, {}, {}, {} ) );
182
+ QCOMPARE ( asset.href (), QStringLiteral ( " https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2.jpg" ) );
149
183
150
184
delete item;
151
185
}
0 commit comments