Initial Commit
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e705fa8 --- /dev/null +++ b/.gitignore
@@ -0,0 +1,15 @@ +.git +.idea/**/*.xml +.settings +.classpath +target +/.idea/compiler.xml +/.idea/*.xml +/.idea/modules.xml +/.idea/vcs.xml +/bin/ +.iml +.project +.classpath +/elogbook.iml +/.idea
diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..4d56157 --- /dev/null +++ b/pom.xml
@@ -0,0 +1,256 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>pta.de</groupId> + <artifactId>mics-home-app</artifactId> + <version>0.0.1_SNAPSHOT</version> + <packaging>war</packaging> + + <properties> + <jersey-bundle.version>1.19.3</jersey-bundle.version> + <org.json.version>20160810</org.json.version> + <jersey.server.version>1.19.3</jersey.server.version> + <gson.version>2.8.0</gson.version> + <log4j.version>1.2.17</log4j.version> + <commons-io.version>2.5</commons-io.version> + <junit.version>4.12</junit.version> + <easymock.version>3.4</easymock.version> + <powermock-api-easymock.version>1.6.6</powermock-api-easymock.version> + <powermock-module-junit4.version>1.7.3</powermock-module-junit4.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <servlet-api>2.5</servlet-api> + <maven.test.skip>false</maven.test.skip> + <jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version> + <sonar-maven-plugin.version>3.0.2</sonar-maven-plugin.version> + </properties> + <dependencies> + + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>${org.json.version}</version> + </dependency> + <dependency> + <groupId>org.jboss.resteasy</groupId> + <artifactId>resteasy-jaxrs</artifactId> + <version>3.0.21.Final</version> + </dependency> + <dependency> + <groupId>org.jboss.resteasy</groupId> + <artifactId>jaxrs-api</artifactId> + <version>3.0.12.Final</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + <version>3.0.1</version> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>${gson.version}</version> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>${log4j.version}</version> + <exclusions> + <exclusion> + <groupId>com.sun.jmx</groupId> + <artifactId>jmxri</artifactId> + </exclusion> + + <exclusion> + <groupId>com.sun.jdmk</groupId> + <artifactId>jmxtools</artifactId> + </exclusion> + + <exclusion> + <groupId>javax.jms</groupId> + <artifactId>jms</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>${commons-io.version}</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.easymock</groupId> + <artifactId>easymock</artifactId> + <version>${easymock.version}</version> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-easymock</artifactId> + <version>${powermock-api-easymock.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + <version>${powermock-module-junit4.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>${jacoco-maven-plugin.version}</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-annotations</artifactId> + <version>2.5.4</version> + </dependency> + </dependencies> + + + <build> + <finalName>${project.artifactId}</finalName> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.1</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>3.0.2</version> + <configuration> + <archive> + <manifest> + <addDefaultImplementationEntries>true</addDefaultImplementationEntries> + <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> + </manifest> + </archive> + </configuration> + </plugin> + <plugin> + <artifactId>maven-war-plugin</artifactId> + <version>2.1</version> + <configuration> + <archive> + <manifest> + <addDefaultImplementationEntries>true</addDefaultImplementationEntries> + <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> + </manifest> + </archive> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-project-info-reports-plugin</artifactId> + <version>2.7</version> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>sonar-maven-plugin</artifactId> + <version>${sonar-maven-plugin.version}</version> + </plugin> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>${jacoco-maven-plugin.version}</version> + <configuration> + <skip>${maven.test.skip}</skip> + <output>file</output> + <append>true</append> + <excludes> + <exclude>**/Globals.*</exclude> + <exclude>**/dao/**/*Dao*.java</exclude> + <exclude>**/controller/BackendController.java</exclude> + </excludes> + </configuration> + <executions> + <execution> + <id>jacoco-initialize</id> + <goals> + <goal>prepare-agent</goal> + </goals> + </execution> + <execution> + <id>jacoco-site</id> + <phase>verify</phase> + <goals> + <goal>report</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.asciidoctor</groupId> + <artifactId>asciidoctor-maven-plugin</artifactId> + <version>1.5.3</version> + <dependencies> + <dependency> + <groupId>org.asciidoctor</groupId> + <artifactId>asciidoctorj-pdf</artifactId> + <version>1.5.0-alpha.11</version> + </dependency> + <dependency> + <groupId>org.jruby</groupId> + <artifactId>jruby-complete</artifactId> + <version>1.7.21</version> + </dependency> + <dependency> + <groupId>org.asciidoctor</groupId> + <artifactId>asciidoctorj</artifactId> + <version>1.5.4</version> + </dependency> + <dependency> + <groupId>org.asciidoctor</groupId> + <artifactId>asciidoctorj-diagram</artifactId> + <version>1.5.4.1</version> + </dependency> + </dependencies> + <configuration> + <sourceDirectory>src/main/asciidoc</sourceDirectory> + <requires> + <require>asciidoctor-diagram</require> + </requires> + <attributes> + <imagesoutdir>${project.build.directory}/generated-docs/images</imagesoutdir> + <imagesDir>${project.build.directory}/generated-docs/images</imagesDir> + </attributes> + </configuration> + <executions> + <execution> + <id>output-html</id> + <phase>generate-resources</phase> + <goals> + <goal>process-asciidoc</goal> + </goals> + <configuration> + <skip>${skip.asciidoc}</skip> + <imagesDir>${project.build.directory}/generated-docs/images</imagesDir> + <requires> + <require>asciidoctor-diagram</require> + </requires> + <sourceHighlighter>coderay</sourceHighlighter> + <backend>html</backend> + <doctype>book</doctype> + <imagesDir>./images</imagesDir> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + + +</project>
diff --git a/src/main/java/de/pta/mics/home/common/BackendConfig.java b/src/main/java/de/pta/mics/home/common/BackendConfig.java new file mode 100644 index 0000000..03437c8 --- /dev/null +++ b/src/main/java/de/pta/mics/home/common/BackendConfig.java
@@ -0,0 +1,49 @@ +package de.pta.mics.home.common; + +import de.pta.mics.home.common.util.ResourceLoaderBase; + +public class BackendConfig { + + private static String configFileName = "backendConfigDevLocal.json"; + + // properties of the configfile + private String micsCentralURL; + private String micsDistributionCluster; + + private static BackendConfig instance; + + private BackendConfig() { + } + + public static synchronized BackendConfig getInstance() { + if (instance == null) { + String jsonConfig = loadJsonConfig(); + instance = JsonGeneratorBase.getGson().fromJson(jsonConfig, BackendConfig.class); + } + + return instance; + } + + private static String loadJsonConfig() { + ResourceLoaderBase resourceLoaderBase = new ResourceLoaderBase(); + return resourceLoaderBase.loadStringFromResource(configFileName); + } + + public String getMicsCentralURL() { + return micsCentralURL; + } + + public String getMicsDistributionCluster() { + return micsDistributionCluster; + } + + public static String getConfigFileName() { + return configFileName; + } + + public static void setConfigFileName(String configFileName) { + BackendConfig.configFileName = configFileName; + } +} + +
diff --git a/src/main/java/de/pta/mics/home/common/Globals.java b/src/main/java/de/pta/mics/home/common/Globals.java new file mode 100644 index 0000000..73558f3 --- /dev/null +++ b/src/main/java/de/pta/mics/home/common/Globals.java
@@ -0,0 +1,8 @@ +package de.pta.mics.home.common; + + +public final class Globals { + public static final String HEADER_JSON_UTF8 = "application/json; charset=utf-8"; + + private Globals() {} +}
diff --git a/src/main/java/de/pta/mics/home/common/GsonUTCDateAdapter.java b/src/main/java/de/pta/mics/home/common/GsonUTCDateAdapter.java new file mode 100644 index 0000000..8387bcc --- /dev/null +++ b/src/main/java/de/pta/mics/home/common/GsonUTCDateAdapter.java
@@ -0,0 +1,40 @@ +package de.pta.mics.home.common; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +public class GsonUTCDateAdapter implements JsonSerializer<Date>, JsonDeserializer<Date> { + + private final DateFormat dateFormat; + + public GsonUTCDateAdapter() { + dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); //This is the format I need + dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); //This is the key line which converts the date to UTC which cannot be accessed with the default serializer + } + + @Override + public synchronized JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) { + return new JsonPrimitive(dateFormat.format(date)); + } + + @Override + public synchronized Date deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) { + try { + return dateFormat.parse(jsonElement.getAsString()); + } catch (ParseException e) { + throw new JsonParseException(e); + } + } +} \ No newline at end of file
diff --git a/src/main/java/de/pta/mics/home/common/HttpStatusException.java b/src/main/java/de/pta/mics/home/common/HttpStatusException.java new file mode 100644 index 0000000..77cb80a --- /dev/null +++ b/src/main/java/de/pta/mics/home/common/HttpStatusException.java
@@ -0,0 +1,13 @@ +package de.pta.mics.home.common; + +public class HttpStatusException extends Exception { + private int httpStatus; + + public HttpStatusException( int httpStatus ) { + this.httpStatus = httpStatus; + } + + public int getHttpStatus() { + return httpStatus; + } +}
diff --git a/src/main/java/de/pta/mics/home/common/InitBackendConfig.java b/src/main/java/de/pta/mics/home/common/InitBackendConfig.java new file mode 100644 index 0000000..3096479 --- /dev/null +++ b/src/main/java/de/pta/mics/home/common/InitBackendConfig.java
@@ -0,0 +1,42 @@ +package de.pta.mics.home.common; + +import org.apache.log4j.Logger; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; + +public class InitBackendConfig extends HttpServlet { + + private static final long serialVersionUID = -7882117179312471533L; + + private static final Logger LOGGER = Logger.getLogger(InitBackendConfig.class.getName()); + + @Override + public void init() throws ServletException { + String environment = getServletContext().getInitParameter("OK_MICS_HOME_ENVIRONMENT"); + setConfigFiles(environment); + } + + private void setConfigFiles(String environment ) { + String env = (environment == null ? "Production": environment); + + String backendConfigFile; + + switch (env){ + case "DevLocal": + backendConfigFile="backendConfigDevLocal.json"; + break; + case "DevServer": + backendConfigFile="backendConfigDevServer.json"; + break; + case "Custom": + backendConfigFile="backendConfigCustom.json"; + break; + default: + backendConfigFile="backendConfigProduction.json"; + } + + BackendConfig.setConfigFileName(backendConfigFile); + LOGGER.info("Portal backendendenviroment is: " +environment+ ". Setting backendConfig accordingly to: "+ backendConfigFile); + } +}
diff --git a/src/main/java/de/pta/mics/home/common/JsonGeneratorBase.java b/src/main/java/de/pta/mics/home/common/JsonGeneratorBase.java new file mode 100644 index 0000000..d1cadee --- /dev/null +++ b/src/main/java/de/pta/mics/home/common/JsonGeneratorBase.java
@@ -0,0 +1,15 @@ +package de.pta.mics.home.common; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import java.util.Date; + +public class JsonGeneratorBase { + private JsonGeneratorBase() {} + public static Gson getGson() { + return new GsonBuilder() + .registerTypeAdapter(Date.class, new GsonUTCDateAdapter()) + .disableHtmlEscaping() + .create(); + } +}
diff --git a/src/main/java/de/pta/mics/home/common/NotificationStatus.java b/src/main/java/de/pta/mics/home/common/NotificationStatus.java new file mode 100644 index 0000000..7b49d2f --- /dev/null +++ b/src/main/java/de/pta/mics/home/common/NotificationStatus.java
@@ -0,0 +1,18 @@ +package de.pta.mics.home.common; + +public enum NotificationStatus { + + UNKNOWN(0, "unknown"), + OPEN(1, "open"), + INPROGRESS(2, "inprogress"), + FINISHED(3, "finished"), + CLOSED(4, "closed"); + + public final int id; + public final String statusName; + + NotificationStatus(int id, String name) { + this.id = id; + this.statusName = name; + } +}
diff --git a/src/main/java/de/pta/mics/home/common/util/LoggerUtil.java b/src/main/java/de/pta/mics/home/common/util/LoggerUtil.java new file mode 100644 index 0000000..a7c902e --- /dev/null +++ b/src/main/java/de/pta/mics/home/common/util/LoggerUtil.java
@@ -0,0 +1,71 @@ +package de.pta.mics.home.common.util; + +import java.io.IOException; +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.apache.log4j.Appender; +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Layout; +import org.apache.log4j.Level; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.net.SyslogAppender; +import org.apache.log4j.spi.RootLogger; +import org.apache.log4j.xml.DOMConfigurator; + +/** + * <b>LoggerConfig</b><br> + * Logging Implementierung + */ +public final class LoggerUtil extends HttpServlet { + /** + * serialVersionUID. + */ + private static final long serialVersionUID = 1L; + + /* + * (non-Javadoc) + * @see javax.servlet.GenericServlet#init() + */ + @Override + public void init() { + final ServletContext context = getServletContext(); + + if (Boolean.valueOf(context.getInitParameter("param.syslog.use"))) { + // configure for syslog using parameters specified in configuration descriptor + BasicConfigurator.resetConfiguration(); + + final String level = context.getInitParameter("param.syslog.level"); + RootLogger.getRootLogger().setLevel(Level.toLevel(level)); + + final String host = context.getInitParameter("param.syslog.host"); + final String facility = context.getInitParameter("param.syslog.facility"); + final Layout layout = new PatternLayout("[%d{yyyy.MM.dd HH:mm:ss}] [%p] [%c] %m%n"); + final Appender syslogAppender = new SyslogAppender(layout, host, + SyslogAppender.getFacility(facility)); + BasicConfigurator.configure(syslogAppender); + + } else { + // configure using parameters specified in xml file + final String prefix = context.getRealPath("/"); + final String file = getInitParameter("log4j-init-file"); + + if (prefix != null && file != null) { + DOMConfigurator.configure(prefix + file); + } + } + } + + /* + * (non-Javadoc) + * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + */ + @Override + protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) + throws ServletException, IOException { + // Nothing done on purpose. + } +}
diff --git a/src/main/java/de/pta/mics/home/common/util/ResourceLoaderBase.java b/src/main/java/de/pta/mics/home/common/util/ResourceLoaderBase.java new file mode 100644 index 0000000..e340198 --- /dev/null +++ b/src/main/java/de/pta/mics/home/common/util/ResourceLoaderBase.java
@@ -0,0 +1,25 @@ +package de.pta.mics.home.common.util; + +import java.io.InputStream; +import java.io.StringWriter; +import org.apache.commons.io.IOUtils; + +public class ResourceLoaderBase { + private String stream2String(InputStream is) { + StringWriter writer = new StringWriter(); + try { + IOUtils.copy(is, writer, "UTF-8"); + } catch (Exception e) { // NOSONAR + return ""; + } + return writer.toString(); + + + } + + public String loadStringFromResource(String filename) { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + InputStream jsonstream = classLoader.getResourceAsStream(filename); + return stream2String(jsonstream); + } +}
diff --git a/src/main/java/de/pta/mics/home/communication/RestServiceWrapper.java b/src/main/java/de/pta/mics/home/communication/RestServiceWrapper.java new file mode 100644 index 0000000..5094562 --- /dev/null +++ b/src/main/java/de/pta/mics/home/communication/RestServiceWrapper.java
@@ -0,0 +1,113 @@ +package de.pta.mics.home.communication; + +import de.pta.mics.home.common.HttpStatusException; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContextBuilder; +import org.apache.http.util.EntityUtils; +import org.apache.log4j.Logger; +import de.pta.mics.home.common.Globals; + + +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +public class RestServiceWrapper { + private static final Logger LOGGER = Logger.getLogger(RestServiceWrapper.class.getName()); + private String baseURL; + private boolean useHttps; + + public RestServiceWrapper(String baseURL, boolean https) { + this.baseURL = baseURL; + this.useHttps = https; + } + + public String performGetRequest(String restFunctionWithParams) throws HttpStatusException { + String completeRequest = restFunctionWithParams; + LOGGER.debug("CompleteUrl: " + completeRequest); + // create HTTP Client + CloseableHttpClient httpClient = createHttpsClient(); + + // create new Request with given URL + HttpGet getRequest = new HttpGet(completeRequest); + getRequest.addHeader("accept", Globals.HEADER_JSON_UTF8); + + HttpResponse response; + // Execute request an catch response + try { + response = httpClient.execute(getRequest); + + } catch (IOException e) { + String errtext = "Communication to <" + completeRequest + "> failed!"; + LOGGER.warn(errtext, e); + throw new HttpStatusException(HttpStatus.SC_SERVICE_UNAVAILABLE); + } + + return createJson(response); + } + + public String performPostRequest(String restFunctionWithParams, String token, String data) throws HttpStatusException { + String completeRequest = baseURL + "/" + restFunctionWithParams; + + // create HTTP Client + CloseableHttpClient httpClient = createHttpsClient(); + + // create new Post Request with given URL + HttpPost postRequest = new HttpPost(completeRequest); + + // add additional header to getRequest which accepts application/JSON data + postRequest.addHeader("accept", Globals.HEADER_JSON_UTF8); + postRequest.addHeader("Content-Type", Globals.HEADER_JSON_UTF8); + + postRequest.setEntity(new StringEntity(data, StandardCharsets.UTF_8)); + + HttpResponse response; + // Execute request an catch response + try { + response = httpClient.execute(postRequest); + } catch (IOException e) { + String errtext = "Communication to <" + completeRequest + "> failed!"; + LOGGER.warn(errtext, e); + throw new HttpStatusException(HttpStatus.SC_SERVICE_UNAVAILABLE); + } + return createJson(response); + } + + private CloseableHttpClient createHttpsClient() throws HttpStatusException { + if (useHttps) { + try { + SSLContextBuilder builder = new SSLContextBuilder(); + builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build()); + + return HttpClients.custom().setSSLSocketFactory(sslsf).build(); + } catch (Exception e) { + LOGGER.error(e); + throw new HttpStatusException(HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + } else { + return HttpClientBuilder.create().build(); + } + } + + private String createJson(HttpResponse response) throws HttpStatusException { + String retJson; + try { + retJson = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); + } catch (IOException e) { + LOGGER.error(e); + throw new HttpStatusException(HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + + return retJson; + } + +}
diff --git a/src/main/java/de/pta/mics/home/controller/BackendController.java b/src/main/java/de/pta/mics/home/controller/BackendController.java new file mode 100644 index 0000000..a8df9be --- /dev/null +++ b/src/main/java/de/pta/mics/home/controller/BackendController.java
@@ -0,0 +1,27 @@ + +package de.pta.mics.home.controller; + +import org.apache.log4j.Logger; +import de.pta.mics.home.viewmodel.VersionInfo; + +public class BackendController { + + private static final Logger LOGGER = Logger.getLogger(BackendController.class.getName()); + + public VersionInfo getVersionInfo() { + LOGGER.info("getVersionInfo is called"); + + try { + return getVersionInfoImpl(getClass().getPackage().getImplementationVersion()); + } finally { + LOGGER.info("getVersionInfo is finished"); + } + } + + private VersionInfo getVersionInfoImpl(String pomVersion) { + VersionInfo vi = new VersionInfo(); + vi.setBackendVersion(pomVersion); + + return vi; + } +}
diff --git a/src/main/java/de/pta/mics/home/controller/CentralProxy.java b/src/main/java/de/pta/mics/home/controller/CentralProxy.java new file mode 100644 index 0000000..01e8b1d --- /dev/null +++ b/src/main/java/de/pta/mics/home/controller/CentralProxy.java
@@ -0,0 +1,17 @@ +package de.pta.mics.home.controller; + +import de.pta.mics.home.common.HttpStatusException; +import de.pta.mics.home.communication.RestServiceWrapper; + +public class CentralProxy { + private final String url; + + public CentralProxy( String url ) { + this.url = url; + } + + public String getServerDistribution( String clusterName ) throws HttpStatusException { + RestServiceWrapper w = new RestServiceWrapper( url, false ); + return w.performGetRequest(url + "/serviceDistribution/" + clusterName ); + } +}
diff --git a/src/main/java/de/pta/mics/home/controller/ResponseBuilderWrapper.java b/src/main/java/de/pta/mics/home/controller/ResponseBuilderWrapper.java new file mode 100644 index 0000000..e5939d5 --- /dev/null +++ b/src/main/java/de/pta/mics/home/controller/ResponseBuilderWrapper.java
@@ -0,0 +1,43 @@ +package de.pta.mics.home.controller; + +import org.apache.http.HttpStatus; +import de.pta.mics.home.common.HttpStatusException; + + +import javax.ws.rs.core.Response; +import java.io.UnsupportedEncodingException; + +public enum ResponseBuilderWrapper { + INSTANCE; + + public Response.ResponseBuilder getResponseBuilder( String json ) throws HttpStatusException { + return getResponseBuilder(jsonStringToBytes( json )); + + } + + private Response.ResponseBuilder getResponseBuilder(byte[] json) { + return Response.status(HttpStatus.SC_OK).entity(json) + .header("Content-Type", "application/json; charset=utf-8") + .header("X-XSS-Protection", "1; mode = block") + .header("X-DNS-Prefetch-Control", "off") + .header("X-Content-Type-Options", "nosniff") + .header("X-Frame-Options", "sameorigin") + .header("Strict-Transport-Security", "max-age=15768000; includeSubDomains") + .header("Cache-Control", "no-cache; no-store; must-revalidate") + .header("Pragma", "no-cache") + .header("Expires", "0") + .header("Access-Control-Allow-Origin", "*"); + } + + private byte[] jsonStringToBytes( String jsonString ) throws HttpStatusException { + try { + return jsonString.getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new HttpStatusException(HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + } + + public Response buildOKResponse(String jsonString) throws HttpStatusException { + return getResponseBuilder( jsonStringToBytes( jsonString)).build(); + } +}
diff --git a/src/main/java/de/pta/mics/home/rest/BackendRestService.java b/src/main/java/de/pta/mics/home/rest/BackendRestService.java new file mode 100644 index 0000000..fbd7989 --- /dev/null +++ b/src/main/java/de/pta/mics/home/rest/BackendRestService.java
@@ -0,0 +1,54 @@ +package de.pta.mics.home.rest; + +import de.pta.mics.home.controller.BackendController; +import de.pta.mics.home.controller.CentralProxy; +import de.pta.mics.home.controller.ResponseBuilderWrapper; +import org.apache.http.HttpStatus; +import org.apache.log4j.Logger; +import de.pta.mics.home.common.BackendConfig; +import de.pta.mics.home.common.HttpStatusException; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; + + +@Path("/mics/home") +public class BackendRestService { + private static final Logger logger = Logger.getLogger(BackendRestService.class.getName()); + + @GET + @Path("/versionInfo/") + @Produces("application/json") + public Response getVersionInfo() { + return Response.ok(new BackendController().getVersionInfo()).build(); + } + + @GET + @Path("/myServerDistribution/") + @Produces("application/json") + public Response getMyServerDistribution() { + try { + BackendConfig bc = BackendConfig.getInstance(); + CentralProxy central = new CentralProxy(bc.getMicsCentralURL()); + return ResponseBuilderWrapper.INSTANCE.buildOKResponse( + central.getServerDistribution(bc.getMicsDistributionCluster())); + } + catch (Exception e) { + return responseFromException(e); + } + } + + + private Response responseFromException(Exception e) { + int errcode; + String retJson; + + if (e instanceof HttpStatusException) { + logger.error("Caught BackendException", e); + errcode = ((HttpStatusException) e).getHttpStatus(); + return Response.status(errcode).build(); + } else { + logger.error("Unexpected exception", e); + return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).build(); + } + } +}
diff --git a/src/main/java/de/pta/mics/home/rest/RestServiceConfiguration.java b/src/main/java/de/pta/mics/home/rest/RestServiceConfiguration.java new file mode 100644 index 0000000..1c4493d --- /dev/null +++ b/src/main/java/de/pta/mics/home/rest/RestServiceConfiguration.java
@@ -0,0 +1,18 @@ +package de.pta.mics.home.rest; + + +import java.util.HashSet; +import java.util.Set; + +public class RestServiceConfiguration extends javax.ws.rs.core.Application { + public RestServiceConfiguration() { + // Standard Contstructor needed + } + + @Override + public Set<Class<?>> getClasses() { + Set<Class<?>> restServicesClasses = new HashSet<>(); + restServicesClasses.add(BackendRestService.class); + return restServicesClasses; + } +}
diff --git a/src/main/java/de/pta/mics/home/viewmodel/ErrorReturn.java b/src/main/java/de/pta/mics/home/viewmodel/ErrorReturn.java new file mode 100644 index 0000000..5965878 --- /dev/null +++ b/src/main/java/de/pta/mics/home/viewmodel/ErrorReturn.java
@@ -0,0 +1,23 @@ +package de.pta.mics.home.viewmodel; + +import java.io.Serializable; + +public class ErrorReturn implements Serializable { + private static final long serialVersionUID = -1841112315318005840L; + + private String errorText; + private int errorCode; + + public String getErrorText() { + return errorText; + } + public void setErrorText(String errorText) { + this.errorText = errorText; + } + public int getErrorCode() { + return errorCode; + } + public void setErrorCode(int errorCode) { + this.errorCode = errorCode; + } +}
diff --git a/src/main/java/de/pta/mics/home/viewmodel/VersionInfo.java b/src/main/java/de/pta/mics/home/viewmodel/VersionInfo.java new file mode 100644 index 0000000..9bf4324 --- /dev/null +++ b/src/main/java/de/pta/mics/home/viewmodel/VersionInfo.java
@@ -0,0 +1,23 @@ +package de.pta.mics.home.viewmodel; + +public class VersionInfo { + private String dbVersion; + private String backendVersion; + + public String getBackendVersion() { + return backendVersion; + } + + public void setBackendVersion(String backendVersion) { + this.backendVersion = backendVersion; + } + + public String getDbVersion() { + return dbVersion; + } + + public void setDbVersion(String dbVersion) { + this.dbVersion = dbVersion; + } + +}
diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..57c51be --- /dev/null +++ b/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> + <persistence-unit name="betriebstagebuch"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <non-jta-data-source>java:comp/env/jdbc/okBetriebstagebuchDS</non-jta-data-source> + <class>org.eclipse.openk.elogbook.persistence.model.RefVersion</class> + <class>org.eclipse.openk.elogbook.persistence.model.RefBranch</class> + <class>org.eclipse.openk.elogbook.persistence.model.RefGridTerritory</class> + <class>org.eclipse.openk.elogbook.persistence.model.RefNotificationStatus</class> + <class>org.eclipse.openk.elogbook.persistence.model.TblNotification</class> + <class>org.eclipse.openk.elogbook.persistence.model.TblResponsibility</class> + <exclude-unlisted-classes>false</exclude-unlisted-classes> + <properties> + </properties> + </persistence-unit> + <persistence-unit name="betriebstagebuchORA"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <non-jta-data-source>java:comp/env/jdbc/okBetriebstagebuchDSO</non-jta-data-source> + <class>org.eclipse.openk.elogbook.persistence.model.RefVersion</class> + <class>org.eclipse.openk.elogbook.persistence.model.RefBranch</class> + <class>org.eclipse.openk.elogbook.persistence.model.RefGridTerritory</class> + <class>org.eclipse.openk.elogbook.persistence.model.RefNotificationStatus</class> + <class>org.eclipse.openk.elogbook.persistence.model.TblNotification</class> + <class>org.eclipse.openk.elogbook.persistence.model.TblResponsibility</class> + <exclude-unlisted-classes>false</exclude-unlisted-classes> + <properties> + <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" /> + <property name="eclipselink.target-database" value="Oracle"/> + </properties> + </persistence-unit> +</persistence>
diff --git a/src/main/resources/backendConfigCustom.json b/src/main/resources/backendConfigCustom.json new file mode 100644 index 0000000..3205e0c --- /dev/null +++ b/src/main/resources/backendConfigCustom.json
@@ -0,0 +1,4 @@ +{ + "micsDistributionCluster" : "elogbook.openK", + "micsCentralURL" : "http://localhost:9500/mics/central/serviceDistribution" +}
diff --git a/src/main/resources/backendConfigDevLocal.json b/src/main/resources/backendConfigDevLocal.json new file mode 100644 index 0000000..79f7aea --- /dev/null +++ b/src/main/resources/backendConfigDevLocal.json
@@ -0,0 +1,4 @@ +{ + "micsDistributionCluster" : "elogbook.openK", + "micsCentralURL" : "http://localhost:9010/mics/central" +}
diff --git a/src/main/resources/backendConfigDevServer.json b/src/main/resources/backendConfigDevServer.json new file mode 100644 index 0000000..d147326 --- /dev/null +++ b/src/main/resources/backendConfigDevServer.json
@@ -0,0 +1,5 @@ +{ + "micsDistributionCluster" : "elogbook.openK", + "micsCentralURL" : "http://localhost:9500/mics/central" + +}
diff --git a/src/main/resources/backendConfigProduction.json b/src/main/resources/backendConfigProduction.json new file mode 100644 index 0000000..0b8e5bf --- /dev/null +++ b/src/main/resources/backendConfigProduction.json
@@ -0,0 +1,4 @@ +{ + "micsDistributionCluster" : "elogbook.openK", + "micsCentralURL" : "http://localhost:9500/mics/central" +} \ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/logger.xml b/src/main/webapp/WEB-INF/logger.xml new file mode 100644 index 0000000..58a1c22 --- /dev/null +++ b/src/main/webapp/WEB-INF/logger.xml
@@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE log4j:configuration PUBLIC + "-//APACHE//DTD LOG4J 1.2//EN" + "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd"> +<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> + + <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> + <param name="Threshold" value="DEBUG"/> + <param name="Target" value="System.out"/> + <layout class="org.apache.log4j.PatternLayout"> + <param name="ConversionPattern" value="[%d{yyyy.MM.dd HH:mm:ss}] [%p] [%c] %m%n"/> + </layout> + </appender> + + <appender name="Socket" class="org.apache.log4j.net.SocketAppender"> + <param name="remoteHost" value="127.0.0.1"/> + <param name="port" value="4560"/> + <layout class="org.apache.log4j.PatternLayout"> + <param name="ConversionPattern" value="[%d{yyyy.MM.dd HH:mm:ss}] [%p] [%c] %m%n"/> + </layout> + </appender> + + <!-- Issue: das Verzeichnis muss existieren ... --> + <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender"> + <param name="Threshold" value="TRACE"/> + <param name="File" value="${catalina.base}/logs/betriebstagebuch.backend.log"/> + <param name="Append" value="true"/> + <param name="DatePattern" value="'.'yyyy-MM-dd"/> + <layout class="org.apache.log4j.PatternLayout"> + <param name="ConversionPattern" value="[%d{yyyy.MM.dd HH:mm:ss}] [%p] [%c] %m%n"/> + </layout> + </appender> + + <!-- Default Logging configuration beginnend mit org.eclipse (= alle Packages) --> + <category name="org.eclipse"> + <priority value="INFO"/> + <!--<priority value="DEBUG"/> --> + <!--<priority value="ERROR"/> --> + <appender-ref ref="CONSOLE"/> + <!--<appender-ref ref="Socket"/> --> + <!--<appender-ref ref="FILE"/> --> + <!--<appender-ref ref="SYSLOG"/> --> + <appender-ref ref="FILE"/> + </category> + <category name="org.jboss.resteasy"> + <priority value="WARN"/> + <!--<priority value="DEBUG"/> --> + <!--<priority value="ERROR"/> --> + <appender-ref ref="CONSOLE"/> + <!--<appender-ref ref="Socket"/> --> + <!--<appender-ref ref="FILE"/> --> + <!--<appender-ref ref="SYSLOG"/> --> + <appender-ref ref="FILE"/> + </category> + <category name="javax.persistence.Persistence"> + <priority value="INFO"/> + <!--<priority value="DEBUG"/> --> + <!--<priority value="ERROR"/> --> + <appender-ref ref="CONSOLE"/> + <!--<appender-ref ref="Socket"/> --> + <!--<appender-ref ref="FILE"/> --> + <!--<appender-ref ref="SYSLOG"/> --> + <appender-ref ref="FILE"/> + </category> + +</log4j:configuration> \ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..3fd3172 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,55 @@ +<web-app id="WebApp_ID" version="2.4" + xmlns="http://java.sun.com/xml/ns/j2ee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee + http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> + <display-name>Restful Web Application</display-name> + + <context-param> + <param-name>resteasy.servlet.mapping.prefix</param-name> + <param-value>/rest</param-value> + </context-param> + + <context-param> + <param-name>resteasy.scan</param-name> + <param-value>false</param-value> + </context-param> + + <listener> + <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class> + </listener> + + <servlet> + <servlet-name>Resteasy</servlet-name> + <servlet-class> + org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher + </servlet-class> + <init-param> + <param-name>javax.ws.rs.Application</param-name> + <param-value>de.pta.mics.home.rest.RestServiceConfiguration</param-value> + </init-param> + </servlet> + + <servlet-mapping> + <servlet-name>Resteasy</servlet-name> + <url-pattern>/rest/*</url-pattern> + </servlet-mapping> + + <servlet> + <servlet-name>log4j-init</servlet-name> + <servlet-class>de.pta.mics.home.common.util.LoggerUtil</servlet-class> + <init-param> + <param-name>log4j-init-file</param-name> + <param-value>WEB-INF/logger.xml</param-value> + </init-param> + <load-on-startup>0</load-on-startup> + </servlet> + + <servlet> + <servlet-name>InitBackendConfig</servlet-name> + <servlet-class>de.pta.mics.home.common.InitBackendConfig</servlet-class> + <load-on-startup>2</load-on-startup> + </servlet> + + +</web-app>
diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html new file mode 100644 index 0000000..97b5341 --- /dev/null +++ b/src/main/webapp/index.html
@@ -0,0 +1,10 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="UTF-8"> +<title>Insert title here</title> +</head> +<body> +it works! +</body> +</html> \ No newline at end of file
diff --git a/src/test/java/de/pta/mics/home/common/BackendConfigTest.java b/src/test/java/de/pta/mics/home/common/BackendConfigTest.java new file mode 100644 index 0000000..e076785 --- /dev/null +++ b/src/test/java/de/pta/mics/home/common/BackendConfigTest.java
@@ -0,0 +1,17 @@ +package de.pta.mics.home.common; + + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class BackendConfigTest { + @Test + public void testConfig() { + BackendConfig bc = BackendConfig.getInstance(); + assertEquals( bc.getMicsCentralURL(), "http://localhost:9010/mics/central" ); + assertEquals( bc.getMicsDistributionCluster(), "elogbook.openK"); + BackendConfig.setConfigFileName("backendConfigProduction.json"); + assertEquals( BackendConfig.getConfigFileName(), "backendConfigProduction.json"); + } +}
diff --git a/src/test/java/de/pta/mics/home/common/HttpStatusExceptionTest.java b/src/test/java/de/pta/mics/home/common/HttpStatusExceptionTest.java new file mode 100644 index 0000000..141c721 --- /dev/null +++ b/src/test/java/de/pta/mics/home/common/HttpStatusExceptionTest.java
@@ -0,0 +1,14 @@ +package de.pta.mics.home.common; + +import org.apache.http.HttpStatus; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class HttpStatusExceptionTest { + @Test + public void testAll() { + HttpStatusException hse = new HttpStatusException( 200 ); + assertEquals( hse.getHttpStatus(), HttpStatus.SC_OK ); + } +}
diff --git a/src/test/java/de/pta/mics/home/common/InitBackendConfigTest.java b/src/test/java/de/pta/mics/home/common/InitBackendConfigTest.java new file mode 100644 index 0000000..e8c72ba --- /dev/null +++ b/src/test/java/de/pta/mics/home/common/InitBackendConfigTest.java
@@ -0,0 +1,38 @@ +package de.pta.mics.home.common; + +import org.junit.Test; +import org.powermock.reflect.Whitebox; + +public class InitBackendConfigTest { + + private InitBackendConfig initBackendConfig = new InitBackendConfig(); + + @Test + public void testSetConfigFiles() throws Exception { + Whitebox.invokeMethod(initBackendConfig, "setConfigFiles", "DevLocal"); + } + + private void testGeneric(String environment ) throws Exception { + Whitebox.invokeMethod(initBackendConfig, "setConfigFiles", environment); + } + + @Test + public void testCombinations() throws Exception { + + testGeneric("DevLocal"); + testGeneric("DevLocal"); + + testGeneric("DevServer"); + testGeneric("DevServer"); + + testGeneric("Custom"); + testGeneric("Custom"); + + testGeneric(null); + testGeneric(null); + + testGeneric(""); + testGeneric(""); + +} +}
diff --git a/src/test/java/de/pta/mics/home/common/NotificationStatusTest.java b/src/test/java/de/pta/mics/home/common/NotificationStatusTest.java new file mode 100644 index 0000000..5ecf746 --- /dev/null +++ b/src/test/java/de/pta/mics/home/common/NotificationStatusTest.java
@@ -0,0 +1,20 @@ +package de.pta.mics.home.common; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class NotificationStatusTest { + + @Test + public void createNotificationStatus() throws Exception { + + assertEquals(0, NotificationStatus.UNKNOWN.id); + assertEquals(1, NotificationStatus.OPEN.id); + assertEquals(2, NotificationStatus.INPROGRESS.id); + assertEquals(3, NotificationStatus.FINISHED.id); + assertEquals(4, NotificationStatus.CLOSED.id); + + } + +}
diff --git a/src/test/java/de/pta/mics/home/common/util/ResourceLoaderBaseTest.java b/src/test/java/de/pta/mics/home/common/util/ResourceLoaderBaseTest.java new file mode 100644 index 0000000..e555d7a --- /dev/null +++ b/src/test/java/de/pta/mics/home/common/util/ResourceLoaderBaseTest.java
@@ -0,0 +1,15 @@ +package de.pta.mics.home.common.util; + + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ResourceLoaderBaseTest { + @Test + public void testloadStringFromResourceError() { + ResourceLoaderBase rlb = new ResourceLoaderBase(); + String str = rlb.loadStringFromResource("UNKNOWN_FILE"); + assertEquals(str, ""); + } +}
diff --git a/src/test/java/de/pta/mics/home/controller/ResponseBuilderWrapperTest.java b/src/test/java/de/pta/mics/home/controller/ResponseBuilderWrapperTest.java new file mode 100644 index 0000000..53b4652 --- /dev/null +++ b/src/test/java/de/pta/mics/home/controller/ResponseBuilderWrapperTest.java
@@ -0,0 +1,29 @@ +package de.pta.mics.home.controller; + + +import org.apache.http.HttpStatus; +import de.pta.mics.home.common.HttpStatusException; +import org.junit.Test; + +import javax.ws.rs.core.Response; + +import static org.junit.Assert.assertEquals; + + +public class ResponseBuilderWrapperTest { + @Test + public void testGetResponseBuilder() throws HttpStatusException { + String json = "{ 'ret' : 'OK' }"; + Response.ResponseBuilder rb = ResponseBuilderWrapper.INSTANCE.getResponseBuilder( json ); + Response resp = rb.build(); + assertEquals(resp.getStatus(), HttpStatus.SC_OK ); + } + + @Test + public void testBuildOkResponse() throws HttpStatusException { + String json = "{ 'test' : 'Value' }"; + Response resp = ResponseBuilderWrapper.INSTANCE.buildOKResponse( json ); + assertEquals( resp.getStatus(), HttpStatus.SC_OK ); + + } +}
diff --git a/src/test/java/de/pta/mics/home/viewmodel/ErrorReturnTest.java b/src/test/java/de/pta/mics/home/viewmodel/ErrorReturnTest.java new file mode 100644 index 0000000..31f5f77 --- /dev/null +++ b/src/test/java/de/pta/mics/home/viewmodel/ErrorReturnTest.java
@@ -0,0 +1,30 @@ +package de.pta.mics.home.viewmodel; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import de.pta.mics.home.common.JsonGeneratorBase; +import de.pta.mics.home.common.util.ResourceLoaderBase; +import org.junit.Test; + +public class ErrorReturnTest extends ResourceLoaderBase { + // IMPORTANT TEST!!! + // Make sure, our Interface produces a DEFINED Json! + // Changes in the interface will HOPEFULLY crash here!!! + + @Test + public void TestStructureAgainstJson() { + String json = super.loadStringFromResource("testErrorReturn.json"); + ErrorReturn errRet = JsonGeneratorBase.getGson().fromJson(json, ErrorReturn.class); + assertFalse(errRet.getErrorText().isEmpty()); + assertEquals(errRet.getErrorCode(), 999); + } + + @Test + public void TestSetters() { + ErrorReturn errRet = new ErrorReturn(); + errRet.setErrorCode(1); + errRet.setErrorText("bla bla"); + } + +}
diff --git a/src/test/java/de/pta/mics/home/viewmodel/VersionInfoTest.java b/src/test/java/de/pta/mics/home/viewmodel/VersionInfoTest.java new file mode 100644 index 0000000..16eee61 --- /dev/null +++ b/src/test/java/de/pta/mics/home/viewmodel/VersionInfoTest.java
@@ -0,0 +1,29 @@ +package de.pta.mics.home.viewmodel; + + +import static org.junit.Assert.assertTrue; + +import de.pta.mics.home.common.JsonGeneratorBase; +import de.pta.mics.home.common.util.ResourceLoaderBase; +import org.junit.Test; + +public class VersionInfoTest extends ResourceLoaderBase { + // IMPORTANT TEST!!! + // Make sure, our Interface produces a DEFINED Json! + // Changes in the interface will HOPEFULLY crash here!!! + + @Test + public void testStructureAgainstJson() { + String json = super.loadStringFromResource("VersionInfo.json"); + VersionInfo vi = JsonGeneratorBase.getGson().fromJson(json, VersionInfo.class); + + assertTrue(vi.getBackendVersion().equals("0x.0x.xx")); + } + + @Test + public void testSetters() { + VersionInfo vi = new VersionInfo(); + vi.setBackendVersion("222"); + } + +}
diff --git a/src/test/resources/VersionInfo.json b/src/test/resources/VersionInfo.json new file mode 100644 index 0000000..35510d9 --- /dev/null +++ b/src/test/resources/VersionInfo.json
@@ -0,0 +1,3 @@ +{ + "backendVersion": "0x.0x.xx" +} \ No newline at end of file
diff --git a/src/test/resources/testErrorReturn.json b/src/test/resources/testErrorReturn.json new file mode 100644 index 0000000..f5540af --- /dev/null +++ b/src/test/resources/testErrorReturn.json
@@ -0,0 +1,4 @@ +{ + "errorText": "TESTAT", + "errorCode": 999 +}