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.opencastproject.remotetest.server.WorkflowRestEndpointTest.java

@Test
public void testStartAndRetrieveWorkflowInstance() 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()));
    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
    HttpResponse r = client.execute(postStart);
    Assert.assertEquals(200, r.getStatusLine().getStatusCode());
    String postResponse = EntityUtils.toString(r.getEntity());
    String id = getWorkflowInstanceId(postResponse);

    // Ensure we can retrieve the workflow instance from the rest endpoint
    HttpGet getWorkflowMethod = new HttpGet(BASE_URL + "/workflow/instance/" + id + ".xml");
    String getResponse = EntityUtils.toString(client.execute(getWorkflowMethod).getEntity());
    Assert.assertEquals(id, getWorkflowInstanceId(getResponse));

    // Make sure we can retrieve it via json, too
    HttpGet getWorkflowJson = new HttpGet(BASE_URL + "/workflow/instance/" + id + ".json");
    String jsonResponse = EntityUtils.toString(client.execute(getWorkflowJson).getEntity());
    JSONObject json = (JSONObject) JSONValue.parse(jsonResponse);
    if (json == null)
        Assert.fail("JSON response should not be null, but is " + jsonResponse);
    JSONObject workflowAsJson = (JSONObject) json.get("workflow");
    Assert.assertEquals(id, workflowAsJson.get("id"));

    // Make sure we can retrieve it as part of a set of workflows as json
    HttpGet getWorkflowsJson = new HttpGet(BASE_URL + "/workflow/instances.json");
    String workflowsResponse = EntityUtils.toString(client.execute(getWorkflowsJson).getEntity());
    JSONObject workflowsJson = (JSONObject) JSONValue.parse(workflowsResponse);
    if (workflowsJson == null)
        Assert.fail("JSON response should not be null, but is " + jsonResponse);
    JSONObject workflows = (JSONObject) workflowsJson.get("workflows");
    Assert.assertTrue(Integer.parseInt((String) workflows.get("totalCount")) > 0);

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

From source file:com.connectsdk.service.google_cast.CastServiceChannelTest.java

@Test
public void testSendMessageWithNullSessionListener() {
    WebAppSessionListener listener = Mockito.mock(WebAppSessionListener.class);
    Mockito.when(session.getWebAppSessionListener()).thenReturn(listener);
    try {//from  www.j  a va  2 s  .  c o  m
        Robolectric.getUiThreadScheduler().pause();
        channel.onMessageReceived(null, null, null);
        // modify session for checking pending UI task
        Mockito.when(session.getWebAppSessionListener()).thenReturn(null);
        Robolectric.runUiThreadTasksIncludingDelayedTasks();
    } catch (RuntimeException e) {
        Assert.fail("onMessageReceived should not thrown an Exception");
    }
}

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

/**
 *
 *//*from w  w  w.jav a  2 s  .  c  o  m*/
