use of com.github.noraui.gherkin.GherkinConditionedLoopedStep in project NoraUi by NoraUi.
the class Step method runAllStepsInLoop.
/**
* Runs a bunch of steps for a Gherkin loop.
*
* @param loopedSteps
* GherkinConditionedLoopedStep steps to run
* @throws TechnicalException
* is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
*/
protected void runAllStepsInLoop(List<GherkinConditionedLoopedStep> loopedSteps) throws TechnicalException {
for (final GherkinConditionedLoopedStep loopedStep : loopedSteps) {
final List<GherkinStepCondition> stepConditions = new ArrayList<>();
final String[] expecteds = loopedStep.getExpected().split(";");
final String[] actuals = loopedStep.getActual().split(";");
if (actuals.length != expecteds.length) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_EXPECTED_ACTUAL_SIZE_DIFFERENT));
}
for (int i = 0; i < expecteds.length; i++) {
stepConditions.add(new GherkinStepCondition(loopedStep.getKey(), expecteds[i], actuals[i]));
}
boolean found = false;
for (final Entry<String, Method> elem : Context.getCucumberMethods().entrySet()) {
final Matcher matcher = Pattern.compile("value=(.*)\\)").matcher(elem.getKey());
if (matcher.find()) {
final Matcher matcher2 = Pattern.compile(matcher.group(1)).matcher(loopedStep.getStep());
if (matcher2.find()) {
Object[] tab;
if (elem.getValue().isAnnotationPresent(Conditioned.class)) {
tab = new Object[matcher2.groupCount() + 1];
tab[matcher2.groupCount()] = stepConditions;
} else {
tab = new Object[matcher2.groupCount()];
}
for (int i = 0; i < matcher2.groupCount(); i++) {
final Parameter param = elem.getValue().getParameters()[i];
if (param.getType() == int.class) {
final int ii = Integer.parseInt(matcher2.group(i + 1));
tab[i] = ii;
} else if (param.getType() == boolean.class) {
tab[i] = Boolean.parseBoolean(matcher2.group(i + 1));
} else {
tab[i] = matcher2.group(i + 1);
}
}
try {
found = true;
elem.getValue().invoke(NoraUiInjector.getNoraUiInjectorSource().getInstance(elem.getValue().getDeclaringClass()), tab);
break;
} catch (final Exception e) {
throw new TechnicalException("\"" + loopedStep.getStep() + "\"", e.getCause());
}
}
}
}
if (!found) {
throw new TechnicalException(String.format(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_STEP_UNDEFINED), loopedStep.getStep()));
}
}
}
use of com.github.noraui.gherkin.GherkinConditionedLoopedStep in project NoraUi by NoraUi.
the class StepUT method testRunAllStepsInLoopWithUndefinedStep.
@Test
public void testRunAllStepsInLoopWithUndefinedStep() {
final List<GherkinConditionedLoopedStep> steps = new ArrayList<>();
final String expected = ".+;(ETS Backbone VLAN LL2048K\\|ETS Accès L2ETH\\|Accès XDSL ETS\\|Backbone VLAN Virtuelle)";
final String actual = "VPNtechnique;OSC_ACC-resource_type";
Context.saveValue("OSC_ACC-resource_type", "ETS Accès L2ETH");
final GherkinConditionedLoopedStep gherkinConditionedLoopedStep = new GherkinConditionedLoopedStep("1", "I wait '4' seconds.", expected, actual);
steps.add(gherkinConditionedLoopedStep);
try {
step.runAllStepsInLoop(steps);
Assert.fail("TechnicalException should have been thrown");
} catch (final TechnicalException e) {
Assert.assertEquals(String.format(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_STEP_UNDEFINED), "I wait '4' seconds."), e.getMessage());
}
}
Aggregations