use of org.openhab.core.persistence.HistoricItem in project openhab1-addons by openhab.
the class AbstractTwoItemIntegrationTest method testQueryUsingNameAndStart.
@Test
public void testQueryUsingNameAndStart() {
FilterCriteria criteria = new FilterCriteria();
criteria.setOrdering(Ordering.ASCENDING);
criteria.setItemName(getItemName());
criteria.setBeginDate(beforeStore);
Iterable<HistoricItem> iterable = BaseIntegrationTest.service.query(criteria);
assertIterableContainsItems(iterable, true);
}
use of org.openhab.core.persistence.HistoricItem in project openhab1-addons by openhab.
the class AbstractTwoItemIntegrationTest method assertIterableContainsItems.
/**
* Asserts that iterable contains correct items and nothing else
*
*/
private void assertIterableContainsItems(Iterable<HistoricItem> iterable, boolean ascending) {
Iterator<HistoricItem> iterator = iterable.iterator();
HistoricItem actual1 = iterator.next();
HistoricItem actual2 = iterator.next();
assertFalse(iterator.hasNext());
for (HistoricItem actual : new HistoricItem[] { actual1, actual2 }) {
assertEquals(getItemName(), actual.getName());
}
HistoricItem storedFirst;
HistoricItem storedSecond;
if (ascending) {
storedFirst = actual1;
storedSecond = actual2;
} else {
storedFirst = actual2;
storedSecond = actual1;
}
assertStateEquals(getFirstItemState(), storedFirst.getState());
assertTrue(storedFirst.getTimestamp().before(afterStore1));
assertTrue(storedFirst.getTimestamp().after(beforeStore));
assertStateEquals(getSecondItemState(), storedSecond.getState());
assertTrue(storedSecond.getTimestamp().before(afterStore2));
assertTrue(storedSecond.getTimestamp().after(afterStore1));
}
use of org.openhab.core.persistence.HistoricItem in project openhab1-addons by openhab.
the class AbstractTwoItemIntegrationTest method testQueryUsingNameAndStartAndEndDesc.
@Test
public void testQueryUsingNameAndStartAndEndDesc() {
FilterCriteria criteria = new FilterCriteria();
criteria.setOrdering(Ordering.DESCENDING);
criteria.setItemName(getItemName());
criteria.setBeginDate(beforeStore);
criteria.setEndDate(afterStore2);
Iterable<HistoricItem> iterable = BaseIntegrationTest.service.query(criteria);
assertIterableContainsItems(iterable, false);
}
use of org.openhab.core.persistence.HistoricItem in project openhab1-addons by openhab.
the class AbstractTwoItemIntegrationTest method testQueryUsingNameAndEndNoMatch.
@Test
public void testQueryUsingNameAndEndNoMatch() {
FilterCriteria criteria = new FilterCriteria();
criteria.setItemName(getItemName());
criteria.setEndDate(beforeStore);
Iterable<HistoricItem> iterable = BaseIntegrationTest.service.query(criteria);
assertFalse(iterable.iterator().hasNext());
}
use of org.openhab.core.persistence.HistoricItem in project openhab1-addons by openhab.
the class AbstractTwoItemIntegrationTest method testQueryUsingNameAndStartAndEndWithLTEOperator.
@Test
public void testQueryUsingNameAndStartAndEndWithLTEOperator() {
FilterCriteria criteria = new FilterCriteria();
criteria.setOperator(Operator.LTE);
criteria.setState(getFirstItemState());
criteria.setItemName(getItemName());
criteria.setBeginDate(beforeStore);
criteria.setEndDate(afterStore2);
Iterable<HistoricItem> iterable = BaseIntegrationTest.service.query(criteria);
Iterator<HistoricItem> iterator = iterable.iterator();
HistoricItem actual1 = iterator.next();
assertFalse(iterator.hasNext());
assertStateEquals(getFirstItemState(), actual1.getState());
assertTrue(actual1.getTimestamp().before(afterStore1));
assertTrue(actual1.getTimestamp().after(beforeStore));
}
Aggregations