diff --git a/pom.xml b/pom.xml
index 6531850..5aa7236 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
org.keen
solar
- 3.5.1
+ 3.5.2
solar
Retrieves solar data from a Fronius inverter and persists it to a data store.
@@ -112,7 +112,7 @@
**/CurrentPowerRetrieverIT.java
**/StringPowerRetrieverIT.java
- **/InverterInfoLoggerIT.java
+ **/SystemInfoLoggerIT.java
diff --git a/src/main/java/org/keen/solar/financial/PowerCostCalculator.java b/src/main/java/org/keen/solar/financial/PowerCostCalculator.java
index 2435d70..8f54f1f 100644
--- a/src/main/java/org/keen/solar/financial/PowerCostCalculator.java
+++ b/src/main/java/org/keen/solar/financial/PowerCostCalculator.java
@@ -1,7 +1,7 @@
package org.keen.solar.financial;
-import org.keen.solar.financial.dal.TariffRepository;
-import org.keen.solar.financial.dal.PowerCostRepository;
+import org.keen.solar.financial.dal.TariffDao;
+import org.keen.solar.financial.dal.PowerCostDao;
import org.keen.solar.financial.domain.PowerCost;
import org.keen.solar.financial.domain.Tariff;
import org.keen.solar.system.domain.CurrentPower;
@@ -39,13 +39,13 @@ public class PowerCostCalculator {
* up to 3600 (the number of seconds in one hour).
*/
private final int collectionFrequencySeconds;
- private final TariffRepository tariffRepository;
- private final PowerCostRepository powerCostRepository;
+ private final TariffDao tariffRepository;
+ private final PowerCostDao powerCostRepository;
private final Deque uncostedPowers = new ConcurrentLinkedDeque<>();
public PowerCostCalculator(@Value("${app.power.collection-frequency-sec}") int collectionFrequencySeconds,
- TariffRepository tariffRepository,
- PowerCostRepository powerCostRepository) {
+ TariffDao tariffRepository,
+ PowerCostDao powerCostRepository) {
validateCollectionFrequency(collectionFrequencySeconds);
this.collectionFrequencySeconds = collectionFrequencySeconds;
@@ -89,7 +89,7 @@ private void calculateCostAndPersist(CurrentPower currentPower) {
LocalTime localTime = measurementZonedDateTime.toLocalTime();
// Get feed-in tariff
Tariff effectiveFeedInTariff = tariffRepository
- .findEffectiveFeedInTariff(dayOfWeek, localTime, currentPower.getEpochTimestamp());
+ .getEffectiveFeedInTariff(dayOfWeek, localTime, currentPower.getEpochTimestamp());
if (effectiveFeedInTariff == null) {
logger.warn("No effective feed-in tariff found; unable to calculate power cost.");
return;
@@ -97,7 +97,7 @@ private void calculateCostAndPersist(CurrentPower currentPower) {
BigDecimal feedInTariffWattSecond = convertTariffToWattSeconds(effectiveFeedInTariff);
// Get usage tariff
Tariff effectiveUsageTariff = tariffRepository
- .findEffectiveUsageTariff(dayOfWeek, localTime, currentPower.getEpochTimestamp());
+ .getEffectiveUsageTariff(dayOfWeek, localTime, currentPower.getEpochTimestamp());
if (effectiveUsageTariff == null) {
logger.warn("No effective usage tariff found; unable to calculate power cost.");
return;
diff --git a/src/main/java/org/keen/solar/financial/dal/PowerCostDao.java b/src/main/java/org/keen/solar/financial/dal/PowerCostDao.java
new file mode 100644
index 0000000..632305a
--- /dev/null
+++ b/src/main/java/org/keen/solar/financial/dal/PowerCostDao.java
@@ -0,0 +1,11 @@
+package org.keen.solar.financial.dal;
+
+import org.keen.solar.financial.domain.PowerCost;
+
+public interface PowerCostDao {
+
+ /**
+ * Persists the given PowerCost to the repository.
+ */
+ void save(PowerCost powerCost);
+}
diff --git a/src/main/java/org/keen/solar/financial/dal/PowerCostDaoSpringDataImpl.java b/src/main/java/org/keen/solar/financial/dal/PowerCostDaoSpringDataImpl.java
new file mode 100644
index 0000000..2b06ff8
--- /dev/null
+++ b/src/main/java/org/keen/solar/financial/dal/PowerCostDaoSpringDataImpl.java
@@ -0,0 +1,20 @@
+package org.keen.solar.financial.dal;
+
+import org.keen.solar.financial.domain.PowerCost;
+import org.springframework.stereotype.Component;
+
+@Component
+public class PowerCostDaoSpringDataImpl implements PowerCostDao {
+
+ private final PowerCostRepository repository;
+
+ public PowerCostDaoSpringDataImpl(PowerCostRepository repository) {
+ this.repository = repository;
+ }
+
+
+ @Override
+ public void save(PowerCost powerCost) {
+ repository.save(powerCost);
+ }
+}
diff --git a/src/main/java/org/keen/solar/financial/dal/TariffDao.java b/src/main/java/org/keen/solar/financial/dal/TariffDao.java
new file mode 100644
index 0000000..a0c5dd3
--- /dev/null
+++ b/src/main/java/org/keen/solar/financial/dal/TariffDao.java
@@ -0,0 +1,31 @@
+package org.keen.solar.financial.dal;
+
+import org.keen.solar.financial.domain.Tariff;
+
+import java.time.DayOfWeek;
+import java.time.LocalTime;
+
+public interface TariffDao {
+
+ /**
+ * Retrieves the feed-in tariff for the given day and time, effective
+ * as at {@code epochTime}.
+ *
+ * @param dayOfWeek the day of the week to retrieve the tariff for
+ * @param localTime the time of day to retrieve the tariff for
+ * @param epochTime the epoch time that the tariff is effective for
+ * @return the feed-in tariff
+ */
+ Tariff getEffectiveFeedInTariff(DayOfWeek dayOfWeek, LocalTime localTime, long epochTime);
+
+ /**
+ * Retrieves the usage tariff for the given day and time, effective
+ * as at {@code epochTime}.
+ *
+ * @param dayOfWeek the day of the week to retrieve the tariff for
+ * @param localTime the time of day to retrieve the tariff for
+ * @param epochTime the epoch time that the tariff is effective for
+ * @return the usage tariff
+ */
+ Tariff getEffectiveUsageTariff(DayOfWeek dayOfWeek, LocalTime localTime, long epochTime);
+}
diff --git a/src/main/java/org/keen/solar/financial/dal/TariffDaoSpringDataImpl.java b/src/main/java/org/keen/solar/financial/dal/TariffDaoSpringDataImpl.java
new file mode 100644
index 0000000..734390c
--- /dev/null
+++ b/src/main/java/org/keen/solar/financial/dal/TariffDaoSpringDataImpl.java
@@ -0,0 +1,27 @@
+package org.keen.solar.financial.dal;
+
+import org.keen.solar.financial.domain.Tariff;
+import org.springframework.stereotype.Component;
+
+import java.time.DayOfWeek;
+import java.time.LocalTime;
+
+@Component
+public class TariffDaoSpringDataImpl implements TariffDao {
+
+ private final TariffRepository repository;
+
+ public TariffDaoSpringDataImpl(TariffRepository repository) {
+ this.repository = repository;
+ }
+
+ @Override
+ public Tariff getEffectiveFeedInTariff(DayOfWeek dayOfWeek, LocalTime localTime, long epochTime) {
+ return repository.findEffectiveFeedInTariff(dayOfWeek, localTime, epochTime);
+ }
+
+ @Override
+ public Tariff getEffectiveUsageTariff(DayOfWeek dayOfWeek, LocalTime localTime, long epochTime) {
+ return repository.findEffectiveUsageTariff(dayOfWeek, localTime, epochTime);
+ }
+}
diff --git a/src/main/java/org/keen/solar/solcast/forecast/ForecastPersister.java b/src/main/java/org/keen/solar/solcast/forecast/ForecastPersister.java
index 86d9724..d832eba 100644
--- a/src/main/java/org/keen/solar/solcast/forecast/ForecastPersister.java
+++ b/src/main/java/org/keen/solar/solcast/forecast/ForecastPersister.java
@@ -1,6 +1,6 @@
package org.keen.solar.solcast.forecast;
-import org.keen.solar.solcast.forecast.dal.ForecastRepository;
+import org.keen.solar.solcast.forecast.dal.ForecastDao;
import org.keen.solar.solcast.forecast.domain.GenerationForecast;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
@@ -21,7 +21,7 @@ public class ForecastPersister {
private ForecastRetriever retriever;
@Autowired
- private ForecastRepository repository;
+ private ForecastDao repository;
@Async
@Scheduled(cron = "${app.solcast.forecast-retrieval-cron}")
@@ -31,17 +31,7 @@ public void retrieveAndPersistAsync() {
public void retrieveAndPersist() {
List forecasts = retriever.retrieve();
- // Retrieve the id for any existing forecast for the same period so that it gets updated in the database,
- // rather than inserted.
- // Not particularly efficient, given that each forecast is retrieved individually from the database.
- // Spring Data JDBC doesn't provide a mechanism to write queries that take collections as parameters.
- forecasts.forEach(forecast -> {
- GenerationForecast existingForecast = repository.findByPeriodEnd(forecast.getPeriod_end_epoch());
- if (existingForecast != null) {
- forecast.setId(existingForecast.getId());
- }
- });
- repository.saveAll(forecasts);
+ repository.save(forecasts);
}
}
diff --git a/src/main/java/org/keen/solar/solcast/forecast/dal/ForecastDao.java b/src/main/java/org/keen/solar/solcast/forecast/dal/ForecastDao.java
new file mode 100644
index 0000000..c857ae3
--- /dev/null
+++ b/src/main/java/org/keen/solar/solcast/forecast/dal/ForecastDao.java
@@ -0,0 +1,13 @@
+package org.keen.solar.solcast.forecast.dal;
+
+import org.keen.solar.solcast.forecast.domain.GenerationForecast;
+
+import java.util.Collection;
+
+public interface ForecastDao {
+
+ /**
+ * Persists the given forecasts to the repository, updating them if they exist.
+ */
+ void save(Collection forecasts);
+}
diff --git a/src/main/java/org/keen/solar/solcast/forecast/dal/ForecastDaoSpringDataImpl.java b/src/main/java/org/keen/solar/solcast/forecast/dal/ForecastDaoSpringDataImpl.java
new file mode 100644
index 0000000..123cbbf
--- /dev/null
+++ b/src/main/java/org/keen/solar/solcast/forecast/dal/ForecastDaoSpringDataImpl.java
@@ -0,0 +1,31 @@
+package org.keen.solar.solcast.forecast.dal;
+
+import org.keen.solar.solcast.forecast.domain.GenerationForecast;
+import org.springframework.stereotype.Component;
+
+import java.util.Collection;
+
+@Component
+public class ForecastDaoSpringDataImpl implements ForecastDao {
+
+ private final ForecastRepository repository;
+
+ public ForecastDaoSpringDataImpl(ForecastRepository repository) {
+ this.repository = repository;
+ }
+
+ @Override
+ public void save(Collection forecasts) {
+ // Retrieve the id for any existing forecast for the same period so that it gets updated in the database,
+ // rather than inserted.
+ // Not particularly efficient, given that each forecast is retrieved individually from the database.
+ // Spring Data JDBC doesn't provide a mechanism to write queries that take collections as parameters.
+ forecasts.forEach(forecast -> {
+ GenerationForecast existingForecast = repository.findByPeriodEnd(forecast.getPeriod_end_epoch());
+ if (existingForecast != null) {
+ forecast.setId(existingForecast.getId());
+ }
+ });
+ repository.saveAll(forecasts);
+ }
+}
diff --git a/src/main/java/org/keen/solar/solcast/measurement/MeasurementUploader.java b/src/main/java/org/keen/solar/solcast/measurement/MeasurementUploader.java
index 3fd6c87..f962763 100644
--- a/src/main/java/org/keen/solar/solcast/measurement/MeasurementUploader.java
+++ b/src/main/java/org/keen/solar/solcast/measurement/MeasurementUploader.java
@@ -1,6 +1,6 @@
package org.keen.solar.solcast.measurement;
-import org.keen.solar.system.dal.CurrentPowerRepository;
+import org.keen.solar.system.dal.CurrentPowerDao;
import org.keen.solar.system.domain.CurrentPower;
import org.keen.solar.solcast.measurement.domain.Measurement;
import org.keen.solar.solcast.measurement.domain.MeasurementResponse;
@@ -28,7 +28,7 @@ public class MeasurementUploader {
private final Logger logger = LoggerFactory.getLogger(MeasurementUploader.class);
private final RestTemplate restTemplate;
- private final CurrentPowerRepository repository;
+ private final CurrentPowerDao repository;
@Value("${app.solcast.base-url}")
private String solcastApiBaseUrl;
@@ -39,7 +39,7 @@ public class MeasurementUploader {
@Value("${app.solcast.api-key}")
private String solcastApiKey;
- public MeasurementUploader(RestTemplateBuilder restTemplateBuilder, CurrentPowerRepository repository) {
+ public MeasurementUploader(RestTemplateBuilder restTemplateBuilder, CurrentPowerDao repository) {
this.restTemplate = restTemplateBuilder.build();
this.repository = repository;
}
@@ -48,7 +48,7 @@ public MeasurementUploader(RestTemplateBuilder restTemplateBuilder, CurrentPower
* Uploads all measurements not yet uploaded to Solcast
*/
public void uploadAll() {
- List currentPowerNotUploaded = repository.findByUploaded(false);
+ List currentPowerNotUploaded = repository.getNotUploaded();
doUpload(currentPowerNotUploaded);
}
@@ -103,7 +103,7 @@ private void updateRepository(List measurementsToUpload, List {
measurement.getSource().parallelStream().forEach(currentPower -> currentPower.setUploaded(true));
- repository.saveAll(measurement.getSource());
+ repository.save(measurement.getSource());
});
// Log which measurements were in error
measurementsToUpload.removeAll(returnedMeasurements);
diff --git a/src/main/java/org/keen/solar/string/dal/StringPowerDao.java b/src/main/java/org/keen/solar/string/dal/StringPowerDao.java
new file mode 100644
index 0000000..0082021
--- /dev/null
+++ b/src/main/java/org/keen/solar/string/dal/StringPowerDao.java
@@ -0,0 +1,11 @@
+package org.keen.solar.string.dal;
+
+import org.keen.solar.string.domain.StringPower;
+
+public interface StringPowerDao {
+
+ /**
+ * Persists the given StringPower to the repository.
+ */
+ void save(StringPower stringPower);
+}
diff --git a/src/main/java/org/keen/solar/string/dal/StringPowerDaoSpringDataImpl.java b/src/main/java/org/keen/solar/string/dal/StringPowerDaoSpringDataImpl.java
new file mode 100644
index 0000000..bb9cbfa
--- /dev/null
+++ b/src/main/java/org/keen/solar/string/dal/StringPowerDaoSpringDataImpl.java
@@ -0,0 +1,19 @@
+package org.keen.solar.string.dal;
+
+import org.keen.solar.string.domain.StringPower;
+import org.springframework.stereotype.Component;
+
+@Component
+public class StringPowerDaoSpringDataImpl implements StringPowerDao {
+
+ private final StringPowerRepository repository;
+
+ public StringPowerDaoSpringDataImpl(StringPowerRepository repository) {
+ this.repository = repository;
+ }
+
+ @Override
+ public void save(StringPower stringPower) {
+ repository.save(stringPower);
+ }
+}
diff --git a/src/main/java/org/keen/solar/string/fronius/StringPowerPersister.java b/src/main/java/org/keen/solar/string/fronius/StringPowerPersister.java
index b639246..2392c70 100644
--- a/src/main/java/org/keen/solar/string/fronius/StringPowerPersister.java
+++ b/src/main/java/org/keen/solar/string/fronius/StringPowerPersister.java
@@ -1,6 +1,6 @@
package org.keen.solar.string.fronius;
-import org.keen.solar.string.dal.StringPowerRepository;
+import org.keen.solar.string.dal.StringPowerDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
@@ -11,7 +11,7 @@ public class StringPowerPersister {
private StringPowerRetriever retriever;
@Autowired
- private StringPowerRepository repository;
+ private StringPowerDao repository;
@Async
@Scheduled(cron = "15 0/5 * * * *")
diff --git a/src/main/java/org/keen/solar/system/dal/CurrentPowerDao.java b/src/main/java/org/keen/solar/system/dal/CurrentPowerDao.java
new file mode 100644
index 0000000..935ebb9
--- /dev/null
+++ b/src/main/java/org/keen/solar/system/dal/CurrentPowerDao.java
@@ -0,0 +1,24 @@
+package org.keen.solar.system.dal;
+
+import org.keen.solar.system.domain.CurrentPower;
+
+import java.util.Collection;
+import java.util.List;
+
+public interface CurrentPowerDao {
+
+ /**
+ * Returns all CurrentPowers not yet uploaded to Solcast.
+ */
+ List getNotUploaded();
+
+ /**
+ * Persists the given CurrentPower to the repository.
+ */
+ void save(CurrentPower currentPower);
+
+ /**
+ * Persists the given CurrentPowers to the repository.
+ */
+ void save(Collection currentPowers);
+}
diff --git a/src/main/java/org/keen/solar/system/dal/CurrentPowerDaoSpringDataImpl.java b/src/main/java/org/keen/solar/system/dal/CurrentPowerDaoSpringDataImpl.java
new file mode 100644
index 0000000..196490c
--- /dev/null
+++ b/src/main/java/org/keen/solar/system/dal/CurrentPowerDaoSpringDataImpl.java
@@ -0,0 +1,32 @@
+package org.keen.solar.system.dal;
+
+import org.keen.solar.system.domain.CurrentPower;
+import org.springframework.stereotype.Component;
+
+import java.util.Collection;
+import java.util.List;
+
+@Component
+public class CurrentPowerDaoSpringDataImpl implements CurrentPowerDao {
+
+ private final CurrentPowerRepository repository;
+
+ public CurrentPowerDaoSpringDataImpl(CurrentPowerRepository repository) {
+ this.repository = repository;
+ }
+
+ @Override
+ public List getNotUploaded() {
+ return repository.findByUploaded(false);
+ }
+
+ @Override
+ public void save(CurrentPower currentPower) {
+ repository.save(currentPower);
+ }
+
+ @Override
+ public void save(Collection currentPowers) {
+ repository.saveAll(currentPowers);
+ }
+}
diff --git a/src/main/java/org/keen/solar/system/fronius/CurrentPowerPersister.java b/src/main/java/org/keen/solar/system/fronius/CurrentPowerPersister.java
index 36464e9..8072ee2 100644
--- a/src/main/java/org/keen/solar/system/fronius/CurrentPowerPersister.java
+++ b/src/main/java/org/keen/solar/system/fronius/CurrentPowerPersister.java
@@ -1,6 +1,6 @@
package org.keen.solar.system.fronius;
-import org.keen.solar.system.dal.CurrentPowerRepository;
+import org.keen.solar.system.dal.CurrentPowerDao;
import org.keen.solar.system.domain.CurrentPower;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
@@ -16,7 +16,7 @@ public class CurrentPowerPersister {
private CurrentPowerRetriever retriever;
@Autowired
- private CurrentPowerRepository repository;
+ private CurrentPowerDao repository;
@Autowired
private ApplicationEventPublisher eventPublisher;
diff --git a/src/test/java/org/keen/solar/financial/PowerCostCalculatorTest.java b/src/test/java/org/keen/solar/financial/PowerCostCalculatorTest.java
index f661408..dc91ff6 100644
--- a/src/test/java/org/keen/solar/financial/PowerCostCalculatorTest.java
+++ b/src/test/java/org/keen/solar/financial/PowerCostCalculatorTest.java
@@ -4,8 +4,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-import org.keen.solar.financial.dal.TariffRepository;
-import org.keen.solar.financial.dal.PowerCostRepository;
+import org.keen.solar.financial.dal.TariffDao;
+import org.keen.solar.financial.dal.PowerCostDao;
import org.keen.solar.financial.domain.Tariff;
import org.keen.solar.financial.domain.PowerCost;
import org.keen.solar.system.domain.CurrentPower;
@@ -30,16 +30,16 @@ public void givenTwoMinutesOfPowerCosts_whenCollectUncostedPowers_thenCostCalcul
// Given
BigDecimal feedInPricePerKwh = BigDecimal.valueOf(33, 3);
- TariffRepository tariffRepository = mock(TariffRepository.class);
- when(tariffRepository.findEffectiveFeedInTariff(any(DayOfWeek.class), any(LocalTime.class), anyLong()))
+ TariffDao tariffRepository = mock(TariffDao.class);
+ when(tariffRepository.getEffectiveFeedInTariff(any(DayOfWeek.class), any(LocalTime.class), anyLong()))
.thenReturn(new Tariff(true, 0, null, null,
null, null, feedInPricePerKwh));
BigDecimal powerPricePerKwh = BigDecimal.valueOf(4082, 4);
- when(tariffRepository.findEffectiveUsageTariff(any(DayOfWeek.class), any(LocalTime.class), anyLong()))
+ when(tariffRepository.getEffectiveUsageTariff(any(DayOfWeek.class), any(LocalTime.class), anyLong()))
.thenReturn(new Tariff(false, 0, null, null,
null, null, powerPricePerKwh));
- PowerCostRepository powerCostRepository = mock(PowerCostRepository.class);
+ PowerCostDao powerCostRepository = mock(PowerCostDao.class);
int collectionFrequencySeconds = 60;
PowerCostCalculator calculator = new PowerCostCalculator(collectionFrequencySeconds, tariffRepository, powerCostRepository);
@@ -80,8 +80,8 @@ public static List getCurrentPowers() throws IOException {
@Test
public void givenNoApplicableTariffFound_whenCollectUncostedPowers_thenNoCostCalculated() {
// Given
- TariffRepository tariffRepository = mock(TariffRepository.class);
- PowerCostRepository powerCostRepository = mock(PowerCostRepository.class);
+ TariffDao tariffRepository = mock(TariffDao.class);
+ PowerCostDao powerCostRepository = mock(PowerCostDao.class);
CurrentPower currentPower = new CurrentPower(1730757659L,100, -100, false);
@@ -102,7 +102,7 @@ public void givenValidCollectionFrequency_whenNewPowerCostCalculator_thenObjectC
// When
PowerCostCalculator calculator = new PowerCostCalculator(collectionFrequencySeconds,
- mock(TariffRepository.class), mock(PowerCostRepository.class));
+ mock(TariffDao.class), mock(PowerCostDao.class));
// Then
Assertions.assertNotNull(calculator);
@@ -116,7 +116,7 @@ public void givenInvalidCollectionFrequency_whenNewPowerCostCalculator_thenExcep
// When/Then
Assertions.assertThrows(IllegalArgumentException.class, () -> new PowerCostCalculator(collectionFrequencySeconds,
- mock(TariffRepository.class), mock(PowerCostRepository.class)));
+ mock(TariffDao.class), mock(PowerCostDao.class)));
}
}
diff --git a/src/test/java/org/keen/solar/solcast/forecast/ForecastPersisterIT.java b/src/test/java/org/keen/solar/solcast/forecast/ForecastPersisterIT.java
index 85516cd..cbe4a03 100644
--- a/src/test/java/org/keen/solar/solcast/forecast/ForecastPersisterIT.java
+++ b/src/test/java/org/keen/solar/solcast/forecast/ForecastPersisterIT.java
@@ -2,7 +2,7 @@
import org.junit.jupiter.api.Test;
import org.keen.solar.system.fronius.CurrentPowerConfiguration;
-import org.keen.solar.solcast.forecast.dal.ForecastRepository;
+import org.keen.solar.solcast.forecast.dal.ForecastDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
@@ -33,7 +33,7 @@ public ForecastPersister forecastPersister() {
private ForecastPersister persister;
@Autowired
- private ForecastRepository repository;
+ private ForecastDao repository;
@Test
public void givenSolcastAPIAndDatabaseOnline_whenRetrieveAndPersist_thenForecastIsPersisted() {
diff --git a/src/test/java/org/keen/solar/solcast/forecast/ForecastPersisterTest.java b/src/test/java/org/keen/solar/solcast/forecast/ForecastPersisterMockDatabaseTest.java
similarity index 99%
rename from src/test/java/org/keen/solar/solcast/forecast/ForecastPersisterTest.java
rename to src/test/java/org/keen/solar/solcast/forecast/ForecastPersisterMockDatabaseTest.java
index d58ed88..9f37fb9 100644
--- a/src/test/java/org/keen/solar/solcast/forecast/ForecastPersisterTest.java
+++ b/src/test/java/org/keen/solar/solcast/forecast/ForecastPersisterMockDatabaseTest.java
@@ -3,6 +3,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.keen.solar.solcast.forecast.dal.ForecastRepository;
+import org.keen.solar.solcast.forecast.dal.ForecastDaoSpringDataImpl;
import org.keen.solar.solcast.forecast.domain.GenerationForecast;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.jdbc.AutoConfigureDataJdbc;
@@ -29,8 +30,8 @@
* The in-memory database is configured in /test/resources/application.properties.
*/
@AutoConfigureDataJdbc
-@RestClientTest(components = ForecastRetriever.class)
-public class ForecastPersisterTest {
+@RestClientTest(components = {ForecastRetriever.class, ForecastDaoSpringDataImpl.class})
+public class ForecastPersisterMockDatabaseTest {
@Autowired
private ForecastRetriever retriever;
diff --git a/src/test/java/org/keen/solar/solcast/measurement/MeasurementUploaderMockIT.java b/src/test/java/org/keen/solar/solcast/measurement/MeasurementUploaderMockIT.java
index 7ff51e7..e476cc4 100644
--- a/src/test/java/org/keen/solar/solcast/measurement/MeasurementUploaderMockIT.java
+++ b/src/test/java/org/keen/solar/solcast/measurement/MeasurementUploaderMockIT.java
@@ -4,7 +4,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.keen.solar.config.TestConfiguration;
-import org.keen.solar.system.dal.CurrentPowerRepository;
+import org.keen.solar.system.dal.CurrentPowerDao;
import org.keen.solar.system.domain.CurrentPower;
import org.mockito.ArgumentCaptor;
import org.springframework.beans.factory.annotation.Autowired;
@@ -48,7 +48,7 @@
public class MeasurementUploaderMockIT {
@MockitoBean
- private CurrentPowerRepository currentPowerRepository;
+ private CurrentPowerDao currentPowerRepository;
@Autowired
private MeasurementUploader measurementUploader;
@@ -70,7 +70,7 @@ public void givenSingleCurrentPower_whenUploadAll_thenMeasurementUploadedAndSave
Instant now = Instant.now().minus(10, ChronoUnit.MINUTES);
long inverterEpochTimestamp = now.toEpochMilli() / 1000;
currentPowerList.add(new CurrentPower(inverterEpochTimestamp, generationWatts, 0D, false));
- when(currentPowerRepository.findByUploaded(false)).thenReturn(currentPowerList);
+ when(currentPowerRepository.getNotUploaded()).thenReturn(currentPowerList);
RestTemplate restTemplate = restTemplateBuilder.build();
MockRestServiceServer restServiceServer = MockRestServiceServer.bindTo(restTemplate).build();
@@ -99,7 +99,7 @@ public void givenSingleCurrentPower_whenUploadAll_thenMeasurementUploadedAndSave
@SuppressWarnings("unchecked")
ArgumentCaptor> argumentCaptor = ArgumentCaptor.forClass(List.class);
- verify(currentPowerRepository).saveAll(argumentCaptor.capture());
+ verify(currentPowerRepository).save(argumentCaptor.capture());
List captorValue = argumentCaptor.getValue();
Assert.notEmpty(captorValue, "Expected non-empty list to be saved");
CurrentPower currentPower = captorValue.get(0);
@@ -117,7 +117,7 @@ public void givenMultipleCurrentPower5MinsApart_whenUploadAll_thenMeasurementsUp
Instant nowPlus5Mins = now.plus(5, ChronoUnit.MINUTES);
long inverterEpochTimestampPlus5Mins = nowPlus5Mins.toEpochMilli() / 1000;
currentPowerList.add(new CurrentPower(inverterEpochTimestampPlus5Mins, generationWatts, 0D, false));
- when(currentPowerRepository.findByUploaded(false)).thenReturn(currentPowerList);
+ when(currentPowerRepository.getNotUploaded()).thenReturn(currentPowerList);
RestTemplate restTemplate = restTemplateBuilder.build();
MockRestServiceServer restServiceServer = MockRestServiceServer.bindTo(restTemplate).build();
@@ -153,7 +153,7 @@ public void givenMultipleCurrentPower5MinsApart_whenUploadAll_thenMeasurementsUp
@SuppressWarnings("unchecked")
ArgumentCaptor> argumentCaptor = ArgumentCaptor.forClass(List.class);
- verify(currentPowerRepository, times(2)).saveAll(argumentCaptor.capture());
+ verify(currentPowerRepository, times(2)).save(argumentCaptor.capture());
List captorValue = argumentCaptor.getAllValues().stream().flatMap(List::stream).toList();
Assert.notEmpty(captorValue, "Expected non-empty list to be saved");
Assert.state(captorValue.size() == 2, "Expected 2 CurrentPowers to be saved");