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.apache.synapse.transport.passthru.TargetResponseTest.java

/**
 * Testing the starting of target response when response body is expected
 *
 * @throws Exception/*from   ww w .  ja  va  2  s .c  o m*/
 */
@Test
public void testTrue() throws Exception {
    ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
    WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
    PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");

    TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool,
            metrics, null);
    targetConfiguration.build();
    HttpResponse response = PowerMockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
    NHttpClientConnection conn = PowerMockito.mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);

    PowerMockito.mockStatic(TargetContext.class);

    TargetContext cntxt = new TargetContext(targetConfiguration);
    PowerMockito.when(TargetContext.get(any(NHttpClientConnection.class))).thenReturn(cntxt);

    TargetResponse targetResponse = new TargetResponse(targetConfiguration, response, conn, true, false);

    try {
        targetResponse.start(conn);
    } catch (Exception e) {
        logger.error(e);
        Assert.fail("Unable to start the target response!");
    }
}

From source file:org.apache.gobblin.writer.AsyncHttpWriterTest.java

@Test
public void testSuccessfulWritesWithLimiter() {
    MockThrottledHttpClient client = new MockThrottledHttpClient(createMockBroker());
    MockRequestBuilder requestBuilder = new MockRequestBuilder();
    MockResponseHandler responseHandler = new MockResponseHandler();
    MockAsyncHttpWriterBuilder builder = new MockAsyncHttpWriterBuilder(client, requestBuilder,
            responseHandler);/*from   w w  w  .jav a2  s .  c o  m*/
    TestAsyncHttpWriter asyncHttpWriter = new TestAsyncHttpWriter(builder);

    List<MockWriteCallback> callbacks = new ArrayList<>();

    for (int i = 0; i < 50; i++) {
        MockWriteCallback callback = new MockWriteCallback();
        callbacks.add(callback);
        asyncHttpWriter.write(new Object(), callback);
    }

    try {
        asyncHttpWriter.close();
    } catch (IOException e) {
        Assert.fail("Close failed");
    }

    // Assert all successful callbacks are invoked
    for (MockWriteCallback callback : callbacks) {
        Assert.assertTrue(callback.isSuccess);
    }

    Assert.assertTrue(client.getSendTimer().getCount() == 50);
    Assert.assertTrue(client.isCloseCalled);
}

From source file:BQJDBC.QueryResultTest.Timeouttest.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   w ww .j  a  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 = Timeouttest.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:eu.stratosphere.pact.runtime.sort.AsynchonousPartialSorterITCase.java

@Test
public void testSmallSortInOneWindow() throws Exception {
    try {//w w  w  .  ja  va 2 s.c om
        final int NUM_RECORDS = 1000;

        // reader
        final TestData.Generator generator = new TestData.Generator(SEED, KEY_MAX, VALUE_LENGTH, KeyMode.RANDOM,
                ValueMode.CONSTANT, VAL);
        final MutableObjectIterator<Record> source = new TestData.GeneratorIterator(generator, NUM_RECORDS);

        // merge iterator
        LOG.debug("Initializing sortmerger...");
        Sorter<Record> sorter = new AsynchronousPartialSorter<Record>(this.memoryManager, source,
                this.parentTask, this.serializer, this.comparator, 32 * 1024 * 1024);

        runPartialSorter(sorter, NUM_RECORDS, 0);
    } catch (Exception t) {
        t.printStackTrace();
        Assert.fail("Test failed due to an uncaught exception: " + t.getMessage());
    }
}

From source file:com.github.brandtg.switchboard.TestMysqlReplicationApplier.java

@Test
public void testRestoreFromBinlog() throws Exception {
    MysqlReplicationApplier applier = null;
    try (Connection conn = DriverManager.getConnection(jdbc, "root", "")) {
        // Write some rows, so we have binlog entries
        PreparedStatement pstmt = conn.prepareStatement("INSERT INTO simple VALUES(?, ?)");
        for (int i = 0; i < 10; i++) {
            pstmt.setInt(1, i);//from   www.j  a  v a2  s . c om
            pstmt.setInt(2, i);
            pstmt.execute();
        }

        // Copy the binlog somewhere
        Statement stmt = conn.createStatement();
        ResultSet rset = stmt.executeQuery("SHOW BINARY LOGS");
        rset.next();
        String binlogName = rset.getString("Log_name");
        rset = stmt.executeQuery("SELECT @@datadir");
        rset.next();
        String dataDir = rset.getString("@@datadir");
        File copyFile = new File(System.getProperty("java.io.tmpdir"),
                TestMysqlReplicationApplier.class.getName());
        FileUtils.copyFile(new File(dataDir + binlogName), copyFile);

        // Clear everything in MySQL
        resetMysql();

        // Get input stream, skipping and checking binlog magic number
        InputStream inputStream = new FileInputStream(copyFile);
        byte[] magic = new byte[MySQLConstants.BINLOG_MAGIC.length];
        int bytesRead = inputStream.read(magic);
        Assert.assertEquals(bytesRead, MySQLConstants.BINLOG_MAGIC.length);
        Assert.assertTrue(CodecUtils.equals(magic, MySQLConstants.BINLOG_MAGIC));

        // Restore from binlog
        PoolingDataSource<PoolableConnection> dataSource = getDataSource();
        applier = new MysqlReplicationApplier(inputStream, dataSource);
        ExecutorService executorService = Executors.newSingleThreadExecutor(new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                Thread t = new Thread(r);
                t.setDaemon(true);
                return t;
            }
        });
        executorService.submit(applier);

        // Poll until we have restored
        long startTime = System.currentTimeMillis();
        long currentTime = startTime;
        do {
            stmt = conn.createStatement();
            rset = stmt.executeQuery("SELECT COUNT(*) FROM test.simple");
            rset.next();
            long count = rset.getLong(1);
            if (count == 10) {
                return;
            }
            Thread.sleep(1000);
            currentTime = System.currentTimeMillis();
        } while (currentTime - startTime < 10000);
    } finally {
        if (applier != null) {
            applier.shutdown();
        }
    }

    Assert.fail("Timed out when polling");
}

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

