11package org .openhab .binding .haywardomnilogiclocal .internal .config ;
22
33import static org .junit .jupiter .api .Assertions .assertEquals ;
4+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
5+
6+ import java .io .IOException ;
7+ import java .io .InputStream ;
8+ import java .nio .charset .StandardCharsets ;
49
510import org .junit .jupiter .api .Test ;
611
914 */
1015public class ConfigParserTest {
1116 @ Test
12- public void testParsePopulatesAllListsAndAttributes () {
13- String xml = "" +
14- "<MSPConfig>" +
15- " <System systemId='SYS'>" +
16- " <Msp-Vsp-Speed-Format>Percent</Msp-Vsp-Speed-Format>" +
17- " <Msp-Time-Format>12 Hour Format</Msp-Time-Format>" +
18- " <Time-Zone>America/New_York</Time-Zone>" +
19- " <DST>Enabled</DST>" +
20- " <Internet-Time>Disabled</Internet-Time>" +
21- " <Units>Metric</Units>" +
22- " <Msp-Chlor-Display>Salt</Msp-Chlor-Display>" +
23- " <Msp-Language>French</Msp-Language>" +
24- " <UI-Show-Backyard>true</UI-Show-Backyard>" +
25- " <UI-Show-Equipment>false</UI-Show-Equipment>" +
26- " <UI-Show-Heaters>true</UI-Show-Heaters>" +
27- " <UI-Show-Lights>true</UI-Show-Lights>" +
28- " <UI-Show-Spillover>false</UI-Show-Spillover>" +
29- " <UI-Show-SuperChlor>true</UI-Show-SuperChlor>" +
30- " <UI-Show-SuperChlorTimeout>false</UI-Show-SuperChlorTimeout>" +
31- " </System>" +
32- " <Backyard>" +
33- " <System-Id>BY</System-Id>" +
34- " <Name>Main Backyard</Name>" +
35- " <Service-Mode-Timeout>15</Service-Mode-Timeout>" +
36- " <Sensor>" +
37- " <System-Id>SENBY1</System-Id>" +
38- " <Name>Air Sensor</Name>" +
39- " <Type>SENSOR_AIR_TEMP</Type>" +
40- " <Units>UNITS_FAHRENHEIT</Units>" +
41- " </Sensor>" +
42- " <BodyOfWater systemId='BOW' type='BOW_POOL' sharedType='BOW_SHARED_EQUIPMENT' supportsSpillover='yes'" +
43- " spilloverMode='manual' spilloverTimedPercent='50' freezeProtectEnabled='yes'" +
44- " freezeProtectSetPoint='38' sizeInLiters='56781'>" +
45- " <Name>Main Pool</Name>" +
46- " <Type>BOW_POOL</Type>" +
47- " <Shared-Type>BOW_SHARED_EQUIPMENT</Shared-Type>" +
48- " <Shared-Priority>SHARED_EQUIPMENT_HIGH_PRIORITY</Shared-Priority>" +
49- " <Shared-Equipment-System-ID>BOW2</Shared-Equipment-System-ID>" +
50- " <Use-Spillover-For-Filter-Operations>yes</Use-Spillover-For-Filter-Operations>" +
51- " <Spillover-Manual-Timeout>10</Spillover-Manual-Timeout>" +
52- " <Spillover-Timed-Timeout>20</Spillover-Timed-Timeout>" +
53- " <Freeze-Protect-Override>no</Freeze-Protect-Override>" +
54- " <Size-In-Gallons>15000</Size-In-Gallons>" +
55- " <Filter systemId='F1' pumpId='P1'>" +
56- " <Name>Filter Pump</Name>" +
57- " <Shared-Type>BOW_SHARED_EQUIPMENT</Shared-Type>" +
58- " <Filter-Type>FMT_VARIABLE_SPEED_PUMP</Filter-Type>" +
59- " <Max-Pump-Speed>100</Max-Pump-Speed>" +
60- " <Min-Pump-Speed>18</Min-Pump-Speed>" +
61- " <Max-Pump-RPM>3450</Max-Pump-RPM>" +
62- " <Min-Pump-RPM>600</Min-Pump-RPM>" +
63- " <Vsp-Low-Pump-Speed>18</Vsp-Low-Pump-Speed>" +
64- " <Vsp-Medium-Pump-Speed>50</Vsp-Medium-Pump-Speed>" +
65- " <Vsp-High-Pump-Speed>100</Vsp-High-Pump-Speed>" +
66- " <Vsp-Custom-Pump-Speed>80</Vsp-Custom-Pump-Speed>" +
67- " <Operation>PEO_FILTER_SAMPLE" +
68- " <Action>PEA_FILTER_SPEED" +
69- " <Parameter name='Speed' dataType='int'>3200</Parameter>" +
70- " </Action>" +
71- " </Operation>" +
72- " </Filter>" +
73- " <Heater systemId='H1' type='gas' sharedType='BOW_SHARED_EQUIPMENT' enabled='yes' currentSetPoint='80'>" +
74- " <Shared-Type>BOW_SHARED_EQUIPMENT</Shared-Type>" +
75- " <Enabled>yes</Enabled>" +
76- " <Current-Set-Point>82</Current-Set-Point>" +
77- " <Max-Water-Temp>104</Max-Water-Temp>" +
78- " <Min-Settable-Water-Temp>65</Min-Settable-Water-Temp>" +
79- " <Max-Settable-Water-Temp>104</Max-Settable-Water-Temp>" +
80- " <Cooldown-Enabled>no</Cooldown-Enabled>" +
81- " <Operation>PEO_HEATER_EQUIPMENT" +
82- " <Heater-Equipment>" +
83- " <System-Id>HX1</System-Id>" +
84- " <Name>Gas Heater</Name>" +
85- " <Type>PET_HEATER</Type>" +
86- " <Heater-Type>HTR_GAS</Heater-Type>" +
87- " <Enabled>yes</Enabled>" +
88- " </Heater-Equipment>" +
89- " </Operation>" +
90- " <Operation>PEO_HEATER_FLOW" +
91- " <Action>PEA_FLOW" +
92- " <Parameter name='Flow' dataType='int'>40</Parameter>" +
93- " </Action>" +
94- " </Operation>" +
95- " </Heater>" +
96- " <Chlorinator systemId='C1' sharedType='BOW_SHARED_EQUIPMENT' enabled='yes'>" +
97- " <Name>Chlorinator</Name>" +
98- " <Mode>CHLOR_OP_MODE_ORP_AUTO</Mode>" +
99- " <Timed-Percent>50</Timed-Percent>" +
100- " <SuperChlor-Timeout>24</SuperChlor-Timeout>" +
101- " <Cell-Type>CELL_TYPE_T15</Cell-Type>" +
102- " <ORP-Timeout>86400</ORP-Timeout>" +
103- " <Operation>PEO_CHLOR_SAMPLE" +
104- " <Action>PEA_SET_PERCENT" +
105- " <Parameter name='Percent' dataType='int'>60</Parameter>" +
106- " </Action>" +
107- " </Operation>" +
108- " </Chlorinator>" +
109- " <ColorLogic-Light systemId='L1'>" +
110- " <Name>Pool Light</Name>" +
111- " <Type>COLOR_LOGIC_UCL</Type>" +
112- " </ColorLogic-Light>" +
113- " <Relay systemId='R1' name='Aux1'>" +
114- " <Type>RLY_HIGH_VOLTAGE_RELAY</Type>" +
115- " <Function>GENERIC</Function>" +
116- " </Relay>" +
117- " <Sensor>" +
118- " <System-Id>SEN1</System-Id>" +
119- " <Name>Water Sensor</Name>" +
120- " <Type>SENSOR_WATER_TEMP</Type>" +
121- " <Units>UNITS_FAHRENHEIT</Units>" +
122- " <Operation>PEO_SENSOR_SAMPLE" +
123- " <Parameter name='SampleRate' dataType='int'>5</Parameter>" +
124- " <Action>PEA_SENSOR_REPORT" +
125- " <Parameter name='Interval' dataType='int'>15</Parameter>" +
126- " </Action>" +
127- " </Operation>" +
128- " </Sensor>" +
129- " </BodyOfWater>" +
130- " <Pump systemId='P1' name='Main'>" +
131- " <Type>PMP_VARIABLE_SPEED_PUMP</Type>" +
132- " <Function>PMP_FILTER</Function>" +
133- " <Max-Pump-RPM>3450</Max-Pump-RPM>" +
134- " <Min-Pump-RPM>600</Min-Pump-RPM>" +
135- " <Min-Pump-Speed>20</Min-Pump-Speed>" +
136- " <Max-Pump-Speed>100</Max-Pump-Speed>" +
137- " <Vsp-Medium-Pump-Speed>60</Vsp-Medium-Pump-Speed>" +
138- " <Vsp-Custom-Pump-Speed>70</Vsp-Custom-Pump-Speed>" +
139- " <Vsp-High-Pump-Speed>100</Vsp-High-Pump-Speed>" +
140- " <Vsp-Low-Pump-Speed>30</Vsp-Low-Pump-Speed>" +
141- " <Operation>PEO_PUMP_SAMPLE" +
142- " <Action>PEA_SET_SPEED" +
143- " <Parameter name='Speed' dataType='int'>3100</Parameter>" +
144- " </Action>" +
145- " <Operation>PEO_PUMP_CHILD" +
146- " <Action>PEA_CHILD_SPEED" +
147- " <Parameter name='Speed' dataType='int'>2800</Parameter>" +
148- " </Action>" +
149- " </Operation>" +
150- " </Operation>" +
151- " </Pump>" +
152- " <VirtualHeater systemId='VH1' name='Spa Heat' enable='yes' currentSetPoint='90'>" +
153- " <Enable>yes</Enable>" +
154- " <Current-Set-Point>92</Current-Set-Point>" +
155- " </VirtualHeater>" +
156- " </Backyard>" +
157- " <Schedules>" +
158- " <Schedule systemId='SCH1' name='Filter' type='equipment'>" +
159- " <Device systemId='P1' name='Main Pump' type='Pump'/>" +
160- " <Parameter name='StartTimeHours' dataType='int'>6</Parameter>" +
161- " <Action type='on'>" +
162- " <Device systemId='R1' name='Aux1' type='Relay'/>" +
163- " </Action>" +
164- " </Schedule>" +
165- " </Schedules>" +
166- " <DMT>" +
167- " <Device systemId='DEV1' name='Filter Pump' type='Pump'>" +
168- " <Parameter name='Speed' dataType='int'>3450</Parameter>" +
169- " </Device>" +
170- " </DMT>" +
171- " <CHECKSUM>12345</CHECKSUM>" +
172- "</MSPConfig>" ;
173-
174- MspConfig config = ConfigParser .parse (xml );
17+ public void testParsePopulatesAllListsAndAttributes () throws IOException {
18+ MspConfig config = parseSampleConfiguration ();
17519 assertEquals (1 , config .getSystems ().size ());
17620
17721 SystemConfig system = config .getSystems ().get (0 );
@@ -361,6 +205,12 @@ public void testParsePopulatesAllListsAndAttributes() {
361205 assertEquals (1 , pumpAction .getParameters ().size ());
362206 assertEquals ("Speed" , pumpAction .getParameters ().get (0 ).getName ());
363207 assertEquals ("3100" , pumpAction .getParameters ().get (0 ).getValue ());
208+ assertEquals (1 , pumpAction .getOperations ().size ());
209+ OperationConfig pumpActionNestedOperation = pumpAction .getOperations ().get (0 );
210+ assertEquals ("PEO_ACTION_CHILD" , pumpActionNestedOperation .getType ());
211+ assertEquals (1 , pumpActionNestedOperation .getParameters ().size ());
212+ assertEquals ("ChildParam" , pumpActionNestedOperation .getParameters ().get (0 ).getName ());
213+ assertEquals ("1" , pumpActionNestedOperation .getParameters ().get (0 ).getValue ());
364214 assertEquals (1 , pumpOperation .getOperations ().size ());
365215 OperationConfig nestedPumpOperation = pumpOperation .getOperations ().get (0 );
366216 assertEquals ("PEO_PUMP_CHILD" , nestedPumpOperation .getType ());
@@ -395,6 +245,10 @@ public void testParsePopulatesAllListsAndAttributes() {
395245 assertEquals ("on" , action .getType ());
396246 assertEquals (1 , action .getDevices ().size ());
397247 assertEquals ("R1" , action .getDevices ().get (0 ).getSystemId ());
248+ assertEquals (1 , action .getParameters ().size ());
249+ ParameterConfig scheduleActionParameter = action .getParameters ().get (0 );
250+ assertEquals ("Duration" , scheduleActionParameter .getName ());
251+ assertEquals ("30" , scheduleActionParameter .getValue ());
398252
399253 assertEquals (1 , config .getDmt ().getDevices ().size ());
400254 DeviceConfig device = config .getDmt ().getDevices ().get (0 );
@@ -407,5 +261,28 @@ public void testParsePopulatesAllListsAndAttributes() {
407261
408262 assertEquals ("12345" , config .getChecksum ());
409263 }
264+
265+ @ Test
266+ public void testParseSampleConfigurationNestedActionOperations () throws IOException {
267+ MspConfig config = parseSampleConfiguration ();
268+
269+ PumpConfig pump = config .getBackyards ().get (0 ).getPumps ().get (0 );
270+ OperationConfig pumpOperation = pump .getOperations ().get (0 );
271+ ActionConfig pumpAction = pumpOperation .getActions ().get (0 );
272+
273+ assertEquals (1 , pumpAction .getOperations ().size ());
274+ OperationConfig nestedOperation = pumpAction .getOperations ().get (0 );
275+ assertEquals ("PEO_ACTION_CHILD" , nestedOperation .getType ());
276+ assertEquals ("ChildParam" , nestedOperation .getParameters ().get (0 ).getName ());
277+ assertEquals ("1" , nestedOperation .getParameters ().get (0 ).getValue ());
278+ }
279+
280+ private static MspConfig parseSampleConfiguration () throws IOException {
281+ try (InputStream stream = ConfigParserTest .class .getResourceAsStream ("request-configuration-sample.xml" )) {
282+ assertNotNull (stream , "Sample RequestConfiguration XML is missing" );
283+ String xml = new String (stream .readAllBytes (), StandardCharsets .UTF_8 );
284+ return ConfigParser .parse (xml );
285+ }
286+ }
410287}
411288
0 commit comments