use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class DBDataProvider method getNbLines.
/**
* {@inheritDoc}
*
* @throws TechnicalException
* is thrown if you have a technical error (IOException on .sql file) in NoraUi.
*/
@Override
public int getNbLines() throws TechnicalException {
String sqlRequest = "";
try {
final Path file = Paths.get(dataInPath + scenarioName + ".sql");
sqlRequest = new String(Files.readAllBytes(file), Charset.forName(Constants.DEFAULT_ENDODING));
sqlSanitized4readOnly(sqlRequest);
} catch (final IOException e) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE) + e.getMessage(), e);
}
try (Connection connection = getConnection();
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = statement.executeQuery(sqlRequest)) {
return rs.last() ? rs.getRow() + 1 : 0;
} catch (final SQLException e) {
logger.error("error DBDataProvider.getNbLines()", e);
return 0;
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class DBDataProvider method readLine.
/**
* {@inheritDoc}
*
* @throws TechnicalException
* is thrown if you have a technical error (IOException on .sql file) in NoraUi.
*/
@Override
public String[] readLine(int line, boolean readResult) throws TechnicalException {
String sqlRequest;
try {
final Path file = Paths.get(dataInPath + scenarioName + ".sql");
sqlRequest = new String(Files.readAllBytes(file), Charset.forName(Constants.DEFAULT_ENDODING));
sqlSanitized4readOnly(sqlRequest);
} catch (final IOException e) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE) + e.getMessage(), e);
}
try (Connection connection = getConnection();
PreparedStatement statement = connection.prepareStatement(sqlRequest);
ResultSet rs = statement.executeQuery()) {
final String[] ret = readResult ? new String[columns.size()] : new String[columns.size() - 1];
if (line == 0) {
for (int i = 0; i < ret.length; i++) {
ret[i] = columns.get(i);
}
} else {
while (rs.next() && rs.getRow() < line) {
}
for (int i = 1; i <= ret.length; i++) {
ret[i - 1] = rs.getString(i);
}
}
return ret;
} catch (final SQLException e) {
logger.debug("In DBDataProvider, this catch aims for testing the end of provided data. DBDataProvider.readLine({}, {})", line, readResult, e);
return null;
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class StepUT method testFormatMessage.
@Test
public void testFormatMessage() {
try {
final DemoPage demoPage = (DemoPage) Page.getInstance(DEMO_PAGE_NAME);
final PageElement pageElement = demoPage.getPageElementByKey("-input_select_field");
final String a = Messages.format("Message %s in %s.", pageElement, demoPage.getApplication());
Assert.assertEquals("", "Message Input Select field in demo.", a);
} catch (final TechnicalException e) {
Assert.assertFalse("Error", true);
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class StepUT method testFormatMessageNotValid2Message.
@Test
public void testFormatMessageNotValid2Message() {
try {
final DemoPage demoPage = (DemoPage) Page.getInstance(DEMO_PAGE_NAME);
final PageElement pageElement = demoPage.getPageElementByKey("-input");
Messages.format("Message %s.", pageElement, demoPage.getApplication());
} catch (final TechnicalException e) {
Assert.assertEquals("TechnicalException found", Messages.getMessage("FAIL_MESSAGE_FORMAT_STRING"), e.getMessage());
}
}
use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.
the class StepUT method testFormatMessage2.
@Test
public void testFormatMessage2() {
try {
final DemoPage demoPage = (DemoPage) Page.getInstance(DEMO_PAGE_NAME);
final PageElement pageElement = demoPage.getPageElementByKey("-submit");
final String a = Messages.format("Message %s in %s.", pageElement, demoPage.getApplication());
Assert.assertEquals("", "Message Submit button in demo.", a);
} catch (final TechnicalException e) {
Assert.assertFalse("Error", true);
}
}
Aggregations