Improved code readability.
Signed-off-by: Dominik Herbst <dominik.herbst@bosch-si.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import javax.persistence.criteria.Order;
|
|||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.eclipse.hawkbit.repository.FilterParams;
|
import org.eclipse.hawkbit.repository.FilterParams;
|
||||||
import org.eclipse.hawkbit.repository.TargetFields;
|
import org.eclipse.hawkbit.repository.TargetFields;
|
||||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||||
@@ -68,7 +69,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
|
|
||||||
@@ -315,17 +315,21 @@ public class JpaTargetManagement implements TargetManagement {
|
|||||||
TargetSpecifications
|
TargetSpecifications
|
||||||
.hasInstalledOrAssignedDistributionSet(filterParams.getFilterByDistributionId()));
|
.hasInstalledOrAssignedDistributionSet(filterParams.getFilterByDistributionId()));
|
||||||
}
|
}
|
||||||
if (!Strings.isNullOrEmpty(filterParams.getFilterBySearchText())) {
|
if (StringUtils.isNotEmpty(filterParams.getFilterBySearchText())) {
|
||||||
specList.add(TargetSpecifications.likeNameOrDescriptionOrIp(filterParams.getFilterBySearchText()));
|
specList.add(TargetSpecifications.likeNameOrDescriptionOrIp(filterParams.getFilterBySearchText()));
|
||||||
}
|
}
|
||||||
if (filterParams.getSelectTargetWithNoTag() != null && (filterParams.getSelectTargetWithNoTag()
|
if (isHasTagsFilterActive(filterParams)) {
|
||||||
|| (filterParams.getFilterByTagNames() != null && filterParams.getFilterByTagNames().length > 0))) {
|
|
||||||
specList.add(TargetSpecifications.hasTags(filterParams.getFilterByTagNames(),
|
specList.add(TargetSpecifications.hasTags(filterParams.getFilterByTagNames(),
|
||||||
filterParams.getSelectTargetWithNoTag()));
|
filterParams.getSelectTargetWithNoTag()));
|
||||||
}
|
}
|
||||||
return specList;
|
return specList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isHasTagsFilterActive(final FilterParams filterParams) {
|
||||||
|
return filterParams.getSelectTargetWithNoTag() != null && (filterParams.getSelectTargetWithNoTag()
|
||||||
|
|| (filterParams.getFilterByTagNames() != null && filterParams.getFilterByTagNames().length > 0));
|
||||||
|
}
|
||||||
|
|
||||||
private Slice<Target> findByCriteriaAPI(final Pageable pageable, final List<Specification<JpaTarget>> specList) {
|
private Slice<Target> findByCriteriaAPI(final Pageable pageable, final List<Specification<JpaTarget>> specList) {
|
||||||
if (specList == null || specList.isEmpty()) {
|
if (specList == null || specList.isEmpty()) {
|
||||||
return convertPage(criteriaNoCountDao.findAll(pageable, JpaTarget.class), pageable);
|
return convertPage(criteriaNoCountDao.findAll(pageable, JpaTarget.class), pageable);
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
|||||||
public class RSQLUtilityTest {
|
public class RSQLUtilityTest {
|
||||||
|
|
||||||
@Spy
|
@Spy
|
||||||
VirtualPropertyResolver macroResolver = new VirtualPropertyResolver(new TimestampCalculator());
|
private VirtualPropertyResolver macroResolver = new VirtualPropertyResolver(new TimestampCalculator());
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
TenantConfigurationManagement confMgmt;
|
private TenantConfigurationManagement confMgmt;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
TimestampCalculator timestampCalculator;
|
private TimestampCalculator timestampCalculator;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Root<Object> baseSoftwareModuleRootMock;
|
private Root<Object> baseSoftwareModuleRootMock;
|
||||||
@@ -287,11 +287,11 @@ public class RSQLUtilityTest {
|
|||||||
.thenReturn(mock(Predicate.class));
|
.thenReturn(mock(Predicate.class));
|
||||||
|
|
||||||
// test
|
// test
|
||||||
Predicate result = RSQLUtility.parse(correctRsql, TestFieldEnum.class, setupMacroLookup())
|
RSQLUtility.parse(correctRsql, TestFieldEnum.class, setupMacroLookup())
|
||||||
.toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
.toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||||
|
|
||||||
// verfication
|
// verification
|
||||||
verify(macroResolver, times(1)).lookup(overdueProp);
|
verify(macroResolver).lookup(overdueProp);
|
||||||
// the macro is already replaced when passed to #lessThanOrEqualTo -> the method is never invoked with the
|
// the macro is already replaced when passed to #lessThanOrEqualTo -> the method is never invoked with the
|
||||||
// placeholder:
|
// placeholder:
|
||||||
verify(criteriaBuilderMock, never()).lessThanOrEqualTo(eq(pathOfString(baseSoftwareModuleRootMock)),
|
verify(criteriaBuilderMock, never()).lessThanOrEqualTo(eq(pathOfString(baseSoftwareModuleRootMock)),
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||||
@@ -19,6 +19,7 @@ import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
|||||||
import org.eclipse.hawkbit.repository.jpa.TimestampCalculator;
|
import org.eclipse.hawkbit.repository.jpa.TimestampCalculator;
|
||||||
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
|
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
|
||||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -36,14 +37,14 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
|||||||
public class VirtualPropertyResolverTest {
|
public class VirtualPropertyResolverTest {
|
||||||
|
|
||||||
@Spy
|
@Spy
|
||||||
VirtualPropertyResolver resolverUnderTest = new VirtualPropertyResolver(new TimestampCalculator());
|
private VirtualPropertyResolver resolverUnderTest = new VirtualPropertyResolver(new TimestampCalculator());
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
TenantConfigurationManagement confMgmt;
|
private TenantConfigurationManagement confMgmt;
|
||||||
|
|
||||||
StrSubstitutor substitutor;
|
private StrSubstitutor substitutor;
|
||||||
|
|
||||||
Long nowTestTime;
|
private Long nowTestTime;
|
||||||
|
|
||||||
private static final TenantConfigurationValue<String> TEST_POLLING_TIME_INTERVAL = TenantConfigurationValue
|
private static final TenantConfigurationValue<String> TEST_POLLING_TIME_INTERVAL = TenantConfigurationValue
|
||||||
.<String> builder().value("00:05:00").build();
|
.<String> builder().value("00:05:00").build();
|
||||||
@@ -65,7 +66,7 @@ public class VirtualPropertyResolverTest {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.substitutor = new StrSubstitutor(resolverUnderTest,
|
substitutor = new StrSubstitutor(resolverUnderTest,
|
||||||
StrSubstitutor.DEFAULT_PREFIX,
|
StrSubstitutor.DEFAULT_PREFIX,
|
||||||
StrSubstitutor.DEFAULT_SUFFIX, StrSubstitutor.DEFAULT_ESCAPE);
|
StrSubstitutor.DEFAULT_SUFFIX, StrSubstitutor.DEFAULT_ESCAPE);
|
||||||
}
|
}
|
||||||
@@ -77,7 +78,7 @@ public class VirtualPropertyResolverTest {
|
|||||||
String testString = "lhs=lt=" + placeholder;
|
String testString = "lhs=lt=" + placeholder;
|
||||||
|
|
||||||
String resolvedPlaceholders = substitutor.replace(testString);
|
String resolvedPlaceholders = substitutor.replace(testString);
|
||||||
assertFalse("NOW_TS has to be resolved!", resolvedPlaceholders.contains(placeholder));
|
assertThat("NOW_TS has to be resolved!", resolvedPlaceholders, not(containsString(placeholder)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -87,7 +88,7 @@ public class VirtualPropertyResolverTest {
|
|||||||
String testString = "lhs=lt=" + placeholder;
|
String testString = "lhs=lt=" + placeholder;
|
||||||
|
|
||||||
String resolvedPlaceholders = substitutor.replace(testString);
|
String resolvedPlaceholders = substitutor.replace(testString);
|
||||||
assertFalse("OVERDUE_TS has to be resolved!", resolvedPlaceholders.contains(placeholder));
|
assertThat("OVERDUE_TS has to be resolved!", resolvedPlaceholders, not(containsString(placeholder)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -97,7 +98,7 @@ public class VirtualPropertyResolverTest {
|
|||||||
String testString = "lhs=lt=" + placeholder;
|
String testString = "lhs=lt=" + placeholder;
|
||||||
|
|
||||||
String resolvedPlaceholders = substitutor.replace(testString);
|
String resolvedPlaceholders = substitutor.replace(testString);
|
||||||
assertFalse("overdue_ts has to be resolved!", resolvedPlaceholders.contains(placeholder));
|
assertThat("overdue_ts has to be resolved!", resolvedPlaceholders, not(containsString(placeholder)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -107,7 +108,7 @@ public class VirtualPropertyResolverTest {
|
|||||||
String testString = "lhs=lt=" + placeholder;
|
String testString = "lhs=lt=" + placeholder;
|
||||||
|
|
||||||
String resolvedPlaceholders = substitutor.replace(testString);
|
String resolvedPlaceholders = substitutor.replace(testString);
|
||||||
assertTrue("unknown should not be resolved!", resolvedPlaceholders.contains(placeholder));
|
assertThat("unknown should not be resolved!", resolvedPlaceholders, containsString(placeholder));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -118,6 +119,6 @@ public class VirtualPropertyResolverTest {
|
|||||||
String testString = "lhs=lt=" + escaptedPlaceholder;
|
String testString = "lhs=lt=" + escaptedPlaceholder;
|
||||||
|
|
||||||
String resolvedPlaceholders = substitutor.replace(testString);
|
String resolvedPlaceholders = substitutor.replace(testString);
|
||||||
assertTrue("Escaped OVERDUE_TS should not be resolved!", resolvedPlaceholders.contains(placeholder));
|
assertThat("Escaped OVERDUE_TS should not be resolved!", resolvedPlaceholders, containsString(placeholder));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,10 +173,7 @@ public class TargetBeanQuery extends AbstractBeanQuery<ProxyTarget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Boolean isOverdueFilterEnabled() {
|
private Boolean isOverdueFilterEnabled() {
|
||||||
if (Boolean.TRUE.equals(overdueState)) {
|
return Boolean.TRUE.equals(overdueState);
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user