Skip to content

Commit

Permalink
Change the way the invalid symbols in command are handled. By default…
Browse files Browse the repository at this point in the history
… this is appended to the testng-results.xml file

and then this file is not valid (parser error)

Change-Id: I4d05bff724321da9df9f3bda1537d7804aa28f8f
Signed-off-by: Florent BENOIT <fbenoit@redhat.com>
  • Loading branch information
benoitf committed Jun 14, 2017
1 parent 3805d04 commit 62f550b
Showing 1 changed file with 39 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static java.util.Collections.singletonList;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

/**
* Test deserialization field {@link ComposeServiceImpl#command}
Expand Down Expand Up @@ -177,17 +178,16 @@ private Object[][] inValidCommand() {
};
}

@Test(expectedExceptions = ReaderException.class,
expectedExceptionsMessageRegExp = "special characters are not allowed",
dataProvider = "inValidSymbols")
public void symbolsShouldBeInvalidForYaml(String command) throws Exception {
String content = format(RECIPE_WITHOUT_COMMAND_VALUE, command);

@Test(dataProvider = "inValidSymbols")
public void symbolsShouldBeInvalidForYaml(InvalidSymbolCommand command) throws Exception {
String content = format(RECIPE_WITHOUT_COMMAND_VALUE, command.getCommand());
try {
composeEnvironmentParser.parse(content, "application/x-yaml");
} catch (Exception e) {
System.out.println(e.getLocalizedMessage());
throw e;
// it should fail.
fail("The command " + command.getCommand() + " has invalid symbol and it should fail");
} catch (ReaderException e) {
// we're checking the exception there without throwing it, else it will print to testng-results.xml file an invalid symbol, thus the xml will be invalid.
assertEquals(e.getMessage(), "special characters are not allowed");
}
}

Expand All @@ -198,19 +198,36 @@ public void symbolsShouldBeInvalidForYaml(String command) throws Exception {
@DataProvider(name = "inValidSymbols")
private Object[][] inValidSymbols() {
return new Object[][] {
{"service mysql start\uFFFE"},
{"service mysql start\uDFFF"},
{"service mysql start\uD800"},
{"service mysql start\u009F"},
{"service mysql start\u0086"},
{"service mysql start\u0084"},
{"service mysql start\u0084"},
{"service mysql start\u007F"},
{"service mysql start\u001F"},
{"service mysql start\u000E"},
{"service mysql start\u000C"},
{"service mysql start\u000B"},
{"service mysql start\u0008"},
{new InvalidSymbolCommand("service mysql start\uFFFE")},
{new InvalidSymbolCommand("service mysql start\uDFFF")},
{new InvalidSymbolCommand("service mysql start\uD800")},
{new InvalidSymbolCommand("service mysql start\u009F")},
{new InvalidSymbolCommand("service mysql start\u0086")},
{new InvalidSymbolCommand("service mysql start\u0084")},
{new InvalidSymbolCommand("service mysql start\u0084")},
{new InvalidSymbolCommand("service mysql start\u007F")},
{new InvalidSymbolCommand("service mysql start\u001F")},
{new InvalidSymbolCommand("service mysql start\u000E")},
{new InvalidSymbolCommand("service mysql start\u000C")},
{new InvalidSymbolCommand("service mysql start\u000B")},
{new InvalidSymbolCommand("service mysql start\u0008")},
};
}

/**
* Use of a custom class for the command, so the DataProvider is not printing the string containing invalid characters in the
* testng-results.xml file
*/
private class InvalidSymbolCommand {

private final String command;

InvalidSymbolCommand(String command) {
this.command = command;
}

String getCommand() {
return this.command;
}
}
}

0 comments on commit 62f550b

Please sign in to comment.