Skip to content

Commit

Permalink
ajout de tests
Browse files Browse the repository at this point in the history
Signed-off-by: gleizesDor <115622893+gleizesDor@users.noreply.github.com>
  • Loading branch information
gleizesDor committed Nov 27, 2023
1 parent 1a59232 commit 26fc78b
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import org.assertj.core.groups.Tuple;
import org.junit.jupiter.api.Test;
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TDO;
import org.lfenergy.compas.scl2007b4.model.TLNodeType;
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class DoServiceTest {

@Test
void getDos() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TLNodeType lnodeType = std.getDataTypeTemplates().getLNodeType().get(0);
DoService doService = new DoService();

//When
List<TDO> dos = doService.getDos(lnodeType).toList();

//Then
assertThat(dos)
.hasSize(14)
.extracting(TDO::getName)
.containsExactly("NumInput1",
"PolConnRef1",
"BrdPos",
"ConnName1",
"PhyHealth",
"ConnRef1",
"NamPlt",
"RfHz1",
"PhyNam",
"Beh",
"BrdNum",
"ARtgLow1",
"ARtgHigh1",
"AnIn1");
}

@Test
void getFilteredDos() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TLNodeType lnodeType = std.getDataTypeTemplates().getLNodeType().get(0);
DoService doService = new DoService();

//When
List<TDO> dos = doService.getFilteredDos(lnodeType, tdo -> "NumInput1".equals(tdo.getName())).toList();

//Then
assertThat(dos)
.hasSize(1)
.extracting(TDO::getName, TDO::getType)
.containsExactly(Tuple.tuple("NumInput1", "RTE_X_X_X_553F8AE90EC0448B1518B00F5EAABB58_ING_V1.0.0"));
}

@Test
void findDo() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TLNodeType lnodeType = std.getDataTypeTemplates().getLNodeType().get(0);
DoService doService = new DoService();

//When
TDO tdo1 = doService.findDo(lnodeType, tdo -> "NumInput1".equals(tdo.getName())).orElseThrow();

//Then
assertThat(tdo1)
.extracting(TDO::getName, TDO::getType)
.containsExactly("NumInput1", "RTE_X_X_X_553F8AE90EC0448B1518B00F5EAABB58_ING_V1.0.0");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import org.assertj.core.groups.Tuple;
import org.junit.jupiter.api.Test;
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TDOType;
import org.lfenergy.compas.scl2007b4.model.TDataTypeTemplates;
import org.lfenergy.compas.scl2007b4.model.TPredefinedCDCEnum;
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class DoTypeServiceTest {

@Test
void getDoTypes() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TDataTypeTemplates dataTypeTemplates = std.getDataTypeTemplates();
DoTypeService doTypeService = new DoTypeService();

//When
List<TDOType> tdoTypes = doTypeService.getDoTypes(dataTypeTemplates).toList();

//Then
assertThat(tdoTypes)
.hasSize(47);
}

@Test
void getFilteredDoTypes() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TDataTypeTemplates dataTypeTemplates = std.getDataTypeTemplates();
DoTypeService doTypeService = new DoTypeService();

//When
List<TDOType> tdoTypes =
doTypeService.getFilteredDoTypes(dataTypeTemplates, tdoType -> TPredefinedCDCEnum.DPL.equals(tdoType.getCdc())).toList();

//Then
assertThat(tdoTypes)
.hasSize(2)
.extracting(TDOType::getCdc, TDOType::getId)
.containsExactly(Tuple.tuple(TPredefinedCDCEnum.DPL, "RTE_X_X_X_48BA5C40D0913654FA5291A28C0D9716_DPL_V1.0.0"),
Tuple.tuple(TPredefinedCDCEnum.DPL, "RTE_X_X_X_D93000A2D6F9B026504B48576A914DA3_DPL_V1.0.0"));

}

@Test
void findDoType() {
//Given
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std");
TDataTypeTemplates dataTypeTemplates = std.getDataTypeTemplates();
DoTypeService doTypeService = new DoTypeService();

//When
TDOType tdoType = doTypeService.findDoType(dataTypeTemplates, tdoType1 -> TPredefinedCDCEnum.DPL.equals(tdoType1.getCdc())).orElseThrow();

//Then
assertThat(tdoType)
.extracting(TDOType::getCdc, TDOType::getId)
.containsExactly(TPredefinedCDCEnum.DPL, "RTE_X_X_X_48BA5C40D0913654FA5291A28C0D9716_DPL_V1.0.0");
}
}

0 comments on commit 26fc78b

Please sign in to comment.