From 8efb887ff41e50ae8e4e72be2dd12007fcd436a0 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Fri, 25 Jun 2021 10:42:50 +0200
Subject: [PATCH] adding 2.2.1 schema, adding inputdataprovider for 2.2.1
 exempted vehicles, adapting testcase for exempted

---
 .../XMLDeclarationVehicleDataProvider.cs      | 18 ++++++
 ...XMLDeclarationInputDataV221InjectModule.cs | 20 +++++++
 .../XMLDeclarationReaderInjectModule.cs       |  1 +
 VectoCore/VectoCore/Utils/XMLDefinitions.cs   |  2 +
 VectoCore/VectoCore/VectoCore.csproj          |  4 ++
 .../Declaration/ExemptedVehicleTest.cs        | 60 ++++++++++++++++++-
 .../ExemptedVehicle/exempted_PEV.xml          |  1 +
 .../ExemptedVehicle/exempted_v2.2.1_PEV.xml   |  1 +
 8 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 VectoCore/VectoCore/InputData/FileIO/XML/Declaration/NinjectModules/XMLDeclarationInputDataV221InjectModule.cs

diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationVehicleDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationVehicleDataProvider.cs
index a0b36cdf6e..ed61a684c6 100644
--- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationVehicleDataProvider.cs
+++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationVehicleDataProvider.cs
@@ -555,4 +555,22 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider
 
 		#endregion
 	}
+
+	// ---------------------------------------------------------------------------------------
+
+	public class XMLDeclarationExemptedVehicleDataProviderV221 : XMLDeclarationExemptedVehicleDataProviderV22
+	{
+		public new static readonly XNamespace NAMESPACE_URI = XMLDefinitions.DECLARATION_DEFINITIONS_NAMESPACE_URI_V221;
+
+		public new const string XSD_TYPE = "ExemptedVehicleDeclarationType";
+
+		public new static readonly string QUALIFIED_XSD_TYPE =
+			XMLHelper.CombineNamespace(NAMESPACE_URI.NamespaceName, XSD_TYPE);
+
+		public XMLDeclarationExemptedVehicleDataProviderV221(
+			IXMLDeclarationJobInputData jobData, XmlNode xmlNode, string sourceFile) : base(jobData, xmlNode,
+			sourceFile)
+		{
+		}
+	}
 }
diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/NinjectModules/XMLDeclarationInputDataV221InjectModule.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/NinjectModules/XMLDeclarationInputDataV221InjectModule.cs
new file mode 100644
index 0000000000..b94d2035f5
--- /dev/null
+++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/NinjectModules/XMLDeclarationInputDataV221InjectModule.cs
@@ -0,0 +1,20 @@
+using Ninject.Modules;
+using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider;
+using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.Interfaces;
+
+namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.NinjectModules
+{
+	public class XMLDeclarationInputDataV221InjectModule : NinjectModule
+	{
+		#region Overrides of NinjectModule
+
+		public override void Load()
+		{
+			Bind<IXMLDeclarationVehicleData>().To<XMLDeclarationExemptedVehicleDataProviderV221>()
+				.Named(XMLDeclarationExemptedVehicleDataProviderV221.QUALIFIED_XSD_TYPE);
+
+		}
+
+		#endregion
+	}
+}
\ No newline at end of file
diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/NinjectModules/XMLDeclarationReaderInjectModule.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/NinjectModules/XMLDeclarationReaderInjectModule.cs
index ee091575f2..006ad0c409 100644
--- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/NinjectModules/XMLDeclarationReaderInjectModule.cs
+++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/NinjectModules/XMLDeclarationReaderInjectModule.cs
@@ -52,6 +52,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration
 				new XMLDeclarationInputDataV20InjectModule(),
 				new XMLDeclarationInputDataV21InjectModule(),
 				new XMLDeclarationInputDataV22InjectModule(),
