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:de.unentscheidbar.validation.swing.trigger.ChangeTriggerTest.java

@Override
protected void provokeTrigger(Iterable<JComponent> components) {

    for (JComponent c : components) {
        Callable<Void> setter = changers.get(Equivalence.identity().wrap(c));
        if (setter == null) {
            Assert.fail("No value changer for " + c);
        }/*from   w w  w  .j  a  va2  s  . c om*/
        runInEdt(setter);
    }
    drainEventQueue();
}

From source file:com.hoccer.tools.TestHelper.java

public static void assertEquals(final String message, final byte[] expected, final byte[] current) {

    int eByte, cByte;
    int i = 0;//w  ww  .j av a  2 s . c o  m
    try {
        for (; i < expected.length; ++i) {
            eByte = expected[i];
            cByte = current[i];

            if (eByte != cByte) {
                Assert.assertEquals(
                        (message != null ? message + ": " : "") + "Byte Array not equal at position " + i,
                        eByte, cByte);
            }
        }
    } catch (final ArrayIndexOutOfBoundsException e) {
        Assert.fail((message != null ? message + ": " : "") + "Byte Array truncated at position  " + i);
    }

    Assert.assertEquals("byte array to long", expected.length, current.length);

}

From source file:com.oneops.util.SearchSenderTest.java

private void assertMessages(MessageData[] expected, MessageData[] actual) {
    if (ArrayUtils.isEmpty(expected) && ArrayUtils.isEmpty(actual))
        return;/*from  www  .  j ava  2 s.com*/
    if (ArrayUtils.isEmpty(expected) || ArrayUtils.isEmpty(actual) || expected.length != actual.length) {
        Assert.fail("expected and actual array lengths are not matching");
    } else {
        Map<String, MessageData> expectedMap = new HashMap<String, MessageData>(expected.length);
        for (MessageData data : expected) {
            expectedMap.put(data.getPayload(), data);
        }
        for (MessageData data : actual) {
            MessageData matching = expectedMap.get(data.getPayload());
            Assert.assertNotNull(matching);
            Assert.assertEquals(matching.getHeaders(), data.getHeaders());
        }
    }
}

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

