mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 01:31:01 +00:00
moved settings serialization from com.sap.sse.common to com.sap.sse; created new test fragment com.sap.sse.test which now hosts the settings serializer test case
This commit is contained in:
1 parent
4ab6d069f3
commit
8ca4f5e8b5
11 files changed
+84
-7
No files matched your search
Executable
+7
@@ -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.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.sap.sse.test</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.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
@@ -0,0 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
pluginProject.extensions=false
|
||||
resolve.requirebundle=false
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: SSE Test
|
||||
Bundle-SymbolicName: com.sap.sse.test
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Vendor: SAP
|
||||
Fragment-Host: com.sap.sse
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Require-Bundle: org.junit4;bundle-version="4.8.2"
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>root</artifactId>
|
||||
<groupId>com.sap.sailing</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>com.sap.sse.test</artifactId>
|
||||
<packaging>eclipse-test-plugin</packaging>
|
||||
</project>
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package com.sap.sse.common.settings;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sse.common.filter.TextOperator;
|
||||
import com.sap.sse.common.filter.TextOperator.Operators;
|
||||
import com.sap.sse.settings.SettingsToJsonSerializer;
|
||||
|
||||
public class SettingsJsonSerializationTest {
|
||||
@Test
|
||||
public void testFlatJsonSerialization() throws ClassNotFoundException {
|
||||
final Map<String, Setting> settingsMap = new HashMap<>();
|
||||
settingsMap.put("humba", new StringSetting("trala"));
|
||||
settingsMap.put("trala", new EnumSetting<>(TextOperator.Operators.Contains));
|
||||
settingsMap.put("num", new NumberSetting(BigDecimal.TEN));
|
||||
settingsMap.put("l", new ListSetting<NumberSetting>(Arrays.asList(new NumberSetting(1), new NumberSetting(2), new NumberSetting(3))));
|
||||
Settings settings = new MapSettings(settingsMap);
|
||||
SettingsToJsonSerializer serializer = new SettingsToJsonSerializer();
|
||||
JSONObject json = serializer.serialize(settings);
|
||||
Settings deserializedSettings = serializer.deserialize(json);
|
||||
assertEquals(settingsMap, deserializedSettings.getNonDefaultSettings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedJsonSerialization() throws ClassNotFoundException {
|
||||
final Map<String, Setting> settingsMap = new HashMap<>();
|
||||
final Map<String, Setting> innerMap = new HashMap<>();
|
||||
settingsMap.put("humba", new StringSetting("trala"));
|
||||
innerMap.put("num", new NumberSetting(123.4));
|
||||
settingsMap.put("map", new MapSettings(innerMap));
|
||||
Settings settings = new MapSettings(settingsMap);
|
||||
SettingsToJsonSerializer serializer = new SettingsToJsonSerializer();
|
||||
JSONObject json = serializer.serialize(settings);
|
||||
Settings deserializedSettings = serializer.deserialize(json);
|
||||
assertEquals(settingsMap, deserializedSettings.getNonDefaultSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* A white-box test that tests property name escaping in case the property name conflicts with how type
|
||||
* names (used particularly for enum settings) are represented in JSON.
|
||||
*/
|
||||
@Test
|
||||
public void testJsonSerializationWithFunnyPropertyName() throws ClassNotFoundException {
|
||||
final Map<String, Setting> settingsMap = new HashMap<>();
|
||||
settingsMap.put("humba___TYPE", new StringSetting("trala"));
|
||||
settingsMap.put("trala___TYPE___TYPE", new EnumSetting<>(TextOperator.Operators.Contains));
|
||||
Settings settings = new MapSettings(settingsMap);
|
||||
SettingsToJsonSerializer serializer = new SettingsToJsonSerializer();
|
||||
JSONObject json = serializer.serialize(settings);
|
||||
Settings deserializedSettings = serializer.deserialize(json);
|
||||
assertEquals(settingsMap, deserializedSettings.getNonDefaultSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* A white-box test that tests property name escaping in case the property name conflicts with how type
|
||||
* names (used particularly for enum settings) are represented in JSON.
|
||||
*/
|
||||
@Test
|
||||
public void testJsonSerializationWithEnumTypedList() throws ClassNotFoundException {
|
||||
final Map<String, Setting> settingsMap = new HashMap<>();
|
||||
final List<EnumSetting<TextOperator.Operators>> list = new ArrayList<>();
|
||||
list.add(new EnumSetting<Operators>(Operators.Contains));
|
||||
list.add(new EnumSetting<Operators>(Operators.EndsWith));
|
||||
settingsMap.put("l", new ListSetting<EnumSetting<TextOperator.Operators>>(list));
|
||||
Settings settings = new MapSettings(settingsMap);
|
||||
SettingsToJsonSerializer serializer = new SettingsToJsonSerializer();
|
||||
JSONObject json = serializer.serialize(settings);
|
||||
Settings deserializedSettings = serializer.deserialize(json);
|
||||
assertEquals(settingsMap, deserializedSettings.getNonDefaultSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* A white-box test that tests property name escaping in case the property name conflicts with how type
|
||||
* names (used particularly for enum settings) are represented in JSON.
|
||||
*/
|
||||
@Test
|
||||
public void testJsonSerializationWithStringifiedEnum() throws ClassNotFoundException {
|
||||
final Map<String, Setting> settingsMap = new HashMap<>();
|
||||
final List<StringSetting> list = new ArrayList<>();
|
||||
list.add(new StringSetting(Operators.Contains));
|
||||
list.add(new StringSetting(Operators.EndsWith));
|
||||
settingsMap.put("l", new ListSetting<StringSetting>(list));
|
||||
Settings settings = new MapSettings(settingsMap);
|
||||
SettingsToJsonSerializer serializer = new SettingsToJsonSerializer();
|
||||
JSONObject json = serializer.serialize(settings);
|
||||
Settings deserializedSettings = serializer.deserialize(json);
|
||||
ListSetting<?> l = (ListSetting<?>) deserializedSettings.getNonDefaultSettings().get("l");
|
||||
assertEquals(Arrays.asList(Operators.Contains, Operators.EndsWith), l.getEnumList(Operators.class));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user