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:eu.stratosphere.pact.runtime.task.ReduceTaskExternalITCase.java

@Test
public void testSingleLevelMergeReduceTask() {
    final int keyCnt = 8192;
    final int valCnt = 8;

    setNumFileHandlesForSort(2);// ww  w.  ja  va  2 s .c  o m

    addInputComparator(this.comparator);
    setOutput(this.outList);
    getTaskConfig().setDriverStrategy(DriverStrategy.SORTED_GROUP_REDUCE);

    try {
        addInputSorted(new UniformRecordGenerator(keyCnt, valCnt, false), this.comparator.duplicate());

        GroupReduceDriver<Record, Record> testTask = new GroupReduceDriver<Record, Record>();

        testDriver(testTask, MockReduceStub.class);
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Exception in Test.");
    }

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

    for (Record record : this.outList) {
        Assert.assertTrue("Incorrect result", record.getField(1, IntValue.class).getValue() == valCnt
                - record.getField(0, IntValue.class).getValue());
    }

    this.outList.clear();

}

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

@Test
public void testSingleLevelMergeCombineTask() {

    int keyCnt = 8192;
    int valCnt = 8;

    super.initEnvironment(3 * 1024 * 1024);
    super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 1);
    super.addOutput(this.outList);

    CombineTask<PactRecord> testTask = new CombineTask<PactRecord>();
    super.getTaskConfig().setLocalStrategy(LocalStrategy.COMBININGSORT);
    super.getTaskConfig().setMemorySize(3 * 1024 * 1024);
    super.getTaskConfig().setNumFilehandles(2);

    final int[] keyPos = 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), keyPos, keyClasses);

    super.registerTask(testTask, MockCombiningReduceStub.class);

    try {//from  w  w w .  java 2  s .  c  om
        testTask.invoke();
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Invoke method caused exception.");
    }

    int expSum = 0;
    for (int i = 1; i < valCnt; i++) {
        expSum += i;
    }

    // wee need to do the final aggregation manually in the test, because the
    // combiner is not guaranteed to do that
    HashMap<PactInteger, PactInteger> aggMap = new HashMap<PactInteger, PactInteger>();
    for (PactRecord record : this.outList) {
        PactInteger key = new PactInteger();
        PactInteger value = new PactInteger();
        key = record.getField(0, key);
        value = record.getField(1, value);
        PactInteger prevVal = aggMap.get(key);
        if (prevVal != null) {
            aggMap.put(key, new PactInteger(prevVal.getValue() + value.getValue()));
        } else {
            aggMap.put(key, value);
        }
    }

    Assert.assertTrue("Resultset size was " + aggMap.size() + ". Expected was " + keyCnt,
            aggMap.size() == keyCnt);

    for (PactInteger integer : aggMap.values()) {
        Assert.assertTrue("Incorrect result", integer.getValue() == expSum);
    }

    this.outList.clear();

}

From source file:org.slc.sli.dashboard.unit.controller.LayoutControllerTest.java

@SuppressWarnings("unchecked")
@Test/* w ww  . j a v a2 s . co  m*/
public void testHandleWithId() throws Exception {
    try {
        ModelAndView mv = layoutController.handleWithId("simpleLayout", null, request);
        ModelAndView mv1 = layoutController.handle("simpleLayout", null, request);
        Map<String, Config> c = (Map<String, Config>) mv.getModel().get(Constants.MM_KEY_VIEW_CONFIGS);
        Map<String, Config> c1 = (Map<String, Config>) mv1.getModel().get(Constants.MM_KEY_VIEW_CONFIGS);
        Assert.assertEquals(2, c.size());
        Assert.assertEquals(2, c1.size());
        for (Map.Entry<String, Config> conf : c.entrySet()) {
            Assert.assertEquals(conf.getValue().getName(), c1.get(conf.getKey()).getName());
        }
    } catch (Exception e) {
        Assert.fail("Should pass but getting " + e.getMessage());
    }
}

From source file:com.redhat.demo.CrmTest.java

/**
 * HTTP GET http://localhost:8181/cxf/crm/customerservice/customers/123
 * returns the XML document representing customer 123
 * <p/>//  w w w .  jav  a  2  s.  c o  m
 * On the server side, it matches the CustomerService's getCustomer() method
 *
 * @throws Exception
 */
@Test
public void getCustomerTest() throws Exception {
    LOG.info("Sent HTTP GET request to query customer info");
    url = new URL(CUSTOMER_TEST_URL);
    InputStream in = null;
    try {
        in = url.openStream();
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_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("123"));
}

From source file:example.crm.CrmIT.java

/**
 * HTTP GET http://localhost:9003/customers/123 returns the JSON document representing customer 123
 * <p/>/*from   w ww.j  av a  2 s  .  c  o  m*/
 * On the server side, it matches the CustomerService's getCustomer() method
 *
 */
