Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor test code to use assertj and using gherkin to define scenarios #307

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void updateAllExtRefIedNames_should_update_iedName_and_ExtRefIedName() {
// Given : An ExtRef with a matching compas:Flow
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_success.xml");
// When
List<SclReportItem> sclReportItems = ExtRefService.updateAllExtRefIedNames(scd);
ExtRefService.updateAllExtRefIedNames(scd);
// Then
TExtRef extRef = findExtRef(scd, "IED_NAME1", "LD_INST11", "STAT_LDSUIED_LPDO 1 Sortie_13_BOOLEAN_18_stVal_1");
assertThat(extRef.getIedName()).isEqualTo("IED_NAME2");
Expand All @@ -65,6 +65,7 @@ void updateAllExtRefIedNames_should_update_iedName_and_ExtRefIedName() {
.getLN0Adapter()
.getCurrentElem()
.getInputs();
//TODO PrivateService methods should not appear in then section
assertThat(PrivateService.extractCompasPrivate(inputs, TCompasFlow.class))
.map(TCompasFlow::getExtRefiedName)
.hasValue("IED_NAME2");
Expand Down Expand Up @@ -393,7 +394,6 @@ private void assertExtRefIsNotBound(TExtRef extRef) {
void updateAllSourceDataSetsAndControlBlocks_should_sort_FCDA_inside_DataSet_and_avoid_duplicates() {
// Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_dataset_and_controlblocks_success_test_fcda_sort.xml");
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
// When
List<SclReportItem> sclReportItems = ExtRefService.createDataSetAndControlBlocks(scd);
// Then
Expand Down Expand Up @@ -522,7 +522,7 @@ void filterDuplicatedExtRefs_should_remove_duplicated_extrefs() {
List<TExtRef> tExtRefList = List.of(tExtRef, tExtRefLnClass, createExtRefExample("CB", TServiceType.GOOSE),
createExtRefExample("CB", TServiceType.GOOSE));
// When
List<TExtRef> result = filterDuplicatedExtRefs(tExtRefList);
List<TExtRef> result = ExtRefService.filterDuplicatedExtRefs(tExtRefList);
// Then
assertThat(result).hasSizeLessThan(tExtRefList.size())
.hasSize(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ void removePrivates_should_remove_privates_of_given_type() {
TBaseElement baseElement = new SCL();
baseElement.getPrivate().add(privateSCD);
TCompasICDHeader tCompasICDHeader = objectFactory.createTCompasICDHeader();
//TODO not should appear in given section, only one When step - PrivateService.createPrivate
baseElement.getPrivate().add(PrivateService.createPrivate(tCompasICDHeader));
// When
PrivateService.removePrivates(baseElement, PrivateEnum.COMPAS_ICDHEADER);
Expand Down Expand Up @@ -269,6 +270,7 @@ void createMapICDSystemVersionUuidAndSTDFile_Should_return_empty_map_when_no_ICD
SCL scl1 = new SCL();
TIED tied1 = new TIED();
TCompasICDHeader compasICDHeader1 = new TCompasICDHeader();
//TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
tied1.getPrivate().add(tPrivate1);
scl1.getIED().add(tied1);
Expand Down Expand Up @@ -296,8 +298,11 @@ void createMapICDSystemVersionUuidAndSTDFile_Should_return_map_with_two_lines()
compasICDHeader2.setICDSystemVersionUUID("UUID-2");
TCompasICDHeader compasICDHeader3 = new TCompasICDHeader();
compasICDHeader3.setICDSystemVersionUUID("UUID-2");
//TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
//TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);
//TODO not should appear in given section, only one When step
TPrivate tPrivate3 = PrivateService.createPrivate(compasICDHeader3);
tied1.getPrivate().add(tPrivate1);
tied2.getPrivate().add(tPrivate2);
Expand All @@ -324,14 +329,14 @@ void checkSTDCorrespondanceWithLNodeCompasICDHeadershoul_throw_scdEception(){
compasICDHeader2.setHeaderId("ID-2");
compasICDHeader2.setHeaderVersion("VER-2");
compasICDHeader2.setHeaderRevision("REV-2");
//TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
//TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);


PrivateService.PrivateLinkedToSTDs privateLinkedToSTDs1 = new PrivateService.PrivateLinkedToSTDs(tPrivate1,Collections.singletonList(new SCL()));
PrivateService.PrivateLinkedToSTDs privateLinkedToSTDs2 = new PrivateService.PrivateLinkedToSTDs(tPrivate2, Arrays.asList(new SCL(), new SCL()));


Map<String, PrivateService.PrivateLinkedToSTDs> stringSCLMap = new HashMap<>();
stringSCLMap.put("UUID-1", privateLinkedToSTDs1);
stringSCLMap.put("UUID-2", privateLinkedToSTDs2);
Expand All @@ -350,14 +355,14 @@ void checkSTDCorrespondanceWithLNodeCompasICDHeader_should_pass(){
compasICDHeader1.setICDSystemVersionUUID("UUID-1");
TCompasICDHeader compasICDHeader2 = new TCompasICDHeader();
compasICDHeader2.setICDSystemVersionUUID("UUID-2");
//TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
//TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);


PrivateService.PrivateLinkedToSTDs privateLinkedToSTDs1 = new PrivateService.PrivateLinkedToSTDs(tPrivate1,Collections.singletonList(new SCL()));
PrivateService.PrivateLinkedToSTDs privateLinkedToSTDs2 = new PrivateService.PrivateLinkedToSTDs(tPrivate2, Collections.singletonList(new SCL()));


Map<String, PrivateService.PrivateLinkedToSTDs> stringSCLMap = new HashMap<>();
stringSCLMap.put("UUID-1", privateLinkedToSTDs1);
stringSCLMap.put("UUID-2", privateLinkedToSTDs2);
Expand All @@ -374,6 +379,7 @@ void stdCheckFormatExceptionMessage_should_return_formatted_message_with_Private
compasICDHeader.setHeaderId("ID-1");
compasICDHeader.setHeaderVersion("VER-1");
compasICDHeader.setICDSystemVersionUUID("UUID-1");
//TODO not should appear in given section, only one When step
TPrivate tPrivate = PrivateService.createPrivate(compasICDHeader);

//When
Expand All @@ -397,8 +403,11 @@ void createMapIEDNameAndPrivate_should_return_map_of_three_items() {
compasICDHeader2.setIEDName("IED-2");
TCompasICDHeader compasICDHeader3 = new TCompasICDHeader();
compasICDHeader3.setIEDName("IED-3");
//TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
//TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);
//TODO not should appear in given section, only one When step
TPrivate tPrivate3 = PrivateService.createPrivate(compasICDHeader3);
tlNode1.getPrivate().add(tPrivate1);
tlNode2.getPrivate().add(tPrivate2);
Expand Down Expand Up @@ -430,6 +439,7 @@ void createMapIEDNameAndPrivate_should_return_empty_map_when_no_compasicdheader_
TLNode tlNode1 = new TLNode();
TCompasBay compasBay = new TCompasBay();
compasBay.setUUID("UUID");
//TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasBay);
tlNode1.getPrivate().add(tPrivate1);
TFunction tFunction = new TFunction();
Expand Down Expand Up @@ -457,7 +467,9 @@ void comparePrivateCompasICDHeaders_should_return_true_equality_not_check_for_IE
compasICDHeader1.setBayLabel("BAY-1");
compasICDHeader1.setIEDSubstationinstance(BigInteger.ONE);
TCompasICDHeader compasICDHeader2 = new TCompasICDHeader();
//TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
//TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);

// When
Expand All @@ -476,7 +488,9 @@ void comparePrivateCompasICDHeaders_should_return_false_equality_not_check_for_I
compasICDHeader1.setICDSystemVersionUUID("UUID-1");
TCompasICDHeader compasICDHeader2 = new TCompasICDHeader();
compasICDHeader2.setICDSystemVersionUUID("UUID-2");
//TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
//TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);

// When
Expand All @@ -495,7 +509,9 @@ void comparePrivateCompasICDHeaders_should_return_true() {
compasICDHeader1.setICDSystemVersionUUID("UUID-1");
TCompasICDHeader compasICDHeader2 = new TCompasICDHeader();
compasICDHeader2.setICDSystemVersionUUID("UUID-1");
//TODO not should appear in given section, only one When step
TPrivate tPrivate1 = PrivateService.createPrivate(compasICDHeader1);
//TODO not should appear in given section, only one When step
TPrivate tPrivate2 = PrivateService.createPrivate(compasICDHeader2);

// When
Expand All @@ -514,20 +530,22 @@ void copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate() {
lNodeCompasICDHeader.setIEDName("IED-1");
lNodeCompasICDHeader.setBayLabel("BAY-1");
lNodeCompasICDHeader.setIEDSubstationinstance(BigInteger.ONE);
//TODO not should appear in given section, only one When step
TPrivate stdTPrivate = PrivateService.createPrivate(stdCompasICDHeader);

// When
PrivateService.copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate(stdTPrivate, lNodeCompasICDHeader);

// Then
TCompasICDHeader result = PrivateService.extractCompasICDHeader(stdTPrivate).get();
//FIXME is this the 'When' extractCompasICDHeader ??? so why test named copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate
assertThat(result).extracting(TCompasICDHeader::getICDSystemVersionUUID, TCompasICDHeader::getIEDName,
TCompasICDHeader::getIEDSubstationinstance, TCompasICDHeader::getBayLabel)
.containsExactlyInAnyOrder("UUID-2", "IED-1", BigInteger.ONE, "BAY-1");
}

@Test
void gettCompasICDHeaders_should_return_ICDHeaders() {
void getCompasICDHeaders_should_return_ICDHeaders() {
//Given
TIED tied = createTIED();

Expand Down
Loading