Example usage for junit.framework Assert fail

List of usage examples for junit.framework Assert fail

Introduction

In this page you can find the example usage for junit.framework Assert fail.

Prototype

static public void fail(String message) 

Source Link

Document

Fails a test with the given message.

Usage

From source file:org.dasein.cloud.azurepack.tests.HttpMethodAsserts.java

private static void assertHttpMethod(HttpUriRequest actualHttpRequest, String expectedHttpMethod,
        String expectedUrl, Header[] expectedHeaders, Object expectedEntity) {
    assertHttpMethod(actualHttpRequest, expectedHttpMethod, expectedUrl, expectedHeaders);
    assertTrue("Incorrect httpRequest found in the call",
            actualHttpRequest instanceof HttpEntityEnclosingRequestBase);

    try {//from  w  ww . j a v  a  2 s.c o m
        Object actualEntity = new JsonStreamToObjectProcessor().read(
                ((HttpEntityEnclosingRequestBase) actualHttpRequest).getEntity().getContent(),
                expectedEntity.getClass());
        assertReflectionEquals("Incorrect value(s) found in the XML body of the request", expectedEntity,
                actualEntity);
    } catch (Exception e) {
        Assert.fail("Incorrect XML body found in the request");
    }
}

From source file:com.hoccer.tools.TestHelper.java

/**
 * Assert two {@linkplain File files} to have equal content.
 * //from w  w  w  .ja  v a  2s  .  c o m
 * @param message
 *            the error message
 * @param expected
 *            reference file
 * @param current
 *            file to compare
 * @author Apache Project (package org.apache.commons.id.test)
 * @license Apache Lichense 2.0
 */
public static void assertFileEquals(final String message, final File expected, final File current) {
    try {
        assertInputStreamEquals(new BufferedInputStream(new FileInputStream(expected)),
                new BufferedInputStream(new FileInputStream(current)));
    } catch (final FileNotFoundException e) {
        Assert.fail((message != null ? message + ": " : "") + e.getMessage());
    }
}

From source file:com.cubusmail.server.user.CreateAddressTestData.java

