Index: src/webservice/CMakeLists.txt
===================================================================
--- src/webservice/CMakeLists.txt	(revision 02fbeb816a6fd00276fc6f4dfc1dd966ba3dc6d5)
+++ src/webservice/CMakeLists.txt	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
@@ -20,7 +20,5 @@
 ######################
 
-SET(WEBSERVICE_OUTPUT_DIRECTORY "${WEB_OUTPUT_DIRECTORY}/webservice")
 SET(WEBSERVICE_OUTPUT_APP_DIRECTORY "${WEBSERVICE_OUTPUT_DIRECTORY}/${WEBSERVICE_API_VERSION}")
-SET(WEBSERVICE_TEST_OUTPUT_DIRECTORY "${WEB_TEST_OUTPUT_DIRECTORY}/webservice")
 
 # switch Slim mode according to CMake debug mode
Index: src/webservice/htdocs/SiWeather/Webservice/DatabaseHandler.php
===================================================================
--- src/webservice/htdocs/SiWeather/Webservice/DatabaseHandler.php	(revision 02fbeb816a6fd00276fc6f4dfc1dd966ba3dc6d5)
+++ src/webservice/htdocs/SiWeather/Webservice/DatabaseHandler.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
@@ -147,5 +147,5 @@
 	public function versionSpatialite(){
 		if(is_null($this->_database)){
-			$this->setLastErrorMessage("Unknown (No database connection)");
+			$this->setLastErrorMessage("No database connection");
 			return 0;
 		}
@@ -162,5 +162,5 @@
 	public function versionSqlite(){
 		if(is_null($this->_database)){
-			$this->setLastErrorMessage("Unknown (No database connection)");
+			$this->setLastErrorMessage("No database connection");
 			return 0;
 		}
Index: src/webservice/htdocs/SiWeather/Webservice/WebserviceApi.php
===================================================================
--- src/webservice/htdocs/SiWeather/Webservice/WebserviceApi.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
+++ src/webservice/htdocs/SiWeather/Webservice/WebserviceApi.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
@@ -0,0 +1,315 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+namespace SiWeather\Webservice;
+
+require(__DIR__ ."/../../inc/envsetup.php");
+
+/**
+  * @brief Implementation of the Webservice API
+  *
+  * @module WebserviceAPI
+  */
+class WebserviceApi {
+	/**
+		* @brief Handles the stations (list) REST requests
+		*/
+	public static function stations(){
+		$stations = Array();
+
+		$db = new DatabaseHandler();
+		if(!$db->connect()){
+			echo json_encode
+			(
+				[
+					"result" => "failed",
+					"message" => "Could not connect to the database",
+				]
+			);
+			return;
+		}
+		$db->exec("BEGIN");
+
+		$sqlStatement = $db->prepare("SELECT stations.uuid as uuid, stations.name as name, X(stations.location) as longitude, Y(stations.location) as latitude, cities.name as city FROM stations, cities WHERE stations.city=cities.id");
+		if(!$sqlStatement){
+			$db->exec("ROLLBACK");
+			echo json_encode
+			(
+				[
+					"result" => "failed",
+					"message" => "Could not fetch stations from database",
+				]
+			);
+			return;
+		}
+		$result = $sqlStatement->execute();
+		while($row = $result->fetchArray()){
+			$station = Array();
+			$station["uuid"] = $row["uuid"];
+			$station["name"] = $row["name"];
+			$station["longitude"] = $row["longitude"];
+			$station["latitude"] = $row["latitude"];
+			$station["city"] = $row["city"];
+	// 		$station["values"] = Array();
+	// 		$station["values"][] = "temperature";
+	// 		$station["values"][] = "humidity";
+			$station["url"] = "stations/". $station["uuid"];
+			$stations[] = $station;
+		}
+		$db->exec("COMMIT");
+
+		echo json_encode($stations);
+	}
+
+	/**
+	* @brief Registers a new weather station
+	*
+	* @note Call this function with a big timeout > 2seconds, because we use another webservice
+	*       to fetch location data. This fetch runs already 2seconds.
+		* @note Requires php-pecl-uuid
+	*/
+	public static function stationsRegister(){
+		$geoLocationRadius = 5;
+
+		try{
+			$app = \Slim\Slim::getInstance("siweather");
+			$body = $app->request->getBody();
+			$json = json_decode($body, true);
+
+			$app->response()->header("Content-Type", "application/json");
+
+			$expectedKeys = array("name", "city", "longitude", "latitude", "email");
+			$missingKeys = array();
+			foreach($expectedKeys as $key){
+				if(!array_key_exists($key, $json))
+					$missingKeys[] = $key;
+			}
+			if(count($missingKeys) > 0){
+				echo json_encode
+				(
+					[
+						"result" => "missingkeys",
+						"message" => "Your request misses the following keys: ". implode(", ", $missingKeys),
+					]
+				);
+				return;
+			}
+
+			if(!Location::ValidLatitude($json["latitude"])){
+				echo json_encode
+				(
+					[
+						"result" => "invalid latitude",
+						"message" => "Your specified an invalid latitude: ". $json["latitude"],
+					]
+				);
+				return;
+			}
+			if(!Location::ValidLongitude($json["longitude"])){
+				echo json_encode
+				(
+					[
+						"result" => "invalid longitude",
+						"message" => "Your specified an invalid longitude: ". $json["longitude"],
+					]
+				);
+				return;
+			}
+			if(empty($json["email"]) || !filter_var($json["email"], FILTER_VALIDATE_EMAIL)){
+				echo json_encode
+				(
+					[
+						"result" => "invalid email",
+						"message" => "Your specified an invalid email address: ". $json["email"],
+					]
+				);
+				return;
+			}
+
+			$errorMessage = "";
+			$locations = GeoLocator::locations($json["latitude"], $json["longitude"], $geoLocationRadius, $errorMessage);
+			if(!$locations || count($locations) < 1){
+				error_log($errorMessage);
+				echo json_encode
+				(
+					[
+						"result" => "unprovenlocation",
+						"message" => "Could not check the city (". $json["city"] .") and location (". $json["latitude"] .", ". $json["longitude"] .") you send with help of your city and geo coordinates. Please make sure, your data is correct.",
+					]
+				);
+				return;
+			}
+			else{
+				$validatedLocation = false;
+				foreach($locations as $location){
+					if($location->city() == $json["city"]){
+						$validatedLocation = $location;
+					}
+				}
+				if(!$validatedLocation){
+					$message  = "The city (". $json[city] .") and location (". $json["latitude"] .", ". $json["longitude"] .") you send, does not suite with locations we found at your given location (city, latitude, longitude):\n";
+					foreach($locations as $location){
+						$message .= "    ". $location->city() .": ". $location->latitude() .", ". $location->longitude() ."\n";
+					}
+					$message .= " Please make sure, your data is correct.";
+
+					echo json_encode
+					(
+						[
+							"result" => "unprovenlocation",
+							"message" => $message,
+						]
+					);
+					return;
+				}
+			}
+
+			$db = new DatabaseHandler();
+			if(!$db->connect()){
+				echo json_encode
+				(
+					[
+						"result" => "failed",
+						"message" => "Could not connect to the database",
+					]
+				);
+				return;
+			}
+			$db->exec("BEGIN");
+
+			// find out, if the city is already there
+			$cityId = -1;
+			$sqlStatement = $db->prepare("SELECT id FROM cities WHERE name=:name AND location=:location");
+			if(!$sqlStatement){
+				$db->exec("ROLLBACK");
+				echo json_encode
+				(
+					[
+						"result" => "failed",
+						"message" => "Could not fetch city from database",
+					]
+				);
+				return;
+			}
+			$sqlStatement->bindValue(":name", $validatedLocation->city());
+			$sqlStatement->bindValue(":location", "POINT(". $location->locationWkt() .")");
+			$result = $sqlStatement->execute();
+			if($result->numColumns() && $result->columnType(0) != SQLITE3_NULL){
+				error_log("not cool");
+				$row = $result->fetchArray();
+				$cityId = $row[0];
+				error_log($row[0]);
+			}
+			else{
+				$sqlStatement = $db->prepare("INSERT INTO cities (name, location) VALUES(:name, GeomFromText(:location, 4326))");
+				if(!$sqlStatement){
+					$db->exec("ROLLBACK");
+					echo json_encode
+					(
+						[
+							"result" => "failed",
+							"message" => "Could insert city into the database",
+						]
+					);
+					return;
+				}
+				$sqlStatement->bindValue(":name", $validatedLocation->city());
+				$sqlStatement->bindValue(":location", "POINT(". $location->locationWkt() .")");
+				$sqlResult = $sqlStatement->execute();
+				if(!$sqlResult){
+					error_log("Failed to add city to the database: ". $db->lastDatabaseErrorMessage());
+					$db->exec("ROLLBACK");
+					echo json_encode
+					(
+						[
+							"result" => "failed",
+							"message" => "Could not add city to the database",
+						]
+					);
+					return;
+				}
+				$cityId = $db->lastInsertRowId();
+			}
+			if($cityId < 0){
+				error_log("Failed to select city from the database: ". $db->lastDatabaseErrorMessage());
+				$db->exec("ROLLBACK");
+				echo json_encode
+				(
+					[
+						"result" => "failed",
+						"message" => "Could not select city from the database",
+					]
+				);
+				return;
+			}
+
+			// insert station
+			$uuid = uuid_create(4);
+			$sqlStatement = $db->prepare("INSERT INTO stations (name, city, uuid, ownerMail, location) VALUES(:name, :city, :uuid, :ownerMail, GeomFromText(:location, 4326))");
+			if(!$sqlStatement){
+				$db->exec("ROLLBACK");
+				echo json_encode
+				(
+					[
+						"result" => "failed",
+						"message" => "Could insert station into the database",
+					]
+				);
+				return;
+			}
+			$sqlStatement->bindValue(":name", $json["name"]);
+			$sqlStatement->bindValue(":city", $cityId);
+			$sqlStatement->bindValue(":uuid", $uuid);
+			$sqlStatement->bindValue(":ownerMail",$json["email"]);
+			$sqlStatement->bindValue(":location", "POINT(". $location->locationWkt() .")");
+			$sqlResult = $sqlStatement->execute();
+			if(!$sqlResult){
+				error_log("Failed to add station to the database: ". $db->lastDatabaseErrorMessage());
+				$db->query("ROLLBACK");
+				echo json_encode
+				(
+					[
+						"result" => "failed",
+						"message" => "Could not add station to the database",
+					]
+				);
+				return;
+			}
+
+			// finish transaction
+			$db->exec("COMMIT");
+
+			echo json_encode
+			(
+				[
+					"result" => "success",
+					"uuid" => $uuid,
+				]
+			);
+		}
+		catch(Exception $exception){
+			error_log("Caught exception handling request stationsRegister: ". $exception->getMessage());
+			$app->response()->status(400);
+			$app->response()->header("X-Status-Reason", $exception->getMessage());
+		}
+	}
+}
+
+?>
Index: src/webservice/htdocs/index.php
===================================================================
--- src/webservice/htdocs/index.php	(revision 02fbeb816a6fd00276fc6f4dfc1dd966ba3dc6d5)
+++ src/webservice/htdocs/index.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
@@ -22,287 +22,4 @@
 
 $settings = new SiWeather\Webservice\WebserviceConfig();
-
-/**
-	* @brief Handles the stations (list) REST requests
-	*/
-function stations(){
-	$stations = Array();
-
-	$db = new SiWeather\Webservice\DatabaseHandler();
-	if(!$db->connect()){
-		echo json_encode
-		(
-			[
-				"result" => "failed",
-				"message" => "Could not connect to the database",
-			]
-		);
-		return;
-	}
-	$db->exec("BEGIN");
-
-	$sqlStatement = $db->prepare("SELECT stations.uuid as uuid, stations.name as name, X(stations.location) as longitude, Y(stations.location) as latitude, cities.name as city FROM stations, cities WHERE stations.city=cities.id");
-	if(!$sqlStatement){
-		$db->exec("ROLLBACK");
-		echo json_encode
-		(
-			[
-				"result" => "failed",
-				"message" => "Could not fetch stations from database",
-			]
-		);
-		return;
-	}
-	$result = $sqlStatement->execute();
-	while($row = $result->fetchArray()){
-		$station = Array();
-		$station["uuid"] = $row["uuid"];
-		$station["name"] = $row["name"];
-		$station["longitude"] = $row["longitude"];
-		$station["latitude"] = $row["latitude"];
-		$station["city"] = $row["city"];
-// 		$station["values"] = Array();
-// 		$station["values"][] = "temperature";
-// 		$station["values"][] = "humidity";
-		$station["url"] = "stations/". $station["uuid"];
-		$stations[] = $station;
-	}
-	$db->exec("COMMIT");
-
-	echo json_encode($stations);
-}
-
-/**
-  * @brief Registers a new weather station
-  *
-  * @note Call this function with a big timeout > 2seconds, because we use another webservice
-  *       to fetch location data. This fetch runs already 2seconds.
-	* @note Requires php-pecl-uuid
-  */
-function stationsRegister(){
-	$geoLocationRadius = 5;
-
-	try{
-		$app = \Slim\Slim::getInstance("siweather");
-		$body = $app->request->getBody();
-		$json = json_decode($body, true);
-
-		$app->response()->header("Content-Type", "application/json");
-
-		$expectedKeys = array("name", "city", "longitude", "latitude", "email");
-		$missingKeys = array();
-		foreach($expectedKeys as $key){
-			if(!array_key_exists($key, $json))
-				$missingKeys[] = $key;
-		}
-		if(count($missingKeys) > 0){
-			echo json_encode
-			(
-				[
-					"result" => "missingkeys",
-					"message" => "Your request misses the following keys: ". implode(", ", $missingKeys),
-				]
-			);
-			return;
-		}
-
-		if(!SiWeather\Webservice\Location::ValidLatitude($json["latitude"])){
-			echo json_encode
-			(
-				[
-					"result" => "invalid latitude",
-					"message" => "Your specified an invalid latitude: ". $json["latitude"],
-				]
-			);
-			return;
-		}
-		if(!SiWeather\Webservice\Location::ValidLongitude($json["longitude"])){
-			echo json_encode
-			(
-				[
-					"result" => "invalid longitude",
-					"message" => "Your specified an invalid longitude: ". $json["longitude"],
-				]
-			);
-			return;
-		}
-		if(empty($json["email"]) || !filter_var($json["email"], FILTER_VALIDATE_EMAIL)){
-			echo json_encode
-			(
-				[
-					"result" => "invalid email",
-					"message" => "Your specified an invalid email address: ". $json["email"],
-				]
-			);
-			return;
-		}
-
-		$errorMessage = "";
-		$locations = SiWeather\Webservice\GeoLocator::locations($json["latitude"], $json["longitude"], $geoLocationRadius, $errorMessage);
-		if(!$locations || count($locations) < 1){
-			error_log($errorMessage);
-			echo json_encode
-			(
-				[
-					"result" => "unprovenlocation",
-					"message" => "Could not check the city (". $json["city"] .") and location (". $json["latitude"] .", ". $json["longitude"] .") you send with help of your city and geo coordinates. Please make sure, your data is correct.",
-				]
-			);
-			return;
-		}
-		else{
-			$validatedLocation = false;
-			foreach($locations as $location){
-				if($location->city() == $json["city"]){
-					$validatedLocation = $location;
-				}
-			}
-			if(!$validatedLocation){
-				$message  = "The city (". $json[city] .") and location (". $json["latitude"] .", ". $json["longitude"] .") you send, does not suite with locations we found at your given location (city, latitude, longitude):\n";
-				foreach($locations as $location){
-					$message .= "    ". $location->city() .": ". $location->latitude() .", ". $location->longitude() ."\n";
-				}
-				$message .= " Please make sure, your data is correct.";
-
-				echo json_encode
-				(
-					[
-						"result" => "unprovenlocation",
-						"message" => $message,
-					]
-				);
-				return;
-			}
-		}
-
-		$db = new SiWeather\Webservice\DatabaseHandler();
-		if(!$db->connect()){
-			echo json_encode
-			(
-				[
-					"result" => "failed",
-					"message" => "Could not connect to the database",
-				]
-			);
-			return;
-		}
-		$db->exec("BEGIN");
-
-		// find out, if the city is already there
-		$cityId = -1;
-		$sqlStatement = $db->prepare("SELECT id FROM cities WHERE name=:name AND location=:location");
-		if(!$sqlStatement){
-			$db->exec("ROLLBACK");
-			echo json_encode
-			(
-				[
-					"result" => "failed",
-					"message" => "Could not fetch city from database",
-				]
-			);
-			return;
-		}
-		$sqlStatement->bindValue(":name", $validatedLocation->city());
-		$sqlStatement->bindValue(":location", "POINT(". $location->locationWkt() .")");
-		$result = $sqlStatement->execute();
-		if($result->numColumns() && $result->columnType(0) != SQLITE3_NULL){
-			error_log("not cool");
-			$row = $result->fetchArray();
-			$cityId = $row[0];
-			error_log($row[0]);
-		}
-		else{
-			$sqlStatement = $db->prepare("INSERT INTO cities (name, location) VALUES(:name, GeomFromText(:location, 4326))");
-			if(!$sqlStatement){
-				$db->exec("ROLLBACK");
-				echo json_encode
-				(
-					[
-						"result" => "failed",
-						"message" => "Could insert city into the database",
-					]
-				);
-				return;
-			}
-			$sqlStatement->bindValue(":name", $validatedLocation->city());
-			$sqlStatement->bindValue(":location", "POINT(". $location->locationWkt() .")");
-			$sqlResult = $sqlStatement->execute();
-			if(!$sqlResult){
-				error_log("Failed to add city to the database: ". $db->lastDatabaseErrorMessage());
-				$db->exec("ROLLBACK");
-				echo json_encode
-				(
-					[
-						"result" => "failed",
-						"message" => "Could not add city to the database",
-					]
-				);
-				return;
-			}
-			$cityId = $db->lastInsertRowId();
-		}
-		if($cityId < 0){
-			error_log("Failed to select city from the database: ". $db->lastDatabaseErrorMessage());
-			$db->exec("ROLLBACK");
-			echo json_encode
-			(
-				[
-					"result" => "failed",
-					"message" => "Could not select city from the database",
-				]
-			);
-			return;
-		}
-
-		// insert station
-		$uuid = uuid_create(4);
-		$sqlStatement = $db->prepare("INSERT INTO stations (name, city, uuid, ownerMail, location) VALUES(:name, :city, :uuid, :ownerMail, GeomFromText(:location, 4326))");
-		if(!$sqlStatement){
-			$db->exec("ROLLBACK");
-			echo json_encode
-			(
-				[
-					"result" => "failed",
-					"message" => "Could insert station into the database",
-				]
-			);
-			return;
-		}
-		$sqlStatement->bindValue(":name", $json["name"]);
-		$sqlStatement->bindValue(":city", $cityId);
-		$sqlStatement->bindValue(":uuid", $uuid);
-		$sqlStatement->bindValue(":ownerMail",$json["email"]);
-		$sqlStatement->bindValue(":location", "POINT(". $location->locationWkt() .")");
-		$sqlResult = $sqlStatement->execute();
-		if(!$sqlResult){
-			error_log("Failed to add station to the database: ". $db->lastDatabaseErrorMessage());
-			$db->query("ROLLBACK");
-			echo json_encode
-			(
-				[
-					"result" => "failed",
-					"message" => "Could not add station to the database",
-				]
-			);
-			return;
-		}
-
-		// finish transaction
-		$db->exec("COMMIT");
-
-		echo json_encode
-		(
-			[
-				"result" => "success",
-				"uuid" => $uuid,
-			]
-		);
-	}
-	catch(Exception $exception){
-		error_log("Caught exception handling request stationsRegister: ". $exception->getMessage());
-		$app->response()->status(400);
-		$app->response()->header("X-Status-Reason", $exception->getMessage());
-	}
-}
 
 $app = new \Slim\Slim
@@ -346,7 +63,10 @@
 	$app->render("setup.php");
 });
