Java Code Examples for junit.framework.TestCase

The following are top voted examples for showing how to use junit.framework.TestCase. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: jentrata-msh   File: MessageHistoryPageletAdaptorTest.java View source code Vote up 6 votes
public void testCheckEmptyAndReturnNull() throws Exception {
	Method m = Class.forName("hk.hku.cecid.ebms.admin.listener.MessageHistoryPageletAdaptor").
		getDeclaredMethod("checkEmptyAndReturnNull", new Class[] {String.class});
	m.setAccessible(true);
	TestCase.assertEquals("abcdefg", (String)m.invoke(adaptor, new Object[] {"abcdefg"}));
	TestCase.assertEquals(null, (String)m.invoke(adaptor, new Object[] {""}));
}
 
Example 2
Project: jentrata-msh   File: EbmsUtilityTest.java View source code Vote up 6 votes
/**
 * Test for converting from a java date object to UTC conformed representation string.
 * 
 * Testing for the scenario the dateTime is represented as java calendar and
 * under the timezone under UTC. 
 */
public void testDate2UTC_Pos1() throws Exception {
	Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
	// [email protected]:24:56.000Z
	cal.set(2007, 06, 16, 13, 24, 56);	
	cal.set(Calendar.MILLISECOND,  789);
	// Convert to UTC representation
	String utc = EbmsUtility.date2UTC(cal.getTime(), cal.getTimeZone());
	
	System.out.println("UTC converted     : " + utc);
			
	// Convert back to java calendar and validate the field.
	Calendar utcCal = EbmsUtility.UTC2Calendar(utc);
	
	// validate whether the timezone is correctly converted.
	String utcTz = utcCal.getTimeZone().getID();
	TestCase.assertTrue(utcTz.equals("UTC") || utcTz.equals("GMT+00:00"));
				
	// validate the calendar field based on cal.
	this.validateCalendar(utcCal, cal);
}
 
Example 3
Project: SOLR   File: TestLBHttpSolrServer.java View source code Vote up 6 votes
public void startJetty() throws Exception {
      jetty = new JettySolrRunner("/solr", port);
      System.setProperty("solr.solr.home", getHomeDir());
      System.setProperty("solr.data.dir", getDataDir());
      jetty.start();
      int newPort = jetty.getLocalPort();
      if (port != 0 && newPort != port) {
        TestCase.fail("TESTING FAILURE: could not grab requested port.");
      }
      this.port = newPort;
//      System.out.println("waiting.........");
//      Thread.sleep(5000);
    }
 
Example 4
Project: jentrata-msh   File: EbmsUtilityTest.java View source code Vote up 6 votes
/**
 * A common method to validate cirtical field for specified <code>target</code>
 * by the value in the calendar <code>control</code>.
 * 
 * @param target
 * 			The target calendar to test for. 
 * @param control
 * 			The reference calendar to test for.
 */
public void validateCalendar(Calendar target, Calendar control)
{
	// Not Null test
	TestCase.assertNotNull(target);
	TestCase.assertNotNull(control);	
	// Assert whether they are representing same time.
	System.out.println("Target  Calendar (de): " + target.getTime());
	System.out.println("Control Calendar (de): " + control.getTime());
	
	System.out.println("Target  Calendar (ms): " + target.getTimeInMillis());
	System.out.println("Control Calendar (ms): " + control.getTimeInMillis());
	
	TestCase.assertEquals (target.getTimeInMillis(), control.getTimeInMillis());	
}
 
Example 5
Project: jentrata-msh   File: EbmsUtilityTest.java View source code Vote up 6 votes
/**
 * Test for the scenario issued by Martin Kalen from the google group.<br/><br/>
 * 
 * <pre>
 * 	I live in the UTC+02:00 timezone and today at 14:01 my time (=12:01
 *  UTC time) an incoming ebXML message with the following TTL timestamp
 *  was considered expired by Hermes: "2007-07-10T12:04:14Z".
 *  Without the change in EbmsUtility above, Hermes regards the incoming
 *  timestamp as 12:04 in my timezone which mutates the expected
 *  12:04:14UTC to 10:04:14UTC = incorrect expiry notification to the
 *  sender.
 * </pre> 
 * 
 * Detail: http://groups.google.com/group/cecid-hermes2/browse_thread/thread/46cca8b51ca21524  
 */
