Skip to content

Commit 742016e

Browse files
authored
Feat #152: Update SCD creation automation service to call #74 issue (Delete all Control Blocks and Dataset and all ExtRef @srcxxx attributes into a given SCL file) (#182)
Signed-off-by: SaintierFr <[email protected]>
1 parent 3a0a86d commit 742016e

File tree

10 files changed

+355
-13
lines changed

10 files changed

+355
-13
lines changed

pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@
157157
</execution>
158158
</executions>
159159
</plugin>
160+
<plugin>
161+
<groupId>org.apache.maven.plugins</groupId>
162+
<artifactId>maven-javadoc-plugin</artifactId>
163+
<version>${maven.plugin.javadoc}</version>
164+
<executions>
165+
<execution>
166+
<id>attach-javadocs</id>
167+
<phase>package</phase>
168+
<goals>
169+
<goal>aggregate</goal>
170+
</goals>
171+
</execution>
172+
</executions>
173+
</plugin>
160174
<plugin>
161175
<groupId>org.apache.maven.plugins</groupId>
162176
<artifactId>maven-source-plugin</artifactId>

sct-app/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
<version>3.6.28</version>
6161
<scope>test</scope>
6262
</dependency>
63+
<dependency>
64+
<groupId>org.assertj</groupId>
65+
<artifactId>assertj-core</artifactId>
66+
<version>3.23.1</version>
67+
</dependency>
6368
</dependencies>
6469
<build>
6570
<plugins>

sct-app/src/main/java/org/lfenergy/compas/sct/app/SclAutomationService.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ public class SclAutomationService {
3333
*/
3434
private static final Map<Pair<String, String>, List<String>> comMap = Map.of(
3535
Pair.of("RSPACE_PROCESS_NETWORK", SubNetworkDTO.SubnetworkType.MMS.toString()), Arrays.asList("PROCESS_AP", "TOTO_AP_GE"),
36-
Pair.of("RSPACE_ADMIN_NETWORK", SubNetworkDTO.SubnetworkType.IP.toString()), Arrays.asList("ADMIN_AP","TATA_AP_EFFACEC"));
36+
Pair.of("RSPACE_ADMIN_NETWORK", SubNetworkDTO.SubnetworkType.IP.toString()), Arrays.asList("ADMIN_AP", "TATA_AP_EFFACEC"));
3737

38-
private SclAutomationService(){throw new IllegalStateException("SclAutomationService class"); }
38+
private SclAutomationService() {
39+
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
40+
}
3941

4042
/**
4143
* Create a SCD file from specified parameters, it calls all functions defined in the process one by one, every step
@@ -48,13 +50,14 @@ public class SclAutomationService {
4850
*/
4951
public static SclRootAdapter createSCD(@NonNull SCL ssd, @NonNull HeaderDTO headerDTO, Set<SCL> stds) throws ScdException {
5052
SclRootAdapter scdAdapter = SclService.initScl(Optional.ofNullable(headerDTO.getId()),
51-
headerDTO.getVersion(),headerDTO.getRevision());
52-
if(!headerDTO.getHistoryItems().isEmpty()) {
53+
headerDTO.getVersion(), headerDTO.getRevision());
54+
if (!headerDTO.getHistoryItems().isEmpty()) {
5355
HeaderDTO.HistoryItem hItem = headerDTO.getHistoryItems().get(0);
5456
SclService.addHistoryItem(scdAdapter.getCurrentElem(), hItem.getWho(), hItem.getWhat(), hItem.getWhy());
5557
}
5658
SubstationService.addSubstation(scdAdapter.getCurrentElem(), ssd);
5759
SclService.importSTDElementsInSCD(scdAdapter, stds, comMap);
60+
SclService.removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(scdAdapter.getCurrentElem());
5861
return scdAdapter;
5962
}
6063
}

sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@
66

77
import org.junit.jupiter.api.BeforeEach;
88
import org.junit.jupiter.api.Test;
9+
import org.lfenergy.compas.scl2007b4.model.LN0;
910
import org.lfenergy.compas.scl2007b4.model.SCL;
1011
import org.lfenergy.compas.sct.commons.dto.HeaderDTO;
1112
import org.lfenergy.compas.sct.commons.exception.ScdException;
13+
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
1214
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
15+
import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter;
1316
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;
1417