+				new XMLDeclarationInputDataV221InjectModule(),
 			});
 
 			#endregion
diff --git a/VectoCore/VectoCore/Utils/XMLDefinitions.cs b/VectoCore/VectoCore/Utils/XMLDefinitions.cs
index 3451a7cf1c..47e530052b 100644
--- a/VectoCore/VectoCore/Utils/XMLDefinitions.cs
+++ b/VectoCore/VectoCore/Utils/XMLDefinitions.cs
@@ -78,6 +78,8 @@ namespace TUGraz.VectoCore.Utils
 
 		public const string DECLARATION_DEFINITIONS_NAMESPACE_URI_V22 = DECLARATION_NAMESPACE + ":v2.2";
 
+		public const string DECLARATION_DEFINITIONS_NAMESPACE_URI_V221 = DECLARATION_NAMESPACE + ":v2.2.1";
+
 
 		public const string DECLARATION_INPUT_NAMESPACE = "urn:tugraz:ivt:VectoAPI:DeclarationInput";
 
diff --git a/VectoCore/VectoCore/VectoCore.csproj b/VectoCore/VectoCore/VectoCore.csproj
index afd6d1c0b6..6da1864459 100644
--- a/VectoCore/VectoCore/VectoCore.csproj
+++ b/VectoCore/VectoCore/VectoCore.csproj
@@ -172,6 +172,7 @@
     <Compile Include="InputData\FileIO\XML\Declaration\Interfaces\IXMLVehicleComponentsDeclaration.cs" />
     <Compile Include="InputData\FileIO\XML\Declaration\NinjectModules\XMLDeclarationInputDataV20InjectModule.cs" />
     <Compile Include="InputData\FileIO\XML\Declaration\NinjectModules\XMLDeclarationInputDataV21InjectModule.cs" />
+    <Compile Include="InputData\FileIO\XML\Declaration\NinjectModules\XMLDeclarationInputDataV221InjectModule.cs" />
     <Compile Include="InputData\FileIO\XML\Declaration\NinjectModules\XMLDeclarationInputDataV22InjectModule.cs" />
     <Compile Include="InputData\FileIO\XML\Declaration\Reader\Impl\AbstractComponentReader.cs" />
     <Compile Include="InputData\FileIO\XML\Declaration\Reader\Impl\XMLADASReader.cs" />
@@ -694,6 +695,9 @@
     <EmbeddedResource Include="Resources\XSD\VectoOutputManufacturer.0.7.1.xsd">
       <SubType>Designer</SubType>
     </EmbeddedResource>
+    <EmbeddedResource Include="Resources\XSD\VectoDeclarationDefinitions.2.2.1.xsd">
+      <SubType>Designer</SubType>
+    </EmbeddedResource>
     <None Include="Utils\VectoVersionCore.tt">
       <Generator>TextTemplatingFileGenerator</Generator>
       <LastGenOutput>VectoVersionCore.cs</LastGenOutput>
diff --git a/VectoCore/VectoCoreTest/Integration/Declaration/ExemptedVehicleTest.cs b/VectoCore/VectoCoreTest/Integration/Declaration/ExemptedVehicleTest.cs
index cd44b19d12..3e4110be73 100644
--- a/VectoCore/VectoCoreTest/Integration/Declaration/ExemptedVehicleTest.cs
+++ b/VectoCore/VectoCoreTest/Integration/Declaration/ExemptedVehicleTest.cs
@@ -46,7 +46,9 @@ using TUGraz.VectoCore.Configuration;
 using TUGraz.VectoCore.InputData.FileIO.XML;
 using TUGraz.VectoCore.InputData.FileIO.XML.Declaration;
 using TUGraz.VectoCore.Models.Simulation.Impl;
+using TUGraz.VectoCore.OutputData;
 using TUGraz.VectoCore.OutputData.FileIO;
