001: package com.sun.portal.rewriter.test.util;
002:
003: import com.clarkware.junitperf.ConstantTimer;
004: import com.clarkware.junitperf.LoadTest;
005: import com.clarkware.junitperf.Timer;
006: import com.sun.portal.rewriter.AbsoluteTranslator;
007: import com.sun.portal.rewriter.RewriterModule;
008: import com.sun.portal.rewriter.Translator;
009: import com.sun.portal.rewriter.engines.LanguageConstants;
010: import com.sun.portal.rewriter.rom.InvalidXMLException;
011: import com.sun.portal.rewriter.rom.RuleSetManager;
012: import com.sun.portal.rewriter.util.Resource;
013: import com.sun.portal.rewriter.util.StringHelper;
014: import com.sun.portal.rewriter.util.uri.PageSpec;
015: import junit.extensions.RepeatedTest;
016: import junit.framework.Assert;
017: import junit.framework.Test;
018: import junit.framework.TestCase;
019: import junit.framework.TestSuite;
020:
021: public class BasicTestCase extends TestCase {
022: public BasicTestCase(String aName) {
023: super (aName);
024: }//constuctor
025:
026: protected final String storeRandomRuleSet(String aRuleSetIDSeed)
027: throws InvalidXMLException {
028: String ruleSetID = "test_ruleset_cache"
029: + Math.round(Math.random() * 10000000);
030: String lRuleSetString = Resource
031: .read(RewriterModule.RESOURCE_GENERIC_RULESET_LOCATION);
032: lRuleSetString = StringHelper.searchAndReplace(lRuleSetString,
033: RuleSetManager.create(lRuleSetString).getID(),
034: ruleSetID);
035: RuleSetManager.getDefault().store(lRuleSetString);
036: return ruleSetID;
037: }//storeRuleSet()
038:
039: protected final Translator getDefaultTranslator() throws Exception {
040: String url = "http://rajanagendra.sun.com/Base/Raja/raja.html?name=raja";
041: PageSpec samplePageSpec = new PageSpec(url);
042: return new AbsoluteTranslator(samplePageSpec);
043: }//getDefaultTranslator()
044:
045: protected final Translator getDefaultJSTranslator()
046: throws Exception {
047: String url = "http://rajanagendra.sun.com/Base/Raja/raja.js?name=raja";
048: PageSpec samplePageSpec = new PageSpec(url,
049: LanguageConstants.JS_MIME);
050: return new AbsoluteTranslator(samplePageSpec);
051: }//getDefaultJSTranslator()
052:
053: protected final Translator getDefaultXMLTranslator()
054: throws Exception {
055: String url = "http://rajanagendra.sun.com/Base/Raja/raja.html?name=raja";
056: PageSpec samplePageSpec = new PageSpec(url,
057: LanguageConstants.XML_MIME);
058: return new AbsoluteTranslator(samplePageSpec);
059: }//getDefaultXMLTranslator()
060:
061: protected static void printAssertCount() {
062: try {
063: //as the junit is modified to make assert count no of asserts used,
064: //using reflection to see that this code compiles even in stand junit
065: System.out.println("Total No of Asserts: "
066: + (Assert.class).getDeclaredField("count")
067: .get(null));
068: } catch (Exception e) {
069: //ingore this exception as this will come
070: //if one uses standard junit.jar
071: //e.printStackTrace();
072: }
073: }//printAssertCount()
074:
075: public static final PackageSuiteBuilder createSuiteBuilder(
076: Class aReferenceClass) {
077: return new PackageSuiteBuilder(aReferenceClass.getName(),
078: RewriterTestFilter.class.getName());
079: }//createSuiteBuilder()
080:
081: public static final void run(Class aClass) {
082: run(new TestSuite(aClass));
083: }//run()
084:
085: public static final Test createPerfSuite(String aUserCount,
086: String aIterations, Test aSuite) {
087: Timer timer = new ConstantTimer(100);
088: Test repeatedTest = new RepeatedTest(aSuite, Integer
089: .parseInt(aIterations));
090: Test loadTest = new LoadTest(repeatedTest, Integer
091: .parseInt(aUserCount), timer);
092: TestSuite perfTestSuite = new TestSuite();
093: perfTestSuite.addTest(loadTest);
094: return perfTestSuite;
095: }//createPerfSuite()
096:
097: public static final void run(Test aSuite) {
098: junit.textui.TestRunner.run(aSuite);
099: printAssertCount();
100: }//run()
101: }//class BasicTestCase
|