diff --git a/src/main/java/org/openlmis/referencedata/service/export/ProgramOrderableImportPersister.java b/src/main/java/org/openlmis/referencedata/service/export/ProgramOrderableImportPersister.java index 1f510bee..73ac93d7 100644 --- a/src/main/java/org/openlmis/referencedata/service/export/ProgramOrderableImportPersister.java +++ b/src/main/java/org/openlmis/referencedata/service/export/ProgramOrderableImportPersister.java @@ -47,6 +47,7 @@ import org.slf4j.profiler.Profiler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @Service("programOrderable.csv") @@ -54,7 +55,8 @@ public class ProgramOrderableImportPersister implements DataImportPersister< ProgramOrderable, ProgramOrderableCsvModel, ProgramOrderableDto> { - private final CurrencyUnit currencyUnit; + @Value("${currencyCode}") + private String currencyCode; @Autowired private FileHelper fileHelper; @Autowired private ProgramOrderableRepository programOrderableRepository; @@ -67,10 +69,6 @@ public class ProgramOrderableImportPersister @Qualifier("importExecutorService") private ExecutorService importExecutorService; - public ProgramOrderableImportPersister() { - currencyUnit = CurrencyUnit.of(System.getenv("CURRENCY_CODE")); - } - @Override public List processAndPersist(InputStream dataStream, Profiler profiler) throws InterruptedException { @@ -118,7 +116,8 @@ private List createOrUpdate(List dto dto.getDisplayOrder(), dto.getDosesPerPatient(), dto.getPricePerPack() != null - ? Money.of(currencyUnit, Double.parseDouble(dto.getPricePerPack())) + ? Money.of( + CurrencyUnit.of(currencyCode), Double.parseDouble(dto.getPricePerPack())) : null, null); @@ -131,7 +130,8 @@ private List createOrUpdate(List dto if (programOrderable == null) { programOrderable = - ProgramOrderable.createNew(program, orderableDisplayCategory, orderable, currencyUnit); + ProgramOrderable.createNew( + program, orderableDisplayCategory, orderable, CurrencyUnit.of(currencyCode)); } programOrderable.updateFrom(programOrderableDto); diff --git a/src/test/java/org/openlmis/referencedata/service/export/ProgramOrderableImportPersisterTest.java b/src/test/java/org/openlmis/referencedata/service/export/ProgramOrderableImportPersisterTest.java index 6d27ad62..d7038c68 100644 --- a/src/test/java/org/openlmis/referencedata/service/export/ProgramOrderableImportPersisterTest.java +++ b/src/test/java/org/openlmis/referencedata/service/export/ProgramOrderableImportPersisterTest.java @@ -28,9 +28,7 @@ import java.util.List; import java.util.function.Supplier; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.contrib.java.lang.system.EnvironmentVariables; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -55,7 +53,6 @@ @RunWith(MockitoJUnitRunner.class) public class ProgramOrderableImportPersisterTest { - @Rule public EnvironmentVariables environmentVariables = new EnvironmentVariables(); private InputStream dataStream; @Mock private FileHelper fileHelper; @@ -69,7 +66,7 @@ public class ProgramOrderableImportPersisterTest { @Before public void setUp() { - environmentVariables.set("CURRENCY_CODE", "USD"); + ReflectionTestUtils.setField(programOrderableImportPersister, "currencyCode", "USD"); ReflectionTestUtils.setField( programOrderableImportPersister,