use of org.openlca.core.model.Currency in project olca-modules by GreenDelta.
the class CurrencyImport method copy.
private void copy(Currency srcCurrency) {
Currency destCurrency = srcCurrency.copy();
if (Objects.equal(srcCurrency, srcCurrency.referenceCurrency)) {
destCurrency.referenceCurrency = destCurrency;
} else {
destCurrency.referenceCurrency = refs.switchRef(srcCurrency.referenceCurrency);
}
destCurrency = destDao.insert(destCurrency);
seq.put(seq.CURRENCY, srcCurrency.refId, destCurrency.id);
}
use of org.openlca.core.model.Currency in project olca-modules by GreenDelta.
the class CurrencyTest method createModel.
private Currency createModel(CurrencyDao dao) {
Currency currency = new Currency();
currency.name = "currency";
currency.refId = UUID.randomUUID().toString();
dao.insert(currency);
return currency;
}
use of org.openlca.core.model.Currency in project olca-modules by GreenDelta.
the class CurrencyTest method doImport.
private void doImport(CurrencyDao dao, Currency currency) {
with(zip -> {
JsonImport jImport = new JsonImport(zip, Tests.getDb());
jImport.run();
});
Assert.assertTrue(dao.contains(currency.refId));
Currency clone = dao.getForRefId(currency.refId);
Assert.assertEquals(currency.name, clone.name);
}
use of org.openlca.core.model.Currency in project olca-modules by GreenDelta.
the class ExchangeCostTest method testCostAttributes.
@Test
public void testCostAttributes() {
Currency currency = createCurrency();
Process process = createProcess(currency);
with(zip -> {
JsonExport export = new JsonExport(Tests.getDb(), zip);
export.write(process);
});
delete(currency, process);
with(zip -> {
JsonImport jImport = new JsonImport(zip, Tests.getDb());
jImport.run();
});
checkImport(process);
}
use of org.openlca.core.model.Currency in project olca-modules by GreenDelta.
the class ConversionTableTest method testGetCurrencyFactor.
@Test
public void testGetCurrencyFactor() {
CurrencyDao dao = new CurrencyDao(database);
Currency eur = make("EUR", 1.0);
Currency usd = make("USD", 0.88);
usd.referenceCurrency = eur;
dao.update(usd);
ConversionTable table = ConversionTable.create(Tests.getDb());
Assert.assertEquals(1.0, table.getCurrencyFactor(eur.id), 1e-10);
Assert.assertEquals(0.88, table.getCurrencyFactor(usd.id), 1e-10);
// the default factor should be 1.0
Assert.assertEquals(1.0, table.getCurrencyFactor(-42L), 1e-10);
dao.delete(usd);
dao.delete(eur);
}
Aggregations