18+
import java.lang.reflect.Constructor;
19+
import java.lang.reflect.InvocationTargetException;
1520
import java.util.Arrays;
1621
import java.util.HashSet;
1722
import java.util.Set;
1823

24+
import static org.assertj.core.api.Assertions.assertThat;
25+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1926
import static org.junit.jupiter.api.Assertions.*;
2027
import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable;
2128

@@ -24,7 +31,7 @@ class SclAutomationServiceTest {
2431
private HeaderDTO headerDTO;
2532

2633
@BeforeEach
27-
void init(){
34+
void init() {
2835
headerDTO = new HeaderDTO();
2936
headerDTO.setRevision("hRevision");
3037
headerDTO.setVersion("hVersion");
@@ -63,7 +70,7 @@ void createSCD_With_HItem() throws Exception {
6370
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO, Set.of(std1, std2, std3));
6471
// Then
6572
assertNotNull(expectedSCD.getCurrentElem().getHeader().getId());
66-
assertEquals(1 ,expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().size());
73+
assertEquals(1, expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().size());
6774
assertEquals(1, expectedSCD.getCurrentElem().getSubstation().size());
6875
assertIsMarshallable(expectedSCD.getCurrentElem());
6976
}
@@ -85,7 +92,7 @@ void createSCD_With_HItems() throws Exception {
8592
SCL std2 = SclTestMarshaller.getSCLFromFile("/std_2.xml");
8693
SCL std3 = SclTestMarshaller.getSCLFromFile("/std_3.xml");
8794
// When
88-
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO,Set.of(std1, std2, std3));
95+
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO, Set.of(std1, std2, std3));
8996
// Then
9097
assertNotNull(expectedSCD.getCurrentElem().getHeader().getId());
9198
assertEquals(1, expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().size());
@@ -98,8 +105,68 @@ void createSCD_SSD_Without_Substation() throws Exception {
98105
// Given
99106
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd_without_substations.xml");
100107
// When & Then
108+
Set<SCL> stdListEmpty = new HashSet<>();
101109
assertThrows(ScdException.class,
102-
() -> SclAutomationService.createSCD(ssd, headerDTO, new HashSet<>()) );
110+
() -> SclAutomationService.createSCD(ssd, headerDTO, stdListEmpty));
111+
}
112+
113+
@Test
114+
void createSCD_should_throw_exception_when_null_ssd() throws Exception {
115+
// Given
116+
HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem();
117+
historyItem.setWhat("what");
118+
historyItem.setWho("me");
119+
historyItem.setWhy("because");
120+
headerDTO.getHistoryItems().add(historyItem);
121+
SCL std1 = SclTestMarshaller.getSCLFromFile("/std_1.xml");
122+
Set<SCL> stdList = Set.of(std1);
123+
124+
// When & Then
125+
assertThrows(NullPointerException.class, () -> SclAutomationService.createSCD(null, headerDTO, stdList));
103126
}
104127

