55package org .lfenergy .compas .sct .commons .scl ;
66
77import org .junit .jupiter .api .Test ;
8- import org .lfenergy .compas .scl2007b4 .model .SCL ;
9- import org .lfenergy .compas .scl2007b4 .model .TExtRef ;
10- import org .lfenergy .compas .scl2007b4 .model .THeader ;
11- import org .lfenergy .compas .scl2007b4 .model .THitem ;
12- import org .lfenergy .compas .scl2007b4 .model .TLLN0Enum ;
13- import org .lfenergy .compas .scl2007b4 .model .TServiceType ;
14- import org .lfenergy .compas .scl2007b4 .model .TVal ;
15- import org .lfenergy .compas .sct .commons .dto .DTO ;
16- import org .lfenergy .compas .sct .commons .dto .HeaderDTO ;
17- import org .lfenergy .compas .sct .commons .testhelpers .MarshallerWrapper ;
18- import org .lfenergy .compas .sct .commons .dto .ConnectedApDTO ;
19- import org .lfenergy .compas .sct .commons .dto .DaTypeName ;
20- import org .lfenergy .compas .sct .commons .dto .DoTypeName ;
21- import org .lfenergy .compas .sct .commons .dto .ExtRefBindingInfo ;
22- import org .lfenergy .compas .sct .commons .dto .ExtRefInfo ;
23- import org .lfenergy .compas .sct .commons .dto .ExtRefSignalInfo ;
24- import org .lfenergy .compas .sct .commons .dto .ExtRefSourceInfo ;
25- import org .lfenergy .compas .sct .commons .dto .LNodeDTO ;
26- import org .lfenergy .compas .sct .commons .dto .ResumedDataTemplate ;
27- import org .lfenergy .compas .sct .commons .dto .SubNetworkDTO ;
8+ import org .junit .jupiter .params .ParameterizedTest ;
9+ import org .junit .jupiter .params .provider .ValueSource ;
10+ import org .lfenergy .compas .scl2007b4 .model .*;
11+ import org .lfenergy .compas .sct .commons .dto .*;
2812import org .lfenergy .compas .sct .commons .exception .ScdException ;
2913import org .lfenergy .compas .sct .commons .scl .ied .IEDAdapter ;
3014import org .lfenergy .compas .sct .commons .scl .ied .LDeviceAdapter ;
3115import org .lfenergy .compas .sct .commons .scl .ied .LN0Adapter ;
16+ import org .lfenergy .compas .sct .commons .testhelpers .MarshallerWrapper ;
3217import org .lfenergy .compas .sct .commons .testhelpers .SclTestMarshaller ;
3318
3419import java .util .List ;
20+ import java .util .Optional ;
3521import java .util .Set ;
3622import java .util .UUID ;
3723
38- import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
39- import static org .junit .jupiter .api .Assertions .assertEquals ;
40- import static org .junit .jupiter .api .Assertions .assertFalse ;
41- import static org .junit .jupiter .api .Assertions .assertNotNull ;
42- import static org .junit .jupiter .api .Assertions .assertNull ;
43- import static org .junit .jupiter .api .Assertions .assertThrows ;
44- import static org .junit .jupiter .api .Assertions .assertTrue ;
24+ import static org .junit .jupiter .api .Assertions .*;
4525
4626class SclServiceTest {
4727
@@ -314,15 +294,23 @@ void testGetDAI() throws Exception {
314294 @ Test
315295 void testInitScl (){
316296 assertDoesNotThrow (
317- () -> SclService .initScl ("hVersion" ,"hRevision" )
297+ () -> SclService .initScl (Optional .empty (), "hVersion" ,"hRevision" )
298+ );
299+ }
300+
301+ @ Test
302+ void testInitScl_With_hId_shouldNotThrowError (){
303+ UUID hid = UUID .randomUUID ();
304+ assertDoesNotThrow (
305+ () -> SclService .initScl (Optional .of (hid ),"hVersion" ,"hRevision" )
318306 );
319307 }
320308
321309 @ Test
322310 void testUpdateHeader () {
323311
324312 SclRootAdapter sclRootAdapter = assertDoesNotThrow (
325- () -> SclService .initScl ("hVersion" ,"hRevision" )
313+ () -> SclService .initScl (Optional . empty (), "hVersion" ,"hRevision" )
326314 );
327315 UUID hId = UUID .fromString (sclRootAdapter .getHeaderAdapter ().getHeaderId ());
328316 HeaderDTO headerDTO = DTO .createHeaderDTO (hId );
@@ -363,4 +351,50 @@ void testGetEnumTypeElements() throws Exception {
363351 );
364352 assertFalse (enumList .isEmpty ());
365353 }
354+
355+ @ ParameterizedTest
356+ @ ValueSource (strings = {"/scd-substation-import-ssd/ssd_with_2_substations.xml" , "/scd-substation-import-ssd/ssd_without_substations.xml" })
357+ void testAddSubstation_Check_SSD_Validity (String ssdFileName ) throws Exception {
358+ SCL scd = SclTestMarshaller .getSCLFromFile ("/scl-root-test-schema-conf/add_ied_test.xml" );
359+ SCL ssd = SclTestMarshaller .getSCLFromFile (ssdFileName );
360+
361+ assertThrows (ScdException .class ,
362+ () ->SclService .addSubstation (scd , ssd ));
363+ }
364+
365+ @ Test
366+ void testAddSubstation_SCD_Without_Substation () throws Exception {
367+ SCL scd = SclTestMarshaller .getSCLFromFile ("/scl-root-test-schema-conf/add_ied_test.xml" );
368+ SclRootAdapter scdRootAdapter = new SclRootAdapter (scd );
369+ SCL ssd = SclTestMarshaller .getSCLFromFile ("/scd-substation-import-ssd/ssd.xml" );
370+ SclRootAdapter ssdRootAdapter = new SclRootAdapter (ssd );
371+ SclRootAdapter expectedScdAdapter = SclService .addSubstation (scd , ssd );
372+
373+ assertNotEquals (scdRootAdapter , expectedScdAdapter );
374+ assertEquals (expectedScdAdapter .getCurrentElem ().getSubstation (), ssdRootAdapter .getCurrentElem ().getSubstation ());
375+ }
376+
377+ @ Test
378+ void testAddSubstation_SCD_With_Different_Substation_Name () throws Exception {
379+ SCL scd = SclTestMarshaller .getSCLFromFile ("/scd-substation-import-ssd/scd_with_substation_name_different.xml" );
380+ SCL ssd = SclTestMarshaller .getSCLFromFile ("/scd-substation-import-ssd/ssd.xml" );
381+
382+ assertThrows (ScdException .class ,
383+ () ->SclService .addSubstation (scd , ssd ));
384+ }
385+
386+ @ Test
387+ void testAddSubstation_SCD_With_Substation () throws Exception {
388+ SCL scd = SclTestMarshaller .getSCLFromFile ("/scd-substation-import-ssd/scd_with_substation.xml" );
389+ SclRootAdapter scdRootAdapter = new SclRootAdapter (scd );
390+ SCL ssd = SclTestMarshaller .getSCLFromFile ("/scd-substation-import-ssd/ssd.xml" );
391+ SclRootAdapter ssdRootAdapter = new SclRootAdapter (ssd );
392+ SclRootAdapter expectedScdAdapter = SclService .addSubstation (scd , ssd );
393+ TSubstation expectedTSubstation = expectedScdAdapter .getCurrentElem ().getSubstation ().get (0 );
394+ TSubstation tSubstation = ssdRootAdapter .getCurrentElem ().getSubstation ().get (0 );
395+
396+ assertNotEquals (scdRootAdapter , expectedScdAdapter );
397+ assertEquals (expectedTSubstation .getName (), tSubstation .getName ());
398+ assertEquals (expectedTSubstation .getVoltageLevel ().size (), tSubstation .getVoltageLevel ().size ());
399+ }
366400}
0 commit comments