Skip to content

Commit

Permalink
Merge pull request #1248 from virtualsatellite/feature/task_1246-Rest…
Browse files Browse the repository at this point in the history
…APi_should_repor

Server API can now access values based on Base Units (usually SI)
  • Loading branch information
PhilMFischer authored Dec 6, 2024
2 parents 1b995c6 + 8aba885 commit 1eeb3a2
Show file tree
Hide file tree
Showing 50 changed files with 777 additions and 237 deletions.
3 changes: 2 additions & 1 deletion de.dlr.sc.virsat.model.concept.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Require-Bundle: de.dlr.sc.virsat.external.lib.apache.poi,
org.eclipse.xtext.testing,
org.eclipse.xtext.xbase.lib,
org.eclipse.xtext.xbase.testing,
org.eclipse.xtext.ecore
org.eclipse.xtext.ecore,
de.dlr.sc.virsat.test.utils
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: de.dlr.sc.virsat.model.concept,
de.dlr.sc.virsat.model.concept.test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
package de.dlr.sc.virsat.model.concept.test.util;

import java.io.IOException;
import java.io.PrintWriter;
import org.junit.Assert;
import de.dlr.sc.virsat.model.concept.test.TestActivator;
import de.dlr.sc.virsat.test.utils.TestUtil;

