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:com.aliyun.oss.perftests.PerftestRunner.java

public void createBucket() {
    String bucketName = scenario.getBucketName();
    try {/*  www.j  a v  a 2 s  .  co  m*/
        ossClient.createBucket(bucketName);
    } catch (OSSException e) {
        log.error("Put bucket " + bucketName + " error " + e.getMessage());
        Assert.fail(e.getMessage());
    } catch (ClientException e) {
        log.error("Put bucket " + bucketName + " error " + e.getMessage());
        Assert.fail(e.getMessage());
    } catch (Exception e) {
        log.error("Put bucket " + bucketName + " error " + e.getMessage());
        Assert.fail(e.getMessage());
    }
}

From source file:functionaltests.TestXMLTransformer.java

/**
 * This opertations are performed:/*w w  w.  j a v  a  2  s  .  c  om*/
 *
 * 1. xmlFile to java => job1
 *
 * 2. job1 = > xmlFle2
 *
 * 3. xmlFile2 to java => job2
 *
 * 4. Compare job1 and job2
 *
 *
 * @param xmlFile
 * @throws Exception
 */
private void transformAndCompare(File xmlFile) throws Exception {
    System.out.println("TestXMLTransformer.transformAndCompare() " + xmlFile.getAbsolutePath());
    // xml to java => job1
    TaskFlowJob job1 = (TaskFlowJob) (JobFactory.getFactory().createJob(xmlFile.getAbsolutePath()));

    // job1 to xmlFile2
    File xmlFile2 = new File(tmpFolder, xmlFile.getName());
    Job2XMLTransformer transformer = new Job2XMLTransformer();
    transformer.job2xmlFile(job1, xmlFile2);

    // xmlFile2 to job2
    TaskFlowJob job2 = null;
    try {
        job2 = (TaskFlowJob) (JobFactory.getFactory().createJob(xmlFile2.getAbsolutePath()));
    } catch (Exception e) {
        String message = "Could not create Job object from generated xml. \n";
        message += "Generated xml content was : \n ****** " + xmlFile2.getAbsolutePath() + " ***********\n ";
        message += FileUtils.readFileToString(xmlFile2, null);
        message += "\n *************************** ";
        throw new Exception(message, e);
    }

    // compare job1 and job2
    JobComparator comparator = new JobComparator();
    if (!comparator.isEqualJob(job1, job2)) {
        String message = "Jobs are not equal for file " + xmlFile + "\n";
        message += "Reason: " + comparator.getDifferenceMessage() + "\n";
        message += "Generated xml content was : \n ****** " + xmlFile2.getAbsolutePath() + " *********** \n ";
        message += FileUtils.readFileToString(xmlFile2, null);
        message += "\n *************************** ";
        Assert.fail(message);
    }

    // delete temporary file
    xmlFile2.delete();

}

From source file:org.jboss.shrinkwrap.jetty_7.test.JettyDeploymentIntegrationUnitTestCase.java

/**
 * Tests that we can execute an HTTP request and it's fulfilled as expected, 
 * proving our deployment succeeded//ww  w  . ja  va 2  s. c  o m
 */
@Test
public void requestWebapp() throws Exception {
    // Get an HTTP Client
    final HttpClient client = new DefaultHttpClient();

    // Make an HTTP Request, adding in a custom parameter which should be echoed back to us
    final String echoValue = "ShrinkWrap>Jetty 7 Integration";
    final List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("to", PATH_ECHO_SERVLET));
    params.add(new BasicNameValuePair("echo", echoValue));
    final URI uri = URIUtils.createURI("http", HTTP_BIND_HOST, HTTP_BIND_PORT,
            NAME_WEBAPP + SEPARATOR + forwardingServletClass.getSimpleName(),
            URLEncodedUtils.format(params, "UTF-8"), null);
    final HttpGet request = new HttpGet(uri);

    // Execute the request
    log.info("Executing request to: " + request.getURI());
    final HttpResponse response = client.execute(request);
    System.out.println(response.getStatusLine());
    final HttpEntity entity = response.getEntity();
    if (entity == null) {
        Assert.fail("Request returned no entity");
    }

    // Read the result, ensure it's what we're expecting (should be the value of request param "echo")
    final BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
    final String line = reader.readLine();
    Assert.assertEquals("Unexpected response from Servlet", echoValue, line);

}

