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:net.padaf.preflight.TestIsartorValidationFromClasspath.java

@Test()
public void validate() throws Exception {
    ValidationResult result = null;//ww  w  .  j a v  a2 s  . co  m
    try {
        InputStream input = this.getClass().getResourceAsStream(path);
        ByteArrayDataSource bds = new ByteArrayDataSource(input);
        result = validator.validate(bds);
        Assert.assertFalse(path + " : Isartor file should be invalid (" + path + ")", result.isValid());
        Assert.assertTrue(path + " : Should find at least one error", result.getErrorsList().size() > 0);
        // could contain more than one error
        boolean found = false;
        for (ValidationError error : result.getErrorsList()) {
            if (error.getErrorCode().equals(this.expectedError)) {
                found = true;
            }
            if (isartorResultFile != null) {
                String log = path.replace(".pdf", "") + "#" + error.getErrorCode() + "#" + error.getDetails()
                        + "\n";
                isartorResultFile.write(log.getBytes());
            }
        }

        if (result.getErrorsList().size() > 1) {
            if (!found) {
                StringBuilder message = new StringBuilder(100);
                message.append(path).append(" : Invalid error code returned. Expected ");
                message.append(this.expectedError).append(", found ");
                for (ValidationError error : result.getErrorsList()) {
                    message.append(error.getErrorCode()).append(" ");
                }
                Assert.fail(message.toString());
            }
        } else {
            Assert.assertEquals(path + " : Invalid error code returned.", this.expectedError,
                    result.getErrorsList().get(0).getErrorCode());
        }
    } catch (ValidationException e) {
        throw new Exception(path + " :" + e.getMessage(), e);
    } finally {
        if (result != null) {
            result.closePdf();
        }
    }
}

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

@Test
public void testSortBoth1MatchTask() {

    int keyCnt1 = 20;
    int valCnt1 = 1;

    int keyCnt2 = 10;
    int valCnt2 = 2;

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

    MatchTask<PactRecord, PactRecord, PactRecord> testTask = new MatchTask<PactRecord, PactRecord, PactRecord>();
    super.getTaskConfig().setLocalStrategy(LocalStrategy.SORT_BOTH_MERGE);

    super.getTaskConfig().setMemorySize(6 * 1024 * 1024);
    super.getTaskConfig().setNumFilehandles(4);

    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 ww  w .j  av a2s .  co m
        testTask.invoke();
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Invoke method caused exception.");
    }

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

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

    this.outList.clear();

}

