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