mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-21 21:25:38 +00:00
Test support for the SailingService added, which provides a method to
clear the state. This is necessary, since test needs a way to create a well defined state. The method is published via a Servlet. To avoid data loss, it is protected by a check of the used database. Only if the database winddbTest is used, the method call will be dispatched to the SailingService.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1 @@
|
||||
/bin
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.sap.sailing.server.gateway.test.support</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
@@ -0,0 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
pluginProject.extensions=false
|
||||
resolve.requirebundle=false
|
||||
@@ -0,0 +1,16 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Test Support
|
||||
Bundle-SymbolicName: com.sap.sailing.server.gateway.test.support
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Vendor: SAP
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Require-Bundle: javax.servlet;bundle-version="2.5.0",
|
||||
org.eclipse.osgi;bundle-version="3.7.1",
|
||||
com.sap.sailing.domain;bundle-version="1.0.0",
|
||||
com.sap.sailing.domain.common;bundle-version="1.0.0",
|
||||
com.sap.sailing.server;bundle-version="1.0.0",
|
||||
com.sap.sailing.mongodb;bundle-version="1.0.0"
|
||||
Bundle-ClassPath: .
|
||||
Web-ContextPath: /sailingserver/test-support
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<web-app version="2.5"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
|
||||
|
||||
<servlet>
|
||||
<servlet-name>ClearSateServlet</servlet-name>
|
||||
<servlet-class>com.sap.sailing.server.gateway.test.support.ClearStateServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>ClearSateServlet</servlet-name>
|
||||
<url-pattern>/clearState</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
||||
@@ -0,0 +1,5 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
WEB-INF/
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package com.sap.sailing.server.gateway.test.support;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
import org.osgi.util.tracker.ServiceTracker;
|
||||
|
||||
import com.sap.sailing.mongodb.MongoDBConfiguration;
|
||||
import com.sap.sailing.mongodb.MongoDBService;
|
||||
|
||||
import com.sap.sailing.server.test.support.RacingEventServiceWithTestSupport;
|
||||
|
||||
public class ClearStateServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = -880795218153271730L;
|
||||
|
||||
private static final String OSGI_BUNDLECONTEXT_ATTRIBUTE_NAME = "osgi-bundlecontext";
|
||||
|
||||
private static String TEST_DB_NAME = "winddbTest";
|
||||
|
||||
private ServiceTracker<RacingEventServiceWithTestSupport, RacingEventServiceWithTestSupport> racingEventTracker;
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
|
||||
ServletContext servletContext = config.getServletContext();
|
||||
BundleContext bundleContext = (BundleContext) servletContext.getAttribute(OSGI_BUNDLECONTEXT_ATTRIBUTE_NAME);
|
||||
|
||||
this.racingEventTracker = new ServiceTracker<>(bundleContext, RacingEventServiceWithTestSupport.class.getName(), null);
|
||||
this.racingEventTracker.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if(this.racingEventTracker != null) {
|
||||
this.racingEventTracker.close();
|
||||
}
|
||||
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
MongoDBConfiguration configuration = MongoDBService.INSTANCE.getConfiguration();
|
||||
String databaseName = configuration.getDatabaseName();
|
||||
|
||||
if(TEST_DB_NAME.equals(databaseName)) {
|
||||
try {
|
||||
RacingEventServiceWithTestSupport racingEventService = getRacingEventService();
|
||||
racingEventService.clearState();
|
||||
|
||||
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
|
||||
} catch (Exception exception) {
|
||||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, exception.getMessage());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Database " + databaseName + " is not the database for testing!");
|
||||
}
|
||||
|
||||
public RacingEventServiceWithTestSupport getRacingEventService() {
|
||||
return this.racingEventTracker.getService();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user