Search in sources :

Example 1 with Model

use of com.github.noraui.model.Model in project NoraUi by NoraUi.

the class MavenRunCounter method countWithModel.

private static void countWithModel(int nbStep, Counter result, List<DataIndex> indexData, Class<Model> model) throws TechnicalException {
    int failures = 0;
    int skipped = 0;
    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()));
            for (int i = 0; i < e.getValue().getIds().size(); i++) {
                final Integer wid = e.getValue().getIds().get(i);
                final String resultColumn = Context.getDataInputProvider().readValue(Context.getDataInputProvider().getResultColumnName(), wid);
                if (!"".equals(resultColumn)) {
                    failures += 1;
                    skipped += nbStep - (int) Double.parseDouble(resultColumn);
                }
            }
        }
    } else {
        logger.error(Messages.getMessage(ScenarioInitiator.SCENARIO_INITIATOR_ERROR_EMPTY_FILE));
    }
    result.setNbcas(indexData.size());
    result.setFailures(failures);
    result.setSkipped(skipped);
}
Also used : ModelList(com.github.noraui.model.ModelList) Model(com.github.noraui.model.Model) DataIndex(com.github.noraui.data.DataIndex)

Example 2 with Model

use of com.github.noraui.model.Model in project NoraUi by NoraUi.

the class ScenarioInitiator method injectWithModel.

private static void injectWithModel(String scenarioName, Class<Model> model) throws TechnicalException {
    try {
        final String[] headers = Context.getDataInputProvider().readLine(0, false);
        if (headers != null) {
            final List<String[]> examples = new ArrayList<>();
            final Constructor<Model> modelConstructor = DataUtils.getModelConstructor(model, headers);
            final Map<String, ModelList> fusionedData = DataUtils.fusionProcessor(model, modelConstructor);
            for (final Entry<String, ModelList> e : fusionedData.entrySet()) {
                examples.add(new String[] { e.getKey(), e.getValue().serialize() });
            }
            GherkinFactory.injectDataInGherkinExamples(scenarioName, examples);
        } else {
            logger.error(Messages.getMessage(SCENARIO_INITIATOR_ERROR_EMPTY_FILE));
        }
    } catch (final Exception te) {
        throw new TechnicalException(Messages.getMessage(SCENARIO_INITIATOR_ERROR_ON_INJECTING_MODEL) + te.getMessage(), te);
    }
}
Also used : ModelList(com.github.noraui.model.ModelList) TechnicalException(com.github.noraui.exception.TechnicalException) ArrayList(java.util.ArrayList) Model(com.github.noraui.model.Model) TechnicalException(com.github.noraui.exception.TechnicalException)

Example 3 with Model

use of com.github.noraui.model.Model 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)

Aggregations

Model (com.github.noraui.model.Model)3 ModelList (com.github.noraui.model.ModelList)3 DataIndex (com.github.noraui.data.DataIndex)2 TechnicalException (com.github.noraui.exception.TechnicalException)2 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 InvalidFileFormatException (org.ini4j.InvalidFileFormatException)1