use of org.opennms.netmgt.collection.api.TimeKeeper in project opennms by OpenNMS.
the class RelativeTimeTest method testYesterdayBeginningDST.
@Test
public void testYesterdayBeginningDST() {
RelativeTime yesterday = RelativeTime.YESTERDAY;
yesterday.setTimeKeeper(new TimeKeeper() {
@Override
public Date getCurrentDate() {
Calendar cal = new GregorianCalendar(m_timeZone, Locale.ENGLISH);
cal.set(m_startYear, m_startMonth, m_startDay, 10, 0, 0);
return cal.getTime();
}
@Override
public long getCurrentTime() {
return getCurrentDate().getTime();
}
@Override
public TimeZone getTimeZone() {
return m_timeZone;
}
});
Date start = yesterday.getStart();
Date end = yesterday.getEnd();
System.err.println("start = " + start);
System.err.println("end = " + end);
Calendar c = new GregorianCalendar(m_timeZone, Locale.ENGLISH);
c.setTime(start);
assertEquals(m_offset, c.get(Calendar.ZONE_OFFSET));
assertEquals(m_startYear, c.get(Calendar.YEAR));
assertEquals(0, c.get(Calendar.HOUR_OF_DAY));
assertEquals(Calendar.SUNDAY, c.get(Calendar.DAY_OF_WEEK));
assertEquals(m_startDay - 1, c.get(Calendar.DAY_OF_MONTH));
c.setTime(end);
assertEquals(m_offset, c.get(Calendar.ZONE_OFFSET));
assertEquals(m_startYear, c.get(Calendar.YEAR));
assertEquals(0, c.get(Calendar.HOUR_OF_DAY));
assertEquals(Calendar.MONDAY, c.get(Calendar.DAY_OF_WEEK));
assertEquals(m_startDay, c.get(Calendar.DAY_OF_MONTH));
assertEquals("end date - start date", 82800000, end.getTime() - start.getTime());
}
use of org.opennms.netmgt.collection.api.TimeKeeper in project opennms by OpenNMS.
the class RelativeTimeTest method testYesterdayEndingDST.
@Test
public void testYesterdayEndingDST() {
RelativeTime yesterday = RelativeTime.YESTERDAY;
yesterday.setTimeKeeper(new TimeKeeper() {
@Override
public Date getCurrentDate() {
Calendar cal = new GregorianCalendar(m_timeZone, Locale.ENGLISH);
cal.set(m_endYear, m_endMonth, m_endDay, 10, 0, 0);
return cal.getTime();
}
@Override
public long getCurrentTime() {
return getCurrentDate().getTime();
}
@Override
public TimeZone getTimeZone() {
return m_timeZone;
}
});
Date start = yesterday.getStart();
Date end = yesterday.getEnd();
Calendar c = new GregorianCalendar(m_timeZone, Locale.ENGLISH);
c.setTime(start);
assertEquals(m_offset, c.get(Calendar.ZONE_OFFSET));
assertEquals(m_endYear, c.get(Calendar.YEAR));
assertEquals(0, c.get(Calendar.HOUR_OF_DAY));
assertEquals(Calendar.SUNDAY, c.get(Calendar.DAY_OF_WEEK));
assertEquals(m_endDay - 1, c.get(Calendar.DAY_OF_MONTH));
c.setTime(end);
assertEquals(m_offset, c.get(Calendar.ZONE_OFFSET));
assertEquals(m_endYear, c.get(Calendar.YEAR));
assertEquals(0, c.get(Calendar.HOUR_OF_DAY));
assertEquals(Calendar.MONDAY, c.get(Calendar.DAY_OF_WEEK));
assertEquals(m_endDay, c.get(Calendar.DAY_OF_MONTH));
assertEquals("end date - start date", 90000000, end.getTime() - start.getTime());
}
use of org.opennms.netmgt.collection.api.TimeKeeper in project opennms by OpenNMS.
the class CollectableService method wrapResourcesWithTimekeeper.
public static CollectionSetVisitor wrapResourcesWithTimekeeper(CollectionSetVisitor visitor, TimeKeeper timeKeeper) {
// Wrap the given visitor and intercept the calls to visit the resources
final CollectionSetVisitor wrappedVisitor = new CollectionSetVisitorWrapper(visitor) {
private CollectionResource wrappedResource;
private CollectionAttribute wrappedAttribute;
private AttributeGroup wrappedGroup;
@Override
public void visitResource(CollectionResource resource) {
// Wrap the given resource and return the custom timekeeper
wrappedResource = new CollectionResourceWrapper(resource) {
@Override
public TimeKeeper getTimeKeeper() {
return timeKeeper;
}
};
visitor.visitResource(wrappedResource);
}
@Override
public void completeResource(CollectionResource resource) {
visitor.completeResource(wrappedResource);
}
@Override
public void visitAttribute(CollectionAttribute attribute) {
// Wrap the given attribute and return the custom resource
wrappedAttribute = new CollectionAttributeWrapper(attribute) {
@Override
public CollectionResource getResource() {
return wrappedResource;
}
};
visitor.visitAttribute(wrappedAttribute);
}
@Override
public void completeAttribute(CollectionAttribute attribute) {
visitor.completeAttribute(wrappedAttribute);
}
@Override
public void visitGroup(AttributeGroup group) {
// Wrap the given attribute group and return the custom resource
wrappedGroup = new AttributeGroupWrapper(group) {
@Override
public CollectionResource getResource() {
return wrappedResource;
}
};
visitor.visitGroup(wrappedGroup);
}
@Override
public void completeGroup(AttributeGroup group) {
visitor.completeGroup(wrappedGroup);
}
};
return wrappedVisitor;
}
Aggregations