use of org.motechproject.commons.api.Range in project motech by motech.
the class AbstractSearchExecutionTest method shouldSetCorrectParams.
@Test
public void shouldSetCorrectParams() {
when(restriction.isEmpty()).thenReturn(false);
when(restriction.isByCreator()).thenReturn(true);
when(query.executeWithArray(anyVararg())).thenReturn(queryResult());
EmailRecordSearchCriteria criteria = new EmailRecordSearchCriteria().withFromAddress("from@address.com").withMessageTimeRange(new Range<>(PAST, FUTURE)).withMessage("text to search").withDeliveryStatuses(DeliveryStatus.RECEIVED, DeliveryStatus.ERROR).withQueryParams(queryParams);
AbstractSearchExecution execution = createExecution(criteria);
Object result = execution.execute(query, restriction);
verify(query).setFilter("deliveryTime>=param0lb && deliveryTime<=param0ub && " + "(deliveryStatus == param1_0 || deliveryStatus == param1_1) && (fromAddress.matches(param2) || " + "message.matches(param3)) && creator == param4");
verify(query).declareParameters("org.joda.time.DateTime param0lb, org.joda.time.DateTime param0ub, " + DeliveryStatus.class.getName() + " param1_0, " + DeliveryStatus.class.getName() + " param1_1, " + "java.lang.String param2, java.lang.String param3, java.lang.String param4");
verify(query).executeWithArray(argThat(new QueryExecutionMatcher()));
verifyImplementationDetails();
assertResult(result);
}
use of org.motechproject.commons.api.Range in project motech by motech.
the class PropertyBuilderTest method shouldGenerateAppropriatePropertyType.
@Test
public void shouldGenerateAppropriatePropertyType() throws Exception {
Set<String> set = new HashSet<>();
Range<Integer> range = new Range<>(0, 1);
Type type = new Type("mds.field.combobox", "", List.class);
Entity entity = new Entity("org.motechproject.mds.Sample");
Field field = new Field(entity, "roles", "roles", type, true, false, false);
// should not create collection property for fields without list field
assertProperty(PropertyBuilder.create("roles", 1L, Long.class.getName()), EqualProperty.class, "roles", 1L);
field.addSetting(new FieldSetting(field, new TypeSetting(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS), "true"));
// should create collection property for enum list
assertProperty(PropertyBuilder.create(field, "role"), CollectionProperty.class, "roles", Arrays.asList("role"));
field.addSetting(new FieldSetting(field, new TypeSetting(Constants.Settings.ALLOW_USER_SUPPLIED), "true"));
// should create collection property for string list
assertProperty(PropertyBuilder.create(field, "role"), CollectionProperty.class, "roles", Arrays.asList("role"));
assertProperty(PropertyBuilder.create("set", set, String.class), SetProperty.class, "set", set);
assertProperty(PropertyBuilder.create("range", range, Integer.class), RangeProperty.class, "range", range);
assertProperty(PropertyBuilder.create("equal", 1L, Long.class), EqualProperty.class, "equal", 1L);
assertProperty(PropertyBuilder.create("text", "someString", String.class.getName(), "matches()"), MatchesProperty.class, "text", ".*someString.*");
assertProperty(PropertyBuilder.create("text", "someString", String.class.getName(), "matches((?i))"), MatchesCaseInsensitiveProperty.class, "text", "(?i).*someString.*");
}
use of org.motechproject.commons.api.Range in project motech by motech.
the class QueryUtilTest method shouldCreateFiltersAndParamDeclarationForRanges.
@Test
public void shouldCreateFiltersAndParamDeclarationForRanges() {
DateTime now = DateTime.now();
DateTime later = now.plusHours(2);
Range<DateTime> range = new Range<>(now, later);
String[] properties = new String[] { "prop1", "prop2" };
Object[] values = new Object[] { range, true };
QueryUtil.useFilter(query, properties, values, typeMap(DateTime.class, Boolean.class));
verify(query).setFilter("prop1>=param0lb && prop1<=param0ub && prop2 == param1");
verify(query).declareParameters("org.joda.time.DateTime param0lb, org.joda.time.DateTime param0ub, java.lang.Boolean param1");
}
use of org.motechproject.commons.api.Range in project motech by motech.
the class TypeHelperTest method shouldBuildRanges.
@Test
public void shouldBuildRanges() {
final DateTime now = DateUtil.now();
final Range dtRange = new Range<>(now, now.plusHours(1));
final Range intRange = new Range<>(1, 5);
assertEquals(intRange, TypeHelper.toRange(new Range<>(1, 5), Integer.class.getName()));
assertEquals(dtRange, TypeHelper.toRange(new Range<>(now, now.plusHours(1)), DateTime.class.getName()));
Map<String, Object> map = new LinkedHashMap<>();
map.put("min", now);
map.put("max", now.plusHours(1));
assertEquals(dtRange, TypeHelper.toRange(map, DateTime.class.getName()));
map.put("min", now.toString());
map.put("max", now.plusHours(1).toString());
assertEquals(dtRange, TypeHelper.toRange(map, DateTime.class.getName()));
// string parsing
assertEquals(dtRange, TypeHelper.toRange(dtRange.getMin() + ".." + dtRange.getMax(), DateTime.class.getName()));
assertEquals(intRange, TypeHelper.toRange("1..5", Integer.class.getName()));
}
use of org.motechproject.commons.api.Range in project motech by motech.
the class PasswordRecoveryServiceImpl method cleanUpExpiredRecoveries.
@Override
@Transactional
public void cleanUpExpiredRecoveries() {
Range<DateTime> range = new Range<>(new DateTime(0), DateUtil.now());
List<PasswordRecovery> expiredRecoveries = passwordRecoveriesDataService.findByExpirationDate(range);
for (PasswordRecovery recovery : expiredRecoveries) {
passwordRecoveriesDataService.delete(recovery);
}
LOGGER.info("Cleaned up all expired password recoveries");
}
Aggregations