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:io.fabric8.quickstarts.cxfcdi.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 w  w .  j  a va2 s  . c o m
 * 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:baggage.BaseTestCase.java

protected static final void assertEquals(byte[] expected, byte[] actual) {
    if (!Arrays.equals(expected, actual)) {
        Assert.fail("Expected " + toString(expected) + ", got " + toString(actual));
    }//from   w  w w . java2s .co  m
}

From source file:org.opencastproject.remotetest.server.RetryStrategiesTest.java

@Test
public void testNone() throws Exception {
    // Start a workflow instance via the rest endpoint
    HttpPost postStart = new HttpPost(BASE_URL + "/workflow/start");
    List<NameValuePair> formParams = new ArrayList<NameValuePair>();

    formParams.add(new BasicNameValuePair("definition", getSampleWorkflowDefinition("workflow-none.xml")));
    formParams.add(new BasicNameValuePair("mediapackage", getSampleMediaPackage()));
    formParams.add(new BasicNameValuePair("properties", "this=that"));
    postStart.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8"));

    // Grab the new workflow instance from the response
    String postResponse = EntityUtils.toString(client.execute(postStart).getEntity());
    String id = getWorkflowInstanceId(postResponse);

    // Ensure that the workflow finishes successfully
    int attempts = 0;
    while (true) {
        if (++attempts == 20)
            Assert.fail("workflow rest endpoint test has hung");
        HttpGet getWorkflowMethod = new HttpGet(BASE_URL + "/workflow/instance/" + id + ".xml");
        String getResponse = EntityUtils.toString(client.execute(getWorkflowMethod).getEntity());
        String state = getWorkflowInstanceStatus(getResponse);
        if ("FAILED".equals(state))
            break;
        if ("SUCCEEDED".equals(state))
            Assert.fail("workflow instance " + id + " succeeded");
        if ("PAUSED".equals(state))
            Assert.fail("workflow instance " + id + " paused");
        System.out.println("workflow " + id + " is " + state);
        Thread.sleep(5000);// w  ww . ja va2  s.  c  o m
    }

    // Get Ingest service state
    // Should be WARNING
    HttpGet getWorkflowMethod = new HttpGet(
            BASE_URL + "/services/services.json?serviceType=org.opencastproject.inspection&host=" + BASE_URL);
    String jsonResponse = EntityUtils.toString(client.execute(getWorkflowMethod).getEntity());
    String state = new JSONObject(jsonResponse).getJSONObject("services").getJSONObject("service")
            .getString("service_state");
    Assert.assertEquals("WARNING", state);

    // Get the number of failed on Ingest service,
    // Should be 1
    getWorkflowMethod = new HttpGet(BASE_URL + "/services/count?serviceType=org.opencastproject.inspection");
    String getResponse = EntityUtils.toString(client.execute(getWorkflowMethod).getEntity());
    logger.debug("Job count response: {}", getResponse);
    Assert.assertEquals(1, Integer.parseInt(getResponse) - initCount);
}

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

/**
 * HTTP GET http://localhost:8181/cxf/crm/customerservice/customers/123
 * returns the XML document representing customer 123
 * <p/>/*from www .  j  a  v  a2s  . c om*/
 * On the server side, it matches the CustomerService's getCustomer() method
 *
 * @throws Exception
 */