public void testMartinKalenIssue2() throws Exception {
	// Incoming ebMS message TTL.
	String localTime   = "2007-07-10T14:01:14+02:00";
	String currentTime = "2007-07-10T12:01:14Z";
	String timeToLive  = "2007-07-10T12:04:14Z";		
	
	Calendar ttlCal  = EbmsUtility.UTC2Calendar(timeToLive);
			
	// Get the two calendar which they are representing same instant.
	Calendar curCal = EbmsUtility.UTC2Calendar(currentTime);
	Calendar locCal = EbmsUtility.UTC2Calendar(localTime);
			
	// Check whether they are representing same instant.
	this.validateCalendar(curCal, locCal);
			
	// Create one more calendar for stimulating the expiration validation flow
	// The timestamp created is 2007-07-10T12:01:14. 
	Calendar sysCal = Calendar.getInstance(TimeZone.getTimeZone("GMT+02:00"));
	sysCal.set(2007, 06, 10, 12, 01, 14);
	
	System.out.println("System calendar : " + ttlCal.getTime());
	System.out.println("System calendar : " + sysCal.getTime());
			
	// The time to live timstamp is later than the system calendar, then it should 
	// return false.
	TestCase.assertFalse(
		"TimeToLive calendar should not eariler than system calendar", 
		ttlCal.getTime().before(sysCal.getTime()));
}
 
Example 6
Project: shrinkwrap   File: PathUtilTestCase.java View source code Vote up 6 votes
/**
 * Ensures the contract of [email protected] PathProvider#parent()} is intact
 */
@Test
public void testParent() {
    // Log
    log.info("testParent");

    // Create new paths
    final String rootString = "/";
    final String subpathString = "subpath/";
    final String contextString = "context";
    final String contextWithFollowingSlashString = "context/";
    final ArchivePath root = ArchivePaths.create(rootString);
    final ArchivePath subpath = ArchivePaths.create(subpathString);
    final ArchivePath context = ArchivePaths.create(subpath, contextString);
    final ArchivePath contextWithFollowingSlash = new BasicPath(subpath, contextWithFollowingSlashString);

    // Test
    TestCase.assertEquals("The parent of the context path should be equal to the initial subpath", subpath,
        PathUtil.getParent(context));
    TestCase.assertEquals(
        "The parent of the context path with a following slash should be equal to the initial subpath", subpath,
        PathUtil.getParent(contextWithFollowingSlash));
    TestCase.assertEquals("The parent of the subpath should be the root", root, PathUtil.getParent(subpath));
    TestCase.assertNull("The parent of the root should be null", PathUtil.getParent(root));
}
 
Example 7
Project: property-db   File: TestCaseUtil.java View source code Vote up 6 votes
public static String getTestName(Test test) {
    if (test instanceof TestCase) {
        TestCase testCase = (TestCase) test;
        return testCase.getName();
    } else if (test instanceof TestSuite) {
        TestSuite testSuite = (TestSuite) test;
        String name = testSuite.getName();
        if (name != null) {
            int index = name.lastIndexOf(".");
            if (index > -1) {
                return name.substring(index + 1);
            } else {
                return name;
            }
        }
    }
    return "";
}
 
Example 8
Project: jena   File: SAX2RDFTest.java View source code Vote up 6 votes
static private void addTests(TestSuite s, String dir, String base, String file){
	TestCase tc = new SAX2RDFTest(dir,base,file);
	tc.setName("SAX "+tc.getName());
	s.addTest(tc);
	
	tc = new DOM2RDFTest(dir,base,file);
	
	tc.setName("DOM "+tc.getName());
	s.addTest(tc);
}
 
Example 9
Project: shrinkwrap   File: ShrinkWrapTestCase.java View source code Vote up 6 votes
/**
 * Ensures that we can create isolated [email protected] Domain}s
 */
@Test
public void createIsolatedDomains() {
    // Make a couple domains
    final Domain domain1 = ShrinkWrap.createDomain();
    final Domain domain2 = ShrinkWrap.createDomain();

    // Ensure they exist
    TestCase.assertNotNull("Domain should exist", domain1);
    TestCase.assertNotNull("Domain should exist", domain2);

    // Ensure they're not equal
    TestCase.assertNotSame("Creation of domains should return new instances", domain1, domain2);

    // Ensure the underlying configs are not equal
    TestCase.assertNotSame("Creation of domains should have unique / isolated configurations",
        domain1.getConfiguration(), domain2.getConfiguration());
}
 
Example 10
Project: RoboBuggy   File: TestCaseTest.java View source code Vote up 6 votes
public void testErrorTearingDownDoesntMaskErrorRunning() {
    final Exception running = new Exception("Running");
    TestCase t = new TestCase() {
        @Override
        protected void runTest() throws Throwable {
            throw running;
        }

        @Override
        protected void tearDown() throws Exception {
            throw new Error("Tearing down");
        }
    };
    try {
        t.runBare();
    } catch (Throwable thrown) {
        assertSame(running, thrown);
    }
}
 