-
-$app->get("/stations", "stations");
-$app->post("/stations/register", "stationsRegister");
+$app->get("/stations", function () use ($app){
+	\SiWeather\Webservice\WebserviceApi::stations();
+});
+$app->post("/stations/register", function () use ($app){
+	\SiWeather\Webservice\WebserviceApi::stationsRegister();
+});
 
 $app->run();
Index: src/webservice/tests/SetupTest.php
===================================================================
--- src/webservice/tests/SetupTest.php	(revision 02fbeb816a6fd00276fc6f4dfc1dd966ba3dc6d5)
+++ src/webservice/tests/SetupTest.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
@@ -19,4 +19,6 @@
 */
 
+require_once(__DIR__ ."/TestHelpers/TestSetup.php");
+
 class SetupTest extends PHPUnit_Framework_TestCase
 {
@@ -31,5 +33,5 @@
 
 		require_once($testconfig["webserviceDirectory"] ."/inc/envsetup.php");
-
+		
 		self::$_webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
 		self::assertNotNull(self::$_webserviceConfig);
@@ -38,4 +40,7 @@
 		self::assertInternaltype("string", self::$_dataDirectory);
 		self::assertTrue(!empty(self::$_dataDirectory));
+		if(file_exists(self::$_dataDirectory))
+			self::assertTrue(TestHelpers\TestSetup::wipeDataDirectory());
+
 		self::assertTrue(!file_exists(self::$_dataDirectory));
 	}