From source file:$.CrmTest.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   w ww  . jav a2 s. c  om*/
     * 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(PRODUCT_ORDER_TEST_URL);
        try {
            in = url.openStream();
        } catch (IOException e) {
            LOG.error("Error connecting to {}", PRODUCT_ORDER_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("product 323"));
    }

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest01() {
    final String sql = "SELECT TOP(word, 10), COUNT(*) FROM publicdata:samples.shakespeare";
    final String description = "The top 10 word from shakespeare #TOP #COUNT";
    String[][] expectation = new String[][] {
            { "you", "yet", "would", "world", "without", "with", "your", "young", "words", "word" },
            { "42", "42", "42", "42", "42", "42", "41", "41", "41", "41" } };
    /** somehow the result changed with time
    { "you", "yet", "would", "world", "without", "with", "will",
            "why", "whose", "whom" },//from  ww  w.  ja v  a 2  s.  c  o m
    { "42", "42", "42", "42", "42", "42", "42", "42", "42", "42" } };
    */

    this.logger.info("Test number: 01");
    this.logger.info("Running query:" + sql);

    java.sql.ResultSet Result = null;
    try {
        Result = QueryResultTest.con.createStatement().executeQuery(sql);
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    Assert.assertNotNull(Result);

    this.logger.debug(description);
    HelperFunctions.printer(expectation);
    try {
        Assert.assertTrue("Comparing failed in the String[][] array",
                this.comparer(expectation, BQSupportMethods.GetQueryResult(Result)));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail(e.toString());
    }
}

From source file:de.tu_berlin.dima.aim3.querysuggestion.QuerySuggTCase.java

/**
 * Test pipeline until given level with given input file
 * /*from   w  w  w .  j  a v a 2  s  .c o m*/
 * @param inputFile
 * @param processLevel
 * @throws Exception
 */
public void basicTest(String inputFile, String resultFile, String processLevel) throws Exception {

    this.inputFile = inputFile;
    this.resultfile = resultFile;
    // pre-submit
    preSubmit();

    // submit job
    JobGraph jobGraph = null;
    try {
        jobGraph = getJobGraph(processLevel);
    } catch (Exception e) {
        LOG.error(e);
        Assert.fail("Failed to obtain JobGraph!");
    }

    try {
        final JobClient client = cluster.getJobClient(jobGraph, getJarFilePath());
        client.submitJobAndWait();
        //      cluster. submitJobAndWait(jobGraph, getJarFilePath());
    } catch (Exception e) {
        LOG.error(e);
        Assert.fail("Job execution failed!");
    }

    // post-submit
    postSubmit();
}

From source file:com.comcast.cim.rest.client.xhtml.TestXhtmlNavigator.java

@Test
public void testThrowsRelationNotFoundExceptionIfLinkNotPresent() throws Exception {
    String rel = "relation";
    expect(mockParser.getLinkWithRelation(doc, rel)).andReturn(null);

    replayMocks();/*from  w w  w. j  av  a2  s.c om*/
    try {
        impl.followLink(initState, rel);
        Assert.fail("should have thrown exception");
    } catch (RelationNotFoundException expected) {
    }
    verifyMocks();
}

From source file:org.netxilia.spi.impl.formula.TestFormulaParser.java

@Test
public void testNumberOperations()
        throws FormulaParsingException, AlreadyExistsException, StorageException, NotFoundException {
    JavaCCFormulaParserImpl parser = getParser();

    Assert.assertEquals(3.0, parser/*  w w  w .  jav a  2s . c o  m*/
            .executeFormula(new Formula("=a1 + 1"), SheetUtils.sheetWithCell("A1", 2.0), null).getNumberValue(),
            0.001);
    Assert.assertEquals(125.0,
            parser.executeFormula(new Formula("=5^3"), SheetUtils.sheetWithCell(), null).getNumberValue(),
            0.001);

    Assert.assertEquals(1.0, parser
            .executeFormula(new Formula("=a1 - 1"), SheetUtils.sheetWithCell("A1", 2.0), null).getNumberValue(),
            0.001);

    Assert.assertEquals(4.0, parser
            .executeFormula(new Formula("=a1 * 2"), SheetUtils.sheetWithCell("A1", 2.0), null).getNumberValue(),
            0.001);

    Assert.assertEquals(1.0, parser
            .executeFormula(new Formula("=a1 / 2"), SheetUtils.sheetWithCell("A1", 2.0), null).getNumberValue(),
            0.001);

    IGenericValue value = parser.executeFormula(new Formula("=a1 / 0"), SheetUtils.sheetWithCell("A1", 2.0),
            null);
    Assert.assertTrue(value instanceof ErrorValue);
    Assert.assertEquals(ErrorValueType.DIV_ZERO, ((ErrorValue) value).getErrorType());

    try {
        value = parser.executeFormula(new Formula("=a1 % 10"), SheetUtils.sheetWithCell("A1", 2.0), null);
        Assert.fail("Expecting FormulaParsingException");
    } catch (FormulaParsingException ex) {
        //
    }
}

From source file:com.aliyun.oss.integrationtests.ImageTest.java

@Test
public void testRotateImage() {
    String style = "image/rotate,90"; // 

    try {//from   w w  w  .j  av  a2  s. c  o m
        GetObjectRequest request = new GetObjectRequest(bucketName, originalImage);
        request.addParameter("x-oss-process", style);

        OSSObject ossObject = ossClient.getObject(request);
        ossClient.putObject(bucketName, newImage, ossObject.getObjectContent());

        ImageInfo imageInfo = getImageInfo(bucketName, originalImage);
        Assert.assertEquals(imageInfo.getHeight(), 267);
        Assert.assertEquals(imageInfo.getWidth(), 400);
        Assert.assertEquals(imageInfo.getSize(), 21839);
        Assert.assertEquals(imageInfo.getFormat(), "jpg");

        imageInfo = getImageInfo(bucketName, newImage);
        Assert.assertEquals(imageInfo.getHeight(), 400);
        Assert.assertEquals(imageInfo.getWidth(), 267);
        Assert.assertEquals(imageInfo.getSize(), 21509);
        Assert.assertEquals(imageInfo.getFormat(), "jpg");

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

From source file:com.redblackit.war.AppSecurityHttpTest.java

/**
 * Test GET using supplied URL, expectedTitle (to identify login or welcome page), and an indication of whether we
 * should authenticate OK, or not.//  w  ww. j  a va  2 s . co m
 *
 * @param url
 * @param expectedTitle
 * @param badClientCertificate
 * @throws Exception
 */
private void testGetUrl(final String url, final String expectedTitle, final boolean badClientCertificate)
        throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append(":url=").append(url).append(":expectedTitle=").append(expectedTitle)
            .append(":badClientCertificate=").append(badClientCertificate).append(":clientAuthMandatory=")
            .append(clientAuthMandatory);
    final String[] spropkeys = { "user.name", "clientAuthMandatory", "javax.net.ssl.keyStore",
            "javax.net.ssl.keyStorePassword", "javax.net.ssl.trustStore", "javax.net.ssl.trustStorePassword" };
    for (String spropkey : spropkeys) {
        sb.append("\n  [").append(spropkey).append("]=").append(System.getProperty(spropkey));
    }

    WebConversation conversation = new WebConversation();
    WebResponse response = null;
    try {
        response = conversation.getResponse(url);
        if (clientAuthMandatory && badClientCertificate) {
            Assert.fail("expected exception for bad certificate:but got response=" + response + sb);
        } else {
            Assert.assertNotNull("response" + sb, response);
            logger.info(response);

            String respUrl = response.getURL().toString();

            Assert.assertTrue("URL should start with '" + baseHttpsUrl + "' ... but was '" + respUrl + "'",
                    respUrl.startsWith(baseHttpsUrl));
            Assert.assertEquals("Title for response page" + sb, expectedTitle, response.getTitle().trim());
        }

    } catch (IOException se) {
        if (clientAuthMandatory && se instanceof SocketException) {
            logger.debug("expected exception" + sb, se);
            Throwable t = se.getCause();
            while (t instanceof SocketException) {
                t = t.getCause();
            }

            if (t != null) {
                logger.debug("root cause exception" + sb, t);
            }
        } else {
            logger.fatal("unexpected exception:" + sb, se);
            throw new RuntimeException("unexpected exception" + sb, se);
        }

    }
}