001 package org.hackystat.dailyprojectdata.resource.unittest; 002 003 import static org.junit.Assert.assertEquals; 004 import static org.junit.Assert.assertTrue; 005 006 import java.math.BigInteger; 007 import java.util.Set; 008 009 import org.hackystat.sensorbase.resource.sensordata.jaxb.SensorData; 010 import org.junit.Before; 011 import org.junit.Test; 012 013 /** 014 * Test UnitTestDPDCounter class. 015 * 016 * @author Pavel Senin. 017 * 018 */ 019 public class TestUnitTestCounter { 020 021 private static final String testClassName = "org.hackystat.util.TestProxyProperty"; 022 private static final String testResource = "file://foo/bar/baz.txt"; 023 private static final String testCaseName = "testNormalFunctionality"; 024 private static final String testFailResult = "fail"; 025 private static final String testPassResult = "pass"; 026 private static final String testFailureString = "Value of failure string"; 027 private static final String testErrorString = "Value of error string"; 028 private static final String user1 = "javadude@javatest.com"; 029 private static final String user2 = "javadude@javafoo.com"; 030 private static final BigInteger bigOne = BigInteger.valueOf(1); 031 private static final BigInteger bigZero = BigInteger.valueOf(0); 032 private UnitTestTestHelper testHelper; 033 private UnitTestCounter counter; 034 035 /** 036 * Sets up testing environment. 037 * 038 * @throws Exception If problem occurs. 039 */ 040 @Before 041 public void setUp() throws Exception { 042 this.testHelper = new UnitTestTestHelper(); 043 this.counter = new UnitTestCounter(); 044 } 045 046 /** 047 * Tests accounting. 048 * 049 * @throws Exception if problem occurs. 050 */ 051 @Test 052 public void addTest() throws Exception { 053 054 // Create a passing sensor data item 055 SensorData passData = this.testHelper.makeUnitTestEvent("2007-04-30T02:00:00", user1, 056 testResource, testClassName, testPassResult, "50", testCaseName, testFailureString, 057 testErrorString); 058 059 // testing the counter with a passing data instance. 060 this.counter.add(passData); 061 Set<String> members = this.counter.getMembers(); 062 assertTrue("Should return test owner", members.contains(user1)); 063 064 // testing accounting. 065 assertEquals("Check failure count", bigZero, this.counter.getFailCount(user1)); 066 assertEquals("Check succcess count", bigOne, this.counter.getPassCount(user1)); 067 068 // Create a failing sensor data item 069 SensorData failData = this.testHelper.makeUnitTestEvent("2007-04-30T02:00:00", user1, 070 testResource, testClassName, testFailResult, "50", testCaseName, testFailureString, 071 testErrorString); 072 073 // add the failure data instance. 074 this.counter.add(failData); 075 076 // test updated counter. 077 assertEquals("Check failure count", bigOne, this.counter.getFailCount(user1)); 078 assertEquals("Check succcess count", bigOne, this.counter.getPassCount(user1)); 079 080 // test what happens when passed a missing user. 081 assertEquals("Checking missing user 1", bigZero, this.counter.getFailCount(user2)); 082 assertEquals("Check missing user 2", bigZero, this.counter.getPassCount(user2)); 083 } 084 085 }