/**
 * Test of update method, of class VehicleDAO.
 *//*from   w  w w  .j  ava2s  . c om*/
@Test
public void testUpdate() {
    try {
        Vehicle mercedes = VehicleDAOTest.getVehicle("Mercedes", 20000, "R4 Diesel", "E",
                UserClassEnum.PRESIDENT, "2a-447i-882a45", 2009, "UEW6828");
        this.vehicleDao.createVehicle(mercedes);
        Long id = mercedes.getId();

        mercedes.setType("C");
        this.vehicleDao.updateVehicle(mercedes);

        Vehicle loaded = this.vehicleDao.getById(id);
        Assert.assertNotSame("Vehicle was not upadted!", "E", loaded.getType());
    } catch (Exception ex) {
        Assert.fail("Unexpected exception was throwed: " + ex + " " + ex.getMessage());
    }
}

From source file:com.atlassian.jira.rest.client.TestUtil.java

public static void assertErrorCodeWithRegexp(int errorCode, String regExp, Runnable runnable) {
    try {//from   w w  w. ja  v a 2s .com
        runnable.run();
        Assert.fail(RestClientException.class + " exception expected");
    } catch (com.atlassian.jira.rest.client.api.RestClientException ex) {
        final ErrorCollection errorElement = getOnlyElement(ex.getErrorCollections().iterator());
        final String errorMessage = getOnlyElement(errorElement.getErrorMessages().iterator());
        Assert.assertTrue("'" + ex.getMessage() + "' does not match regexp '" + regExp + "'",
                errorMessage.matches(regExp));
        Assert.assertTrue(ex.getStatusCode().isPresent());
        Assert.assertEquals(errorCode, ex.getStatusCode().get().intValue());
    }
}

From source file:com.intellijob.BaseTester.java

protected List<SkillNode> readResourceData(String resourcePath) {
    List<SkillNode> result = new ArrayList<>();

    BufferedReader br;/*  w  ww  . ja  v a 2s. c o  m*/
    String line;
    try (InputStream inputStream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream(resourcePath)) {
        br = new BufferedReader(new InputStreamReader(inputStream, DEFAULT_ENCODING));
        while ((line = br.readLine()) != null) {
            LocalizableObject localizableObject = new LocalizableObject(line);
            SkillNode skillNode = new SkillNode(new ObjectId(), localizableObject);
            skillNode.setName(line);
            result.add(skillNode);
        }
    } catch (Exception e) {
        LOG.error("Error occurred while read file (" + resourcePath + ")", e);
        Assert.fail("Can not read file");
    }

    return result;
}

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

/**
 *
 *///from ww  w  . jav  a2  s . c  o m
@Test
public void testFindAllByVehicleWithNullArgument() {
    try {
        serviceIntervalDAO.findAllByVehicle(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:org.atemsource.atem.utility.compare.OrderableCollectionComparatorTest.java

@Test
public void testAddedAndChanged() {
    EntityA a1 = createEntityA();/*ww  w .ja v  a2s. c om*/
    EntityB b1 = createEntityB();
    EntityA a2 = createEntityA();
    EntityB b2 = createEntityB();
    EntityB b3 = createEntityB();
    b1.setInteger(1);
    b2.setInteger(5);
    b3.setInteger(7);
    a2.getList().add(b2);
    a2.getList().add(b1);
    a1.getList().add(b3);

    Set<Difference> differences = comparisonAssociative.getDifferences(a1, a2);

    Assert.assertEquals(2, differences.size());
    for (Difference difference : differences) {
        if (difference instanceof Addition) {
            Assert.assertEquals("list.1", ((Addition) difference).getPath().toString());
        } else if (difference instanceof AttributeChange) {
            Assert.assertEquals("list.0.integer", ((AttributeChange) difference).getPath().toString());
        } else {
            Assert.fail("we expect a change and an addition");
        }
    }
}