Skip to content

Commit

Permalink
test permutability error reason
Browse files Browse the repository at this point in the history
  • Loading branch information
lharzenetter committed Aug 21, 2020
1 parent 2783e8d commit 0bb148f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public class PermutationGenerator {
protected final Map<QName, TRelationshipType> relationshipTypes = new HashMap<>();
protected final Map<QName, TNodeType> nodeTypes = new HashMap<>();

protected final String errorMessage = "Permutations cannot be determined automatically! Reason: {}.";
protected String permutabilityErrorReason = "";

public PermutationGenerator() {
this.relationshipTypes.putAll(RepositoryFactory.getRepository().getQNameToElementMapping(RelationshipTypeId.class));
this.nodeTypes.putAll(RepositoryFactory.getRepository().getQNameToElementMapping(NodeTypeId.class));
Expand All @@ -71,6 +74,8 @@ public PermutationGenerator(Map<QName, TRelationshipType> relationshipTypes, Map

public boolean checkPermutability(OTTopologyFragmentRefinementModel refinementModel) {
logger.info("Starting permutability check of {}", refinementModel.getIdFromIdOrNameField());
this.permutabilityErrorReason = "";

List<TNodeTemplate> detectorNodeTemplates = refinementModel.getDetector().getNodeTemplates();
Set<TNodeTemplate> permutableNodes = detectorNodeTemplates.stream()
.filter(nodeTemplate -> !isStayingElement(nodeTemplate, refinementModel))
Expand Down Expand Up @@ -116,8 +121,8 @@ public boolean checkPermutability(OTTopologyFragmentRefinementModel refinementMo
}

if (refinementModel.getPermutationMappings() == null) {
logger.info("Permutations cannot be determined automatically! " +
"Reason: No permutation mappings could be identified.");
this.permutabilityErrorReason = "No permutation mappings could be identified";
logger.info(this.errorMessage, this.permutabilityErrorReason);
return false;
}

Expand All @@ -128,9 +133,9 @@ public boolean checkPermutability(OTTopologyFragmentRefinementModel refinementMo
.collect(Collectors.toList());

if (unmappedDetectorNodes.size() > 0) {
logger.info("Permutations cannot be determined automatically! " +
"Reason: There are detector nodes which could not be mapped to a refinement node: {}",
String.join(", ", unmappedDetectorNodes));
this.permutabilityErrorReason = "There are detector nodes which could not be mapped to a refinement node: "
+ String.join(", ", unmappedDetectorNodes);
logger.info(this.errorMessage, this.permutabilityErrorReason);
return false;
}

Expand All @@ -141,9 +146,9 @@ public boolean checkPermutability(OTTopologyFragmentRefinementModel refinementMo
.collect(Collectors.toList());

if (unmappedRefinementNodes.size() > 0) {
logger.info("Permutations cannot be determined automatically! " +
"Reason: There are refinement nodes which could not be mapped to a detector node: {}",
String.join(", ", unmappedRefinementNodes));
this.permutabilityErrorReason = "There are refinement nodes which could not be mapped to a detector node: "
+ String.join(", ", unmappedRefinementNodes);
logger.info(this.errorMessage, this.permutabilityErrorReason);
return false;
}

Expand Down Expand Up @@ -171,8 +176,8 @@ public boolean checkPermutability(OTTopologyFragmentRefinementModel refinementMo
}

if (detectorNodeRefinesToMultipleNodes) {
logger.info("Permutations cannot be determined automatically! " +
"Reason: There are relations that cannot be redirected during the generation.");
this.permutabilityErrorReason = "There are relations that cannot be redirected during the generation";
logger.info(this.errorMessage, this.permutabilityErrorReason);
return false;
}

Expand Down Expand Up @@ -252,4 +257,8 @@ private void checkComponentPermutability(TNodeTemplate refinementNode,
).forEach(dependee -> this.checkComponentPermutability(dependee, detectorNode, refinementModel));
}
}

public String getPermutabilityErrorReason() {
return permutabilityErrorReason;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void checkPermutabilityOfNotPermuatablePrmWithPatternSet() {

PermutationGenerator permutationGenerator = new PermutationGenerator();
assertFalse(permutationGenerator.checkPermutability(refinementModel));
assertEquals("There are detector nodes which could not be mapped to a refinement node: 3",
permutationGenerator.getPermutabilityErrorReason());

assertEquals(3, refinementModel.getPermutationMappings().size());
refinementModel.getPermutationMappings()
Expand Down Expand Up @@ -106,6 +108,21 @@ void checkPermutabilityOfNotPermuatablePrmBecauseOfARelationThatCannotBeRedirect

PermutationGenerator permutationGenerator = new PermutationGenerator();
assertFalse(permutationGenerator.checkPermutability(refinementModel));
assertEquals("There are relations that cannot be redirected during the generation",
permutationGenerator.getPermutabilityErrorReason());
}

@Test
void checkPermutabilityOfNotPermuatablePrmBecauseOfANotMappableRefinementNode() {
OTPatternRefinementModel refinementModel = generatePrm();
addPermutationMappings(refinementModel);

refinementModel.getPermutationMappings().removeIf(map -> map.getId().equals("p2_to_n14"));

PermutationGenerator permutationGenerator = new PermutationGenerator();
assertFalse(permutationGenerator.checkPermutability(refinementModel));
assertEquals("There are refinement nodes which could not be mapped to a detector node: 14",
permutationGenerator.getPermutabilityErrorReason());
}

@Test
Expand All @@ -121,6 +138,7 @@ void checkPermutabilityOfPermuatablePrmWithPermutationMapping() {

PermutationGenerator permutationGenerator = new PermutationGenerator();
assertTrue(permutationGenerator.checkPermutability(refinementModel));
assertEquals("", permutationGenerator.getPermutabilityErrorReason());

assertEquals(7, refinementModel.getPermutationMappings().size());
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap ->
Expand Down

0 comments on commit 0bb148f

Please sign in to comment.