@Test public void test() throws Exception { InputStream is = HpackTest.class.getResourceAsStream(TEST_DIR + fileName); TestCase testCase = TestCase.load(is); testCase.testCompress(); testCase.testDecompress(); }
public double computeSumAPOn(List<TestCase> testCases, RankingAlgo.Type type) { double apSum = 0.0; for (TestCase testCase : testCases) { apSum += computeAPOn(testCase.getRankRecords(type), testCase.getAnsRecords()); } return apSum; }
/** * Makes sure the MDX runs correctly and not in native mode. * * @param rowCount Number of rows returned * @param mdx Query * @param expectedResult Expected result string */ protected void checkNotNative(int rowCount, String mdx, String expectedResult) { getConnection().getCacheControl(null).flushSchemaCache(); Connection con = getTestContext().withSchemaPool(false).getConnection(); RolapNativeRegistry reg = getRegistry(con); reg.setListener( new Listener() { public void foundEvaluator(NativeEvent e) { fail("should not be executed native"); } public void foundInCache(TupleEvent e) {} public void executingSql(TupleEvent e) {} }); TestCase c = new TestCase(con, 0, rowCount, mdx); Result result = c.run(); if (expectedResult != null) { String nonNativeResult = TestContext.toString(result); if (!nonNativeResult.equals(expectedResult)) { TestContext.assertEqualsVerbose( expectedResult, nonNativeResult, false, "Non Native implementation returned different result than " + "expected; MDX=" + mdx); } } }
public TestResult run() { for (TestCase testCase : tests) { testCase.run(result); } return result; }
private Iterable<TestResult> pruneToDepth(List<TestResult> results, Integer depth) { // Prune the response to the requested depth // 0 - TestResult // 1 - TestCapability // 2 - TestSuite // 3 - TestCase // 4 - Entire response // null - Entire response if (depth == null || depth > 3) { return results; } for (TestResult result : results) { if (depth == 0) { result.getTestCapabilities().clear(); } else { for (TestCapability testCapability : result.getTestCapabilities()) { if (depth == 1) { testCapability.getTestSuites().clear(); } else { for (TestSuite testSuite : testCapability.getTestSuites()) { if (depth == 2) { testSuite.getTestCases().clear(); } else { // depth == 3 for (TestCase testCase : testSuite.getTestCases()) { testCase.getTestSteps().clear(); } } } } } } } return results; }
protected void addTest(Class<?> clazz, ITestResult result) { try { TestCase test_case = new TestCase( result.getStatus(), clazz.getName(), getMethodName(result), result.getStartMillis(), result.getEndMillis()); switch (result.getStatus()) { case ITestResult.FAILURE: case ITestResult.SKIP: Throwable ex = result.getThrowable(); if (ex != null) { String failure_type = ex.getClass().getName(); String failure_msg = ex.getMessage(); String stack_trace = printException(ex); test_case.setFailure(failure_type, failure_msg, stack_trace); } else test_case.setFailure("exception", "SKIPPED", null); break; } synchronized ( this) { // handle concurrent access by different threads, if test methods are run in // parallel DataOutputStream output = tests.get(clazz); test_case.writeTo(output); } } catch (Exception e) { error(e.toString()); } }
public void testNamelessTestCase() { TestCase t = new TestCase() {}; try { t.run(); fail(); } catch (AssertionFailedError e) { } }
protected void doRun(TestCase testCase) throws Exception { if (testCase.isIgnored()) { logWarning(Text.valueOf("Ignore ").plus(testCase.getName())); return; } logMessage("test", Text.valueOf(testCase.getName())); super.doRun(testCase); }
public void initTestCaseInfo() { for (TestExpect ep : expectedList) { TestCase testCase = new TestCase(); testCase.setBussinessDesp(ep.getBussinessDesp()); testCase.setResult(ep.getResult()); testCase.setRemark(ep.getExpect() + "\n" + ep.getActual()); testResult.getItem().add(testCase); } }
/** Returns execution details as sonar-conform XML */ public String getDetails() { StringBuilder details = new StringBuilder(); details.append("<tests-details>"); for (TestCase tc : testCases) { details.append(tc.getDetails()); } details.append("</tests-details>"); return details.toString(); }
@Test public void shouldInjectActivityIntoTestCaseMarkedAsSubject() throws NoSuchFieldException, IllegalAccessException { when(testCase.getTestSubjectClassType()).thenReturn(Activity.class); when(testCase.getTestSubjectField()).thenReturn(getSampleField()); when(testCase.getTestCaseInstance()).thenReturn(testCaseInstance); when(injector.getInstance(Activity.class)).thenReturn(activity); testFieldInjector.setupTestCase(); verify(reflectionUtils).forceSetValueOnField(getSampleField(), testCaseInstance, activity); }
public static boolean unequalSizeCheck(Test test) { int ins = test.getNet().getInputLayer().size(); int outs = test.getNet().getOutputLayer().size(); for (TestCase tc : test.getCases()) { if ((tc.getInputs().length != ins) || (tc.getOutputs().length != outs)) { return false; } } return true; }
public void run(CommandExecutor executor) { TestCase[] testcases = { new TestCase(1, "testcaseMethod1"), new TestCase(2, "testcaseMethod2"), new TestCase(3, "testcaseMethod3"), new TestCase(4, "testcaseMethod4"), }; // Lock compilation makes all compiles stay in queue or compile thread before completion WB.lockCompilation(); // Enqueue one test method for each available level int[] complevels = CompilerUtils.getAvailableCompilationLevels(); for (int level : complevels) { TestCase testcase = testcases[level - 1]; boolean added = WB.enqueueMethodForCompilation(testcase.method, testcase.level); // Set results to false for those methods we must to find // We will also assert if we find any test method we don't expect Assert.assertEquals(added, WB.isMethodQueuedForCompilation(testcase.method)); testcase.check = false; } // Get output from dcmd (diagnostic command) OutputAnalyzer output = executor.execute("Compiler.queue"); Iterator<String> lines = output.asLines().iterator(); // Loop over output set result for all found methods while (lines.hasNext()) { String str = lines.next(); // Fast check for common part of method name if (str.contains("testcaseMethod")) { for (TestCase testcase : testcases) { if (str.contains(testcase.methodName)) { Assert.assertFalse(testcase.check, "Must not be found or already found."); testcase.check = true; } } } } for (TestCase testcase : testcases) { if (!testcase.check) { // If this method wasn't found it must have been removed by policy, // verify that it is now removed from the queue Assert.assertFalse( WB.isMethodQueuedForCompilation(testcase.method), "Must be found or not in queue"); } // Otherwise all good. } // Enable compilations again WB.unlockCompilation(); }
private void doStoreTestNow() throws HoneycombTestException { TestCase self = createTestCase("setupStore", "filesize=" + getFilesize()); self.addTag(Tag.SMOKE); self.addTag(Tag.REGRESSION); self.addTag(Tag.POSITIVE); self.addTag(Tag.SMOKE); self.addTag(HoneycombTag.STOREDATA); self.addTag(HoneycombTag.JAVA_API); self.addTag(HoneycombTag.EMULATOR); if (self.excludeCase()) return; storeResult = store(getFilesize()); // successful result will only be posted if we didn't throw self.testPassed( "Stored file of size " + getFilesize() + " as oid " + storeResult.mdoid + " @ " + (storeResult.filesize * 1000 / storeResult.time) + " bytes/sec"); setupOK = true; }
private TestCase getTestCase(Access access1, Access access2) { try { return TestCase.valueOf(access1.toString() + "_" + access2.toString()); } catch (Exception e1) { try { return TestCase.valueOf(access2.toString() + "_" + access1.toString()); } catch (Exception e2) { return null; } } }
@Test public void testSelfSimilarity() { TestCase test = new DefaultTestCase(); PrimitiveStatement<?> aInt = new IntPrimitiveStatement(test, 42); test.addStatement(aInt); double score = DiversityObserver.getNeedlemanWunschScore(test, test); Assert.assertTrue(score > 0); }
@Override protected void tearDown() throws Exception { super.tearDown(); framework.stop(); IO.delete(tmp); Main.stop(); IO.delete(IO.getFile("generated/cache")); IO.delete(IO.getFile("generated/storage")); framework.waitForStop(100000); super.tearDown(); }
protected void runTestProfiled() throws Throwable { // Warmup run, notably to trigger all needed classloading. super.runTest(); long t0 = System.nanoTime(); try { super.runTest(); } finally { long elapsedMillis = millisElapsedSince(t0); if (elapsedMillis >= profileThreshold) System.out.printf("%n%s: %d%n", toString(), elapsedMillis); } }
/** * Adds the given test case to this testsuite maintaining the internal statistics * * @param tc the test case to add */ public void addTestCase(TestCase tc) { if (tc.isSkipped()) { skipped++; } else if (tc.isFailure()) { failures++; } else if (tc.isError()) { errors++; } tests++; time += tc.getTime(); testCases.add(tc); }
@Test public void shouldInjectFragmentIntoTestCaseMarkedAsSubject() throws NoSuchFieldException, IllegalAccessException { when(testCase.getTestSubjectClassType()).thenReturn(RoboFragment.class); when(testCase.getTestSubjectField()).thenReturn(getSampleField()); when(testCase.getTestCaseInstance()).thenReturn(testCaseInstance); when(reflectionUtils.classIsOfAssignableForm(RoboFragment.class, RoboFragment.class)) .thenReturn(true); when(reflectionUtils.createObjectProxy(RoboFragment.class, testFieldInjector)) .thenReturn(fragment); testFieldInjector.setupTestCase(); verify(reflectionUtils).forceSetValueOnField(getSampleField(), testCaseInstance, fragment); }
@Test public void shouldSetMocksIntoTestCase() throws NoSuchFieldException, IllegalAccessException { Object mockOne = mock(Object.class); Object mockTwo = mock(Object.class); when(testCase.getTestCaseInstance()).thenReturn(testCaseInstance); when(testCase.getFieldsMarkedWithMock()) .thenReturn(Lists.newArrayList(getSampleField(), getSecondSampleField())); when(injector.getInstance(getSampleField().getType())).thenReturn(mockOne); when(injector.getInstance(getSecondSampleField().getType())).thenReturn(mockTwo); testFieldInjector.setupTestCase(); verify(reflectionUtils).forceSetValueOnField(getSampleField(), testCaseInstance, mockOne); verify(reflectionUtils).forceSetValueOnField(getSecondSampleField(), testCaseInstance, mockTwo); }
public static void main(String[] args) { try { // to init Utils before call SecurityManager Class.forName(Utils.class.getName(), true, Utils.class.getClassLoader()); } catch (ClassNotFoundException e) { throw new Error("[TEST BUG]: jdk.test.lib.Utils not found", e); } try { TestCase mode = TestCase.valueOf(args[0]); mode.run(); } catch (IllegalArgumentException e) { throw new Error("[TEST BUG]: Unknown mode " + args[0], e); } }
/** * Launch the test. * * @param args the command line arguments * @generatedBy CodePro at 18/10/13 19:08 */ public static void main(String[] args) { if (args.length == 0) { // Run all of the tests junit.textui.TestRunner.run(EC2WorkerTest.class); } else { // Run only the named tests TestSuite suite = new TestSuite("Selected tests"); for (int i = 0; i < args.length; i++) { TestCase test = new EC2WorkerTest(); test.setName(args[i]); suite.addTest(test); } junit.textui.TestRunner.run(suite); } }
public void test(TestCase testCase) { System.out.println(testCase.name()); ConstantPool cp = testCase.getConstantPool(); String cpStringRep = cp.toString(); String cpClassSimpleName = CompilerToVMHelper.HotSpotConstantPoolClass().getSimpleName(); if (!cpStringRep.contains(cpClassSimpleName) || !cpStringRep.contains(TEST_CLASS.getName())) { String msg = String.format( "%s : " + " Constant pool is not valid." + " String representation should contain \"%s\" and \"%s\"", testCase.name(), cpClassSimpleName, TEST_CLASS.getName()); throw new AssertionError(msg); } }
@Test public void testBasicSimilarity() { TestCase test1 = new DefaultTestCase(); TestCase test2 = new DefaultTestCase(); PrimitiveStatement<?> aInt = new IntPrimitiveStatement(test1, 42); test1.addStatement(aInt); PrimitiveStatement<?> bInt = new IntPrimitiveStatement(test2, 42); test2.addStatement(bInt); double score = DiversityObserver.getNeedlemanWunschScore(test1, test2); Assert.assertTrue(score > 0); }
@Override protected void tearDown() throws Exception { framework.stop(); framework.waitForStop(10000); IO.delete(tmp); super.tearDown(); }
@Test public void testSingleStorable() { class TestCase implements Storable { @Store private int value = 0; } TestCase test = new TestCase(); test.value = 256; Data data = new Data(); test.save(data); test = new TestCase(); test.load(data); assertThat(test.value).isEqualTo(256); }
/** Intercept test case invocation and delegate it to a remote server. */ public void runBare() throws Throwable { if (shouldRunTestOnServer()) { runBareClient(); } else { super.runBare(); } }
protected void tearDown() throws Exception { _styleSheet = null; _hWPFDocFixture.tearDown(); _hWPFDocFixture = null; super.tearDown(); }
@Override protected void setUp() throws Exception { tmp = IO.getFile("generated/tmp"); tmp.mkdirs(); configuration = new HashMap<String, Object>(); configuration.put( Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); configuration.put(Constants.FRAMEWORK_STORAGE, new File(tmp, "fwstorage").getAbsolutePath()); configuration.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.4"); framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration); framework.init(); framework.start(); BundleContext context = framework.getBundleContext(); String[] bundles = { "../cnf/repo/osgi.cmpn/osgi.cmpn-4.3.1.jar", "testdata/slf4j-simple-1.7.12.jar", "testdata/slf4j-api-1.7.12.jar", "testdata/org.apache.aries.util-1.1.0.jar", "testdata/org.apache.aries.jmx-1.1.1.jar", "generated/biz.aQute.remote.test.jmx.jar" }; for (String bundle : bundles) { String location = "reference:" + IO.getFile(bundle).toURI().toString(); Bundle b = context.installBundle(location); if (!bundle.contains("slf4j-simple")) { b.start(); } } super.setUp(); }