From source file:jp.co.opentone.bsol.linkbinder.dao.impl.DistTemplateTestBase.java

/**
 * McMaster???.//from  w w  w  .  ja v a2s.c  o m
 * @param expected 
 * @param actual 
 * @param fields ?????
 */
protected void assertEquals(Object expected, Object actual, String[] fields) {
    Assert.assertNotNull(expected);
    Assert.assertNotNull(actual);
    Assert.assertNotNull(fields);

    for (String field : fields) {
        try {
            String methodName = String.format("get%s%s", field.substring(0, 1).toUpperCase(),
                    field.substring(1));
            Method expMethod = expected.getClass().getMethod(methodName, (Class[]) null);
            Object expObj = expMethod.invoke(expected, (Object[]) null);
            Method actMethod = actual.getClass().getMethod(methodName, (Class[]) null);
            Object actObj = actMethod.invoke(actual, (Object[]) null);
            Assert.assertEquals(expObj, actObj);
        } catch (Exception e) {
            Assert.fail(e.toString());
        }
    }
}

From source file:org.outermedia.solrfusion.adapter.solr.DefaultSolrAdapterTest.java

@Test
public void testErrorCase() throws URISyntaxException, IOException {
    DefaultSolrAdapter adapter = spy((DefaultSolrAdapter) DefaultSolrAdapter.Factory.getInstance());
    SearchServerConfig sc = new SearchServerConfig();
    sc.setUrl("http://localhost");
    adapter.init(sc);//from   w  w w  .j  a v  a2  s  .  c  om
    CloseableHttpClient client = mock(CloseableHttpClient.class);
    HttpPost request = mock(HttpPost.class);
    CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    StatusLine sl = mock(StatusLine.class);
    HttpEntity entity = mock(HttpEntity.class);
    when(adapter.newHttpClient()).thenReturn(client);
    doReturn(request).when(adapter).newHttpPost(anyString(), any(SolrFusionUriBuilder.class));
    when(client.execute(request)).thenReturn(response);
    when(response.getStatusLine()).thenReturn(sl);
    when(sl.getStatusCode()).thenReturn(400);
    when(sl.getReasonPhrase()).thenReturn("Bad Query");
    when(response.getEntity()).thenReturn(entity);

    // without response
    when(entity.getContent()).thenReturn(null);
    Multimap<String> params = new Multimap<>();
    params.put(QUERY, "*:*");
    params.put(SORT, "score desc");
    try {
        SolrFusionUriBuilder ub = adapter.buildHttpClientParams(null, null, null, params, new Version("4.1"));
        adapter.sendQuery(ub, 2000);
        Assert.fail("Expected SearchServerResponseException for http status 400");
    } catch (SearchServerResponseException se) {
        String msg = se.getMessage();
        Assert.assertEquals("Expected other error message", "ERROR 400: Bad Query", msg);
    }

    // with response
    when(entity.getContent()).thenReturn(new StringBufferInputStream("Bad Content"));
    try {
        SolrFusionUriBuilder ub = adapter.buildHttpClientParams(null, null, null, params, new Version("4.1"));
        adapter.sendQuery(ub, 2000);
        Assert.fail("Expected SearchServerResponseException for http status 400");
    } catch (SearchServerResponseException se) {
        String msg = se.getMessage();
        Assert.assertEquals("Expected other error message", "ERROR 400: Bad Query", msg);
        Assert.assertNotNull("Response should be set", se.getHttpContent());
    }
}

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

/**
 *
 *//*w  ww . j  av  a 2  s .c  om*/
