Search in sources :

Example 16 with JsonExport

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);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) ProductSystem(org.openlca.core.model.ProductSystem) Parameter(org.openlca.core.model.Parameter) JsonExport(org.openlca.jsonld.output.JsonExport) ProductSystemDao(org.openlca.core.database.ProductSystemDao) ParameterRedefSet(org.openlca.core.model.ParameterRedefSet) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 17 with JsonExport

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);
}
Also used : MemStore(org.openlca.jsonld.MemStore) JsonExport(org.openlca.jsonld.output.JsonExport) Test(org.junit.Test)

Example 18 with JsonExport

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));
}
Also used : JsonExport(org.openlca.jsonld.output.JsonExport)

Example 19 with JsonExport

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));
}
Also used : JsonExport(org.openlca.jsonld.output.JsonExport)

Example 20 with JsonExport

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);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) Currency(org.openlca.core.model.Currency) Process(org.openlca.core.model.Process) JsonExport(org.openlca.jsonld.output.JsonExport) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Aggregations

JsonExport (org.openlca.jsonld.output.JsonExport)25 Test (org.junit.Test)13 JsonImport (org.openlca.jsonld.input.JsonImport)7 AbstractZipTest (org.openlca.jsonld.AbstractZipTest)6 File (java.io.File)4 MemStore (org.openlca.jsonld.MemStore)3 Parameter (org.openlca.core.model.Parameter)2 Process (org.openlca.core.model.Process)2 ProductSystem (org.openlca.core.model.ProductSystem)2 Rpc (org.openlca.ipc.Rpc)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)1 ParameterDao (org.openlca.core.database.ParameterDao)1 ProcessDao (org.openlca.core.database.ProcessDao)1 ProductSystemDao (org.openlca.core.database.ProductSystemDao)1 Currency (org.openlca.core.model.Currency)1