Search in sources :

Example 16 with ProcessDao

use of org.openlca.core.database.ProcessDao 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 17 with ProcessDao

use of org.openlca.core.database.ProcessDao in project olca-modules by GreenDelta.

the class ProcessTest method testProcess.

@Test
public void testProcess() throws Exception {
    ProcessDao dao = new ProcessDao(db);
    Process process = createSimpleModel(dao);
    doExport(process);
    dao.delete(process);
    doImport();
    assertTestProcess(process, dao);
    delete(process, Tests.getDb());
}
Also used : ProcessDao(org.openlca.core.database.ProcessDao) Process(org.openlca.core.model.Process) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 18 with ProcessDao

use of org.openlca.core.database.ProcessDao in project olca-modules by GreenDelta.

the class ProcessTest method testCyclicProvider.

@Test
public void testCyclicProvider() {
    IDatabase db = Tests.getDb();
    ProcessDao dao = new ProcessDao(db);
    Process[] processes = createCyclicModel(db);
    doExport(processes[0]);
    dao.delete(processes[0]);
    dao.delete(processes[1]);
    doImport();
    assertTestCyclicProvider(processes, dao);
    delete(processes[0], Tests.getDb());
    delete(processes[1], Tests.getDb());
}
Also used : IDatabase(org.openlca.core.database.IDatabase) ProcessDao(org.openlca.core.database.ProcessDao) Process(org.openlca.core.model.Process) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 19 with ProcessDao

use of org.openlca.core.database.ProcessDao in project olca-modules by GreenDelta.

the class ProcessesTest method testFindForLabel.

@Test
public void testFindForLabel() {
    IDatabase db = Tests.getDb();
    Supplier<ProcessDescriptor> query = () -> Processes.findForLabel(db, "cow milking - CH");
    assertNull(query.get());
    ProcessDao dao = new ProcessDao(db);
    Process p1 = new Process();
    p1.name = "cow milking";
    dao.insert(p1);
    assertEquals(p1.id, query.get().id);
    Location loc = new Location();
    loc.code = "CH";
    Daos.base(db, Location.class).insert(loc);
    Process p2 = new Process();
    p2.name = "cow milking";
    p2.location = loc;
    dao.insert(p2);
    assertEquals(p2.id, query.get().id);
    Daos.base(db, Location.class).delete(loc);
    for (Process p : dao.getForName("cow milking")) {
        dao.delete(p);
    }
    assertNull(query.get());
}
Also used : IDatabase(org.openlca.core.database.IDatabase) ProcessDao(org.openlca.core.database.ProcessDao) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Process(org.openlca.core.model.Process) Location(org.openlca.core.model.Location) Test(org.junit.Test)

Example 20 with ProcessDao

use of org.openlca.core.database.ProcessDao in project olca-modules by GreenDelta.

the class FormulaInterpreterTest method setUp.

/**
 * sets the following parameters:
 *
 * fi_tests_global = 32
 *
 * fi_tests_local = fi_tests_global + 10
 */
@Before
public void setUp() {
    globalParam = new Parameter();
    globalParam.name = "fi_tests_global";
    globalParam.isInputParameter = true;
    globalParam.scope = ParameterScope.GLOBAL;
    globalParam.value = 32;
    new ParameterDao(db).insert(globalParam);
    process = new Process();
    var localParam = new Parameter();
    localParam.name = "fi_tests_local";
    localParam.formula = "fi_tests_global + 10";
    localParam.isInputParameter = false;
    localParam.scope = ParameterScope.PROCESS;
    process.parameters.add(localParam);
    process = new ProcessDao(db).insert(process);
    interpreter = ParameterTable.interpreter(db, Collections.singleton(process.id), Collections.emptySet());
}
Also used : ParameterDao(org.openlca.core.database.ParameterDao) ProcessDao(org.openlca.core.database.ProcessDao) Parameter(org.openlca.core.model.Parameter) Process(org.openlca.core.model.Process) Before(org.junit.Before)

Aggregations

ProcessDao (org.openlca.core.database.ProcessDao)51 Process (org.openlca.core.model.Process)26 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)14 IDatabase (org.openlca.core.database.IDatabase)12 FlowDao (org.openlca.core.database.FlowDao)11 Test (org.junit.Test)10 ProductSystemDao (org.openlca.core.database.ProductSystemDao)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 ParameterDao (org.openlca.core.database.ParameterDao)5 HashMap (java.util.HashMap)4 Before (org.junit.Before)4 NativeSql (org.openlca.core.database.NativeSql)4 Exchange (org.openlca.core.model.Exchange)4 RootDescriptor (org.openlca.core.model.descriptors.RootDescriptor)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)3 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)3 ImpactMethodDao (org.openlca.core.database.ImpactMethodDao)3