@Test
public void testValidUpdate() {
    try {
        Vehicle mercedes = ServiceIntervalDAOTest.getVehicle("Mercedes", 20000, "R4 Diesel", "E",
                UserClassEnum.PRESIDENT, "2a-447i-882a45", 2009);
        vehicleDao.createVehicle(mercedes);
        ServiceInterval interval1 = ServiceIntervalDAOTest.getServiceInterval(new ArrayList<Date>(),
                "Prehodeni koles", 7, mercedes);
        serviceIntervalDAO.createSI(interval1);

        interval1.setDescription("Vymeneni oleje");
        serviceIntervalDAO.updateSI(interval1);

        ServiceInterval loaded = serviceIntervalDAO.getById(interval1.getId());
        Assert.assertNotSame("Description has not been updated.", "Prehodeni koles", loaded.getDescription());
    } catch (Exception ex) {
        Assert.fail("Unexpected exception was throwed: " + ex + " " + ex.getMessage());
    }
}

From source file:com.edgenius.wiki.service.impl.TestVolumnPageService.java

@Test
public void testSaveVolumePage() {
    //save 15,000 pages into test database
    final int maxPages = 1500;
    //      final int maxPages = 15;
    final int maxLevel = 7;
    final int spaceLen = spaces.size();
    final int maxSpacePages = (int) maxPages / spaceLen + (maxPages % spaceLen != 0 ? 1 : 0);

    String title = "First page";
    String lastTitle = "http://geniuswiki.com";
    int level = maxLevel + 1; //first page won't have parent
    Page parentPage = null;//from w  w w.ja v  a 2  s.c  o m
    int spaceIndex = 0;

    for (int idx = 0; idx < maxPages; idx++) {

        if (idx >= (maxSpacePages * (spaceIndex + 1))) {
            //another space pages, need reset some value
            level = maxLevel + 1;
            parentPage = null;
            title = "First page";
            lastTitle = "http://geniuswiki.com";
            spaceIndex++;
        }

        Page page = new Page();
        Space space = new Space();
        PageContent pct = new PageContent();

        space.setUnixName(spaces.get(spaceIndex));

        page.setSpace(space);
        page.setContent(pct);
        page.setTitle(title);

        String my = content.replaceAll("@PAGE_TITLE@", lastTitle);
        pct.setContent(my);
        if (level < maxLevel) {
            page.setParent(parentPage);
            level++;
        } else {
            //root page - no parent
            level = 0;
        }
        try {
            parentPage = pageService.savePage(page, WikiConstants.NOTIFY_NONE, true);
            //just get a random string
            title = parentPage.getPageUuid();
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail(e.getMessage());
        }

    }

}

From source file:de.hybris.platform.acceleratorservices.email.impl.DefaultEmailServiceTest.java

@Test
public void testSend() {
    final EmailAddressModel toAddress = mock(EmailAddressModel.class);
    final EmailAddressModel fromAddress = mock(EmailAddressModel.class);
    final EmailMessageModel emailMessageModel = mock(EmailMessageModel.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())//from  ww w  . j  a  v a  2 s  . co  m
            .willReturn("body - This is a test email from CommerceServices.DefaultEmailServiceTest.testSend()");

    try {
        when(email.send()).thenReturn("messageId");
    } catch (final EmailException e) {
        Assert.fail("EmailException was thrown");
    }

    final boolean result = emailService.send(emailMessageModel);

    verify(modelService, times(1)).save(emailMessageModel);
    Assert.assertTrue(result);
}

From source file:com.github.brandtg.discovery.TestHelixServiceDiscoveryBundle.java

private static void waitForServices(HelixServiceDiscoverer serviceDiscoverer, int expectedInstances) {
    long startTimeMillis = System.currentTimeMillis();
    do {//www  .  j av  a2s .co  m
        List<InetSocketAddress> services = serviceDiscoverer.getServices();
        if (services != null && services.size() == expectedInstances) {
            return;
        }
    } while (System.currentTimeMillis() - startTimeMillis < 10000);

    Assert.fail("Timed out while waiting for services to become " + expectedInstances);
}

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

private static void assertExpectedErrors(final Collection<ErrorCollection> expectedErrors,
        final Runnable runnable) {
    try {/* w  ww. java2 s  .  co m*/
        runnable.run();
        Assert.fail(RestClientException.class + " exception expected");
    } catch (com.atlassian.jira.rest.client.api.RestClientException e) {
        Assert.assertEquals(e.getErrorCollections(), expectedErrors);
    }
}