Skip to content

Commit f45fa66

Browse files
authored
Merge pull request #328 from com-pas/feat/refactor_doiadapter_method_type_to_public
refactor: make methods public
2 parents 4c2dd4d + fb4f657 commit f45fa66

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapter.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,21 +252,22 @@ public Pair<String,DOTypeAdapter> findPathDoTypeToDA(String daName) throws ScdEx
252252

253253
/**
254254
* Find path from a SDO to DA (defined by names)
255+
*
255256
* @param sdoName SDO from which find a path
256-
* @param daName DA for which find a path to
257+
* @param daName DA for which find a path to
257258
* @return pair of DO/SDO and DoType. DO/SDO references the DOType
258259
* @throws ScdException when inconsistency are found in th SCL's
259-
* DataTypeTemplate (unknown reference for example). Which should normally not happens.
260+
* DataTypeTemplate (unknown reference for example). Which should normally not happens.
260261
*/
261-
Pair<String,DOTypeAdapter> findPathSDOToDA(String sdoName, String daName) throws ScdException {
262-
String errMsg = String.format("No coherence or path between DO/SDO(%s) and DA(%s)", sdoName,daName);
262+
public Pair<String, DOTypeAdapter> findPathSDOToDA(String sdoName, String daName) throws ScdException {
263+
String errMsg = String.format("No coherence or path between DO/SDO(%s) and DA(%s)", sdoName, daName);
263264
Optional<TSDO> opSdo = getSDOByName(sdoName);
264-
if(opSdo.isEmpty()) {
265+
if (opSdo.isEmpty()) {
265266
throw new ScdException(errMsg);
266267
}
267268

268269
DOTypeAdapter doTypeAdapter = parentAdapter.getDOTypeAdapterById(opSdo.get().getType()).orElse(null);
269-
if(doTypeAdapter == null) {
270+
if (doTypeAdapter == null) {
270271
throw new ScdException(errMsg);
271272
}
272273
if(doTypeAdapter.containsDAWithDAName(daName)){

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ public void updateDAI(@NonNull DataAttributeRef dataAttributeRef) throws ScdExce
731731
return;
732732
}
733733

734-
AbstractDAIAdapter<?> daiAdapter = createDoiSdiDaiChainIfNotExists(dataAttributeRef.getDataAttributes(), dataAttributeRef.isUpdatable());
734+
AbstractDAIAdapter<?> daiAdapter = (AbstractDAIAdapter<?>) createDoiSdiDaiChainIfNotExists(dataAttributeRef.getDataAttributes(), dataAttributeRef.isUpdatable());
735735
daiAdapter.update(dataAttributeRef.getDaName().getDaiValues());
736736
}
737737

@@ -752,7 +752,7 @@ public void updateDAI(@NonNull DataAttributeRef dataAttributeRef) throws ScdExce
752752
* @param setValImportOnCreate when this method creates the DAI, it will set DAI.valImport attribute with this parameter
753753
* @return adapter for existing DAI or created DAI.
754754
*/
755-
private AbstractDAIAdapter<?> createDoiSdiDaiChainIfNotExists(String dataTypeRef, boolean setValImportOnCreate) {
755+
public Object createDoiSdiDaiChainIfNotExists(String dataTypeRef, boolean setValImportOnCreate) {
756756
String[] names = dataTypeRef.split("\\.");
757757
if (names.length < 2 || Arrays.stream(names).anyMatch(StringUtils::isBlank)) {
758758
throw new IllegalArgumentException("dataTypeRef must be valid with at least a DO and a DA, but got: " + dataTypeRef);

sct-commons/src/test/java/org/lfenergy/compas/sct/commons/scl/dtt/DOTypeAdapterTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package org.lfenergy.compas.sct.commons.scl.dtt;
66

7+
import org.apache.commons.lang3.tuple.Pair;
78
import org.junit.jupiter.api.Tag;
89
import org.junit.jupiter.api.Test;
910
import org.junit.jupiter.params.ParameterizedTest;
@@ -240,7 +241,29 @@ void getDAByName_should_not_throw_exception(String daName, String fc, String typ
240241
// Then
241242
assertThat(result).isNotNull()
242243
.extracting(TDA::getName, TDA::getFc, TDA::getType)
243-
.containsExactlyInAnyOrder(daName,TFCEnum.fromValue(fc),type);
244+
.containsExactlyInAnyOrder(daName, TFCEnum.fromValue(fc), type);
244245
}
245246

247+
@Test
248+
void findPathSDOToDA_should_return_pair_of_sdo_doType() {
249+
// Given
250+
DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID);
251+
DOTypeAdapter doTypeAdapter = dttAdapter.getDOTypeAdapterById("DO1").get();
252+
// When
253+
Pair<String, DOTypeAdapter> result = doTypeAdapter.findPathSDOToDA("origin", "origin");
254+
//Then
255+
assertThat(result.getLeft()).isEqualTo("origin");
256+
assertThat(result.getRight().getCurrentElem().getId()).isEqualTo("DO4");
257+
}
258+
259+
@Test
260+
void findPathSDOToDA_should_throw_exception() {
261+
// Given
262+
DataTypeTemplateAdapter dttAdapter = initDttAdapterFromFile(SCD_DTT_DIFF_CONTENT_SAME_ID);
263+
DOTypeAdapter doTypeAdapter = dttAdapter.getDOTypeAdapterById("DO2").get();
264+
// When Then
265+
assertThatCode(() -> doTypeAdapter.findPathSDOToDA("origin", "ctVal"))
266+
.isInstanceOf(ScdException.class)
267+
.hasMessage("No coherence or path between DOType(DO3) and DA(ctVal)");
268+
}
246269
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
package org.lfenergy.compas.sct.commons.scl.ied;
66

7-
import org.junit.jupiter.api.*;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Tag;
9+
import org.junit.jupiter.api.Test;
810
import org.junit.jupiter.params.ParameterizedTest;
911
import org.junit.jupiter.params.provider.Arguments;
12+
import org.junit.jupiter.params.provider.CsvSource;
1013
import org.junit.jupiter.params.provider.MethodSource;
1114
import org.junit.jupiter.params.provider.ValueSource;
1215
import org.lfenergy.compas.scl2007b4.model.*;
@@ -867,4 +870,16 @@ private static Stream<Arguments> provideGetTControlsByTypeException() {
867870
);
868871
}
869872

873+
@ParameterizedTest
874+
@CsvSource(value = {"ARtgHigh1.d:d", "ARtgHigh1.units.multiplier:multiplier", "Beh.d:d"}, delimiter = ':')
875+
void createDoiSdiDaiChainIfNotExists_should_create_dai_if_not_exist(String dataTypeRef, String expected) {
876+
// Given
877+
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
878+
LNAdapter lnAdapter = findLn(scd, "IED4d4fe1a8cda64cf88a5ee4176a1a0eef", "LDSUIED", "LPAI", "1", null);
879+
// When
880+
AbstractDAIAdapter<?> daiAdapter = (AbstractDAIAdapter<?>) lnAdapter.createDoiSdiDaiChainIfNotExists(dataTypeRef, true);
881+
//Then
882+
assertThat(daiAdapter.getCurrentElem().getName()).isEqualTo(expected);
883+
}
884+
870885
}

0 commit comments

Comments
 (0)