1+ // SPDX-FileCopyrightText: 2021 RTE FRANCE
2+ //
3+ // SPDX-License-Identifier: Apache-2.0
4+
5+ package org .lfenergy .compas .sct .app ;
6+
7+ import org .junit .jupiter .api .BeforeEach ;
8+ import org .junit .jupiter .api .Test ;
9+ import org .lfenergy .compas .scl2007b4 .model .SCL ;
10+ import org .lfenergy .compas .sct .commons .dto .HeaderDTO ;
11+ import org .lfenergy .compas .sct .commons .exception .ScdException ;
12+ import org .lfenergy .compas .sct .commons .scl .SclRootAdapter ;
13+ import org .lfenergy .compas .sct .commons .testhelpers .SclTestMarshaller ;
14+
15+ import java .util .Arrays ;
16+
17+ import static org .junit .jupiter .api .Assertions .*;
18+
19+ class SclAutomationServiceTest {
20+
21+ private HeaderDTO headerDTO ;
22+
23+ @ BeforeEach
24+ void init (){
25+ headerDTO = new HeaderDTO ();
26+ headerDTO .setRevision ("hRevision" );
27+ headerDTO .setVersion ("hVersion" );
28+ }
29+
30+ @ Test
31+ void createSCD () throws Exception {
32+ SCL ssd = SclTestMarshaller .getSCLFromFile ("/scd-substation-import-ssd/ssd.xml" );
33+ SclRootAdapter expectedSCD = SclAutomationService .createSCD (ssd , headerDTO );
34+ assertNotNull (expectedSCD .getCurrentElem ().getHeader ().getId ());
35+ assertNull (expectedSCD .getCurrentElem ().getHeader ().getHistory ());
36+ assertEquals (1 , expectedSCD .getCurrentElem ().getSubstation ().size ());
37+ }
38+
39+ @ Test
40+ void createSCD_With_HItem () throws Exception {
41+ HeaderDTO .HistoryItem historyItem = new HeaderDTO .HistoryItem ();
42+ historyItem .setWhat ("what" );
43+ historyItem .setWho ("me" );
44+ historyItem .setWhy ("because" );
45+ headerDTO .getHistoryItems ().add (historyItem );
46+ SCL ssd = SclTestMarshaller .getSCLFromFile ("/scd-substation-import-ssd/ssd.xml" );
47+ SclRootAdapter expectedSCD = SclAutomationService .createSCD (ssd , headerDTO );
48+ assertNotNull (expectedSCD .getCurrentElem ().getHeader ().getId ());
49+ assertEquals (1 ,expectedSCD .getCurrentElem ().getHeader ().getHistory ().getHitem ().size ());
50+ assertEquals (1 , expectedSCD .getCurrentElem ().getSubstation ().size ());
51+ }
52+
53+ @ Test
54+ void createSCD_With_HItems () throws Exception {
55+ HeaderDTO .HistoryItem historyItem = new HeaderDTO .HistoryItem ();
56+ historyItem .setWhat ("what" );
57+ historyItem .setWho ("me" );
58+ historyItem .setWhy ("because" );
59+ HeaderDTO .HistoryItem historyItemBis = new HeaderDTO .HistoryItem ();
60+ historyItemBis .setWhat ("what Bis" );
61+ historyItemBis .setWho ("me bis" );
62+ historyItemBis .setWhy ("because bis" );
63+ headerDTO .getHistoryItems ().addAll (Arrays .asList (historyItem , historyItemBis ));
64+ SCL ssd = SclTestMarshaller .getSCLFromFile ("/scd-substation-import-ssd/ssd.xml" );
65+ SclRootAdapter expectedSCD = SclAutomationService .createSCD (ssd , headerDTO );
66+ assertNotNull (expectedSCD .getCurrentElem ().getHeader ().getId ());
67+ assertEquals (2 ,expectedSCD .getCurrentElem ().getHeader ().getHistory ().getHitem ().size ());
68+ }
69+
70+
71+ @ Test
72+ void createSCD_SSD_Without_Substation () throws Exception {
73+ SCL ssd = SclTestMarshaller .getSCLFromFile ("/scd-substation-import-ssd/ssd_without_substations.xml" );
74+ assertThrows (ScdException .class ,
75+ () -> SclAutomationService .createSCD (ssd , headerDTO ) );
76+ }
77+ }
0 commit comments