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:fll.web.WebTestUtils.java

/**
 * Submit a query to developer/QueryHandler, parse the JSON and return it.
 */// www  .j  av a2  s  .co m
public static QueryHandler.ResultData executeServerQuery(final String query) throws IOException, SAXException {
    final WebClient conversation = getConversation();

    final URL url = new URL(TestUtils.URL_ROOT + "developer/QueryHandler");
    final WebRequest request = new WebRequest(url);
    request.setRequestParameters(
            Collections.singletonList(new NameValuePair(QueryHandler.QUERY_PARAMETER, query)));

    final Page response = loadPage(conversation, request);
    final String contentType = response.getWebResponse().getContentType();
    if (!"application/json".equals(contentType)) {
        final String text = getPageSource(response);
        final File output = File.createTempFile("json-error", ".html", new File("screenshots"));
        final FileWriter writer = new FileWriter(output);
        writer.write(text);
        writer.close();
        Assert.fail("Error JSON from QueryHandler: " + response.getUrl()
                + " Contents of error page written to: " + output.getAbsolutePath());
    }

    final String responseData = getPageSource(response);

    final ObjectMapper jsonMapper = new ObjectMapper();
    QueryHandler.ResultData result = jsonMapper.readValue(responseData, QueryHandler.ResultData.class);
    Assert.assertNull("SQL Error: " + result.getError(), result.getError());

    return result;
}

From source file:baggage.BaseTestCase.java

protected void assertNoEventsSoFar() {
    if (eventQueue.size() != 0) {
        Assert.fail("There are " + eventQueue.size() + " pending events, should be none");
    }//from  w  ww . j a v  a  2  s .c  om
}

From source file:com.aliyun.oss.integrationtests.ImageProcessTest.java