@@ -43,18 +48,6 @@
 	public static function tearDownAfterClass()
 	{
-		if(!file_exists(self::$_dataDirectory)){
-			return;
-		}
-		// clear data directory (not recursive, because there should be only a database file in it
-		$content = scandir(self::$_dataDirectory);
-		self::assertInternalType("array", $content);
-		foreach($content as $file){
-			if(!in_array($file, array(".",".."))){
-				self::assertTrue(unlink(self::$_dataDirectory ."/". $file));
-			}
-		}
-		
-		// remove datadirectory
-		self::assertTrue(rmdir(self::$_dataDirectory));
+		if(file_exists(self::$_dataDirectory))
+			self::assertTrue(TestHelpers\TestSetup::wipeDataDirectory());
 	}
 
@@ -163,9 +156,9 @@
 		$this->assertLessThan($versionSpatalite, 0, $prefix ." (Could not determine Spatalite version: ". $errorMessage .")");
 		$this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
-   }
+	}
    
-   protected static $_webserviceConfig;
-   protected static $_dataDirectory;
-   protected static $_testconfig;
+	protected static $_webserviceConfig;
+	protected static $_dataDirectory;
+	protected static $_testconfig;
 }
 ?>
Index: src/webservice/tests/StationsTest.php
===================================================================
--- src/webservice/tests/StationsTest.php	(revision 02fbeb816a6fd00276fc6f4dfc1dd966ba3dc6d5)
+++ src/webservice/tests/StationsTest.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
@@ -19,7 +19,6 @@
 */
 
