use of org.activityinfo.test.driver.ApiApplicationDriver in project activityinfo by bedatadriven.
the class InstanceTableUiTest method background.
private void background() throws Exception {
driver.login();
ApiApplicationDriver api = (ApiApplicationDriver) driver.setup();
api.createDatabase(property("name", DATABASE));
api.addPartner("NRC", DATABASE);
api.createForm(name(FORM_NAME), property("database", DATABASE));
api.createField(property("form", FORM_NAME), property("name", "quantity"), property("type", "quantity"), property("code", "1"));
api.createField(property("form", FORM_NAME), property("name", "enum"), property("type", "enum"), property("items", Lists.newArrayList("item1", "item2", "item3")), property("code", "2"));
api.createField(property("form", FORM_NAME), property("name", "text"), property("type", "text"), property("code", "3"));
api.createField(property("form", FORM_NAME), property("name", "multi-line"), property("type", "NARRATIVE"), property("code", "4"));
api.createField(property("form", FORM_NAME), property("name", "barcode"), property("type", "BARCODE"), property("code", "5"));
// submit with null values
api.submitForm(FORM_NAME, Arrays.asList(new FieldValue("Partner", "NRC"), new FieldValue("quantity", -1)));
for (int j = 0; j < 5; j++) {
// chunk on 5 batch commands to avoid SQL timeout
api.startBatch();
for (int i = 0; i < 100; i++) {
api.submitForm(FORM_NAME, Arrays.asList(new FieldValue("Partner", "NRC"), new FieldValue("quantity", i), new FieldValue("enum", i % 2 == 0 ? "item1" : "item1, item2").setType(Optional.of(EnumType.TYPE_CLASS)), new FieldValue("text", "text" + i), new FieldValue("multi-line", "line1\nline2"), new FieldValue("barcode", "barcode")), Arrays.asList("Partner", "quantity", "enum", "text", "multi-line", "barcode"));
}
api.submitBatch();
}
}
use of org.activityinfo.test.driver.ApiApplicationDriver in project activityinfo by bedatadriven.
the class ActionExecution method runAction.
private boolean runAction(UserAction action) {
String oldThreadName = Thread.currentThread().getName();
try {
ActionMetrics actionMetrics = getMetrics(action.getClass());
long started = actionMetrics.start();
Thread.currentThread().setName("UserAction " + action.toString());
try {
ApiApplicationDriver driver = new ApiApplicationDriver(context.getServer(), context.getAccounts(), context.getAliasTable());
driver.login(context.getAccounts().ensureAccountExists(user.getNickName()));
LOGGER.fine(String.format("%s: %s Starting", user.getNickName(), action.toString()));
action.execute(driver);
LOGGER.fine(String.format("%s: %s Completed.", user.getNickName(), action.toString()));
actionMetrics.succeeded(started);
return true;
} catch (Error | IllegalStateException e) {
// Fail early and fast on configuration and pure programming errors
e.printStackTrace();
System.exit(-1);
return false;
} catch (Exception e) {
actionMetrics.failed();
LOGGER.log(Level.FINE, String.format("%s: %s Failed [%s]", user.getNickName(), action.toString(), e.getMessage()), e);
return false;
}
} finally {
Thread.currentThread().setName(oldThreadName);
}
}
Aggregations