+using TUGraz.VectoCore.Tests.Integration.Declaration;
 using TUGraz.VectoCore.Tests.Models.Simulation;
 using TUGraz.VectoCore.Tests.Utils;
 using TUGraz.VectoCore.Utils;
@@ -63,8 +65,8 @@ namespace TUGraz.VectoCore.Tests.Integration
 		const string ExemptedVehicleV2 = @"Testdata\Integration\DeclarationMode\ExemptedVehicle\vecto_vehicle-sample_exempted_v2.xml";
 		const string ExemptedVehicleV2NoHEV = @"Testdata\Integration\DeclarationMode\ExemptedVehicle\vecto_vehicle-sample_exempted_v2_nonHEV.xml";
 
-		private const string ExemptedAxl = @"TestData\Integration\DeclarationMode\ExemptedVehicle\exempted_axl.xml";
 		private const string ExemptedMin = @"TestData\Integration\DeclarationMode\ExemptedVehicle\exempted.xml";
+		private const string ExemptedAxl = @"TestData\Integration\DeclarationMode\ExemptedVehicle\exempted_axl.xml";
 		private const string ExemptedAxlSleeperT = @"TestData\Integration\DeclarationMode\ExemptedVehicle\exempted_axl+sleeperT.xml";
 		private const string ExemptedAxlSleeperF = @"TestData\Integration\DeclarationMode\ExemptedVehicle\exempted_axl+sleeperF.xml";
 		private const string ExemptedSleeperT = @"TestData\Integration\DeclarationMode\ExemptedVehicle\exempted_sleeperT.xml";
@@ -281,6 +283,62 @@ namespace TUGraz.VectoCore.Tests.Integration
 		}
 
 
