/
GeoServerDataStoresTest.php
268 lines (215 loc) · 11.1 KB
/
GeoServerDataStoresTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?php
/*
* GeoServer PHP Client
*
* Copyright (c) 2018 Oneoff-tech UG, Germany, www.oneofftech.xyz
*
* This program is Free Software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
namespace Tests\Integration;
use Tests\TestCase;
use OneOffTech\GeoServer\GeoFile;
use OneOffTech\GeoServer\GeoType;
use Tests\Concern\SetupIntegrationTest;
use OneOffTech\GeoServer\Models\Feature;
use OneOffTech\GeoServer\Models\DataStore;
use OneOffTech\GeoServer\Exception\StoreNotFoundException;
class GeoServerDataStoresTest extends TestCase
{
use SetupIntegrationTest;
public function test_shapefile_can_be_uploaded()
{
$datastoreName = 'shapefile_test';
$data = GeoFile::from(__DIR__.'/../fixtures/shapefile.shp')->name($datastoreName);
$feature = $this->geoserver->upload($data);
$this->assertInstanceOf(Feature::class, $feature);
$this->assertEquals(GeoType::VECTOR, $feature->type());
$this->assertEquals("shapefile_test", $feature->name);
$this->assertEquals("shapefile_test", $feature->title);
$this->assertEquals("shapefile_test", $feature->nativeName);
$this->assertEquals("EPSG:404000", $feature->srs);
$this->assertTrue($feature->enabled);
$this->assertFalse($feature->overridingServiceSRS);
$this->assertFalse($feature->skipNumberMatched);
$this->assertFalse($feature->circularArcPresent);
$this->assertNotNull($feature->store);
$this->assertNotNull($feature->keywords);
$this->assertNotNull($feature->nativeBoundingBox);
$this->assertNotNull($feature->boundingBox);
$this->assertEquals("EPSG:4326", $feature->boundingBox->crs);
$this->assertEquals(314618.446, $feature->boundingBox->minX);
$this->assertEquals(5536155.822, $feature->boundingBox->minY);
$this->assertEquals(315358.647, $feature->boundingBox->maxX);
$this->assertEquals(5536652.114, $feature->boundingBox->maxY);
return $datastoreName;
}
/**
* @depends test_shapefile_can_be_uploaded
*/
public function test_datastore_can_be_retrieved_by_name($datastoreName)
{
$datastore = $this->geoserver->datastore($datastoreName);
$this->assertInstanceOf(DataStore::class, $datastore);
$this->assertEquals(getenv('GEOSERVER_WORKSPACE'), $datastore->workspace);
$this->assertEmpty($datastore->href);
$this->assertNotEmpty($datastore->featureTypes);
$this->assertNotEmpty($datastore->connectionParameters);
$this->assertTrue($datastore->enabled);
$this->assertTrue($datastore->exists);
return $datastoreName;
}
/**
* @depends test_datastore_can_be_retrieved_by_name
*/
public function test_datastores_are_retrieved($datastoreName)
{
$datastores = $this->geoserver->datastores();
$this->assertContainsOnlyInstancesOf(DataStore::class, $datastores);
return $datastoreName;
}
/**
* @depends test_datastores_are_retrieved
*/
public function test_datastore_can_be_deleted($datastoreName)
{
$datastore = $this->geoserver->deleteDatastore($datastoreName);
$this->assertInstanceOf(DataStore::class, $datastore);
$this->assertEquals(getenv('GEOSERVER_WORKSPACE'), $datastore->workspace);
$this->assertTrue($datastore->enabled);
$this->assertFalse($datastore->exists);
return $datastoreName;
}
public function test_non_existing_datastore_cannot_be_retrieved()
{
$this->expectException(StoreNotFoundException::class);
$datastore = $this->geoserver->datastore('some_name');
}
public function test_shapefile_can_be_uploaded_and_deleted()
{
$datastoreName = 'shapefile_test'.time();
$data = GeoFile::from(__DIR__.'/../fixtures/shapefile.shp')->name($datastoreName);
$feature = $this->geoserver->upload($data);
$this->assertInstanceOf(Feature::class, $feature);
$this->assertTrue($this->geoserver->exist($data), "Data not existing after upload");
$deleteResult = $this->geoserver->remove($data);
$this->assertTrue($deleteResult, "GeoFile not deleted");
$this->assertFalse($this->geoserver->exist($data), "Data still exists after remove");
}
public function test_shapefile_in_zip_archive_can_be_uploaded_and_deleted()
{
$datastoreName = 'buildings';
$data = GeoFile::from(__DIR__.'/../fixtures/buildings.zip')->name($datastoreName);
$feature = $this->geoserver->upload($data);
$this->assertInstanceOf(Feature::class, $feature);
$this->assertEquals(GeoType::VECTOR, $feature->type());
$this->assertEquals($datastoreName, $feature->name);
$this->assertEquals($datastoreName, $feature->title);
$this->assertEquals($datastoreName, $feature->nativeName);
$this->assertEquals("EPSG:4326", $feature->srs);
$this->assertTrue($feature->enabled);
$this->assertFalse($feature->overridingServiceSRS);
$this->assertFalse($feature->skipNumberMatched);
$this->assertFalse($feature->circularArcPresent);
$this->assertNotNull($feature->store);
$this->assertNotNull($feature->keywords);
$this->assertNotNull($feature->nativeBoundingBox);
$this->assertNotNull($feature->boundingBox);
$this->assertEquals("EPSG:4326", $feature->boundingBox->crs);
$this->assertEquals(69.07695, $feature->boundingBox->minX);
$this->assertEquals(34.41829, $feature->boundingBox->minY);
$this->assertEquals(69.3082, $feature->boundingBox->maxX);
$this->assertEquals(34.57558, $feature->boundingBox->maxY);
$this->assertTrue($this->geoserver->exist($data), "Data not existing after upload");
$deleteResult = $this->geoserver->remove($data);
$this->assertTrue($deleteResult, "GeoFile not deleted");
$this->assertFalse($this->geoserver->exist($data), "Data still exists after remove");
}
public function test_utf8_shapefile_in_zip_archive_can_be_uploaded_and_deleted()
{
$datastoreName = 'shapefile-utf8-inside';
$data = GeoFile::from(__DIR__.'/../fixtures/some_shapefile_with_cyrillicйфячыцус.zip')->name($datastoreName);
$feature = $this->geoserver->upload($data);
$this->assertInstanceOf(Feature::class, $feature);
$this->assertEquals(GeoType::VECTOR, $feature->type());
$this->assertEquals($datastoreName, $feature->name);
$this->assertEquals($datastoreName, $feature->title);
$this->assertEquals($datastoreName, $feature->nativeName);
$this->assertEquals("EPSG:3857", $feature->srs);
$this->assertTrue($feature->enabled);
$this->assertTrue($this->geoserver->exist($data), "Data not existing after upload");
$deleteResult = $this->geoserver->remove($data);
$this->assertTrue($deleteResult, "GeoFile not deleted");
$this->assertFalse($this->geoserver->exist($data), "Data still exists after remove");
}
public function test_shapefile_in_zip_archive_can_be_renamed_during_upload_and_deleted()
{
$datastoreName = 'shapezipfile_test'.time();
$data = GeoFile::from(__DIR__.'/../fixtures/buildings.zip')->name($datastoreName);
$feature = $this->geoserver->upload($data);
$this->assertTrue(file_exists($data->path()), "File has been deleted");
$this->assertInstanceOf(Feature::class, $feature);
$this->assertEquals(GeoType::VECTOR, $feature->type());
$this->assertEquals($datastoreName, $feature->name);
$this->assertEquals($datastoreName, $feature->title);
$this->assertEquals($datastoreName, $feature->nativeName);
$this->assertEquals("EPSG:4326", $feature->srs);
$this->assertTrue($feature->enabled);
$this->assertFalse($feature->overridingServiceSRS);
$this->assertFalse($feature->skipNumberMatched);
$this->assertFalse($feature->circularArcPresent);
$this->assertNotNull($feature->store);
$this->assertNotNull($feature->keywords);
$this->assertNotNull($feature->nativeBoundingBox);
$this->assertNotNull($feature->boundingBox);
$this->assertEquals("EPSG:4326", $feature->boundingBox->crs);
$this->assertEquals(69.07695, $feature->boundingBox->minX);
$this->assertEquals(34.41829, $feature->boundingBox->minY);
$this->assertEquals(69.3082, $feature->boundingBox->maxX);
$this->assertEquals(34.57558, $feature->boundingBox->maxY);
$this->assertTrue($this->geoserver->exist($data), "Data not existing after upload");
$deleteResult = $this->geoserver->remove($data);
$this->assertTrue($deleteResult, "GeoFile not deleted");
$this->assertFalse($this->geoserver->exist($data), "Data still exists after remove");
}
public function test_geopackage_can_be_uploaded_and_deleted()
{
$datastoreName = 'rivers';
$data = GeoFile::from(__DIR__.'/../fixtures/rivers.gpkg')->name($datastoreName);
$feature = $this->geoserver->upload($data);
$this->assertInstanceOf(Feature::class, $feature);
$this->assertEquals(GeoType::VECTOR, $feature->type());
$this->assertEquals($datastoreName, $feature->name);
$this->assertEquals($datastoreName, $feature->title);
$this->assertEquals($datastoreName, $feature->nativeName);
$this->assertEquals("EPSG:3857", $feature->srs);
$this->assertTrue($feature->enabled);
$this->assertFalse($feature->overridingServiceSRS);
$this->assertFalse($feature->skipNumberMatched);
$this->assertFalse($feature->circularArcPresent);
$this->assertNotNull($feature->store);
$this->assertNotNull($feature->keywords);
$this->assertNotNull($feature->nativeBoundingBox);
$this->assertNotNull($feature->boundingBox);
$this->assertEquals("EPSG:4326", $feature->boundingBox->crs);
$this->assertEquals(-180.00000000000003, $feature->boundingBox->minX);
$this->assertEquals(-85, $feature->boundingBox->minY);
$this->assertEquals(180.00000000000003, $feature->boundingBox->maxX);
$this->assertEquals(85, $feature->boundingBox->maxY);
$this->assertTrue($this->geoserver->exist($data), "Data not existing after upload");
$deleteResult = $this->geoserver->remove($data);
$this->assertTrue($deleteResult, "GeoFile not deleted");
$this->assertFalse($this->geoserver->exist($data), "Data still exists after remove");
}
}