use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.
the class ParameterRedefTest method testInParameterRedefSet.
@Test
public void testInParameterRedefSet() {
// create the model
ProductSystemDao dao = new ProductSystemDao(db);
ProductSystem sys = new ProductSystem();
sys.refId = UUID.randomUUID().toString();
ParameterRedefSet paramSet = new ParameterRedefSet();
sys.parameterSets.add(paramSet);
paramSet.isBaseline = true;
paramSet.name = "Baseline";
paramSet.parameters.add(redef);
dao.insert(sys);
// write and clear DB
with(zip -> new JsonExport(Tests.getDb(), zip).write(sys));
db.clear();
Assert.assertNull(dao.getForRefId(sys.refId));
Assert.assertNull(paramDao.getForRefId(globalParam.refId));
// import and check
with(zip -> new JsonImport(zip, db).run());
ProductSystem sys2 = dao.getForRefId(sys.refId);
Assert.assertEquals("R", sys2.parameterSets.get(0).parameters.get(0).name);
Parameter p = paramDao.getForRefId(globalParam.refId);
Assert.assertEquals("R", p.name);
}
use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.
the class UnitGroupImportTest method testUpdateUnit.
@Test
public void testUpdateUnit() {
// create and export the unit group
var group = db.insert(UnitGroup.of("Mass units", Unit.of("kg")));
var store = new MemStore();
new JsonExport(db, store).write(group);
// update the JSON object
var json = store.get(ModelType.UNIT_GROUP, group.refId);
json.addProperty("description", "unit group description");
json.addProperty("version", "42.0.0");
var units = Json.getArray(json, "units");
var unit = units.get(0).getAsJsonObject();
unit.addProperty("description", "unit description");
// update it
new JsonImport(store, db).setUpdateMode(UpdateMode.IF_NEWER).run();
var updated = db.get(UnitGroup.class, group.id);
db.delete(updated);
// check updated fields
assertEquals("unit group description", updated.description);
assertEquals("unit description", updated.referenceUnit.description);
}
use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.
the class CategoryTest method doExport.
private void doExport(Category category, CategoryDao dao) {
with(zip -> {
JsonExport export = new JsonExport(Tests.getDb(), zip);
export.write(category);
});
dao.delete(category);
Assert.assertFalse(dao.contains(category.refId));
}
use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.
the class CurrencyTest method doExport.
private void doExport(Currency currency, CurrencyDao dao) {
with(zip -> {
JsonExport export = new JsonExport(Tests.getDb(), zip);
export.write(currency);
});
dao.delete(currency);
Assert.assertFalse(dao.contains(currency.refId));
}
use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.
the class ExchangeCostTest method testCostAttributes.
@Test
public void testCostAttributes() {
Currency currency = createCurrency();
Process process = createProcess(currency);
with(zip -> {
JsonExport export = new JsonExport(Tests.getDb(), zip);
export.write(process);
});
delete(currency, process);
with(zip -> {
JsonImport jImport = new JsonImport(zip, Tests.getDb());
jImport.run();
});
checkImport(process);
}
Aggregations