128+
@Test
129+
void createSCD_should_throw_exception_when_null_headerDTO() throws Exception {
130+
// Given
131+
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd.xml");
132+
SCL std1 = SclTestMarshaller.getSCLFromFile("/std_1.xml");
133+
Set<SCL> stdList = Set.of(std1);
134+
135+
// When & Then
136+
assertThrows(NullPointerException.class, () -> SclAutomationService.createSCD(ssd, null, stdList));
137+
}
138+
139+
@Test
140+
void createSCD_should_delete_ControlBlocks_DataSet_and_ExtRef_src_attributes() throws Exception {
141+
// Given
142+
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/ssd.xml");
143+
SCL std = SclTestMarshaller.getSCLFromFile("/scl-remove-controlBlocks-dataSet-extRefSrc/scl-with-control-blocks.xml");
144+
// When
145+
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO, Set.of(std));
146+
// Then
147+
LN0 ln0 = expectedSCD.streamIEDAdapters()
148+
.findFirst()
149+
.map(iedAdapter -> iedAdapter.getLDeviceAdapterByLdInst("lDeviceInst1").orElseThrow())
150+
.map(LDeviceAdapter::getLN0Adapter)
151+
.map(SclElementAdapter::getCurrentElem)
152+
.orElseThrow(() -> new RuntimeException("Test shouldn't fail here, please check your XML input file"));
153+
154+
assertThat(ln0.getDataSet()).isEmpty();
155+
assertThat(ln0.getInputs().getExtRef()).hasSize(2);
156+
assertFalse(ln0.getInputs().getExtRef().get(0).isSetSrcLDInst());
157+
assertIsMarshallable(expectedSCD.getCurrentElem());
158+
}
159+
160+
@Test
161+
void class_should_not_be_instantiable() {
162+
// Given
163+
Constructor<?>[] constructors = SclAutomationService.class.getDeclaredConstructors();
164+
assertThat(constructors).hasSize(1);
165+
Constructor<?> constructor = constructors[0];
166+
constructor.setAccessible(true);
167+
// When & Then
168+
assertThatThrownBy(constructor::newInstance)
169+
.isInstanceOf(InvocationTargetException.class)
170+
.getCause().isInstanceOf(UnsupportedOperationException.class);
171+
}
105172
}

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ied/AbstractLNAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public List<ControlBlock<?>> getControlBlocksForMatchingFCDA(@NonNull ExtRefInfo
350350
List<TDataSet> tDataSets = this.getDataSetMatchingExtRefInfo(extRefInfo);
351351
return getControlBlocks(tDataSets, extRefInfo.getBindingInfo().getServiceType());
352352
}
353-
353+
354354
/**
355355
* Gets all Control Blocks from LNode for specified Service Type (GOOSE, SMV and REPORT) and Data Sets
356356
*

sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/DAITrackerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
1313
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;
1414

15+
import static org.assertj.core.api.Assertions.assertThat;
1516
import static org.junit.jupiter.api.Assertions.*;
1617

1718
class DAITrackerTest {

sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/ied/IEDAdapterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.lfenergy.compas.sct.commons.exception.ScdException;
1414
import org.lfenergy.compas.sct.commons.scl.ObjectReference;
1515
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
16+
import org.lfenergy.compas.sct.commons.scl.com.SubNetworkAdapter;
1617
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;
1718
import org.mockito.Mockito;
1819

sct-commons/src/test/resources/scd-ied-dtt-com-import-stds/ssd.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-->
77
<SCL xmlns:compas="https://www.lfenergy.org/compas/extension/v1" xmlns="http://www.iec.ch/61850/2003/SCL" version="2007" revision="B" release="4">
88
<Private type="COMPAS-SclFileType">
9-
<compas:SclFileType>SCD</compas:SclFileType>
9+
<compas:SclFileType>SSD</compas:SclFileType>
1010
</Private>
1111
<Header id="HeaderId" version="HeaderVersion" revision="HeaderRevision"/>
1212
<Substation name="SITE">
@@ -16,7 +16,7 @@
1616
<Function name="FUNCTION_1">
1717
<LNode iedName="None" ldInst="LDGW" lnClass="LLN0">
1818
<Private type="COMPAS-ICDHeader">
19-
<compas:ICDHeader IEDType="GTW" IEDinstance="0" BayLabel="SITE1" IEDName="SITESITE1GTW0" ICDSystemVersionUUID="IED4d4fe1a8cda64cf88a5ee4176a1a0eef" VendorName="ABC" IEDredundancy="A" IEDmodel="ICDfromModeling" hwRev="01.00.00" swRev="01.00.00" headerId="f8dbc8c1-2db7-4652-a9d6-0b414bdeccfa" headerVersion="01.00.00" headerRevision="01.00.00"/>
19+
<compas:ICDHeader IEDType="GTW" IEDinstance="0" BayLabel="SITE1" IEDName="ied1" ICDSystemVersionUUID="IED4d4fe1a8cda64cf88a5ee4176a1a0eef" VendorName="ABC" IEDredundancy="A" IEDmodel="ICDfromModeling" hwRev="01.00.00" swRev="01.00.00" headerId="f8dbc8c1-2db7-4652-a9d6-0b414bdeccfa" headerVersion="01.00.00" headerRevision="01.00.00"/>
2020
</Private>
2121
</LNode>
2222
</Function>

0 commit comments

Comments
 (0)