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:baggage.BaseTestCase.java

protected static void assertFailure(Class<? extends Exception> klass, Fallible fallible) {
    try {//from w w  w  .ja  v a 2 s. c  o m
        fallible.execute();
    } catch (Exception e) {
        if (!klass.isAssignableFrom(e.getClass())) {
            throw new RuntimeException(
                    "Expected a " + klass.getSimpleName() + ", got a " + e.getClass().getSimpleName(), e);
        }
        return;
    }
    Assert.fail("Expected a " + klass.getSimpleName() + ", got no exceptions at all");
}

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

@SuppressWarnings("unchecked")
@Test/*  w  w w. j  ava 2  s . c o  m*/
public void testHandle() throws Exception {
    try {
        ModelAndView mv = layoutController.handle("simpleLayout", null, request);
        Assert.assertEquals(2, ((Map<String, Config>) mv.getModel().get(Constants.MM_KEY_VIEW_CONFIGS)).size());
        Assert.assertEquals(1, ((Map<String, GenericEntity>) mv.getModel().get(Constants.MM_KEY_DATA)).size());
        Assert.assertEquals(1, ((Collection<Config>) mv.getModel().get(Constants.MM_KEY_LAYOUT)).size());
    } catch (Exception e) {
        Assert.fail("Should pass but getting " + e.getMessage());
    }
}

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

@Test
public void testTempTask() {
    int keyCnt = 1024;
    int valCnt = 4;

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

    TempTask<PactRecord> testTask = new TempTask<PactRecord>();
    super.getTaskConfig().setMemorySize(1 * 1024 * 1024);

    super.registerTask(testTask, PrevStub.class);

    try {//from www.  j  a  va2 s. c om
        testTask.invoke();
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Invoke method caused exception.");
    }

    Assert.assertTrue(this.outList.size() == keyCnt * valCnt);

}

From source file:com.ngdata.hbaseindexer.conf.XmlIndexerConfWriterTest.java

@Test
public void testWrite() throws Exception {
    Map<String, String> params = Maps.newHashMap();
    params.put("thename", "thevalue");
    IndexerConf conf = new IndexerConfBuilder().table("the-table").mappingType(IndexerConf.MappingType.COLUMN)
            .rowReadMode(IndexerConf.RowReadMode.DYNAMIC).uniqueyKeyField("keyfield").rowField("rf")
            .columnFamilyField("cf-field").tableNameField("tn-field").globalParams(params)
            .mapperClass(DefaultResultToSolrMapper.class)
            .uniqueKeyFormatterClass(StringUniqueKeyFormatter.class)
            .addFieldDefinition("fieldname", "fieldvalue", FieldDefinition.ValueSource.VALUE, "fieldtype",
                    params)//from   w w w .  j av  a2  s.  co  m
            .addDocumentExtractDefinition("theprefix", "valueexpr", FieldDefinition.ValueSource.VALUE,
                    "deftype", params)
            .build();

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    XmlIndexerConfWriter.writeConf(conf, os);

    String xmlString = os.toString();

    IndexerConf conf2 = null;
    try {
        IndexerComponentFactory factory = IndexerComponentFactoryUtil.getComponentFactory(
                DefaultIndexerComponentFactory.class.getName(), IOUtils.toInputStream(xmlString),
                Maps.<String, String>newHashMap());
        conf2 = factory.createIndexerConf();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Xml is not valid");
    }

    Assert.assertEquals(conf.getTable(), conf2.getTable());
    Assert.assertEquals(conf.getMappingType(), conf2.getMappingType());
    Assert.assertEquals(conf.getRowReadMode(), conf2.getRowReadMode());
    Assert.assertEquals(conf.getUniqueKeyField(), conf2.getUniqueKeyField());
    Assert.assertEquals(conf.getRowField(), conf2.getRowField());
    Assert.assertEquals(conf.getColumnFamilyField(), conf2.getColumnFamilyField());
    Assert.assertEquals(conf.getTableNameField(), conf2.getTableNameField());
    Assert.assertEquals(conf.getGlobalParams(), conf2.getGlobalParams());
    Assert.assertEquals(conf.getMapperClass(), conf2.getMapperClass());
    Assert.assertEquals(conf.getUniqueKeyFormatterClass(), conf2.getUniqueKeyFormatterClass());
    Assert.assertEquals(conf.getFieldDefinitions().size(), conf2.getFieldDefinitions().size());
    Assert.assertEquals(conf.getDocumentExtractDefinitions().size(),
            conf2.getDocumentExtractDefinitions().size());
}

From source file:de.hybris.vjdbc.VirtualDriverTest.java

@Test
public void testConnectWithAcceptedIncorrectUrl() throws Exception {
    try {/*from  w  w w  .  j  av a 2s.co m*/
        driver.connect("jdbc:hybris:foobar//baz", null);
        Assert.fail("should have failed");
    } catch (SQLException e) {
        assertFirstLineOfSQLException("java.sql.SQLException: Unknown protocol identifier foobar//baz", e);
    }

    Mockito.verify(virtualConnectionBuilder).setProperties(null);
    Mockito.verify(virtualConnectionBuilder, Mockito.times(0)).setDataSourceString(Mockito.anyString());
    Mockito.verify(virtualConnectionBuilder, Mockito.times(0)).setUrl("");
}

From source file:com.mnxfst.testing.server.cfg.TestPTestServerConfigurationParser.java