@Test
public void createTestData() {

    try {//from  w  w  w . ja v a2s. c om
        UserAccount account = this.userAccountDao.getUserAccountByUsername("schlierf");
        List<AddressFolder> folderList = this.userAccountDao.retrieveAddressFolders(account);
        AddressFolder addressFolder = folderList.get(0);
        for (int i = 0; i < alpha.length(); i++) {
            char begin = alpha.charAt(i);
            for (int j = 1; j < 2; j++) {
                Address address = this.applicationContext.getBean(Address.class);
                address.setFirstName(begin + "firstName" + j);
                address.setMiddleName(begin + "middleName" + j);
                address.setLastName(begin + "lastName" + j);
                address.setTitle(begin + "title" + j);
                address.setBirthDate(new Date());
                address.setCompany(begin + "company" + j);
                address.setPosition(begin + "position" + j);
                address.setDepartment(begin + "department" + j);

                address.setEmail(begin + "email" + j);
                if ((i % 2) == 0) {
                    address.setEmail2(begin + "email2" + j);
                    address.setEmail3(begin + "email3" + j);
                    address.setEmail4(begin + "email4" + j);
                    address.setEmail5(begin + "email5" + j);
                }
                address.setIm(begin + "im" + j);
                address.setUrl(begin + "url" + j);

                address.setPrivatePhone(begin + "privatePhone" + j);
                address.setWorkPhone(begin + "workPhone" + j);
                address.setPrivateMobile(begin + "privateMobile" + j);
                address.setWorkMobile(begin + "workMobile" + j);
                address.setPrivateFax(begin + "privateFax" + j);
                address.setWorkFax(begin + "workFax" + j);
                address.setPager(begin + "pager" + j);

                address.setPrivateStreet(begin + "privateStreet" + j);
                address.setPrivateZipcode(begin + "privateZipcode" + j);
                address.setPrivateCity(begin + "privateCity" + j);
                address.setPrivateState(begin + "privateState" + j);
                address.setPrivateCountry(begin + "privateCountry" + j);

                if ((i % 2) == 0) {
                    address.setWorkStreet(begin + "workStreet" + j);
                    address.setWorkZipcode(begin + "workZipcode" + j);
                    address.setWorkCity(begin + "workCity" + j);
                    address.setWorkState(begin + "workState" + j);
                    address.setWorkCountry(begin + "workCountry" + j);
                }
                address.setNotes(begin + "notes" + j);

                address.setAddressFolder(addressFolder);
                this.userAccountDao.saveAddress(address);
            }

        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        Assert.fail(e.getMessage());
    }
}

From source file:BQJDBC.QueryResultTest.BQForwardOnlyResultSetFunctionTest.java

/**
 * For testing isValid() , Close() , isClosed()
 *//*ww w. j av  a2 s.c om*/
@Test
public void isClosedValidtest() {
    try {
        Assert.assertEquals(true, BQForwardOnlyResultSetFunctionTest.con.isValid(0));
    } catch (SQLException e) {
        Assert.fail("Got an exception" + e.toString());
        e.printStackTrace();
    }
    try {
        Assert.assertEquals(true, BQForwardOnlyResultSetFunctionTest.con.isValid(10));
    } catch (SQLException e) {
        Assert.fail("Got an exception" + e.toString());
        e.printStackTrace();
    }
    try {
        BQForwardOnlyResultSetFunctionTest.con.isValid(-10);
    } catch (SQLException e) {
        Assert.assertTrue(true);
        // e.printStackTrace();
    }

    try {
        BQForwardOnlyResultSetFunctionTest.con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    try {
        Assert.assertTrue(BQForwardOnlyResultSetFunctionTest.con.isClosed());
    } catch (SQLException e1) {
        e1.printStackTrace();
    }

    try {
        BQForwardOnlyResultSetFunctionTest.con.isValid(0);
    } catch (SQLException e) {
        Assert.assertTrue(true);
        e.printStackTrace();
    }

}

From source file:com.novoda.imageloader.core.file.util.FileUtilTest.java

private File createFile(String name, long lastModified) {
    try {/*from  www  . j  a  v a2s  .  c  om*/
        File f1 = new File(cacheDir, name + ".tmp");
        FileUtils.write(f1, name);
        if (lastModified != -1) {
            f1.setLastModified(lastModified);
        }
        return f1;
    } catch (Exception e) {
        Assert.fail("Can't crete file for the test" + e.getMessage());
        throw new RuntimeException("Can't crete file for the test " + e.getMessage());
    }
}

From source file:net.sf.dynamicreports.test.jasper.chart.GroupedStackedBarChartData3Test.java

private void testMap(JFreeChart chart, String... groups) {
    GroupedStackedBarRenderer renderer = (GroupedStackedBarRenderer) chart.getCategoryPlot().getRenderer();
    try {/*from  w  w  w .j a  v a 2s . com*/
        Field field = renderer.getClass().getDeclaredField("seriesToGroupMap");
        field.setAccessible(true);
        KeyToGroupMap map = (KeyToGroupMap) field.get(renderer);
        Assert.assertEquals("map", groups.length, map.getGroupCount());
        List<?> groups2 = map.getGroups();
        for (int i = 0; i < groups2.size(); i++) {
            Assert.assertEquals("map", groups[i], groups2.get(i));
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}

From source file:eu.stratosphere.pact.runtime.task.MatchTaskExternalITCase.java

@Test
public void testExternalHash1MatchTask() {

    int keyCnt1 = 32768;
    int valCnt1 = 8;

    int keyCnt2 = 65536;
    int valCnt2 = 8;

    int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
    this.outList.ensureCapacity(expCnt);

    super.initEnvironment(4 * 1024 * 1024);
    super.addInput(new UniformPactRecordGenerator(keyCnt1, valCnt1, false), 1);
    super.addInput(new UniformPactRecordGenerator(keyCnt2, valCnt2, false), 2);
    super.addOutput(outList);

    final MatchTask<PactRecord, PactRecord, PactRecord> testTask = new MatchTask<PactRecord, PactRecord, PactRecord>();
    super.getTaskConfig().setMemorySize(4 * 1024 * 1024);
    super.getTaskConfig().setLocalStrategy(LocalStrategy.HYBRIDHASH_FIRST);

    final int[] keyPos1 = new int[] { 0 };
    final int[] keyPos2 = new int[] { 0 };
    @SuppressWarnings("unchecked")
    final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class };

    PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(),
            super.getTaskConfig().getPrefixForInputParameters(0), keyPos1, keyClasses);
    PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(),
            super.getTaskConfig().getPrefixForInputParameters(1), keyPos2, keyClasses);

    super.registerTask(testTask, MockMatchStub.class);

    try {/*from  w  ww  .  j  a  v a2 s . c o m*/
        testTask.invoke();
    } catch (Exception e) {
        LOG.debug(e);
        e.printStackTrace();
        Assert.fail("Invoke method caused exception.");
    }

    Assert.assertTrue("Resultset size was " + outList.size() + ". Expected was " + expCnt,
            outList.size() == expCnt);

    outList.clear();

}

From source file:io.fabric8.quickstarts.restdsl.spark.CrmIT.java

/**
 * HTTP GET http://localhost:8181/cxf/crm/customerservice/orders/223/products/323
 * returns the XML document representing product 323 in order 223
 * <p/>//from   ww w .ja va 2 s  . com
 * On the server side, it matches the Order's getProduct() method
 *
 * @throws Exception
 */
@Test
public void getProductOrderTest() throws Exception {

    LOG.info("Sent HTTP GET request to query sub resource product info");
    url = new URL(CUSTOMER_ORDERS_TEST_URL);
    try {
        in = url.openStream();
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_ORDERS_TEST_URL);
        LOG.error(
                "You should build the 'rest' quick start and deploy it to a local Fabric8 before running this test");
        LOG.error("Please read the README.md file in 'rest' quick start root");
        Assert.fail("Connection error");
    }

    String res = getStringFromInputStream(in);
    LOG.info(res);
    Assert.assertTrue(res.contains("product 323"));
}

