List of usage examples for junit.framework AssertionFailedError AssertionFailedError
public AssertionFailedError(String message)
From source file:org.csc.phynixx.connection.recovery.RecoveryIT.java
@Test public void testInterruptedRollback() throws Exception { ITestConnection con = RecoveryIT.this.factory.getConnection(); con.setInitialCounter(3);//w w w .j a v a 2 s. c o m con.act(5); con.act(4); con.setInterruptFlag(TestInterruptionPoint.ROLLBACK); try { con.rollback(); throw new AssertionFailedError("ActionInterruptedException expected"); } catch (Exception e) { } // close on an incomplete connections does not destroy the restore data con.close(); final ITestConnection[] recoveredConnection = new ITestConnection[1]; PhynixxRecovery<ITestConnection> recovery = new PhynixxRecovery<ITestConnection>( new TestConnectionFactory()); IPhynixxLoggerSystemStrategy<ITestConnection> loggerStrategy = this.factory.getLoggerSystemStrategy(); loggerStrategy.close(); recovery.addConnectionProxyDecorator(new TestConnectionStatusListener()); recovery.setLoggerSystemStrategy(loggerStrategy); recovery.recover(new IPhynixxRecovery.IRecoveredManagedConnection<ITestConnection>() { @Override public void managedConnectionRecovered(ITestConnection con) { recoveredConnection[0] = con; Assert.assertEquals(3, con.getCounter()); } }); Assert.assertTrue(recoveredConnection[0] != null); LOG.info(TestConnectionStatusManager.toDebugString()); TestStatusStack recoveredStatusStack = TestConnectionStatusManager .getStatusStack(recoveredConnection[0].getConnectionId()); Assert.assertTrue(recoveredStatusStack.isRecoverd()); Assert.assertTrue(recoveredStatusStack.isFreed()); }
From source file:org.drugis.addis.util.JSMAAintegration.NetworkBenefitRiskTestBase.java
protected void checkResults(SMAAModel model, SMAA2Simulation simulation, double slack) { checkAlternativeOrder(model.getAlternatives(), false); assertEquals("Diarrhea", model.getCriteria().get(0).getName()); assertEquals("HAM-D Responders", model.getCriteria().get(2).getName()); // verify CWs & CFs for (int i = 0; i < model.getAlternatives().size(); ++i) { Alternative alt = model.getAlternatives().get(i); for (int j = 0; j < model.getCriteria().size(); ++j) { Criterion crit = model.getCriteria().get(j); final double actual = simulation.getResults().getCentralWeightVectors().get(alt).get(crit); final double expected = EXPECTED_CW[i][j]; if (Math.abs(actual - expected) > EPSILON_CW * slack) { throw new AssertionFailedError("Central weight for " + alt + " differs on " + crit + ": expected <" + expected + ">, actual <" + actual + ">"); }/*from ww w . j av a2 s .c om*/ } final double actual = simulation.getResults().getConfidenceFactors().get(alt); final double expected = EXPECTED_CF[i]; if (Math.abs(actual - expected) > EPSILON_CW * slack) { throw new AssertionFailedError("Confidence factor for " + alt + " differs: expected <" + expected + ">, actual <" + actual + ">"); } } // verify RAs for (int i = 0; i < model.getAlternatives().size(); ++i) { for (int r = 0; r < model.getAlternatives().size(); ++r) { Alternative alt = model.getAlternatives().get(i); final double actual = simulation.getResults().getRankAcceptabilities().get(alt).get(r); final double expected = EXPECTED_RA[i][r]; if (Math.abs(actual - expected) > EPSILON_RA * slack) { throw new AssertionFailedError("Rank probability for " + alt + " differs on " + (r + 1) + ": expected <" + expected + ">, actual <" + actual + ">"); } } } }
From source file:org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.java
public static CertificateCredentials getCertificateCredentials() { File keyStoreFile;/* w w w.j ava 2 s .c om*/ try { keyStoreFile = CommonTestUtil.getFile(CommonTestUtil.class, "testdata/keystore"); String password = CommonTestUtil.getUserCredentials().getPassword(); return new CertificateCredentials(keyStoreFile.getAbsolutePath(), password, null); } catch (IOException cause) { AssertionFailedError e = new AssertionFailedError("Failed to load keystore file"); e.initCause(cause); throw e; } }
From source file:org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.java
public static UserCredentials getCredentials(PrivilegeLevel level, String realm) { Properties properties = new Properties(); try {/*from w w w . jav a2s. c o m*/ File file; String filename = System.getProperty(KEY_CREDENTIALS_FILE); if (filename != null) { // 1. use user specified file file = new File(filename); } else { // 2. check in home directory file = new File(new File(System.getProperty("user.home"), ".mylyn"), "credentials.properties"); if (!file.exists()) { // 3. fall back to included credentials file file = getFile(CommonTestUtil.class, "testdata/credentials.properties"); } } properties.load(new FileInputStream(file)); } catch (Exception e) { AssertionFailedError error = new AssertionFailedError( "must define credentials in $HOME/.mylyn/credentials.properties"); error.initCause(e); throw error; } String defaultPassword = properties.getProperty("pass"); realm = (realm != null) ? realm + "." : ""; switch (level) { case ANONYMOUS: return createCredentials(properties, realm + "anon.", "", ""); case GUEST: return createCredentials(properties, realm + "guest.", "guest@mylyn.eclipse.org", defaultPassword); case USER: return createCredentials(properties, realm, "tests@mylyn.eclipse.org", defaultPassword); case READ_ONLY: return createCredentials(properties, realm, "read-only@mylyn.eclipse.org", defaultPassword); case ADMIN: return createCredentials(properties, realm + "admin.", "admin@mylyn.eclipse.org", null); } throw new AssertionFailedError("invalid privilege level"); }
From source file:org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.java
public static File getFile(Object source, String filename) throws IOException { Class<?> clazz = (source instanceof Class<?>) ? (Class<?>) source : source.getClass(); if (Platform.isRunning()) { ClassLoader classLoader = clazz.getClassLoader(); try {/*from w w w . j a v a2 s . co m*/ if (isOsgiVersion310orNewer(classLoader)) { return checkNotNull(getFileFromClassLoader4Luna(filename, classLoader)); } else { return checkNotNull(getFileFromClassLoaderBeforeLuna(filename, classLoader)); } } catch (Exception e) { AssertionFailedError exception = new AssertionFailedError( NLS.bind("Could not locate {0} using classloader for {1}", filename, clazz)); exception.initCause(e); throw exception; } } else { return getFileFromNotRunningPlatform(filename, clazz); } }
From source file:org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.java
private static File getFileFromNotRunningPlatform(String filename, Class<?> clazz) throws UnsupportedEncodingException, IOException { URL localURL = clazz.getResource(""); String path = URLDecoder.decode(localURL.getFile(), Charset.defaultCharset().name()); int i = path.indexOf("!"); if (i != -1) { int j = path.lastIndexOf(File.separatorChar, i); if (j != -1) { path = path.substring(0, j) + File.separator; } else {/*from ww w. j a va 2 s. c om*/ throw new AssertionFailedError( "Unable to determine location for '" + filename + "' at '" + path + "'"); } // class file is nested in jar, use jar path as base if (path.startsWith("file:")) { path = path.substring(5); } return new File(path + filename); } else { // remove all package segments from name String directory = clazz.getName().replaceAll("[^.]", ""); directory = directory.replaceAll(".", "../"); if (path.contains("/bin/")) { // account for bin/ when running from Eclipse workspace directory += "../"; } else if (path.contains("/target/classes/")) { // account for bin/ when running from Eclipse workspace directory += "../../"; } filename = path + (directory + filename).replaceAll("/", Matcher.quoteReplacement(File.separator)); return new File(filename).getCanonicalFile(); } }
From source file:org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.java
private static UserCredentials createCredentials(Properties properties, String prefix, String defaultUsername, String defaultPassword) { String username = properties.getProperty(prefix + "user"); String password = properties.getProperty(prefix + "pass"); if (username == null) { username = defaultUsername;/*ww w .j a v a2 s .com*/ } if (password == null) { password = defaultPassword; } if (username == null || password == null) { throw new AssertionFailedError("username or password not found for " + prefix + " in <plug-in dir>/credentials.properties, make sure file is valid"); } return new UserCredentials(username, password); }
From source file:org.exoplatform.social.addons.test.AbstractCoreTest.java
@Override /**// ww w.jav a 2s . c o m * Override to run the test and assert its state. * @throws Throwable if any exception is thrown */ protected void runTest() throws Throwable { String fName = getName(); assertNotNull("TestCase.fName cannot be null", fName); // Some VMs crash when calling getMethod(null,null); Method runMethod = null; try { // use getMethod to get all public inherited // methods. getDeclaredMethods returns all // methods of this class but excludes the // inherited ones. runMethod = getClass().getMethod(fName, (Class[]) null); } catch (NoSuchMethodException e) { fail("Method \"" + fName + "\" not found"); } if (!Modifier.isPublic(runMethod.getModifiers())) { fail("Method \"" + fName + "\" should be public"); } try { MaxQueryNumber queryNumber = runMethod.getAnnotation(MaxQueryNumber.class); if (queryNumber != null) { wantCount = true; maxQuery = queryNumber.value(); } runMethod.invoke(this); } catch (InvocationTargetException e) { e.fillInStackTrace(); throw e.getTargetException(); } catch (IllegalAccessException e) { e.fillInStackTrace(); throw e; } if (hasByteMan) { if (wantCount && count > maxQuery) { throw new AssertionFailedError( "" + count + " JDBC queries was executed but the maximum is : " + maxQuery); } } }
From source file:org.exoplatform.social.core.test.AbstractCoreTest.java
@Override /**//from w w w.j a va 2 s.co m * Override to run the test and assert its state. * @throws Throwable if any exception is thrown */ protected void runTest() throws Throwable { String fName = getName(); assertNotNull("TestCase.fName cannot be null", fName); // Some VMs crash when calling getMethod(null,null); Method runMethod = null; try { // use getMethod to get all public inherited // methods. getDeclaredMethods returns all // methods of this class but excludes the // inherited ones. runMethod = getClass().getMethod(fName, (Class[]) null); } catch (NoSuchMethodException e) { fail("Method \"" + fName + "\" not found"); } if (!Modifier.isPublic(runMethod.getModifiers())) { fail("Method \"" + fName + "\" should be public"); } try { MaxQueryNumber queryNumber = runMethod.getAnnotation(MaxQueryNumber.class); if (queryNumber != null) { wantCount = true; maxQuery = queryNumber.value(); } runMethod.invoke(this); } catch (InvocationTargetException e) { e.fillInStackTrace(); throw e.getTargetException(); } catch (IllegalAccessException e) { e.fillInStackTrace(); throw e; } if (wantCount && count > maxQuery) { throw new AssertionFailedError( "" + count + " JDBC queries was executed but the maximum is : " + maxQuery); } }
From source file:org.intermine.modelviewer.jaxb.ConfigParserTest.java
/** * Test whether the model read from <code>src/test/(no)schema/core.xml</code> * is correct./* w w w .j a v a2 s . co m*/ * * @param model The core Model. * * @param sourceFile The source file. */ private void coreCorrect(Model model, File sourceFile) { try { assertEquals("Model name wrong", "genomic", model.getName()); assertEquals("Package wrong", "org.intermine.model.bio", model.getPackage()); assertEquals("Wrong number of classes", 34, model.getClazz().size()); Map<String, Class> classMap = new HashMap<String, Class>(); for (Class c : model.getClazz()) { classMap.put(c.getName(), c); } Class relation = classMap.get("Relation"); assertNotNull("Class 'Relation' not found", relation); assertEquals("Relation extends wrong", "SymmetricalRelation", relation.getExtends()); assertTrue("Relation interface wrong", relation.isIsInterface()); assertEquals("Relation should have no attributes", 0, relation.getAttribute().size()); assertNotNull("Relation should have 2 references (list unset)", relation.getReference()); assertEquals("Relation should have 2 references", 2, relation.getReference().size()); ClassReference ref = relation.getReference().get(0); assertEquals("Reference name wrong", "subject", ref.getName()); assertEquals("Reference type wrong", "BioEntity", ref.getReferencedType()); assertEquals("Reference reverse wrong", "objects", ref.getReverseReference()); assertNotNull("Relation should have 2 collections (list unset)", relation.getCollection()); assertEquals("Relation should have 2 collections", 2, relation.getCollection().size()); ClassReference col = relation.getCollection().get(0); assertEquals("Collection name wrong", "evidence", col.getName()); assertEquals("Collection type wrong", "Evidence", col.getReferencedType()); assertEquals("Collection reverse wrong", "relations", col.getReverseReference()); Class comment = classMap.get("Comment"); assertNotNull("Class 'Comment' not found", comment); assertNull("Comment extends wrong", comment.getExtends()); assertTrue("Comment interface wrong", comment.isIsInterface()); assertEquals("Comment should have 2 attributes", 2, comment.getAttribute().size()); Attribute att = comment.getAttribute().get(0); assertEquals("Attribute name wrong", "text", att.getName()); assertEquals("Attribute type wrong", String.class.getName(), att.getType()); assertNotNull("Comment should have 1 reference (list unset)", comment.getReference()); assertEquals("Comment should have 1 reference", 1, comment.getReference().size()); ref = comment.getReference().get(0); assertEquals("Reference name wrong", "source", ref.getName()); assertEquals("Reference type wrong", "InfoSource", ref.getReferencedType()); assertNull("Reference reverse wrong", ref.getReverseReference()); assertEquals("Comment should have 0 collections", 0, comment.getCollection().size()); } catch (AssertionFailedError e) { AssertionFailedError addition = new AssertionFailedError( "Failure with file " + sourceFile.getAbsolutePath() + " :\n" + e.getMessage()); addition.initCause(e.getCause()); addition.setStackTrace(e.getStackTrace()); throw addition; } }