diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java
index 05249f017..245e4d57a 100644
--- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java
+++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java
@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.autoconfigure.repository;
import org.eclipse.hawkbit.EnableJpaRepository;
-import org.eclipse.hawkbit.repository.jpa.TimestampCalculator;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyResolver;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -34,7 +33,7 @@ public class JpaRepositoryAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public VirtualPropertyReplacer virtualPropertyReplacer() {
- return new VirtualPropertyResolver(new TimestampCalculator());
+ return new VirtualPropertyResolver();
}
}
diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/TimestampCalculator.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/TimestampCalculator.java
index ea467b316..303c9ea3a 100644
--- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/TimestampCalculator.java
+++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/TimestampCalculator.java
@@ -22,7 +22,7 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
* Therefore tenant specific configuration may be considered.
*
*/
-public class TimestampCalculator {
+public final class TimestampCalculator {
/**
* Calculates the overdue timestamp (overdue_ts) based on the
@@ -36,20 +36,20 @@ public class TimestampCalculator {
* @return overdue_ts in milliseconds since Unix epoch as long
* value
*/
- public long calculateOverdueTimestamp() {
+ public static long calculateOverdueTimestamp() {
return Instant.now().toEpochMilli() - getDurationForKey(TenantConfigurationKey.POLLING_TIME_INTERVAL).toMillis()
- getDurationForKey(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL).toMillis();
}
- private Duration getDurationForKey(TenantConfigurationKey key) {
+ private static Duration getDurationForKey(TenantConfigurationKey key) {
return DurationHelper.formattedStringToDuration(getRawStringForKey(key));
}
- private String getRawStringForKey(TenantConfigurationKey key) {
+ private static String getRawStringForKey(TenantConfigurationKey key) {
return getTenantConfigurationManagement().getConfigurationValue(key, String.class).getValue();
}
- protected TenantConfigurationManagement getTenantConfigurationManagement() {
+ public static TenantConfigurationManagement getTenantConfigurationManagement() {
return TenantConfigurationManagementHolder.getInstance().getTenantConfigurationManagement();
}
}
diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolver.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolver.java
index e0f1483aa..14f23b5be 100644
--- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolver.java
+++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolver.java
@@ -8,12 +8,17 @@
*/
package org.eclipse.hawkbit.repository.jpa.rsql;
+import java.time.Duration;
import java.time.Instant;
import org.apache.commons.lang3.text.StrLookup;
import org.apache.commons.lang3.text.StrSubstitutor;
+import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.jpa.TimestampCalculator;
+import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManagementHolder;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
+import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
+import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
/**
* Adds macro capabilities to RSQL expressions that are used to filter for
@@ -43,21 +48,8 @@ import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
*/
public class VirtualPropertyResolver extends StrLookup implements VirtualPropertyReplacer {
- private final TimestampCalculator timestampCalculator;
-
private StrSubstitutor substitutor;
- /**
- * Instantiates a new virtual property resolver with the given timestamp
- * calculator
- *
- * @param timestampCalculator
- * calculates timestamps
- */
- public VirtualPropertyResolver(TimestampCalculator timestampCalculator) {
- this.timestampCalculator = timestampCalculator;
- }
-
@Override
public String lookup(String rhs) {
String resolved = null;
@@ -65,7 +57,7 @@ public class VirtualPropertyResolver extends StrLookup implements Virtua
if ("now_ts".equalsIgnoreCase(rhs)) {
resolved = String.valueOf(Instant.now().toEpochMilli());
} else if ("overdue_ts".equalsIgnoreCase(rhs)) {
- resolved = String.valueOf(getTimestampCalculator().calculateOverdueTimestamp());
+ resolved = String.valueOf(TimestampCalculator.calculateOverdueTimestamp());
}
return resolved;
}
@@ -79,7 +71,4 @@ public class VirtualPropertyResolver extends StrLookup implements Virtua
return substitutor.replace(input);
}
- TimestampCalculator getTimestampCalculator() {
- return timestampCalculator;
- }
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml
index 9f7a0bbb7..44f74e97c 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml
+++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml
@@ -141,6 +141,16 @@
fest-assert
test
+
+ org.powermock
+ powermock-module-junit4
+ test
+
+
+ org.powermock
+ powermock-api-mockito
+ test
+
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java
index 9a412f9aa..0240f8458 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java
@@ -309,7 +309,7 @@ public class JpaTargetManagement implements TargetManagement {
}
if (filterParams.getOverdueState() != null) {
specList.add(
- TargetSpecifications.isOverdue(new TimestampCalculator().calculateOverdueTimestamp()));
+ TargetSpecifications.isOverdue(TimestampCalculator.calculateOverdueTimestamp()));
}
if (filterParams.getFilterByDistributionId() != null) {
specList.add(
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java
index 20f5305c6..db5f04c8a 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
@@ -36,28 +37,27 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
-@RunWith(MockitoJUnitRunner.class)
+@RunWith(PowerMockRunner.class)
@Features("Component Tests - Repository")
@Stories("RSQL search utility")
+@PrepareForTest(TimestampCalculator.class)
// TODO: fully document tests -> @Description for long text and reasonable
// method name as short text
public class RSQLUtilityTest {
@Spy
- private VirtualPropertyResolver macroResolver = new VirtualPropertyResolver(new TimestampCalculator());
+ private VirtualPropertyResolver macroResolver = new VirtualPropertyResolver();
@Mock
private TenantConfigurationManagement confMgmt;
- @Mock
- private TimestampCalculator timestampCalculator;
-
@Mock
private Root