@Test
public void getCustomerTest() throws Exception {
    LOG.info("Sent HTTP GET request to query customer info");
    url = new URL(CUSTOMER_TEST_URL);
    InputStream in = null;
    try {
        in = url.openStream();
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_TEST_URL);
        LOG.error(
                "You should build the 'camel-netty4-http' quick start and deploy it to a local Fabric8 before running this test");
        LOG.error("Please read the README.md file in 'camel-netty4-http' quick start root");
        Assert.fail("Connection error");
    }
    String res = getStringFromInputStream(in);
    LOG.info(res);
    Assert.assertTrue(res.contains("123"));
}

From source file:cz.PA165.vozovyPark.dao.ServiceIntervalDAOTest.java

/**
 *
 *//*from ww w  . j  a  va2s  .co  m*/
@Test
public void testCreateWithNullArgument() {
    try {
        serviceIntervalDAO.createSI(null);
        Assert.fail("Exception for null argument was not throwed!");
    } catch (IllegalArgumentException ex) {
    } catch (Exception ex) {
        Assert.fail("Unknown exception type was throwed: " + ex + " " + ex.getMessage());
    }
}

From source file:BQJDBC.QueryResultTest.Timeouttest.java

/**
 * Makes a new Bigquery Connection to Hardcoded URL and gives back the
 * Connection to static con member.//from  w ww  .  j  av  a2  s.  c  om
 */
@Before
public void NewConnection() {

    try {
        if (Timeouttest.con == null || !Timeouttest.con.isValid(0)) {
            this.logger.info("Testing the JDBC driver");
            try {

                Class.forName("net.starschema.clouddb.jdbc.BQDriver");
                Timeouttest.con = DriverManager.getConnection(
                        BQSupportFuncts.constructUrlFromPropertiesFile(
                                BQSupportFuncts.readFromPropFile("serviceaccount.properties")),
                        BQSupportFuncts.readFromPropFile("serviceaccount.properties"));
            } catch (Exception e) {
                this.logger.error("Error in connection" + e.toString());
                Assert.fail("General Exception:" + e.toString());
            }
            this.logger.info(((BQConnection) Timeouttest.con).getURLPART());
        }
    } catch (SQLException e1) {
        e1.printStackTrace();
    }
    try {
        this.logger.info("thread will sleep for 1 minute");
        Thread.sleep(1000 * 1); // 1000milisec = 1 sec * 60 = 1 minute

    } catch (InterruptedException e) {
        e.printStackTrace();
    }

}

From source file:io.fabric8.quickstarts.cxfcdi.CrmTest.java

/**
 * HTTP GET http://localhost:8181/cxf/crm/customerservice/customers/123
 * returns the XML document representing customer 123
 * <p/>/*w  w  w .  j  a v  a2  s  .c om*/
 * On the server side, it matches the CustomerService's getCustomer() method
 *
 * @throws Exception
 */
@Test
public void getCustomerTest() throws Exception {
    LOG.info("Sent HTTP GET request to query customer info");
    url = new URL(CUSTOMER_TEST_URL);
    InputStream in = null;
    try {
        in = url.openStream();
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_TEST_URL);
        LOG.error(
                "You should build the 'cxf-cdi' quick start and deploy it to a local Fabric8 before running this test");
        LOG.error("Please read the README.md file in 'cxf-cdi' quick start root");
        Assert.fail("Connection error");
    }
    String res = getStringFromInputStream(in);
    LOG.info(res);
    Assert.assertTrue(res.contains("123"));
}

From source file:com.acuityph.commons.jpa.ActiveJpaDaoTest.java

/**
 * Test {@link ActiveJpaDao#listAll()} throws Exception
 *///from www . ja va 2  s. c  om
@Test
public void testListAllThrowsException() {
    final String expectedMessage = "Unable to execute listAll(): neither listAllNamedQueryName or listAllQuery are properly set!";

    myEntityJpaDao.setListAllNamedQueryName(null);
    myEntityJpaDao.setListAllQuery(null);
    try {
        myEntityJpaDao.listAll();
        Assert.fail("Should have thrown JpaException(\"" + expectedMessage + "\")!");
    } catch (final JpaException e) {
        assertEquals(expectedMessage, e.getMessage());
    }
}

From source file:com.googlecode.ehcache.annotations.integration.ConfigurationFailureTest.java

/**
 * Test verifies behavior when the "default-cache-key-generator" attribute
 * on the main config element refers to a bean name that does not exist. 
 *///  w ww.  j a  v  a 2  s  .  c  o  m
@Test
public void testMissingOverrideDefaultCacheKeyGenerator() {
    try {
        new ClassPathXmlApplicationContext("/noOverrideDefaultCacheKeyGeneratorTestContext.xml");
        Assert.fail("Test should have failed with due to missing bean for default-cache-key-generator");
    } catch (BeanCreationException bce) {
        Throwable cause = bce;
        while (cause.getCause() != null) {
            cause = cause.getCause();
        }

        final StringWriter stack = new StringWriter();
        cause.printStackTrace(new PrintWriter(stack));
        Assert.assertTrue(
                "Root cause must be NoSuchBeanDefinitionException but was: " + cause + "\n " + stack.toString(),
                cause instanceof NoSuchBeanDefinitionException);
    }
}