Overdue target filter based on makro resolution of placeholders
Signed-off-by: Marcel Mager (INST-IOT/ESB) <Marcel.Mager@bosch-si.com>
This commit is contained in:
@@ -9,14 +9,8 @@
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
@@ -26,18 +20,24 @@ import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.persistence.metamodel.Attribute;
|
||||
|
||||
import org.apache.commons.lang3.text.StrLookup;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetFields;
|
||||
import org.eclipse.hawkbit.repository.FieldNameProvider;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@@ -48,6 +48,12 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
// method name as short text
|
||||
public class RSQLUtilityTest {
|
||||
|
||||
@Spy
|
||||
VirtualPropertyMakroResolver makroResolver = new VirtualPropertyMakroResolver();
|
||||
|
||||
@Mock
|
||||
TenantConfigurationManagement confMgmt;
|
||||
|
||||
@Mock
|
||||
private Root<Object> baseSoftwareModuleRootMock;
|
||||
|
||||
@@ -59,11 +65,16 @@ public class RSQLUtilityTest {
|
||||
@Mock
|
||||
private Attribute attribute;
|
||||
|
||||
private static final TenantConfigurationValue<String> TEST_POLLING_TIME_INTERVAL = TenantConfigurationValue
|
||||
.<String>builder().value("00:05:00").build();
|
||||
private static final TenantConfigurationValue<String> TEST_POLLING_OVERDUE_TIME_INTERVAL = TenantConfigurationValue
|
||||
.<String>builder().value("00:07:37").build();
|
||||
|
||||
@Test
|
||||
public void wrongRsqlSyntaxThrowSyntaxException() {
|
||||
final String wrongRSQL = "name==abc;d";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
RSQLUtility.parse(wrongRSQL, SoftwareModuleFields.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterSyntaxException e) {
|
||||
@@ -75,7 +86,7 @@ public class RSQLUtilityTest {
|
||||
final String wrongRSQL = "unknownField==abc";
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
RSQLUtility.parse(wrongRSQL, SoftwareModuleFields.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
fail("Missing an expected RSQLParameterUnsupportedFieldException because of unknown RSQL field");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
@@ -87,7 +98,8 @@ public class RSQLUtilityTest {
|
||||
public void wrongRsqlMapSyntaxThrowSyntaxException() {
|
||||
String wrongRSQL = TargetFields.ATTRIBUTE + "==abc";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
@@ -95,7 +107,8 @@ public class RSQLUtilityTest {
|
||||
|
||||
wrongRSQL = TargetFields.ATTRIBUTE + ".unkwon.wrong==abc";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
@@ -103,7 +116,7 @@ public class RSQLUtilityTest {
|
||||
|
||||
wrongRSQL = DistributionSetFields.METADATA + "==abc";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, DistributionSetFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
RSQLUtility.parse(wrongRSQL, DistributionSetFields.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
@@ -115,7 +128,8 @@ public class RSQLUtilityTest {
|
||||
public void wrongRsqlSubEntitySyntaxThrowSyntaxException() {
|
||||
String wrongRSQL = TargetFields.ASSIGNEDDS + "==abc";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
@@ -123,7 +137,8 @@ public class RSQLUtilityTest {
|
||||
|
||||
wrongRSQL = TargetFields.ASSIGNEDDS + ".unknownField==abc";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
@@ -131,7 +146,8 @@ public class RSQLUtilityTest {
|
||||
|
||||
wrongRSQL = TargetFields.ASSIGNEDDS + ".unknownField.ToMuch==abc";
|
||||
try {
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
RSQLUtility.parse(wrongRSQL, TargetFields.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
@@ -146,11 +162,11 @@ public class RSQLUtilityTest {
|
||||
when(baseSoftwareModuleRootMock.get("version")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
when(criteriaBuilderMock.<String>greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
@@ -164,12 +180,12 @@ public class RSQLUtilityTest {
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
when(criteriaBuilderMock.<String>greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
|
||||
.thenReturn(pathOfString(baseSoftwareModuleRootMock));
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
@@ -185,12 +201,12 @@ public class RSQLUtilityTest {
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
when(criteriaBuilderMock.<String>greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
|
||||
.thenReturn(pathOfString(baseSoftwareModuleRootMock));
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
@@ -206,10 +222,10 @@ public class RSQLUtilityTest {
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
when(criteriaBuilderMock.<String>greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
@@ -226,7 +242,8 @@ public class RSQLUtilityTest {
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, TestFieldEnum.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock,
|
||||
RSQLUtility.parse(correctRsql, TestFieldEnum.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock,
|
||||
criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
@@ -244,7 +261,7 @@ public class RSQLUtilityTest {
|
||||
|
||||
try {
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, TestFieldEnum.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
RSQLUtility.parse(correctRsql, TestFieldEnum.class, null).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
fail("missing RSQLParameterUnsupportedFieldException for wrong enum value");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
@@ -252,6 +269,65 @@ public class RSQLUtilityTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the resolution of overdue_ts placeholder in context of a RSQL expression.")
|
||||
public void correctRsqlWithOverdueMakro() {
|
||||
reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
final String overdueProp = "overdue_ts";
|
||||
final String overduePropPlaceholder = "${" + overdueProp + "}";
|
||||
final String correctRsql = "testfield=le=" + overduePropPlaceholder;
|
||||
when(baseSoftwareModuleRootMock.get("testfield")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) String.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String>lessThanOrEqualTo(any(Expression.class), eq(overduePropPlaceholder)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
|
||||
// test
|
||||
Predicate result = RSQLUtility.parse(correctRsql, TestFieldEnum.class, setupMakroLookup())
|
||||
.toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
verify(makroResolver, times(1)).lookup(overdueProp);
|
||||
// the makro is already replaced when passed to #lessThanOrEqualTo -> the method is never invoked with the
|
||||
// placeholder:
|
||||
verify(criteriaBuilderMock, never()).lessThanOrEqualTo(eq(pathOfString(baseSoftwareModuleRootMock)),
|
||||
eq(overduePropPlaceholder));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests RSQL expression with an unknown placeholder.")
|
||||
public void correctRsqlWithUnknownMakro() {
|
||||
reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
final String overdueProp = "unknown";
|
||||
final String overduePropPlaceholder = "${" + overdueProp + "}";
|
||||
final String correctRsql = "testfield=le=" + overduePropPlaceholder;
|
||||
when(baseSoftwareModuleRootMock.get("testfield")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) String.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String>lessThanOrEqualTo(any(Expression.class), eq(overduePropPlaceholder)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
|
||||
// test
|
||||
Predicate result = RSQLUtility.parse(correctRsql, TestFieldEnum.class, setupMakroLookup())
|
||||
.toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
verify(makroResolver, times(1)).lookup(overdueProp);
|
||||
// the makro is unknown and hence never replaced -> #lessThanOrEqualTo is invoked with the placeholder:
|
||||
verify(criteriaBuilderMock, times(1)).lessThanOrEqualTo(eq(pathOfString(baseSoftwareModuleRootMock)),
|
||||
eq(overduePropPlaceholder));
|
||||
}
|
||||
|
||||
public StrLookup<String> setupMakroLookup() {
|
||||
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class))
|
||||
.thenReturn(TEST_POLLING_TIME_INTERVAL);
|
||||
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class))
|
||||
.thenReturn(TEST_POLLING_OVERDUE_TIME_INTERVAL);
|
||||
when(makroResolver.getTenantConfigurationManagement()).thenReturn(confMgmt);
|
||||
|
||||
return makroResolver;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <Y> Path<Y> pathOfString(final Path<?> path) {
|
||||
return (Path<Y>) path;
|
||||
@@ -262,10 +338,8 @@ public class RSQLUtilityTest {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.hawkbit.server.rest.resource.model.FieldNameProvider#
|
||||
* getFieldName()
|
||||
*
|
||||
* @see org.eclipse.hawkbit.server.rest.resource.model.FieldNameProvider# getFieldName()
|
||||
*/
|
||||
@Override
|
||||
public String getFieldName() {
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* Copyright (c) 2016 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Unit Tests - Repository")
|
||||
@Stories("Placeholder resolution for virtual properties")
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class VirtualPropertyMakroResolverTest {
|
||||
|
||||
@Spy
|
||||
VirtualPropertyMakroResolver resolverUnderTest = new VirtualPropertyMakroResolver();
|
||||
|
||||
@Mock
|
||||
TenantConfigurationManagement confMgmt;
|
||||
|
||||
StrSubstitutor substitutor;
|
||||
|
||||
Long nowTestTime;
|
||||
|
||||
private static final TenantConfigurationValue<String> TEST_POLLING_TIME_INTERVAL = TenantConfigurationValue
|
||||
.<String> builder().value("00:05:00").build();
|
||||
private static final TenantConfigurationValue<String> TEST_POLLING_OVERDUE_TIME_INTERVAL = TenantConfigurationValue
|
||||
.<String> builder().value("00:07:37").build();
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
nowTestTime = Instant.now().toEpochMilli();
|
||||
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class))
|
||||
.thenReturn(TEST_POLLING_TIME_INTERVAL);
|
||||
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class))
|
||||
.thenReturn(TEST_POLLING_OVERDUE_TIME_INTERVAL);
|
||||
when(resolverUnderTest.getTenantConfigurationManagement()).thenReturn(confMgmt);
|
||||
|
||||
this.substitutor = new StrSubstitutor(resolverUnderTest, StrSubstitutor.DEFAULT_PREFIX,
|
||||
StrSubstitutor.DEFAULT_SUFFIX, StrSubstitutor.DEFAULT_ESCAPE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests resolution of NOW_TS by using a StrSubstitutor configured with the VirtualPropertyMakroResolver.")
|
||||
public void resolveNowTimestampPlaceholder() {
|
||||
String placeholder = "${NOW_TS}";
|
||||
String testString = "lhs=lt=" + placeholder;
|
||||
|
||||
String resolvedPlaceholders = substitutor.replace(testString);
|
||||
assertFalse(resolvedPlaceholders.contains(placeholder));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests resolution of OVERDUE_TS by using a StrSubstitutor configured with the VirtualPropertyMakroResolver.")
|
||||
public void resolveOverdueTimestampPlaceholder() {
|
||||
String placeholder = "${OVERDUE_TS}";
|
||||
String testString = "lhs=lt=" + placeholder;
|
||||
|
||||
String resolvedPlaceholders = substitutor.replace(testString);
|
||||
assertFalse(resolvedPlaceholders.contains(placeholder));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests case insensititity of VirtualPropertyMakroResolver.")
|
||||
public void resolveOverdueTimestampPlaceholderLowerCase() {
|
||||
String placeholder = "${overdue_ts}";
|
||||
String testString = "lhs=lt=" + placeholder;
|
||||
|
||||
String resolvedPlaceholders = substitutor.replace(testString);
|
||||
assertFalse(resolvedPlaceholders.contains(placeholder));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests VirtualPropertyMakroResolver with a placeholder unknown to VirtualPropertyMakroResolver.")
|
||||
public void handleUnknownPlaceholder() {
|
||||
String placeholder = "${unknown}";
|
||||
String testString = "lhs=lt=" + placeholder;
|
||||
|
||||
String resolvedPlaceholders = substitutor.replace(testString);
|
||||
assertTrue(resolvedPlaceholders.contains(placeholder));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests escape mechanism for placeholders (syntax is $${SOME_PLACEHOLDER}).")
|
||||
public void handleEscapedPlaceholder() {
|
||||
String placeholder = "${OVERDUE_TS}";
|
||||
String escaptedPlaceholder = StrSubstitutor.DEFAULT_ESCAPE + placeholder;
|
||||
String testString = "lhs=lt=" + escaptedPlaceholder;
|
||||
|
||||
String resolvedPlaceholders = substitutor.replace(testString);
|
||||
assertTrue(resolvedPlaceholders.contains(placeholder));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user