@Test
public void testRemoveWithNullArgument() {
    try {
        serviceIntervalDAO.removeSI(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:eu.stratosphere.pact.runtime.task.CoGroupTaskTest.java

@Test
public void testSortBoth1CoGroupTask() {

    int keyCnt1 = 100;
    int valCnt1 = 2;

    int keyCnt2 = 200;
    int valCnt2 = 1;

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

    CoGroupTask<PactRecord, PactRecord, PactRecord> testTask = new CoGroupTask<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, MockCoGroupStub.class);

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

    int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2) + Math.max(keyCnt1, keyCnt2)
            - 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:com.amalto.core.load.LoadParserTest.java

public void testCallbackFailure() {
    LoadParserCallback callback = new LoadParserCallback() {
        public void flushDocument(XMLReader docReader, InputSource input) {
            throw new RuntimeException();
        }/*  w w  w.  j a  v  a2  s . c om*/
    };

    try {
        LoadParser.Configuration config = new LoadParser.Configuration("root", new String[] { "Id" }, false,
                "clusterName", "modelName", idGenerator);
        LoadParser.parse(new ByteArrayInputStream("<root><Id>0</Id></root>".getBytes()), config, callback);
        Assert.fail("Should have failed due to callback exception.");
    } catch (Exception e) {
        assertNotNull(e.getCause());
        assertTrue(e.getCause() instanceof ParserCallbackException);
    }
}

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

/**
 * Test of remove method, of class VehicleDAO.
 *//*from  w w w  .  ja  va 2 s.c om*/
@Test
public void testRemove() {
    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();
        System.out.println("Log: vehicle created!");
        em.getTransaction().begin();
        this.vehicleDao.removeVehicle(mercedes);
        em.getTransaction().commit();
        System.out.println("Log: vehicle removed!");

        Vehicle loaded = this.vehicleDao.getById(id);
        System.out.println("Log: vehicle loaded!");

        Assert.assertNull("Vehicle was not deleted from database", loaded);
    } catch (Exception ex) {
        Assert.fail("Unexpected exception was throwed: " + ex + " " + ex.getMessage());
    }
}

From source file:common.utils.ReflectionAssert.java

/**
 * Asserts that two objects are equal. Reflection is used to compare all fields of these values.
 * If they are not equal an AssertionFailedError is thrown.
 * <p/>/*from  w w  w .ja  v a 2s  .  c  o  m*/
 * The comparator modes determine how strict to compare the values.
 *
 * @param message  a message for when the assertion fails
 * @param expected the expected object
 * @param actual   the given object
 * @param modes    the comparator modes
 * @throws AssertionFailedError when both objects are not equals
 */
public static void assertReflectionEquals(String message, Object expected, Object actual,
        ReflectionComparatorMode... modes) throws AssertionFailedError {
    ReflectionComparator reflectionComparator = createRefectionComparator(modes);
    Difference difference = reflectionComparator.getDifference(expected, actual);
    if (difference != null) {
        Assert.fail(getFailureMessage(message, difference));
    }
}

From source file:example.crm.CrmIT.java

/**
 * HTTP GET http://localhost:9003/public/index.html
 * returns the index page./*from  w  w w . j  a  v  a 2s .c  o  m*/
 */
@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 '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("Camel REST DSL Example"));
}

From source file:baggage.BaseTestCase.java

protected static final void assertNotEquals(Object left, Object right) {
    if (left.equals(right)) {
        Assert.fail(left + " is equal to " + right);
    }/*w ww  . ja v a 2s . c  o  m*/
}

From source file:org.atemsource.atem.utility.view.ViewBuilderTest.java

@Test
public void testRemoveAndIncludePrimitives() {
    EntityType<EntityA> entityType = entityTypeRepository.getEntityType(EntityA.class);
    ViewBuilder viewBuilder = factory.create(entityType);
    viewBuilder.includePrimitives(false);
    viewBuilder.remove("intP");
    View view = viewBuilder.create();
    final Attribute intPAttribute = entityType.getAttribute("intP");
    final AtomicInteger count = new AtomicInteger();
    final ViewVisitor mockViewVisitor = new ViewVisitor<Object>() {

        @Override/*  w  w  w  . j a  v a 2  s.  c  om*/
        public void visit(Object context, Attribute attribute) {

            if (attribute == intPAttribute) {
                Assert.fail("intP was removed");
            } else if (attribute.getTargetType() instanceof PrimitiveType<?>
                    && attribute instanceof SingleAttribute<?>) {
                count.incrementAndGet();
            } else {
                Assert.fail("not a single primitive " + attribute.getCode());
            }
        }

        @Override
        public void visit(Object context, Attribute attribute, Visitor<Object> visitor) {
            Assert.fail("not a primitive " + attribute.getCode());
        }

        @Override
        public void visitSubView(Object context, View view, Visitor<Object> subViewVisitor) {
        }

        @Override
        public void visitSuperView(Object context, View view, Visitor<Object> superViewVisitor) {
        }

    };
    HierachyVisitor.visit(view, mockViewVisitor, null);
    Assert.assertTrue(count.intValue() > 2);
}