下面列出了io.netty.channel.ChannelMetadata#junit.framework.AssertionFailedError 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void lookupBooleanEntry() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
final Boolean expected = Boolean.TRUE;
final Boolean actual = (Boolean) ctx.lookup("java:comp/env/stateful/references/Boolean");
Assert.assertNotNull("The Boolean looked up is null", actual);
Assert.assertEquals(expected, actual);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
public static Window waitForWindow(Class<?> windowClass) {
if ((!Dialog.class.isAssignableFrom(windowClass)) &&
(!Frame.class.isAssignableFrom(windowClass))) {
throw new IllegalArgumentException(
windowClass.getName() + " does not extend Dialog or Frame.");
}
int timeout = DEFAULT_WAIT_TIMEOUT;
int totalTime = 0;
while (totalTime <= timeout) {
Set<Window> winList = getAllWindows();
Iterator<Window> it = winList.iterator();
while (it.hasNext()) {
Window w = it.next();
if (windowClass.isAssignableFrom(w.getClass()) && w.isVisible()) {
return w;
}
}
totalTime += sleep(DEFAULT_WAIT_DELAY);
}
throw new AssertionFailedError("Timed-out waiting for window of class: " + windowClass);
}
public void lookupPersistenceContext() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
Assert.assertNotNull("The EntityManager is null", em);
// call a do nothing method to assure entity manager actually exists
em.getFlushMode();
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
@Override
public void lookupBooleanEntry() throws TestFailureException {
try {
try {
final Boolean expected = true;
final Boolean actual = (Boolean) mdbContext.lookup("stateless/references/Boolean");
Assert.assertNotNull("The Boolean looked up is null", actual);
Assert.assertEquals(expected, actual);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
public void lookupBooleanEntry() throws TestFailureException {
try {
try {
final Boolean expected = true;
final Boolean actual = (Boolean) getMessageDrivenContext().lookup("stateless/references/Boolean");
Assert.assertNotNull("The Boolean looked up is null", actual);
Assert.assertEquals(expected, actual);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
private static void waitForCondition(BooleanSupplier condition, boolean failOnTimeout,
Supplier<String> failureMessageSupplier) throws AssertionFailedError {
int totalTime = 0;
while (totalTime <= DEFAULT_WAIT_TIMEOUT) {
if (condition.getAsBoolean()) {
return; // success
}
totalTime += sleep(DEFAULT_WAIT_DELAY);
}
if (!failOnTimeout) {
return;
}
String failureMessage = "Timed-out waiting for condition";
if (failureMessageSupplier != null) {
failureMessage = failureMessageSupplier.get();
}
throw new AssertionFailedError(failureMessage);
}
/**
* Fails iff values does not contain a number within epsilon of z.
*
* @param msg message to return with failure
* @param values complex array to search
* @param z value sought
* @param epsilon tolerance
*/
public static void assertContains(String msg, Complex[] values,
Complex z, double epsilon) {
int i = 0;
boolean found = false;
while (!found && i < values.length) {
try {
assertEquals(values[i], z, epsilon);
found = true;
} catch (AssertionFailedError er) {
// no match
}
i++;
}
if (!found) {
Assert.fail(msg +
" Unable to find " + ComplexFormat.formatComplex(z));
}
}
protected void closeAndReopenProject() {
executeOnSwingWithoutBlocking(() -> {
try {
// we want to trigger the saving of tools to the toolchest for our tests
// just closing the project doesn't save anything.
testEnv.getProject().saveSessionTools();
testEnv.getProject().save();
testEnv.closeAndReopenProject();
}
catch (IOException e) {
AssertionFailedError afe = new AssertionFailedError();
afe.initCause(e);
throw afe;
}
});
waitForPostedSwingRunnables();
}
public void assertThrows(Class<? extends Throwable> expectedExceptionClass,
Runnable... throwingActions) {
for (Runnable throwingAction : throwingActions) {
boolean threw = false;
try { throwingAction.run(); }
catch (Throwable t) {
threw = true;
if (!expectedExceptionClass.isInstance(t)) {
AssertionFailedError afe =
new AssertionFailedError
("Expected " + expectedExceptionClass.getName() +
", got " + t.getClass().getName());
afe.initCause(t);
threadUnexpectedException(afe);
}
}
if (!threw)
shouldThrow(expectedExceptionClass.getName());
}
}
@Override
public void lookupShortEntry() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
final Short expected = (short) 1;
final Short actual = (Short) ctx.lookup("java:comp/env/stateless/references/Short");
Assert.assertNotNull("The Short looked up is null", actual);
Assert.assertEquals(expected, actual);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
public void lookupStringEntry() throws TestFailureException {
try {
try {
final String expected = new String("1");
final String actual = (String) ejbContext.lookup("singleton/references/String");
Assert.assertNotNull("The String looked up is null", actual);
Assert.assertEquals(expected, actual);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
@Override
public void lookupDoubleEntry() throws TestFailureException {
try {
try {
final Double expected = 1.0D;
final Double actual = (Double) mdbContext.lookup("stateless/references/Double");
Assert.assertNotNull("The Double looked up is null", actual);
Assert.assertEquals(expected, actual);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
@Override
public void lookupPersistenceContext() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
Assert.assertNotNull("The EntityManager is null", em);
// call a do nothing method to assure entity manager actually exists
em.getFlushMode();
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
/**
* Extra checks that get done for all test cases.
*
* Triggers test case failure if any thread assertions have failed,
* by rethrowing, in the test harness thread, any exception recorded
* earlier by threadRecordFailure.
*
* Triggers test case failure if interrupt status is set in the main thread.
*/
public void tearDown() throws Exception {
Throwable t = threadFailure.getAndSet(null);
if (t != null) {
if (t instanceof Error)
throw (Error) t;
else if (t instanceof RuntimeException)
throw (RuntimeException) t;
else if (t instanceof Exception)
throw (Exception) t;
else {
AssertionFailedError afe =
new AssertionFailedError(t.toString());
afe.initCause(t);
throw afe;
}
}
if (Thread.interrupted())
tearDownFail("interrupt status set in main thread");
checkForkJoinPoolThreadLeaks();
}
public void lookupBooleanEntry() throws TestFailureException {
try {
try {
final Boolean expected = Boolean.TRUE;
final Boolean actual = (Boolean) getSessionContext().lookup("singleton/references/Boolean");
Assert.assertNotNull("The Boolean looked up is null", actual);
Assert.assertEquals(expected, actual);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
@Override
public void lookupMessageDrivenContext() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
// lookup in enc
final MessageDrivenContext messageDrivenContext = (MessageDrivenContext) ctx.lookup("java:comp/env/mdbcontext");
Assert.assertNotNull("The SessionContext got from java:comp/env/mdbcontext is null", messageDrivenContext);
// lookup using global name
final EJBContext ejbCtx = (EJBContext) ctx.lookup("java:comp/EJBContext");
Assert.assertNotNull("The SessionContext got from java:comp/EJBContext is null ", ejbCtx);
// verify context was set via legacy set method
Assert.assertNotNull("The MdbContext is null from setter method", mdbContext);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
public void lookupFloatEntry() throws TestFailureException {
try {
try {
final Float expected = new Float(1.0F);
final Float actual = (Float) getSessionContext().lookup("singleton/references/Float");
Assert.assertNotNull("The Float looked up is null", actual);
Assert.assertEquals(expected, actual);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
public void lookupLongEntry() throws TestFailureException {
try {
try {
final Long expected = new Long(1L);
final Long actual = (Long) ejbContext.lookup("stateful/references/Long");
Assert.assertNotNull("The Long looked up is null", actual);
Assert.assertEquals(expected, actual);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
@Override
public void testDatesAndTimes() throws IOException, SQLException {
final int TOTAL_RECORDS = 10;
ColumnGenerator genDate = getDateColumnGenerator();
ColumnGenerator genTime = getTimeColumnGenerator();
try {
createTextFile(0, TOTAL_RECORDS, false, genDate, genTime);
createTable(genDate, genTime);
runExport(getArgv(true, 10, 10));
verifyExport(TOTAL_RECORDS);
assertColMinAndMax(forIdx(0), genDate);
assertColMinAndMax(forIdx(1), genTime);
} catch (AssertionFailedError afe) {
genDate = getNewDateColGenerator();
genTime = getNewTimeColGenerator();
createTextFile(0, TOTAL_RECORDS, false, genDate, genTime);
createTable(genDate, genTime);
runExport(getArgv(true, 10, 10));
verifyExport(TOTAL_RECORDS);
assertColMinAndMax(forIdx(0), genDate);
assertColMinAndMax(forIdx(1), genTime);
}
}
@Test
public void test_listGeneratedArtifacts_including_generated_artifacts() throws Exception {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/maven-spy-deploy-jar.xml");
in.getClass(); // check non null
Element mavenSpyLogs = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in).getDocumentElement();
List<MavenArtifact> generatedArtifacts = XmlUtils.listGeneratedArtifacts(mavenSpyLogs, true);
System.out.println(generatedArtifacts);
Assert.assertThat(generatedArtifacts.size(), Matchers.is(3)); // a jar file and a pom file are generated
for (MavenArtifact mavenArtifact:generatedArtifacts) {
Assert.assertThat(mavenArtifact.getGroupId(), Matchers.is("com.example"));
Assert.assertThat(mavenArtifact.getArtifactId(), Matchers.is("my-jar"));
if("pom".equals(mavenArtifact.getType())) {
Assert.assertThat(mavenArtifact.getExtension(), Matchers.is("pom"));
Assert.assertThat(mavenArtifact.getClassifier(), Matchers.isEmptyOrNullString());
} else if ("jar".equals(mavenArtifact.getType())) {
Assert.assertThat(mavenArtifact.getExtension(), Matchers.is("jar"));
Assert.assertThat(mavenArtifact.getClassifier(), Matchers.isEmptyOrNullString());
} else if ("java-source".equals(mavenArtifact.getType())) {
Assert.assertThat(mavenArtifact.getExtension(), Matchers.is("jar"));
Assert.assertThat(mavenArtifact.getClassifier(), Matchers.is("sources"));
} else {
throw new AssertionFailedError("Unsupported type for " + mavenArtifact);
}
}
}
@Override
public void lookupCharacterEntry() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
final Character expected = 'D';
final Character actual = (Character) ctx.lookup("java:comp/env/stateless/references/Character");
Assert.assertNotNull("The Character looked up is null", actual);
Assert.assertEquals(expected, actual);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
public void lookupFloatEntry() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
final Float expected = new Float(1.0F);
final Float actual = (Float) ctx.lookup("java:comp/env/entity/cmp/references/Float");
Assert.assertNotNull("The Float looked up is null", actual);
Assert.assertEquals(expected, actual);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
public void lookupByteEntry() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
final Byte expected = new Byte((byte) 1);
final Byte actual = (Byte) ctx.lookup("java:comp/env/entity/cmp/references/Byte");
Assert.assertNotNull("The Byte looked up is null", actual);
Assert.assertEquals(expected, actual);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
void doTest(TestData t) throws OperationException {
DocOpBuffer d = new DocOpBuffer();
DocOpBuffer m = new DocOpBuffer();
boolean expected = t.build(d, m);
BootstrapDocument doc = new BootstrapDocument();
// initialize document
doc.consume(d.finishUnchecked());
// check whether m would apply
ViolationCollector v = new ViolationCollector();
ValidationResult result =
DocOpValidator.validate(v, t.getSchemaConstraints(), doc, m.finishUnchecked());
try {
assertEquals(expected, v.isValid());
assertEquals(result, v.getValidationResult());
} catch (AssertionFailedError e) {
System.err.println("test data:");
System.err.println(DocOpUtil.toConciseString(d.finish()));
System.err.println(DocOpUtil.toConciseString(m.finish()));
System.err.println("violations:");
v.printDescriptions(System.err);
throw e;
}
}
public void testAssertNull() {
assertNull(null);
try {
assertNull(new Object());
} catch (AssertionFailedError e) {
return;
}
fail();
}
public void lookupPersistenceUnit() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
final EntityManagerFactory emf = (EntityManagerFactory) ctx.lookup("java:comp/env/persistence/TestUnit");
Assert.assertNotNull("The EntityManagerFactory is null", emf);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
public void checkMethodLevelBusinessMethodInterception() throws TestFailureException {
try {
Assert.assertTrue("Method Level Business Method Interception failed for Mdb", methodLevelBusinessMethodInterception);
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
@Test
public void testDeleted() throws InterruptedException {
logger.info("testDeleted");
KubernetesClient client = server.getClient().inNamespace("test");
server.expect()
.withPath(path)
.andReturn(200, "Failed WebSocket Connection").once();
server.expect().withPath(path).andReturnChunked(200,
new WatchEvent(pod1, "DELETED"), "\n",
new WatchEvent(pod1, "ADDED"), "\n").once();
final CountDownLatch addLatch = new CountDownLatch(1);
final CountDownLatch deleteLatch = new CountDownLatch(1);
try (Watch watch = client.pods().withName("pod1").withResourceVersion("1").watch(new Watcher<Pod>() {
@Override
public void eventReceived(Action action, Pod resource) {
switch (action) {
case DELETED:
deleteLatch.countDown();
break;
case ADDED:
addLatch.countDown();
break;
default:
throw new AssertionFailedError();
}
}
@Override
public void onClose(KubernetesClientException cause) {}
})) /* autoclose */ {
assertTrue(addLatch.await(10, TimeUnit.SECONDS));
assertTrue(deleteLatch.await(10, TimeUnit.SECONDS));
}
}
public void lookupStatelessBusinessLocal() throws TestFailureException {
try {
Assert.assertNotNull("The EJB BusinessLocal is null", statelessBusinessLocal);
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
public void lookupIntegerEntry() throws TestFailureException {
try {
final Integer expected = new Integer(1);
Assert.assertNotNull("The Integer looked up is null", inteegerField);
Assert.assertEquals(expected, inteegerField);
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}