@Test
public void testStreamEmptyInnerCrossTask() {

    int keyCnt1 = 10;
    int valCnt1 = 1;

    int keyCnt2 = 0;
    int valCnt2 = 0;

    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_STREAMED_OUTER_FIRST);
    super.getTaskConfig().setMemorySize(1 * 1024 * 1024);

    super.registerTask(testTask, MockCrossStub.class);

    try {//w  w  w .  ja  v  a  2 s .com
        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:de.hybris.platform.acceleratorservices.email.impl.DefaultEmailServiceTest.java

@Test
public void testSendWithAttachments() {
    final EmailAddressModel toAddress = mock(EmailAddressModel.class);
    final EmailAddressModel fromAddress = mock(EmailAddressModel.class);
    final EmailMessageModel emailMessageModel = mock(EmailMessageModel.class);
    final HtmlEmail email = mock(HtmlEmail.class);
    given(emailMessageModel.getToAddresses()).willReturn(Collections.singletonList(toAddress));
    given(emailMessageModel.getFromAddress()).willReturn(fromAddress);
    given(toAddress.getEmailAddress()).willReturn("ramana@neoworks.com");
    given(toAddress.getDisplayName()).willReturn("ramana ulluri");
    given(fromAddress.getEmailAddress()).willReturn("customerservices@hybris.com");
    given(fromAddress.getDisplayName()).willReturn("Customer Services");
    given(emailMessageModel.getSubject()).willReturn("subject - test");
    given(emailMessageModel.getBody()).willReturn(
            "body - This is a test email with dummy attachment from CommerceServices.DefaultEmailServiceTest.testSendWithAttachments()");

    final EmailAttachmentModel attachment = mock(EmailAttachmentModel.class);
    given(mediaService.getDataFromMedia(attachment)).willReturn(new byte[] {});
    given(emailMessageModel.getAttachments()).willReturn(Collections.singletonList(attachment));
    given(attachment.getMime()).willReturn("image/jpeg");
    given(attachment.getRealFileName()).willReturn("test");

    try {//from ww w  . j a v  a 2s  .co  m
        when(email.send()).thenReturn("messageId");
    } catch (final EmailException e) {
        Assert.fail("EmailException was thrown");
    }

    final boolean result = emailService.send(emailMessageModel);

    verify(attachment, times(1)).getMime();
    verify(modelService, times(1)).save(emailMessageModel);

    Assert.assertTrue(result);
}

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

@Test
public void testDeleteAddressFolders() {

    try {/*from   www .j a  v  a2  s . com*/
        List<AddressFolder> folders = (List<AddressFolder>) this.applicationContext
                .getBean("testAddressFolders");
        int foldersCount = folders.size();
        for (AddressFolder folder : folders) {
            folder.setUserAccount(this.testUserAccount);
            this.userAccountDao.saveAddressFolder(folder);
        }

        List<Long> ids = new ArrayList<Long>();
        ids.add(folders.get(0).getId());
        ids.add(folders.get(1).getId());
        this.userAccountDao.deleteAddressFolders(ids);

        List<AddressFolder> savedAdressFolders = this.userAccountDao
                .retrieveAddressFolders(this.testUserAccount);
        Assert.assertNotNull(savedAdressFolders);
        Assert.assertEquals(savedAdressFolders.size(), foldersCount - 2);
        Assert.assertEquals(savedAdressFolders.get(0).getName(), folders.get(2).getName());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        Assert.fail(e.getMessage());
    }
}

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

/**
 * HTTP POST http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of
 * the add_customer.xml file to add a new customer to the system.
 * <p/>/* w  w w .  jav  a 2  s .  c  om*/
 * On the server side, it matches the CustomerService's addCustomer() method
 *
 * @throws Exception
 */
@Test
@Ignore
public void postCustomerTest() throws IOException {
    LOG.info("Sent HTTP POST request to add customer");
    String inputFile = this.getClass().getResource("/add_customer.xml").getFile();
    File input = new File(inputFile);
    PostMethod post = new PostMethod(CUSTOMER_SERVICE_URL);
    post.addRequestHeader("Accept", "application/xml");
    RequestEntity entity = new FileRequestEntity(input, "application/xml; charset=ISO-8859-1");
    post.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    String res = "";

    try {
        int result = httpclient.executeMethod(post);
        LOG.info("Response status code: " + result);
        LOG.info("Response body: ");
        res = post.getResponseBodyAsString();
        LOG.info(res);
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_SERVICE_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");
    } finally {
        // Release current connection to the connection pool once you are
        // done
        post.releaseConnection();
    }
    Assert.assertTrue(res.contains("Jack"));

}

From source file:io.fabric8.quickstarts.fabric.rest.secure.CrmSecureTest.java

/**
 * HTTP PUT http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of
 * the update_customer.xml file to update the customer information for customer 123.
 * <p/>/*from   w w w  .  j a v  a 2 s.c o m*/
 * On the server side, it matches the CustomerService's updateCustomer() method
 *
 * @throws Exception
 */
@Test
public void putCustomerTest() throws IOException {

    LOG.info("============================================");
    LOG.info("Sent HTTP PUT request to update customer info");

    String inputFile = this.getClass().getResource("/update_customer.xml").getFile();
    File input = new File(inputFile);
    PutMethod put = new PutMethod(CUSTOMER_SERVICE_URL);
    put.getHostAuthState().setAuthScheme(scheme);
    RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
    put.setRequestEntity(entity);

    int result = 0;
    try {
        result = httpClient.executeMethod(put);
        LOG.info("Response status code: " + result);
        LOG.info("Response body: ");
        LOG.info(put.getResponseBodyAsString());
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_SERVICE_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");
    } finally {
        // Release current connection to the connection pool once you are
        // done
        put.releaseConnection();
    }

    Assert.assertEquals(result, 200);
}

From source file:org.opencastproject.remotetest.Main.java

private static void loadSeleneseData() throws Exception {
    System.out.println("Loading sample data for selenium HTML tests");
    // get the zipped mediapackage from the classpath
    byte[] bytesToPost = IOUtils.toByteArray(Main.class.getResourceAsStream("/ingest.zip"));

    // post it to the ingest service
    HttpPost post = new HttpPost(BASE_URL + "/ingest/addZippedMediaPackage");
    post.setEntity(new ByteArrayEntity(bytesToPost));
    TrustedHttpClient client = getClient();
    HttpResponse response = client.execute(post);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    String workflowXml = EntityUtils.toString(response.getEntity());

    // Poll the workflow service to ensure this recording processes successfully
    String workflowId = WorkflowUtils.getWorkflowInstanceId(workflowXml);
    while (true) {
        if (WorkflowUtils.isWorkflowInState(workflowId, "SUCCEEDED")) {
            SELENESE_DATA_LOADED = true;
            break;
        }/* w  ww .ja  va 2 s. com*/
        if (WorkflowUtils.isWorkflowInState(workflowId, "FAILED")) {
            Assert.fail("Unable to load sample data for selenese tests.");
        }
        Thread.sleep(5000);
        System.out.println("Waiting for sample data to process");
    }
    returnClient(client);
}

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

/**
 *
 *//* w w  w.j av a 2  s. c om*/
@Test
public void testValidRemove() {
    try {
        Vehicle mercedes = ServiceIntervalDAOTest.getVehicle("Mercedes", 14000, "R4 Diesel", "A",
                UserClassEnum.PRESIDENT, "2f-4xxi-121245", 2009);
        this.vehicleDao.createVehicle(mercedes);
        ServiceInterval interval1 = ServiceIntervalDAOTest.getServiceInterval(new ArrayList<Date>(),
                "Prehodeni koles", 7, mercedes);
        this.serviceIntervalDAO.createSI(interval1);
        ServiceInterval loaded = serviceIntervalDAO.getById(interval1.getId());
        Assert.assertNotNull("Service interval was not created", loaded);

        em.getTransaction().begin();
        serviceIntervalDAO.removeSI(interval1);
        em.getTransaction().commit();

        loaded = serviceIntervalDAO.getById(interval1.getId());
        if (loaded != null) {
            Assert.fail("Interval was not deleted from database.");
        }
        Assert.assertNull("Service interval was not deleted from database", loaded);
    } catch (Exception ex) {
        Assert.fail("Unexpected exception was throwed: " + ex + " " + ex.getMessage());
    }
}