use of ru.sbtqa.tag.pagefactory.exceptions.FragmentException in project page-factory-2 by sbtqa.
the class FragmentUtils method getFragmentName.
/**
* Find the name of the scenario (fragment) to substitute for this step
*
* @param step step to substitute
* @param language step's language
* @return name of the scenario (fragment) to substitute
*/
static String getFragmentName(Step step, String language) throws FragmentException {
Map<String, String> props = getFragmentStepRegex(language);
for (Map.Entry<String, String> entry : props.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (key.startsWith(FRAGMENT_STEP_REGEX_KEY)) {
Pattern pattern = Pattern.compile(value);
Matcher matcher = pattern.matcher(step.getText());
if (matcher.find()) {
return matcher.group(1);
}
}
}
throw new FragmentException("Fragment name not found");
}
use of ru.sbtqa.tag.pagefactory.exceptions.FragmentException in project page-factory-2 by sbtqa.
the class FragmentReplacer method replace.
/**
* In the graph, terminal fragments are searched and substituted cyclically.
* The cycle will be completed when all fragments are substituted and there are no edges left in the graph.
*
* @throws IllegalAccessException if it was not possible to replace a step with a fragment
* @throws FragmentException if fragments replacing is in an infinite loop
*/
public void replace() throws IllegalAccessException, FragmentException, DataException {
while (!fragmentsGraph.edges().isEmpty()) {
int fragmentsGraphSize = fragmentsGraph.edges().size();
for (EndpointPair edge : new ArrayList<>(fragmentsGraph.edges())) {
ScenarioDefinition fragment = (ScenarioDefinition) edge.nodeV();
ScenarioDefinition scenario = (ScenarioDefinition) edge.nodeU();
String data = fragmentsGraph.edgeValue(edge.nodeU(), edge.nodeV()).get();
if (isTerminal(fragment)) {
replaceFragmentInScenario(scenario, fragment, data);
fragmentsGraph.removeEdge(scenario, fragment);
}
}
if (fragmentsGraphSize == fragmentsGraph.edges().size()) {
throw new FragmentException("Fragments replacing is no longer performed, it will lead to an infinite loop. Interrupting...");
}
}
}
Aggregations