Search in sources :

Example 21 with JsonExport

use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.

the class FlowPropertyTest method doExport.

private void doExport(FlowProperty property, FlowPropertyDao dao) {
    with(zip -> {
        JsonExport export = new JsonExport(Tests.getDb(), zip);
        export.write(property);
    });
    dao.delete(property);
    Assert.assertFalse(dao.contains(property.refId));
}
Also used : JsonExport(org.openlca.jsonld.output.JsonExport)

Example 22 with JsonExport

use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.

the class FlowTest method exportAndDelete.

private void exportAndDelete(Flow flow, FlowDao dao) {
    with(zip -> {
        JsonExport export = new JsonExport(Tests.getDb(), zip);
        export.write(flow);
    });
    dao.delete(flow);
    Assert.assertFalse(dao.contains(flow.refId));
}
Also used : JsonExport(org.openlca.jsonld.output.JsonExport)

Example 23 with JsonExport

use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.

the class DepTest method testDep.

@Test
public void testDep() throws Exception {
    var unitLib = libDir.create("units 1.0");
    var units = UnitGroup.of("Units of mass", "kg");
    try (var zip = ZipStore.open(new File(unitLib.folder(), "meta.zip"))) {
        var exp = new JsonExport(zip);
        exp.write(units);
    }
    var propsLib = libDir.create("props 1.0");
    propsLib.addDependency(unitLib);
    var prop = FlowProperty.of("Mass", units);
    try (var zip = ZipStore.open(new File(propsLib.folder(), "meta.zip"))) {
        var exp = new JsonExport(zip);
        exp.write(prop);
    }
    propsLib.mountTo(db);
    assertTrue(db.getLibraries().contains("units 1.0"));
    assertTrue(db.getLibraries().contains("props 1.0"));
}
Also used : JsonExport(org.openlca.jsonld.output.JsonExport) File(java.io.File) Test(org.junit.Test)

Example 24 with JsonExport

use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.

the class LibraryPackageTest method testDependencyUnpack.

@Test
public void testDependencyUnpack() throws Exception {
    var baseDir = Files.createTempDirectory("_olca").toFile();
    System.out.println(baseDir.getAbsolutePath());
    var units = UnitGroup.of("Units of mass", "kg");
    var mass = FlowProperty.of("Mass", units);
    // library with units
    var sourceDir = LibraryDir.of(new File(baseDir, "source"));
    var unitLib = sourceDir.create("units");
    try (var zip = unitLib.openJsonZip()) {
        new JsonExport(zip).write(units);
    }
    // library with flow properties
    var propLib = sourceDir.create("props");
    propLib.addDependency(unitLib);
    try (var zip = propLib.openJsonZip()) {
        new JsonExport(zip).withReferences(false).write(mass);
    }
    // pack and unpack
    var pack = new File(baseDir, "pack.zip");
    LibraryPackage.zip(propLib, pack);
    var targetDir = LibraryDir.of(new File(baseDir, "target"));
    LibraryPackage.unzip(pack, targetDir);
    unitLib = targetDir.getLibrary("units").orElseThrow();
    propLib = targetDir.getLibrary("props").orElseThrow();
    // check unpacked libraries
    assertTrue(propLib.getDirectDependencies().contains(unitLib));
    try (var zip = unitLib.openJsonZip()) {
        var json = zip.get(ModelType.UNIT_GROUP, units.refId);
        assertEquals("Units of mass", Json.getString(json, "name"));
    }
    try (var zip = propLib.openJsonZip()) {
        var json = zip.get(ModelType.FLOW_PROPERTY, mass.refId);
        assertEquals("Mass", Json.getString(json, "name"));
    }
    Dirs.delete(baseDir);
}
Also used : JsonExport(org.openlca.jsonld.output.JsonExport) File(java.io.File) Test(org.junit.Test)

Example 25 with JsonExport

use of org.openlca.jsonld.output.JsonExport in project olca-modules by GreenDelta.

the class MountCheckTest method testUsed.

@Test
public void testUsed() throws Exception {
    var group = UnitGroup.of("Units of mass", "kg");
    db.insert(group);
    try (var zip = lib.openJsonZip()) {
        new JsonExport(zip).write(group);
    }
    var state = MountCheck.check(db, lib);
    assertFalse(state.isOk());
    assertTrue(state.isUsed());
    assertFalse(state.isError());
    assertNull(state.error());
    db.delete(group);
}
Also used : JsonExport(org.openlca.jsonld.output.JsonExport) 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