@Test
public void testEvaluateStringWithValidExprAndNullDocument() {
    try {//from  ww  w .  j a v a  2  s .  com
        PTestServerConfigurationParser p = new PTestServerConfigurationParser();
        p.evaluateString(p.xpathExpressionHostname, null);
        Assert.fail("Valid expression, invalid document");
    } catch (XPathExpressionException e) {
        //
    }
}

From source file:com.impetus.kundera.EntityManagerImplTest.java

/**
 * On test persist.//from   w  w w .j  a  va 2s  .co m
 * 
 */
@Test
public void testPersist() {
    try {
        for (int i = 1; i <= 1000000; i++) {
            final SampleEntity entity = new SampleEntity();
            entity.setKey(i);
            entity.setName("name" + i);
            if (i % 5000 == 0) {
                em.clear();
            }

            em.persist(entity);

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

From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java

@Test
public void ChainedCursorFunctionTest() {
    this.logger.info("ChainedFunctionTest");
    try {/* www  .j  a va  2  s . c  om*/
        BQResultSetFunctionTest.Result.beforeFirst();
        Assert.assertTrue(BQResultSetFunctionTest.Result.next());
        Assert.assertEquals("you", BQResultSetFunctionTest.Result.getString(1));

    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    try {
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(10));
        Assert.assertEquals("word", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertFalse(BQResultSetFunctionTest.Result.next());
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertEquals("", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        boolean ct = e.toString().contains("Cursor is not in a valid Position");
        if (ct == true) {
            Assert.assertTrue(ct);
        } else {
            this.logger.error("SQLexception" + e.toString());
            Assert.fail("SQLException" + e.toString());
        }

    }

    try {
        Assert.assertTrue(BQResultSetFunctionTest.Result.first());
        Assert.assertEquals("you", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertTrue(BQResultSetFunctionTest.Result.isFirst());
        Assert.assertFalse(BQResultSetFunctionTest.Result.previous());
        BQResultSetFunctionTest.Result.afterLast();
        Assert.assertTrue(BQResultSetFunctionTest.Result.isAfterLast());
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(-1));
        Assert.assertEquals("word", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertTrue(BQResultSetFunctionTest.Result.relative(-5));
        Assert.assertEquals("without", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertFalse(BQResultSetFunctionTest.Result.relative(6));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertEquals("without", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        boolean ct = e.toString().contains("Cursor is not in a valid Position");
        if (ct == true) {
            Assert.assertTrue(ct);
        } else {
            this.logger.error("SQLexception" + e.toString());
            Assert.fail("SQLException" + e.toString());
        }
    }
    this.logger.info("chainedfunctiontest end");
}

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

@Test
public void testExternalBlockCrossTask() {

    int keyCnt1 = 2;
    int valCnt1 = 1;

    // 43690 fit into memory, 43691 do not!
    int keyCnt2 = 43700;
    int valCnt2 = 1;

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

    CrossTask<PactRecord, PactRecord, PactRecord> testTask = new CrossTask<PactRecord, PactRecord, PactRecord>();
    super.getTaskConfig().setLocalStrategy(LocalStrategy.NESTEDLOOP_BLOCKED_OUTER_FIRST);
    super.getTaskConfig().setMemorySize(1 * 1024 * 1024);

    super.registerTask(testTask, MockCrossStub.class);

    try {//from www.j  a  v  a 2 s .co m
        testTask.invoke();
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Invoke method caused exception.");
    }

    int expCnt = keyCnt1 * valCnt1 * keyCnt2 * valCnt2;

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

    this.outList.clear();

}

From source file:BQJDBC.QueryResultTest.BQScrollableResultSetFunctionTest.java

@Test
public void ChainedCursorFunctionTest() {
    this.logger.info("ChainedFunctionTest");
    try {//from w  w  w. j a  v  a 2 s  .c  o m
        BQScrollableResultSetFunctionTest.Result.beforeFirst();
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.next());
        Assert.assertEquals("you", BQScrollableResultSetFunctionTest.Result.getString(1));

    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    try {
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(10));
        Assert.assertEquals("word", BQScrollableResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertFalse(BQScrollableResultSetFunctionTest.Result.next());
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertEquals("", BQScrollableResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        boolean ct = e.toString().contains("Cursor is not in a valid Position");
        if (ct == true) {
            Assert.assertTrue(ct);
        } else {
            this.logger.error("SQLexception" + e.toString());
            Assert.fail("SQLException" + e.toString());
        }

    }

    try {
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.first());
        Assert.assertEquals("you", BQScrollableResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.isFirst());
        Assert.assertFalse(BQScrollableResultSetFunctionTest.Result.previous());
        BQScrollableResultSetFunctionTest.Result.afterLast();
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.isAfterLast());
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(-1));
        Assert.assertEquals("word", BQScrollableResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.relative(-5));
        Assert.assertEquals("without", BQScrollableResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertFalse(BQScrollableResultSetFunctionTest.Result.relative(6));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertEquals("without", BQScrollableResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        boolean ct = e.toString().contains("Cursor is not in a valid Position");
        if (ct == true) {
            Assert.assertTrue(ct);
        } else {
            this.logger.error("SQLexception" + e.toString());
            Assert.fail("SQLException" + e.toString());
        }
    }
    this.logger.info("chainedfunctiontest end");
}