From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java

/**
 * Check the invalid next period to start.
 *//*from  w ww  . ja  v  a  2  s.c  om*/
@Test
public void updateInvalidNextPeriodToStart() {
    DbeExpendControl control = new DbeExpendControl();
    DbeExpendLimitPK id = new DbeExpendLimitPK();
    id.setTxElType("InvalidPeriod");
    control.setId(id);
    Date currentDate = new Date();
    control.setDtNextPeriodStart(currentDate);
    try {
        utils.updateNextPeriodToStart(control);
        Assert.fail("Ok with invalid period");
    } catch (RSSException e) {
        Assert.assertEquals("Exeption type", e.getExceptionType(), UNICAExceptionType.INVALID_PARAMETER);
        Assert.assertTrue(e.getMessage().contains("Period"));
    }
}

From source file:es.upm.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java

/**
 * Check the invalid next period to start.
 *//*from  w  w w.  ja  v a  2s .  com*/
public void updateInvalidNextPeriodToStart() {
    DbeExpendControl control = new DbeExpendControl();
    DbeExpendLimitPK id = new DbeExpendLimitPK();
    id.setTxElType("InvalidPeriod");
    control.setId(id);
    Date currentDate = new Date();
    control.setDtNextPeriodStart(currentDate);
    try {
        utils.updateNextPeriodToStart(control);
        Assert.fail("Ok with invalid period");
    } catch (RSSException e) {
        Assert.assertEquals("Exeption type", e.getExceptionType(), UNICAExceptionType.INVALID_PARAMETER);
        Assert.assertTrue(e.getMessage().contains("Period"));
    }
}