Search in sources :

Example 26 with TechnicalException

use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.

the class CommonDataProvider method getModel.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public Class<Model> getModel(String modelPackagesCsv) throws TechnicalException {
    if (modelPackagesCsv != null && !"".equals(modelPackagesCsv)) {
        String[] packages = modelPackagesCsv.split(";");
        try {
            if (packages.length > 0) {
                Set<Class<?>> returnedClasses;
                logger.debug("packages length is {}", packages.length);
                for (String p : packages) {
                    returnedClasses = getClasses(p);
                    logger.debug("package [{}] return {} classes", p, returnedClasses.size());
                    for (Class<?> c : returnedClasses) {
                        if (Model.class.isAssignableFrom(c)) {
                            boolean mappingOK = false;
                            for (Field f : c.getDeclaredFields()) {
                                if (f.isAnnotationPresent(Column.class)) {
                                    mappingOK = columns.contains(f.getAnnotation(Column.class).name());
                                }
                            }
                            if (mappingOK) {
                                return (Class<Model>) c;
                            }
                        }
                    }
                }
            }
            return null;
        } catch (Exception e) {
            throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_DATA_IOEXCEPTION), e);
        }
    } else {
        return null;
    }
}
Also used : Field(java.lang.reflect.Field) TechnicalException(com.github.noraui.exception.TechnicalException) Column(com.github.noraui.annotation.Column) TechnicalException(com.github.noraui.exception.TechnicalException)

Example 27 with TechnicalException

use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.

the class Context method initDataId.

private static void initDataId(String scenarioName) throws TechnicalException {
    final List<DataIndex> indexData = new ArrayList<>();
    try {
        Context.getDataInputProvider().prepare(scenarioName);
        final Class<Model> model = Context.getDataInputProvider().getModel(Context.getModelPackages());
        if (model != null) {
            final String[] headers = Context.getDataInputProvider().readLine(0, false);
            if (headers != null) {
                final Constructor<Model> modelConstructor = DataUtils.getModelConstructor(model, headers);
                final Map<String, ModelList> fusionedData = DataUtils.fusionProcessor(model, modelConstructor);
                int dataIndex = 0;
                for (final Entry<String, ModelList> e : fusionedData.entrySet()) {
                    dataIndex++;
                    indexData.add(new DataIndex(dataIndex, e.getValue().getIds()));
                }
            } else {
                logger.error(Messages.getMessage(ScenarioInitiator.SCENARIO_INITIATOR_ERROR_EMPTY_FILE));
            }
        } else {
            for (int i = 1; i < Context.getDataInputProvider().getNbLines(); i++) {
                final List<Integer> index = new ArrayList<>();
                index.add(i);
                indexData.add(new DataIndex(i, index));
            }
        }
        Context.getDataInputProvider().setIndexData(indexData);
    } catch (final Exception te) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE) + te.getMessage(), te);
    }
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) ArrayList(java.util.ArrayList) InvalidFileFormatException(org.ini4j.InvalidFileFormatException) IOException(java.io.IOException) TechnicalException(com.github.noraui.exception.TechnicalException) ModelList(com.github.noraui.model.ModelList) DataIndex(com.github.noraui.data.DataIndex) Model(com.github.noraui.model.Model)

Example 28 with TechnicalException

use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.

the class ShellCommand method run.

public int run() throws TechnicalException {
    final Runtime rt = Runtime.getRuntime();
    final List<String> cmdList = new ArrayList<>();
    cmdList.add(command);
    logger.info(Messages.getMessage(SHELL_RUNNING_COMMAND), command);
    for (final String param : parameters) {
        logger.info(param);
        cmdList.add(param);
    }
    try {
        final Process p = rt.exec(cmdList.toArray(new String[cmdList.size()]));
        final BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            logger.info(line);
        }
        return p.waitFor();
    } catch (IOException | InterruptedException e) {
        logger.error("error ShellCommand.run()", e);
        Thread.currentThread().interrupt();
        throw new TechnicalException(e.getMessage(), e);
    }
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 29 with TechnicalException

use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.

the class DataUtils method fusionProcessor.

public static Map<String, ModelList> fusionProcessor(Class<Model> model, Constructor<Model> modelConstructor) throws TechnicalException {
    final Map<String, ModelList> fusionedData = new LinkedHashMap<>();
    try {
        final Class<? extends ModelList> modelListClass = model.newInstance().getModelList();
        String[] example = Context.getDataInputProvider().readLine(1, false);
        int i = 2;
        do {
            final String key = example[0];
            final Object[] data = addStringToBeginningOfObjectArray(String.valueOf(i - 1), Arrays.copyOfRange(example, 1, example.length));
            if (fusionedData.containsKey(key)) {
                fusionedData.put(key, fusionedData.get(key).addModel(modelConstructor.newInstance(data)));
            } else {
                fusionedData.put(key, modelListClass.newInstance().addModel(modelConstructor.newInstance(data)));
            }
            example = Context.getDataInputProvider().readLine(i, false);
            i++;
        } while (example != null);
    } catch (IllegalAccessException | InstantiationException | IllegalArgumentException | InvocationTargetException e) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_FUSION_PROCESSOR), e);
    }
    return fusionedData;
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedHashMap(java.util.LinkedHashMap) ModelList(com.github.noraui.model.ModelList)

Example 30 with TechnicalException

use of com.github.noraui.exception.TechnicalException in project NoraUi by NoraUi.

the class DBDataProvider method initColumns.

private void initColumns() throws DatabaseException, TechnicalException {
    columns = new ArrayList<>();
    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()) {
        if (rs.getMetaData().getColumnCount() < 1) {
            throw new DatabaseException("Input data is empty. No column have been found.");
        }
        for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
            columns.add(rs.getMetaData().getColumnLabel(i));
        }
    } catch (final SQLException e) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE) + e.getMessage(), e);
    }
    resultColumnName = Messages.getMessage(ResultColumnNames.RESULT_COLUMN_NAME);
}
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) DatabaseException(com.github.noraui.exception.data.DatabaseException)

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