@Test
public void getIndexTest() throws Exception {
    LOG.info("Sent HTTP GET request to get the index.html page");
    url = new URL(INDEX_TEST_URL);
    InputStream in = null;
    try {
        in = url.openStream();
    } catch (IOException e) {
        LOG.error("Error connecting to {}", INDEX_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("Camel Spark Rest Example"));
}

From source file:com.amazonaws.http.AmazonHttpClientRequestTimeoutTest.java

@Test(timeout = 25 * 1000)
public void testRequestTimeoutEnforcedWithRetries() throws IOException {
    ProblematicServer server = new ProblematicServer(ProblematicServer.ServerIssue.OVERLOADED);
    server.startServer();//  w w w  .  j  a va  2 s .c o m

    int maxRetries = 2;
    ClientConfiguration config = new ClientConfiguration().withRequestTimeout(1 * 1000)
            .withMaxErrorRetry(maxRetries);
    HttpClientFactory httpClientFactory = new HttpClientFactory();
    HttpClient rawHttpClient = spy(httpClientFactory.createHttpClient(config));
    String localhostEndpoint = "http://localhost:" + server.getPort();
    Request<?> request = new EmptyHttpRequest(localhostEndpoint, HttpMethodName.GET);

    AmazonHttpClient httpClient = new AmazonHttpClient(config, rawHttpClient, null);

    try {
        httpClient.execute(request, new NullResponseHandler(), new NullErrorResponseHandler(),
                new ExecutionContext());
        Assert.fail("Client-side request timeout is expected!");
    } catch (AmazonClientException e) {
        /* Assert the expected exception and number of requests. */
        Assert.assertTrue(e.getCause() instanceof HttpRequestTimeoutException);
        int expectedNumberOfRequests = 1 + maxRetries;
        verify(rawHttpClient, times(expectedNumberOfRequests)).execute(any(HttpRequestBase.class),
                any(HttpContext.class));
        ScheduledThreadPoolExecutor httpRequestTimer = httpClient.getHttpRequestTimer().getExecutor();
        Assert.assertEquals(expectedNumberOfRequests, httpRequestTimer.getCompletedTaskCount());
    }

    server.stopServer();
    httpClient.shutdown();
}

From source file:net.sf.dynamicreports.googlecharts.test.AbstractJasperTest.java

protected JRPrintElement getElementAt(String key, int index) {
    List<JRPrintElement> elements = findElement(key);
    if (elements.size() - 1 < index) {
        Assert.fail("Element " + key + " at index " + index + " not found");
        return null;
    }/*from w w  w . j a  v  a  2 s.  c o  m*/
    return elements.get(index);
}

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

/**
 *
 *//*from w ww . jav  a  2s  . co m*/
@Test
public void testGetByIdWithNullArgument() {
    try {
        serviceIntervalDAO.getById(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:com.netflix.hystrix.contrib.metrics.controller.HystricsMetricsControllerTest.java

@Test
public void testConcurrency() throws Exception {
    executeHystrixCommand(); // Execute a Hystrix command so that metrics are initialized.
    List<EventInput> streamList = new ArrayList<EventInput>();
    // Fire 5 requests, validate their responses and hold these connections.
    for (int i = 0; i < 5; i++) {
        EventInput stream = getStream();
        System.out.println("Received Response for Request#" + (i + 1));
        streamList.add(stream);//w  ww  .  j a  v a  2  s .  c o  m
        validateStream(stream, 1000);
        System.out.println("Validated Response#" + (i + 1));
    }

    // Sixth request should fail since max configured connection is 5.
    try {
        streamList.add(getStreamFailFast());
        Assert.fail("Expected 'ServiceUnavailableException' but, request went through.");
    } catch (ServiceUnavailableException e) {
        System.out.println("Got ServiceUnavailableException as expected.");
    }

    // Close one of the connections
    streamList.get(0).close();

    // Try again after closing one of the connections. This request should go through.
    EventInput eventInput = getStream();
    streamList.add(eventInput);
    validateStream(eventInput, 1000);

}

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

@Test
public void testCreateUpdateUserAccount() {

    try {//w ww .  j  av a 2 s . com
        UserAccount userAccount = this.userAccountDao.getUserAccountByUsername("testuser");
        Assert.assertNotNull(userAccount);

        userAccount.getPreferences().setTheme("Testtheme");
        this.userAccountDao.saveUserAccount(userAccount);

        UserAccount userAccount2 = this.userAccountDao.getUserAccountByUsername("testuser");
        Assert.assertEquals("Testtheme", userAccount2.getPreferences().getTheme());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        Assert.fail(e.getMessage());
    }
}

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

@Test
public void testReduceTaskOnPreSortedInput() {
    final int keyCnt = 100;
    final int valCnt = 20;

    addInput(new UniformRecordGenerator(keyCnt, valCnt, true));
    addInputComparator(this.comparator);
    setOutput(this.outList);
    getTaskConfig().setDriverStrategy(DriverStrategy.SORTED_GROUP_REDUCE);

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

    try {//w  ww.  j a  v a 2s.c om
        testDriver(testTask, MockReduceStub.class);
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Invoke method caused exception.");
    }

    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();
}