+
+		[
+		TestCase(ExemptedMin, null, null, null, null, false),
+		TestCase(ExemptedAxl, AxleConfiguration.AxleConfig_4x2, null, 30000, 20000, false),
+		TestCase(ExemptedAxlSleeperT, AxleConfiguration.AxleConfig_4x2, true, 30000, 20000, false),
+		TestCase(ExemptedAxlSleeperF, AxleConfiguration.AxleConfig_4x2, false, 30000, 20000, false),
+		TestCase(ExemptedSleeperT, null, true, 30000, 20000, false),
+		TestCase(ExemptedSleeperF, null, false, 30000, 20000, false),
+		TestCase(ExemptedPEVMaxNetPower, AxleConfiguration.AxleConfig_4x2, true, 30000, 20000, true),
+		TestCase(ExemptedPEVMaxNetPower, AxleConfiguration.AxleConfig_4x2, null, null, null, true),
+
+		TestCase(ExemptedMin_v2, null, null, null, null, false),
+		TestCase(ExemptedAxl_v2, AxleConfiguration.AxleConfig_4x2, null, 30000, 20000, false),
+		TestCase(ExemptedAxlSleeperT_v2, AxleConfiguration.AxleConfig_4x2, true, 30000, 20000, false),
+		TestCase(ExemptedAxlSleeperF_v2, AxleConfiguration.AxleConfig_4x2, false, 30000, 20000, false),
+		TestCase(ExemptedSleeperT_v2, null, true, 30000, 20000, false),
+		TestCase(ExemptedSleeperF_v2, null, false, 30000, 20000, false),
+		TestCase(ExemptedPEVMaxNetPower_v2, AxleConfiguration.AxleConfig_4x2, true, 30000, 20000, true),
+		TestCase(ExemptedPEVMaxNetPower_v2, AxleConfiguration.AxleConfig_4x2, null, null, null, true),
+		]
+		public void TestExemptedVehiclesAxleConfSleeperCabMRF(string filename, AxleConfiguration? expectedMrfAxleConf,
+			bool? expectedMrfSleeperCab, double? expectedMaxNetPower1, double? expectedMaxNetPower2, bool zeHDV)
+		{
+			var writer = new MockDeclarationWriter(filename);
+
+
+			var inputData = xmlInputReader.CreateDeclaration(filename);
+
+			var factory = new SimulatorFactory(ExecutionMode.Declaration, inputData, writer) {
+				WriteModalResults = true,
+				ActualModalData = true
+			};
+			var jobContainer = new JobContainer(new MockSumWriter());
+
+			var runs = factory.SimulationRuns().ToList();
+			Assert.AreEqual(1, runs.Count);
+			foreach (var run in runs) {
+				jobContainer.AddRun(run);
+			}
+			//jobContainer.AddRuns(factory);
+
+			jobContainer.Execute();
+			jobContainer.WaitFinished();
+			var progress = jobContainer.GetProgress();
+			Assert.IsTrue(progress.All(r => r.Value.Success), string.Concat<Exception>(progress.Select(r => r.Value.Error)));
+
+
+			var validator = new XMLValidator(writer.GetReport(ReportType.DeclarationReportManufacturerXML).CreateReader());
+			Assert.IsTrue(validator.ValidateXML(XmlDocumentType.ManufacturerReport));
+
+			var val2 = new XMLValidator(writer.GetReport(ReportType.DeclarationReportCustomerXML).CreateReader());
+			Assert.IsTrue(val2.ValidateXML(XmlDocumentType.CustomerReport));
+
+			Assert.Fail("not fully implemented");
+		}
+
 		private static void SetExemptedParameters(XPathNavigator nav, bool zeroEmission, bool hybrid, bool dualFuel)
 		{
 			var manager = new XmlNamespaceManager(nav.NameTable);
diff --git a/VectoCore/VectoCoreTest/TestData/Integration/DeclarationMode/ExemptedVehicle/exempted_PEV.xml b/VectoCore/VectoCoreTest/TestData/Integration/DeclarationMode/ExemptedVehicle/exempted_PEV.xml
index 2f664cb057..67fdf8d43c 100644
--- a/VectoCore/VectoCoreTest/TestData/Integration/DeclarationMode/ExemptedVehicle/exempted_PEV.xml
+++ b/VectoCore/VectoCoreTest/TestData/Integration/DeclarationMode/ExemptedVehicle/exempted_PEV.xml
@@ -13,6 +13,7 @@
 		<Date>2017-02-15T11:00:00Z</Date>
 		<LegislativeClass>N3</LegislativeClass>
 		<VehicleCategory>Tractor</VehicleCategory>
+		<AxleConfiguration>4x2</AxleConfiguration>
 		<CurbMassChassis>7100</CurbMassChassis>
 		<GrossVehicleMass>40000</GrossVehicleMass>
 		<ZeroEmissionVehicle>true</ZeroEmissionVehicle>
diff --git a/VectoCore/VectoCoreTest/TestData/Integration/DeclarationMode/ExemptedVehicle/exempted_v2.2.1_PEV.xml b/VectoCore/VectoCoreTest/TestData/Integration/DeclarationMode/ExemptedVehicle/exempted_v2.2.1_PEV.xml
index 1edd71575a..88602ed6f4 100644
--- a/VectoCore/VectoCoreTest/TestData/Integration/DeclarationMode/ExemptedVehicle/exempted_v2.2.1_PEV.xml
+++ b/VectoCore/VectoCoreTest/TestData/Integration/DeclarationMode/ExemptedVehicle/exempted_v2.2.1_PEV.xml
@@ -14,6 +14,7 @@
 		<Date>2017-02-15T11:00:00Z</Date>
 		<LegislativeClass>N3</LegislativeClass>
 		<VehicleCategory>Tractor</VehicleCategory>
+		<AxleConfiguration>4x2</AxleConfiguration>
 		<CurbMassChassis>7100</CurbMassChassis>
 		<GrossVehicleMass>40000</GrossVehicleMass>
 		<ZeroEmissionVehicle>true</ZeroEmissionVehicle>
-- 
GitLab