@Test
public void testRotateImage() {
    String style = "image/rotate,90"; // 

    try {/*w ww . j  a va  2 s .c om*/
        GetObjectRequest request = new GetObjectRequest(bucketName, originalImage);
        request.setProcess(style);

        OSSObject ossObject = ossClient.getObject(request);
        ossClient.putObject(bucketName, newImage, ossObject.getObjectContent());

        ImageInfo imageInfo = getImageInfo(bucketName, originalImage);
        Assert.assertEquals(imageInfo.getHeight(), 267);
        Assert.assertEquals(imageInfo.getWidth(), 400);
        Assert.assertEquals(imageInfo.getSize(), 21839);
        Assert.assertEquals(imageInfo.getFormat(), "jpg");

        imageInfo = getImageInfo(bucketName, newImage);
        Assert.assertEquals(imageInfo.getHeight(), 400);
        Assert.assertEquals(imageInfo.getWidth(), 267);
        Assert.assertEquals(imageInfo.getSize(), 21509);
        Assert.assertEquals(imageInfo.getFormat(), "jpg");

    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}

From source file:hk.hku.cecid.corvus.ws.EBMSMessageHistoryQuerySenderTest.java

@Test
public void testNormalCriteriaData() throws Exception {

    EBMSMessageHistoryRequestData expectData = new EBMSMessageHistoryRequestData();
    expectData.setEndPoint(TEST_ENDPOINT);

    expectData.setMessageBox("INbox");
    expectData.setStatus("dL");

    expectData.setMessageId("20080402-105745-64017@127.0.0.1");
    expectData.setService("cecid:cecid");
    expectData.setAction("Order");
    expectData.setConversationId("convId");
    expectData.setCpaId("cpaid");

    this.target = new EBMSMessageHistoryQuerySender(this.testClassLogger, expectData);
    try {//from   w ww.  j  a va2s. c  o m
        this.target.run();
    } catch (Error err) {
        Assert.fail("Error should Not be thrown here.");
    }

    EBMSMessageHistoryRequestData actualData = getHttpRequestData();
    Assert.assertEquals(expectData.getMessageId(), actualData.getMessageId());
    Assert.assertEquals(expectData.getService(), actualData.getService());
    Assert.assertEquals(expectData.getAction(), actualData.getAction());
    Assert.assertEquals(expectData.getCpaId(), actualData.getCpaId());
    Assert.assertEquals(expectData.getConversationId(), actualData.getConversationId());

    Assert.assertTrue("inbox".equalsIgnoreCase(actualData.getMessageBox()));
    Assert.assertTrue("DL".equalsIgnoreCase(actualData.getStatus()));

}

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

@Before
public void setUp() throws IOException {

    System.out.println("Load test file from URL:"
            + this.getClass().getClassLoader().getResource("testcase/pageservice/samplepagecontent.txt"));
    URL samplePage = this.getClass().getClassLoader().getResource("testcase/pageservice/samplepagecontent.txt");
    content = FileUtils.readFileToString(new File(samplePage.getPath()));

    System.out.println("Load test file from URL:"
            + this.getClass().getClassLoader().getResource("testcase/pageservice/spacelist.txt"));
    URL spaceList = this.getClass().getClassLoader().getResource("testcase/pageservice/spacelist.txt");
    spaces = FileUtils.readLines(new File(spaceList.getPath()));

    HttpServletRequest request = new MockHttpServletRequest() {

        public String getRemoteUser() {
            return "admin";
        }/*from  w  w w.java  2 s  .com*/

    };
    ServletUtils.setRequest(request);
    //      MockServletContext servletContext = new MockServletContext();
    //      WebApplicationContext springContext;
    //      servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE   , springContext);
    //      ServletUtils.setServletContext(servletContext);

    Authentication authentication = new UsernamePasswordAuthenticationToken("admin", "admin");
    SecurityContextHolder.getContext().setAuthentication(authentication);
    //create spaces
    for (String uname : spaces) {
        Space space = new Space();
        space.setUnixName(uname);
        space.setName("Title:" + uname);
        space.setDescription("Description:" + uname);
        WikiUtil.setTouchedInfo(userReadingService, space);
        try {
            spaceService.createSpace(space);
        } catch (SpaceException e) {
            e.printStackTrace();
            Assert.fail(e.toString());
        }
    }
}

From source file:com.hybris.datahub.service.impl.DefaultJsonServiceTest.java

/**
 * convertTmallTradesJson/* w ww . j  a  v  a  2  s. c  o m*/
 *
 * @throws Exception
 */
@Test
public void convertTmallTradesJson() throws Exception {
    final Class<? extends DefaultJsonServiceTest> instance = getClass();
    if (instance != null) {
        final ClassLoader classLoader = instance.getClassLoader();
        if (classLoader != null) {

            String json = "";
            InputStream resourceAsStream = null;
            try {
                resourceAsStream = classLoader.getResourceAsStream(SAMPLE_TMALL_TRADES_JSON);
                json = IOUtils.toString(resourceAsStream);
            } catch (final IOException e) {
                LOG.error(e.getMessage(), e);
            } finally {
                if (resourceAsStream != null) {
                    try {
                        resourceAsStream.close();
                    } catch (final IOException e) {
                        LOG.error(e.getMessage(), e);
                    }
                }
            }
            final List<Map<String, String>> csv = service.parse(json);
            final Map<String, String> raw = csv.get(0);

            Assert.assertTrue(raw.containsKey("marketplaceStoreName"));
            Assert.assertTrue(raw.containsKey("currency"));
            Assert.assertTrue(raw.containsKey("productCatalogVersion"));
            Assert.assertTrue(raw.containsKey("trades"));

            Assert.assertEquals("CNY", raw.get("currency"));
            Assert.assertEquals("electronics-cnProductCatalog:Online", raw.get("productCatalogVersion"));

            final Map<String, String> rawTrade = service.parse(raw.get("trades")).get(0);

            Assert.assertEquals("2100703549093", rawTrade.get("numIid"));
            Assert.assertEquals("TRADE_CLOSED_BY_TAOBAO", rawTrade.get("status"));
        }
    } else {
        Assert.fail("Class not found.");
    }
}

From source file:example.crm.CrmIT.java

/**
 * HTTP GET http://localhost:9003/customers/123/orders
 * returns the JSON document representing the orders for customer 123
 *//* w  ww.  j  a v  a 2s.  c o  m*/
@Test
public void getProductOrderTest() throws Exception {

    LOG.info("Sent HTTP GET request to query sub resource product info");
    url = new URL(CUSTOMER_ORDERS_TEST_URL);
    try {
        in = url.openStream();
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_ORDERS_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("product 323"));
}

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

@Test
public void testInsertIdentities() {

    try {//w  w w  .  j a v a  2s . c o m
        this.userAccountDao.saveIdentities(this.testUserAccount);

        UserAccount userAccount = userAccountDao.getUserAccountByUsername("testuser");
        Assert.assertNotNull(userAccount.getIdentities());
        Assert.assertTrue("identities not loaded!", userAccount.getIdentities().size() >= 4);
        Assert.assertEquals(userAccount, userAccount.getIdentities().get(0).getUserAccount());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        Assert.fail(e.getMessage());
    }
}

From source file:de.fhg.iais.cortex.search.SolrSearchServerTest.java

@Test
public void testStart() throws Exception {
    SolrSearchServer solrSearchServer = new SolrSearchServer(this.homeMock, this.factoryMock, this.CONTEXT_URI,
            this.SOLR_SEARCH_DIR, this.SOLR_NODESTORE_DIR, this.SOLR_ENTITY_DIR);

    Jetty9SolrRunner runnerMock = Mockito.mock(Jetty9SolrRunner.class);
    Mockito.when(this.factoryMock.createJetty9SolrRunner(new File(this.baseDir, "solr").getAbsolutePath(), "",
            8183, false, 5000)).thenReturn(runnerMock);

    try {/*from   ww w  .j a va2s .  c o  m*/
        solrSearchServer.doStart();
    } catch (DbcException e) {
        Assert.fail("Should not throw a DbcException.");
    }

    try {
        solrSearchServer.doStart();
    } catch (DbcException e) {
        Assert.fail("Should not throw a DbcException.");
    }

    Mockito.verify(runnerMock, Mockito.times(1)).start(false);
    Mockito.verify(this.factoryMock, Mockito.times(1))
            .createJetty9SolrRunner(new File(this.baseDir, "solr").getAbsolutePath(), "", 8183, false, 5000);

    Assert.assertEquals(System.getProperty("solr.data.index.dir"), this.SOLR_SEARCH_DIR);
    Assert.assertEquals(System.getProperty("solr.nodestore.index.dir"), this.SOLR_NODESTORE_DIR);
    Assert.assertEquals(System.getProperty("solr.entity.index.dir"), this.SOLR_ENTITY_DIR);
    Assert.assertEquals(System.getProperty("javax.xml.parsers.DocumentBuilderFactory"),
            "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");

}

From source file:de.hybris.vjdbc.VirtualDriverTest.java

@Test
public void testConnectWithAcceptedFlexUrl() throws Exception {
    final Properties props = new Properties();

    Mockito.when(commandSinkProvider.create(Mockito.eq("//baz?flexMode=true"), Mockito.eq(OF_EMPTY_MAP)))
            .thenThrow(new ExpectedException());

    try {//from w w w  .  j ava 2  s.c  om
        driver.connect("jdbc:hybris:flexiblesearch://baz", props);
        Assert.fail("should have failed");
    } catch (SQLException e) {
        assertFirstLineOfSQLException("de.hybris.vjdbc.VirtualDriverTest$ExpectedException", e);
    }

    Mockito.verify(virtualConnectionBuilder).setProperties(props);
    Mockito.verify(virtualConnectionBuilder, Mockito.times(0)).setUrl("");
    Mockito.verify(virtualConnectionBuilder)
            .setDataSourceString(Mockito.eq(VjdbcConnectionStringParser.VJDBC_DEFAULT_DATASOURCE));
}