-/**
-	* @todo Reset database before this test is run
-	*/
+require_once(__DIR__ ."/TestHelpers/TestSetup.php");
+
 class StationsTest extends PHPUnit_Framework_TestCase
 {
@@ -37,4 +36,16 @@
 		$this->_webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
 		$this->assertNotNull($this->_webserviceConfig);
+
+		$this->_dataDirectory = $this->_webserviceConfig->getConfig("dataDirectory");
+		$this->assertInternaltype("string", $this->_dataDirectory);
+		$this->assertTrue(!empty($this->_dataDirectory));
+		if(file_exists($this->_dataDirectory))
+			$this->assertTrue(TestHelpers\TestSetup::wipeDataDirectory());
+		$this->assertTrue(TestHelpers\TestSetup::databaseSetup());
+    }
+    
+    protected function tearDown(){
+		if(file_exists($this->_dataDirectory))
+			$this->assertTrue(TestHelpers\TestSetup::wipeDataDirectory());
     }
 
@@ -44,18 +55,14 @@
 
 		$this->assertInternalType("array", $stations);
+		$message = "";
+		if(array_key_exists("message", $stations))
+			$message = $stations["message"];
+		$this->assertTrue(!array_key_exists("result", $stations), $message);
 		$this->assertEquals(count($stations), 0);
 	}
