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);
}
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);
}
}
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());
}
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);
}
}
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;
}
Aggregations