001 package org.hackystat.telemetry.analyzer.function.impl; 002 003 import junit.framework.TestCase; 004 005 import org.hackystat.telemetry.analyzer.function.TelemetryFunctionManager; 006 import org.hackystat.telemetry.analyzer.model.TelemetryStreamCollection; 007 import org.hackystat.sensorbase.resource.projects.jaxb.Project; 008 import org.hackystat.utilities.time.interval.DayInterval; 009 import org.hackystat.utilities.time.period.Day; 010 011 /** 012 * Test suite for <code>IdempotentFunction</code>. 013 * 014 * @author (Cedric) Qin ZHANG 015 */ 016 public class TestIdempotentFunction extends TestCase { 017 018 private TelemetryFunctionManager manager = TelemetryFunctionManager.getInstance(); 019 private String projectName = "TestIdempotentFunction"; 020 private Project project; 021 private DayInterval interval; 022 023 /** 024 * Sets up this test case. 025 * @throws Exception If test case cannot be set up. 026 */ 027 @Override 028 protected void setUp() throws Exception { 029 030 //this.project = ProjectManager.getInstance().createTestProjectClientSide(projectName); 031 this.project = new Project(); 032 this.project.setName(projectName); 033 Day startDay = Day.getInstance("01-Jan-2004"); 034 this.interval = new DayInterval(startDay, startDay.inc(1)); 035 } 036 037 /** 038 * Tears down this test case. 039 * @throws Exception If tear down failed. 040 */ 041 @Override 042 protected void tearDown() throws Exception { 043 //ProjectManager.getInstance().deleteProject(this.projectName); 044 } 045 046 /** 047 * Tests with numbers. 048 * @throws Exception If test fails. 049 */ 050 public void testNumbers() throws Exception { 051 Number num = Integer.valueOf(1); 052 Object result = this.manager.compute("idempotent", new Number[]{num}); 053 assertSame(num, result); 054 } 055 056 /** 057 * Tests with 1 telemetry stream collection and 1 numbers. 058 * @throws Exception If test fails. 059 */ 060 public void testWithTelemetryStreamCollectionAndNumber() throws Exception { 061 TelemetryStreamCollection input 062 = new TelemetryStreamCollection("test", this.project, this.interval); 063 TelemetryStreamCollection output = (TelemetryStreamCollection) 064 this.manager.compute("idempotent", new Object[]{input}); 065 assertSame(input, output); 066 } 067 }