-	
-	public function testStationRewrite()
-	{
-		$stations = $this->query("stations");
 
-		$this->assertInternalType("array", $stations);
-		$this->assertEquals(count($stations), 0);
-	}
-	
 	public function testRegisterStationUnprovenLocation()
 	{
-		$baseUrl = $this->_webserviceConfig->webserviceBaseUrl();
+		$baseUrl = TestHelpers\TestSetup::webserviceTestBaseUrl();
 		$this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl);
 		$this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl);
@@ -82,5 +89,5 @@
 	public function testRegisterStation()
 	{
-		$baseUrl = $this->_webserviceConfig->webserviceBaseUrl();
+		$baseUrl = TestHelpers\TestSetup::webserviceTestBaseUrl();
 		$this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl);
 		$this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl);
@@ -94,5 +101,4 @@
 		);
 
-		// sending must failing register request, caused by unproven location
 		$response = $client->post("index.php/stations/register",
 			[ "json" => ["name" => "My Weather Station", "city" => "Clausthal-Zellerfeld", "longitude" => 10.28152, "latitude" => 51.8281, "email" => "test@example.org"]]
@@ -113,5 +119,5 @@
 	
 	protected function query($url){
-		$baseUrl = $this->_webserviceConfig->webserviceBaseUrl();
+		$baseUrl = TestHelpers\TestSetup::webserviceTestBaseUrl();
 		$this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl);
 		$this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl);
