Search in sources :

Example 11 with HistoricItem

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);
}
Also used : FilterCriteria(org.openhab.core.persistence.FilterCriteria) HistoricItem(org.openhab.core.persistence.HistoricItem) Test(org.junit.Test)

Example 12 with HistoricItem

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));
}
Also used : HistoricItem(org.openhab.core.persistence.HistoricItem)

Example 13 with HistoricItem

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);
}
Also used : FilterCriteria(org.openhab.core.persistence.FilterCriteria) HistoricItem(org.openhab.core.persistence.HistoricItem) Test(org.junit.Test)

Example 14 with HistoricItem

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());
}
Also used : FilterCriteria(org.openhab.core.persistence.FilterCriteria) HistoricItem(org.openhab.core.persistence.HistoricItem) Test(org.junit.Test)

Example 15 with HistoricItem

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));
}
Also used : FilterCriteria(org.openhab.core.persistence.FilterCriteria) HistoricItem(org.openhab.core.persistence.HistoricItem) Test(org.junit.Test)

Aggregations

HistoricItem (org.openhab.core.persistence.HistoricItem)34 FilterCriteria (org.openhab.core.persistence.FilterCriteria)19 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)12 Item (org.openhab.core.items.Item)6 State (org.openhab.core.types.State)5 Date (java.util.Date)4 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)4 DecimalType (org.openhab.core.library.types.DecimalType)4 JdbcItem (org.openhab.persistence.jdbc.model.JdbcItem)3 Calendar (java.util.Calendar)2 GroupItem (org.openhab.core.items.GroupItem)2 ColorItem (org.openhab.core.library.items.ColorItem)2 ContactItem (org.openhab.core.library.items.ContactItem)2 DateTimeItem (org.openhab.core.library.items.DateTimeItem)2 DimmerItem (org.openhab.core.library.items.DimmerItem)2 NumberItem (org.openhab.core.library.items.NumberItem)2 RollershutterItem (org.openhab.core.library.items.RollershutterItem)2 SwitchItem (org.openhab.core.library.items.SwitchItem)2 DateTimeType (org.openhab.core.library.types.DateTimeType)2