/**
* Some special Assert Statements to check the code generators with
* reference content stored in the plugin/ test fragment resources
* @author fisc_ph
*
*/
public class GeneratorJunitAssert {

Expand All @@ -28,42 +25,16 @@ public class GeneratorJunitAssert {
private GeneratorJunitAssert() {
}

/**
* Set this flag to output the actual content to the console
*/

private static final String ENV_VARIABLE_FLUSH_ACTUAL = "flushActualGeneratorFiles";
private static final String ENV_VARIABLE_FLUSH_ACTUAL_TRUE = "true";
private static final String ENV_VARIABLE_FLUSH_PATH = "flushActualPath";


/**
* Method to check content against a reference from the resources folder
* @param actual the current content as string
* @param expectedFilePath the path to the file containing the expected content
* @throws IOException in case the expected content file could not be read
*/
public static void assertEqualContent(String actual, String expectedFilePath) throws IOException {

if (ENV_VARIABLE_FLUSH_ACTUAL_TRUE.equalsIgnoreCase(System.getenv(ENV_VARIABLE_FLUSH_ACTUAL))) {
String fileName = System.getenv(ENV_VARIABLE_FLUSH_PATH) + expectedFilePath.substring(expectedFilePath.lastIndexOf('/'), expectedFilePath.length());

PrintWriter writer = new PrintWriter(fileName, "UTF-8");
writer.println(actual);
writer.close();
return;
}

String expectedString = TestActivator.getResourceContentAsString(expectedFilePath);
String expectedNoWs = expectedString.replaceAll("\\s+", "");
String actualNoWs = actual.replaceAll("\\s+", "");

if (!expectedNoWs.equals(actualNoWs)) {
Assert.assertEquals("File content for " + expectedFilePath + " is correct", expectedString, actual);
}
TestUtil.assertEqualContent(actual, TestActivator.FRAGMENT_ID, expectedFilePath);
}


/**
* Method to check content against a reference from the resources folder
* @param actual the current content as CharSequence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ public Double getValue() {
}
}

@XmlJavaTypeAdapter(DoubleAdapter.class)
@XmlElement(nillable = true)
@Schema(description = "Double")
/**
* Convenience Method to directly convert the value to its base unit
* @return the value in its base unit
*/
public Double getValueInBaseUnit() {
if (ti.getValue() == null) {
return Double.NaN;
} else {
return getValueToBaseUnit();
}
}

/**
* Convenience method to easily set a value in the frame of base unit and have it
* converted to the currently set unit.
* @param inputValue the value to be set in base unit frame
*/
public void setValueInBaseUnit(Double inputValue) {
if (inputValue != null) {
setValueAsBaseUnit(inputValue);
}
}

/**
* Convenience Method to directly convert the value to its base unit
* @return the value in its base unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package de.dlr.sc.virsat.model.concept.types.property;

import jakarta.xml.bind.annotation.XmlElement;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
Expand Down Expand Up @@ -65,6 +64,49 @@ public Long getValue() throws NumberFormatException {
return null;
}


@XmlElement(nillable = true)
@Schema(description = "Long")
/**
* Convenience Method to directly convert the value to its base unit
* @return the value in its base unit
*/
public Long getValueInBaseUnit() {
if (ti.getValue() == null) {
return null;
} else {
return getValueToBaseUnit();
}
}

/**
* Convenience method to easily set a value in the frame of base unit and have it
* converted to the currently set unit.
* @param inputValue the value to be set in base unit frame
*/
public void setValueInBaseUnit(Long inputValue) {
if (inputValue != null) {
setValueAsBaseUnit(inputValue);
}
}

/**
* Convenience Method to directly convert the value to its base unit
* @return the value in its base unit
*/
public Long getValueToBaseUnit() {
return Double.valueOf(ti.getValueToBaseUnit()).longValue();
}

/**
* Convenience method to easily set a value in the frame of base unit and have it
* converted to the currently set unit.
* @param inputValue the value to be set in base unit frame
*/
public void setValueAsBaseUnit(Long inputValue) {
ti.setValueAsBaseUnit(inputValue);
}

@Schema(
description = "Always returns constant: \"int\"",
example = "int",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Require-Bundle: org.junit,
de.dlr.sc.virsat.model.ext.core,
de.dlr.sc.virsat.external.lib.matlabfile,
de.dlr.sc.virsat.build,
org.hamcrest.library
org.hamcrest.library,
de.dlr.sc.virsat.test.utils
Export-Package: de.dlr.sc.virsat.model.extension.tests.test
Automatic-Module-Name: de.dlr.sc.virsat.model.extension.tests.test
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
"propertyType" : "float",
"override" : false,
"unitBean" : "e2203b42-e703-4429-9bf9-dbd4882c341c",
"value" : 0.0
"value" : 0.0,
"valueInBaseUnit" : 0.0
},
"testIntBean" : {
"uuid" : "0f37aff6-ccc0-436f-a592-bd466f74bd80",
"isCalculated" : false,
"propertyType" : "int",
"override" : false,
"unitBean" : "e2203b42-e703-4429-9bf9-dbd4882c341c",
"value" : 1
"value" : 1,
"valueInBaseUnit" : 1000
},
"testResourceBean" : {
"uuid" : "fa822159-51a5-4bf2-99cf-e565b67e0eb0",
Expand All @@ -47,4 +49,4 @@
"override" : false,
"value" : "this is a test"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
"propertyType" : "float",
"override" : false,
"unitBean" : null,
"value" : null
"value" : null,
"valueInBaseUnit" : null
},
"testIntBean" : {
"uuid" : "0f37aff6-ccc0-436f-a592-bd466f74bd80",
"isCalculated" : false,
"propertyType" : "int",
"override" : false,
"unitBean" : null,
"value" : null
"value" : null,
"valueInBaseUnit" : null
},
"testResourceBean" : {
"uuid" : "fa822159-51a5-4bf2-99cf-e565b67e0eb0",
Expand All @@ -47,4 +49,4 @@
"override" : false,
"value" : null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"type" : "de.dlr.sc.virsat.model.extension.tests.TestCategoryBeanA",
"uuid" : "f34d30b0-80f5-4c96-864f-29ab4d3ae9f2",
"name" : "TestCategoryBeanA"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@
"propertyType" : "float",
"override" : false,
"unitBean" : null,
"value" : null
"value" : null,
"valueInBaseUnit" : null
},
"testIntBean" : {
"uuid" : "0f37aff6-ccc0-436f-a592-bd466f74bd84",
"isCalculated" : false,
"propertyType" : "int",
"override" : false,
"unitBean" : null,
"value" : null
"value" : null,
"valueInBaseUnit" : null
},
"testResourceBean" : {
"uuid" : "fa822159-51a5-4bf2-99cf-e565b67e0eb4",
Expand Down Expand Up @@ -86,15 +88,17 @@
"propertyType" : "float",
"override" : false,
"unitBean" : null,
"value" : null
"value" : null,
"valueInBaseUnit" : null
},
"testIntBean" : {
"uuid" : "0f37aff6-ccc0-436f-a592-bd466f74bd80",
"isCalculated" : false,
"propertyType" : "int",
"override" : false,
"unitBean" : null,
"value" : null
"value" : null,
"valueInBaseUnit" : null
},
"testResourceBean" : {
"uuid" : "fa822159-51a5-4bf2-99cf-e565b67e0eb0",
Expand Down Expand Up @@ -140,15 +144,17 @@
"propertyType" : "float",
"override" : false,
"unitBean" : null,
"value" : null
"value" : null,
"valueInBaseUnit" : null
},
"testIntBean" : {
"uuid" : "0f37aff6-ccc0-436f-a592-bd466f74bd81",
"isCalculated" : false,
"propertyType" : "int",
"override" : false,
"unitBean" : null,
"value" : null
"value" : null,
"valueInBaseUnit" : null
},
"testResourceBean" : {
"uuid" : "fa822159-51a5-4bf2-99cf-e565b67e0eb1",
Expand Down Expand Up @@ -194,15 +200,17 @@
"propertyType" : "float",
"override" : false,
"unitBean" : null,
"value" : null
"value" : null,
"valueInBaseUnit" : null
},
"testIntBean" : {
"uuid" : "0f37aff6-ccc0-436f-a592-bd466f74bd82",
"isCalculated" : false,
"propertyType" : "int",
"override" : false,
"unitBean" : null,
"value" : null
"value" : null,
"valueInBaseUnit" : null
},
"testResourceBean" : {
"uuid" : "fa822159-51a5-4bf2-99cf-e565b67e0eb2",
Expand Down Expand Up @@ -248,15 +256,17 @@
"propertyType" : "float",
"override" : false,
"unitBean" : null,
"value" : null
"value" : null,
"valueInBaseUnit" : null
},
"testIntBean" : {
"uuid" : "0f37aff6-ccc0-436f-a592-bd466f74bd83",
"isCalculated" : false,
"propertyType" : "int",
"override" : false,
"unitBean" : null,
"value" : null
"value" : null,
"valueInBaseUnit" : null
},
"testResourceBean" : {
"uuid" : "fa822159-51a5-4bf2-99cf-e565b67e0eb3",
Expand All @@ -274,4 +284,4 @@
}
}
} ]
}
}
Loading

0 comments on commit 1eeb3a2

Please sign in to comment.