Search in sources :

Example 1 with JsonImport

use of org.openlca.jsonld.input.JsonImport in project olca-modules by GreenDelta.

the class SourceTest method doImport.

private void doImport(SourceDao dao, Source source) {
    with(zip -> {
        JsonImport jImport = new JsonImport(zip, Tests.getDb());
        jImport.run();
    });
    Assert.assertTrue(dao.contains(source.refId));
    Source clone = dao.getForRefId(source.refId);
    Assert.assertEquals(source.name, clone.name);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) Source(org.openlca.core.model.Source)

Example 2 with JsonImport

use of org.openlca.jsonld.input.JsonImport in project olca-modules by GreenDelta.

the class UnitGroupTest method doImport.

private void doImport(UnitGroupDao dao, UnitGroup group) {
    with(zip -> {
        JsonImport jImport = new JsonImport(zip, Tests.getDb());
        jImport.run();
    });
    Assert.assertTrue(dao.contains(group.refId));
    UnitGroup clone = dao.getForRefId(group.refId);
    Assert.assertEquals(group.name, clone.name);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) UnitGroup(org.openlca.core.model.UnitGroup)

Example 3 with JsonImport

use of org.openlca.jsonld.input.JsonImport in project olca-modules by GreenDelta.

the class ParameterTest method testProcess.

@Test
public void testProcess() {
    var process = new Process();
    process.refId = UUID.randomUUID().toString();
    var param = process.parameter("param", 42);
    var dao = new ProcessDao(Tests.getDb());
    dao.insert(process);
    with(zip -> {
        JsonExport export = new JsonExport(Tests.getDb(), zip);
        export.write(process);
    });
    dao.delete(process);
    with(zip -> {
        JsonImport jImport = new JsonImport(zip, Tests.getDb());
        jImport.run();
    });
    var clone = dao.getForRefId(process.refId);
    Assert.assertEquals(param.refId, clone.parameters.get(0).refId);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) ProcessDao(org.openlca.core.database.ProcessDao) Process(org.openlca.core.model.Process) JsonExport(org.openlca.jsonld.output.JsonExport) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 4 with JsonImport

use of org.openlca.jsonld.input.JsonImport in project olca-modules by GreenDelta.

the class ParameterTest method testGlobal.

@Test
public void testGlobal() {
    var param = Parameter.global("param", "1+1");
    var dao = new ParameterDao(Tests.getDb());
    dao.insert(param);
    with(zip -> {
        JsonExport export = new JsonExport(Tests.getDb(), zip);
        export.write(param);
    });
    dao.delete(param);
    Assert.assertFalse(dao.contains(param.refId));
    with(zip -> {
        JsonImport jImport = new JsonImport(zip, Tests.getDb());
        jImport.run();
    });
    Assert.assertTrue(dao.contains(param.refId));
    dao.delete(param);
}
Also used : ParameterDao(org.openlca.core.database.ParameterDao) JsonImport(org.openlca.jsonld.input.JsonImport) JsonExport(org.openlca.jsonld.output.JsonExport) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 5 with JsonImport

use of org.openlca.jsonld.input.JsonImport in project olca-modules by GreenDelta.

the class ParameterTest method testImpactCategory.

@Test
public void testImpactCategory() {
    var impact = new ImpactCategory();
    impact.refId = UUID.randomUUID().toString();
    var param = impact.parameter("param", 42);
    var dao = new ImpactCategoryDao(Tests.getDb());
    dao.insert(impact);
    with(zip -> {
        JsonExport export = new JsonExport(Tests.getDb(), zip);
        export.write(impact);
    });
    dao.delete(impact);
    with(zip -> {
        JsonImport jImport = new JsonImport(zip, Tests.getDb());
        jImport.run();
    });
    ImpactCategory clone = dao.getForRefId(impact.refId);
    Assert.assertEquals(param.refId, clone.parameters.get(0).refId);
}
Also used : JsonImport(org.openlca.jsonld.input.JsonImport) ImpactCategory(org.openlca.core.model.ImpactCategory) JsonExport(org.openlca.jsonld.output.JsonExport) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Aggregations

JsonImport (org.openlca.jsonld.input.JsonImport)28 Test (org.junit.Test)14 JsonExport (org.openlca.jsonld.output.JsonExport)8 AbstractZipTest (org.openlca.jsonld.AbstractZipTest)6 ProductSystem (org.openlca.core.model.ProductSystem)5 Flow (org.openlca.core.model.Flow)4 Process (org.openlca.core.model.Process)4 MemStore (org.openlca.jsonld.MemStore)4 Parameter (org.openlca.core.model.Parameter)3 TechFlow (org.openlca.core.matrix.index.TechFlow)2 Currency (org.openlca.core.model.Currency)2 FlowProperty (org.openlca.core.model.FlowProperty)2 ImpactCategory (org.openlca.core.model.ImpactCategory)2 Location (org.openlca.core.model.Location)2 ParameterRedefSet (org.openlca.core.model.ParameterRedefSet)2 Result (org.openlca.core.model.Result)2 UnitGroup (org.openlca.core.model.UnitGroup)2 ZipStore (org.openlca.jsonld.ZipStore)2 Gson (com.google.gson.Gson)1 JsonObject (com.google.gson.JsonObject)1