Search in sources :

Example 1 with ModelList

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

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

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

the class LogoUT method checkGetModelListTest.

@Test
public void checkGetModelListTest() throws InstantiationException, IllegalAccessException {
    // prepare mock
    Logo amazon = new Logo();
    amazon.setBrand("amazon");
    Logo redbull = new Logo();
    redbull.setBrand("redbull");
    Class<? extends ModelList> c = amazon.getModelList();
    ModelList cl = c.newInstance();
    cl.addModel(amazon);
    cl.addModel(redbull);
    // run test
    Assert.assertEquals("[{\"brand\":\"amazon\"},{\"brand\":\"redbull\"}]", cl.serialize());
}
Also used : ModelList(com.github.noraui.model.ModelList) Test(org.junit.Test)

Example 4 with ModelList

use of com.github.noraui.model.ModelList 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 5 with ModelList

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

Aggregations

ModelList (com.github.noraui.model.ModelList)6 TechnicalException (com.github.noraui.exception.TechnicalException)3 Model (com.github.noraui.model.Model)3 DataIndex (com.github.noraui.data.DataIndex)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedHashMap (java.util.LinkedHashMap)1 InvalidFileFormatException (org.ini4j.InvalidFileFormatException)1