Example 11
Project: eclipselink.runtime   File: TestTools.java View source code Vote up 6 votes
/**
 * Clear out all the instance variable of the specified test case,
 * allowing the various test fixtures to be garbage-collected.
 * Typically this is called in the #tearDown() method.
 */
public static void clear(TestCase testCase) throws IllegalAccessException {
    for (Class tempClass = testCase.getClass(); tempClass != TestCase_class; tempClass = tempClass.getSuperclass()) {
        Field[] fields = tempClass.getDeclaredFields();
        for (int i = fields.length; i-- > 0; ) {
            Field field = fields[i];
            // leave primitives alone - they don't get garbage-collected, and we can't set them to null...
            if (field.getType().isPrimitive()) {
                continue;
            }
            // leave static fields alone (?)
            if (Modifier.isStatic(field.getModifiers())) {
                continue;
            }
            field.setAccessible(true);
            field.set(testCase, null);
        }
    }
}
 
Example 12
Project: shrinkwrap   File: ShrinkWrapTestCase.java View source code Vote up 6 votes
/**
 * Ensures all calls to get the default domain return the same reference
 */
@Test
public void getDefaultDomain() {
    // Get the default domain twice
    final Domain domain1 = ShrinkWrap.getDefaultDomain();
    final Domain domain2 = ShrinkWrap.getDefaultDomain();

    // Ensure they exist
    TestCase.assertNotNull("Domain should exist", domain1);
    TestCase.assertNotNull("Domain should exist", domain2);

    // Ensure they're not equal
    TestCase.assertSame(
        "Obtaining the default domain should always return the same instance (idempotent operation)", domain1,
        domain2);

}
 
Example 13
Project: PUMA   File: MyUiAutomatorTestRunner.java View source code Vote up 5 votes
/**
 * Called after all test classes are in place, ready to test
 */
protected void start() {
	TestCaseCollector collector = getTestCaseCollector(this.getClass().getClassLoader());
	try {
		collector.addTestClasses(mTestClasses);
	} catch (ClassNotFoundException e) {
		// will be caught by uncaught handler
		throw new RuntimeException(e.getMessage(), e);
	}
	if (mDebug) {
		Debug.waitForDebugger();
	}
	mHandlerThread = new HandlerThread(HANDLER_THREAD_NAME);
	mHandlerThread.setDaemon(true);
	mHandlerThread.start();
	UiAutomationShellWrapper automationWrapper = new UiAutomationShellWrapper();
	automationWrapper.connect();

	long startTime = SystemClock.uptimeMillis();
	TestResult testRunResult = new TestResult();
	ResultReporter resultPrinter;
	String outputFormat = mParams.getString("outputFormat");
	List<TestCase> testCases = collector.getTestCases();
	Bundle testRunOutput = new Bundle();
	if ("simple".equals(outputFormat)) {
		resultPrinter = new SimpleResultPrinter(System.out, true);
	} else {
		resultPrinter = new WatcherResultPrinter(testCases.size());
	}
	try {
		automationWrapper.setRunAsMonkey(mMonkey);
		mUiDevice = MyUiDevice.getInstance();
		UiAutomation uiAutomation = automationWrapper.getUiAutomation();
		mUiDevice.initialize(new ShellUiAutomatorBridge(uiAutomation));
		mUiDevice.setUiAutomation(uiAutomation);

		String traceType = mParams.getString("traceOutputMode");
		if (traceType != null) {
			Tracer.Mode mode = Tracer.Mode.valueOf(Tracer.Mode.class, traceType);
			if (mode == Tracer.Mode.FILE || mode == Tracer.Mode.ALL) {
				String filename = mParams.getString("traceLogFilename");
				if (filename == null) {
					throw new RuntimeException("Name of log file not specified. " + "Please specify it using traceLogFilename parameter");
				}
				Tracer.getInstance().setOutputFilename(filename);
			}
			Tracer.getInstance().setOutputMode(mode);
		}

		// add test listeners
		testRunResult.addListener(resultPrinter);
		// add all custom listeners
		for (TestListener listener : mTestListeners) {
			testRunResult.addListener(listener);
		}

		// run tests for realz!
		for (TestCase testCase : testCases) {
			prepareTestCase(testCase);
			testCase.run(testRunResult);
		}
	} catch (Throwable t) {
		// catch all exceptions so a more verbose error message can be outputted
		resultPrinter.printUnexpectedError(t);
	} finally {
		long runTime = SystemClock.uptimeMillis() - startTime;
		resultPrinter.print(testRunResult, runTime, testRunOutput);
		automationWrapper.disconnect();
		automationWrapper.setRunAsMonkey(false);
		mHandlerThread.quit();
	}
}