@@ -138,4 +144,5 @@
 	protected $_testconfig;
 	protected $_webserviceConfig;
+	protected $_dataDirectory;
 }
 ?>
Index: src/webservice/tests/TestHelpers/TestSetup.php
===================================================================
--- src/webservice/tests/TestHelpers/TestSetup.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
+++ src/webservice/tests/TestHelpers/TestSetup.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
@@ -0,0 +1,133 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+namespace TestHelpers;
+
+class TestSetup {
+	
+	public static function webserviceTestBaseUrl(){
+		$file = __DIR__ ."/../testconfig/testconfig.php";
+		if(!file_exists($file)){
+			error_log("testconfig file ". $file ." not found");
+			return false;
+		}
+		require($file);
+		if(is_null($testconfig)){
+			error_log("No testconfig found");
+			return false;
+		}
+		require($testconfig["webserviceDirectory"] ."/inc/envsetup.php");
+		require_once($testconfig["webserviceDirectory"] ."/SiWeather/Webservice/WebserviceConfig.php");
+		
+		$webserviceConfig = new \SiWeather\Webservice\WebserviceConfig();
+		if(is_null($webserviceConfig)){
+			error_log("No webservice config created");
+			return false;
+		}
+		return "http://localhost:9999/". $webserviceConfig->getConfig("webserviceApiVersion") ."/";
+	}
+
+	/**
+	  * @brief Configures the database of the webservice which is used for the tests.
+	  *
+	  * @note This function checks whether the webservice base url starts with localhost. If not,
+	  *       false is returned and the remote webservice is not touched. We do not touch remote
+	  *       webservices, not on localhost for testing purposes.
+	  */
+	public static function databaseSetup(){
+		$file = __DIR__ ."/../testconfig/testconfig.php";
+		if(!file_exists($file)){
+			error_log("testconfig file ". $file ." not found");
+			return false;
+		}
+		require($file);
+		if(is_null($testconfig)){
+			error_log("No testconfig found");
+			return false;
+		}
+		
+		require($testconfig["webserviceDirectory"] ."/inc/envsetup.php");
+		require_once($testconfig["webserviceDirectory"] ."/SiWeather/Webservice/WebserviceConfig.php");
+		
+		$webserviceConfig = new \SiWeather\Webservice\WebserviceConfig();
+		if(is_null($webserviceConfig)){
+			error_log("No webservice config created");
+			return false;
+		}
+
+		$webserviceBaseUrl = self::webserviceTestBaseUrl();
+		if(empty($webserviceBaseUrl) || !preg_match("/^https?:\/\/localhost/", $webserviceBaseUrl)){
+			error_log("NOT TESTING AGAINST REMOTE WEBSERVICE. INSTALL WEBSERVICE ON LOCALHOST TO TEST IT!");
+			return false;
+		}
+		
+		$client = new \GuzzleHttp\Client
+		(
+			[
+				"base_uri" => $webserviceBaseUrl,
+				"timeout" => 5.0,
+				"http_errors" => false,
+			]
+		);
+		$response = $client->get("setup.php");
+		if($response->getStatusCode() !=  200){
+			error_log("Failed to setup webservice database: ". $response->getReasonPhrase());
+			return false;
+		}
+		$body = $response->getBody();
+		if(empty($body)){
+			error_log("Failed to setup webservice database: Empty response!");
+			return false;
+		}
+		
+		if(strpos($body, "error")){
+			error_log("Failed to setup webservice database: Found error in reply (". $body .")");
+			return false;
+		}
+
+		return true;
+	}
+
+	public static function wipeDataDirectory(){
+		$webserviceConfig = new \SiWeather\Webservice\WebserviceConfig();
+		$dataDirectory = $webserviceConfig->dataDirectory();
+		if(!file_exists($dataDirectory))
+			return true;
+
+		// clear data directory (not recursive, because there should be only a database file in it
+		$content = scandir($dataDirectory);
+		if(!is_array($content)){
+			error_log("result of scandir is not an array");
+			return false;
+		}
+		foreach($content as $file){
+			if(!in_array($file, array(".",".."))){
+				$file = $dataDirectory ."/". $file;
+				if(!unlink($file)){
+					error_log("Failed to delete file ". $file);
+					return false;
+				}
+			}
+		}
+		return rmdir($dataDirectory);
+	}
+}
+
+?>
Index: src/webservice/tests/bootstrap.php
===================================================================
--- src/webservice/tests/bootstrap.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
+++ src/webservice/tests/bootstrap.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
@@ -0,0 +1,49 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+    
+    Followed the guide at http://tech.vg.no/2013/07/19/using-phps-built-in-web-server-in-your-test-suites/
+*/
+
+// Command that starts the built-in web server
+$command = sprintf(
+    'php -S %s:%d -t %s >/dev/null 2>&1 & echo $!',
+    WEB_SERVER_HOST,
+    WEB_SERVER_PORT,
+    WEB_SERVER_DOCROOT
+);
+ 
+// Execute the command and store the process ID
+$output = array(); 
+exec($command, $output);
+$pid = (int) $output[0];
+ 
+echo sprintf(
+    '%s - Web server started on %s:%d with PID %d', 
+    date('r'),
+    WEB_SERVER_HOST, 
+    WEB_SERVER_PORT, 
+    $pid
+) . PHP_EOL;
+ 
+// Kill the web server when the process ends
+register_shutdown_function(function() use ($pid) {
+    echo sprintf('%s - Killing process with ID %d', date('r'), $pid) . PHP_EOL;
+    exec('kill ' . $pid);
+});
+?>
