Search in sources :

Example 31 with TechnicalException

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;
    }
}
Also used : Path(java.nio.file.Path) TechnicalException(com.github.noraui.exception.TechnicalException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IOException(java.io.IOException)

Example 32 with TechnicalException

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;
    }
}
Also used : Path(java.nio.file.Path) TechnicalException(com.github.noraui.exception.TechnicalException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException)

Example 33 with TechnicalException

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);
    }
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) DemoPage(com.github.noraui.application.page.demo.DemoPage) PageElement(com.github.noraui.application.page.Page.PageElement) Test(org.junit.Test)

Example 34 with TechnicalException

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());
    }
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) DemoPage(com.github.noraui.application.page.demo.DemoPage) PageElement(com.github.noraui.application.page.Page.PageElement) Test(org.junit.Test)

Example 35 with TechnicalException

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);
    }
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) DemoPage(com.github.noraui.application.page.demo.DemoPage) PageElement(com.github.noraui.application.page.Page.PageElement) Test(org.junit.Test)

Aggregations

TechnicalException (com.github.noraui.exception.TechnicalException)39 FailureException (com.github.noraui.exception.FailureException)13 Result (com.github.noraui.exception.Result)12 WebElement (org.openqa.selenium.WebElement)10 IOException (java.io.IOException)9 ParseException (java.text.ParseException)9 Test (org.junit.Test)8 PageElement (com.github.noraui.application.page.Page.PageElement)6 DemoPage (com.github.noraui.application.page.demo.DemoPage)6 ArrayList (java.util.ArrayList)5 Then (cucumber.api.java.en.Then)4 File (java.io.File)4 Path (java.nio.file.Path)4 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 GherkinStepCondition (com.github.noraui.gherkin.GherkinStepCondition)3 ModelList (com.github.noraui.model.ModelList)3 Conditioned (com.github.noraui.cucumber.annotation.Conditioned)2