package org.openlca.core.matrix.cache;

import java.util.HashSet;
import java.util.Set;

import org.junit.Assert;
import org.junit.Test;
import org.openlca.core.Tests;
import org.openlca.core.database.IDatabase;
import org.openlca.core.database.ProcessDao;
import org.openlca.core.matrix.CalcExchange;
import org.openlca.core.model.Exchange;
import org.openlca.core.model.Process;

/**
 * Tests that we get all uncertainty information from the matrix-table loaders.
 */
public class UncertaintyTableTest {

	private IDatabase database = Tests.getDb();
	private MatrixCache cache = MatrixCache.createLazy(database);

	@Test
	public void testForExchange() throws Exception {
		Exchange exchange = new Exchange();
		Process process = new Process();
		process.exchanges.add(exchange);
		ProcessDao dao = new ProcessDao(database);
		dao.insert(process);
		Set<Long> set = new HashSet<>();
		set.add(process.id);
		var exchanges = cache.getExchangeCache().get(process.id);
		checkExchange(exchanges.get(0));
		dao.delete(process);
	}

	private void checkExchange(CalcExchange e) {
		Assert.assertEquals(1, e.parameter1, 1e-16);
		Assert.assertEquals(2, e.parameter2, 1e-16);
		Assert.assertEquals(3, e.parameter3, 1e-16);
	}

}

@@ -37,63 +37,22 @@
 e;%0A%0A
+%0A
 import 
-java.util.HashSet;%0Aimport java.util.Set;%0A%0Aimport
+static
  org
@@ -64,17 +64,20 @@
 t.Assert
-;
+.*;%0A
 %0Aimport 
@@ -171,98 +171,8 @@
 se;%0A
-import org.openlca.core.database.ProcessDao;%0Aimport org.openlca.core.matrix.CalcExchange;%0A
 impo
@@ -245,16 +245,59 @@
 Process;
+%0Aimport org.openlca.core.model.Uncertainty;
 %0A%0A/**%0A *
@@ -424,16 +424,22 @@
 private 
+final 
 IDatabas
@@ -441,23 +441,17 @@
 tabase d
-atabase
+b
  = Tests
@@ -469,16 +469,22 @@
 private 
+final 
 MatrixCa
@@ -519,23 +519,17 @@
 teLazy(d
-atabase
+b
 );%0A%0A%09@Te
@@ -585,18 +585,14 @@
 n %7B%0A
+%0A
 %09%09
-Exchange
+var
  exc
@@ -617,23 +617,75 @@
 ge();%0A%09%09
-Process
+exchange.uncertainty = Uncertainty.triangle(1, 2, 3);%0A%09%09var
  process
@@ -743,147 +743,36 @@
 ;%0A%09%09
-ProcessDao dao = new ProcessDao(database);%0A%09%09dao.insert(process);%0A%09%09Set%3CLong%3E set = new HashSet%3C%3E();%0A%09%09set.add(process.id);%0A%09%09var exchanges
+db.insert(process);%0A%0A%09%09var e
  = c
@@ -794,16 +794,20 @@
 eCache()
+%0A%09%09%09
 .get(pro
@@ -818,127 +818,23 @@
 .id)
-;
 %0A%09%09
-checkExchange(exchanges
+%09
 .get(0)
-)
 ;%0A%09%09
-dao.delete(process);%0A%09%7D%0A%0A%09private void checkExchange(CalcExchange e) %7B%0A%09%09Assert.
 asse
@@ -861,39 +861,32 @@
 ter1, 1e-16);%0A%09%09
-Assert.
 assertEquals(2, 
@@ -909,23 +909,16 @@
 -16);%0A%09%09
-Assert.
 assertEq
@@ -951,10 +951,32 @@
 6);%0A
+%0A%09%09db.delete(process);%0A
 %09%7D
-%0A
 %0A%7D%0A

fix failing test