Example usage for junit.framework Assert assertTrue

List of usage examples for junit.framework Assert assertTrue

Introduction

In this page you can find the example usage for junit.framework Assert assertTrue.

Prototype

static public void assertTrue(String message, boolean condition) 

Source Link

Document

Asserts that a condition is true.

Usage

From source file:org.wso2.carbon.esb.api.apidefinition.ESBJAVA4907SwaggerGenerationTestCase.java

@Test(groups = "wso2.esb", description = "Test API definition request is served correctly")
public void apiDefinitionRequestTest() throws Exception {
    String restURL = getMainSequenceURL() + "StockQuoteAPI?swagger.json";
    SimpleHttpClient httpClient = new SimpleHttpClient();
    HttpResponse response = httpClient.doGet(restURL, null);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    response.getEntity().writeTo(baos);//from w  ww  .j  a v a  2s . com

    log.info("Swagger Definition Response : " + baos.toString());
    Assert.assertTrue("Swagger definition did not contained in the response",
            baos.toString().contains("API Definition of StockQuoteAPI"));
}

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

@Test
public void testSingleLevelMergeReduceTask() {
    final int keyCnt = 8192;
    final int valCnt = 8;

    setNumFileHandlesForSort(2);//from  ww w. j av a2 s  .  c om

    addInputComparator(this.comparator);
    setOutput(this.outList);
    getTaskConfig().setDriverStrategy(DriverStrategy.SORTED_GROUP_REDUCE);

    try {
        addInputSorted(new UniformRecordGenerator(keyCnt, valCnt, false), this.comparator.duplicate());

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

        testDriver(testTask, MockReduceStub.class);
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Exception in Test.");
    }

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

}

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

@Test
public void testBlock1CrossTask() {
    int keyCnt1 = 10;
    int valCnt1 = 1;

    int keyCnt2 = 100;
    int valCnt2 = 4;

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

    super.registerTask(testTask, MockCrossStub.class);

    try {//from   w  w w  .ja v a 2s  .c o  m
        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:org.thingsplode.server.repositories.RepositoryTest.java

@Test
public void testDeleteConfigs() throws UnknownHostException {
    Device d1 = deviceRepo.save(TestFactory.createDevice("test_device_1", "1231234235", "1"));
    d1 = deviceRepo.save(d1);//  ww w .j a  v a 2s  . c o  m
    //d1.getConfiguration().removeAll(d1.getConfiguration());
    d1.getConfiguration().clear();
    d1 = deviceRepo.save(d1);
    int orphanConfigs = this.getCountWhere(Configuration.TABLE_NAME, Component.COMP_REF + " is null");
    Assert.assertTrue("the orphan configs should be null", orphanConfigs == 0);
    d1.getComponents().forEach((c) -> {
        System.out.println("=============> Clearing configurations for component: " + c.getIdentification());
        c.getConfiguration().clear();
    });
    d1 = deviceRepo.save(d1);
    Assert.assertTrue("the orphan configs should be null", orphanConfigs == 0);
}

From source file:org.wso2.ei.businessprocess.integration.tests.bpmn.rest.BPMNRestProcessInstancesTest.java

@Test(groups = {
        "wso2.bps.bpmn.rest" }, description = "get process instances", priority = 1, singleThreaded = true)
public void testGetProcessInstances() throws Exception {
    BPMNProcess[] bpmnProcesses = workflowServiceClient.getProcesses();
    BPMNInstanceServiceStub bpmnInstanceServiceStub = workflowServiceClient.getInstanceServiceStub();
    for (BPMNProcess process : bpmnProcesses) {
        bpmnInstanceServiceStub.startProcess(process.getProcessId());
    }//from   w  w  w .  jav a  2  s  .c om

    //HTTP get request
    String result = BPMNTestUtils.getRequest(backEndUrl + instanceUrl);
    JSONObject jsonObject = new JSONObject(result);
    Assert.assertEquals("runtime/process-instances/ test", workflowServiceClient.getProcessInstances().length,
            jsonObject.getInt("total"));
    Assert.assertTrue("runtime/process-instances/ test",
            jsonObject.getString("data").contains(bpmnProcesses[0].getProcessId()));
    Assert.assertTrue("runtime/process-instances/ test",
            jsonObject.getString("data").contains(bpmnProcesses[1].getProcessId()));

    //send request with ?id= parameter
    result = BPMNTestUtils.getRequest(
            backEndUrl + instanceUrl + "?id=" + workflowServiceClient.getProcessInstances()[0].getInstanceId());
    jsonObject = new JSONObject(result);
    Assert.assertEquals("runtime/process-instances?id= test",
            workflowServiceClient.getProcessInstances()[0].getInstanceId(),
            ((JSONObject) ((JSONArray) (jsonObject.get("data"))).get(0)).getString("id"));

    //send request with "?processDefinitionId=" parameter
    result = BPMNTestUtils
            .getRequest(backEndUrl + instanceUrl + "?processDefinitionId=" + bpmnProcesses[0].getProcessId());
    jsonObject = new JSONObject(result);
    Assert.assertEquals("runtime/process-instances?processDefinitionId= test", bpmnProcesses[0].getProcessId(),
            ((JSONObject) ((JSONArray) (jsonObject.get("data"))).get(0)).getString("processDefinitionId"));

    result = BPMNTestUtils.getRequest(backEndUrl + instanceUrl + "?processDefinitionId=" + "nonExistingId");
    jsonObject = new JSONObject(result);
    Assert.assertEquals("runtime/process-instances?processDefinitionId= test", 0, jsonObject.getInt("total"));

    //send request with "?suspended=" parameter
    result = BPMNTestUtils.getRequest(backEndUrl + instanceUrl + "?suspended=false");
    jsonObject = new JSONObject(result);
    Assert.assertEquals("runtime/process-instances?suspended= test",
            workflowServiceClient.getProcessInstances().length, jsonObject.getInt("total"));

    //send request with /{instanceId}
    result = BPMNTestUtils.getRequest(
            backEndUrl + instanceUrl + "/" + workflowServiceClient.getProcessInstances()[0].getInstanceId());
    jsonObject = new JSONObject(result);
    Assert.assertEquals("runtime/process-instances/{instanceId} test",
            workflowServiceClient.getProcessInstances()[0].getInstanceId(), jsonObject.getString("id"));

}

From source file:org.openspaces.eviction.test.LRUSingleOrderTest.java

@Override
protected void assertMultiThreadedOperationsTest() {
    Assert.assertTrue("more silver or bronze than gold",
            gigaSpace.count(new GoldMedal()) > gigaSpace.count(new SilverMedal())
                    && gigaSpace.count(new GoldMedal()) > gigaSpace.count(new BronzeMedal()));
}

From source file:org.sakaiproject.iclicker.dao.IClickerDaoImplTest.java

protected void onSetUpInTransaction() {
    // load the spring created dao class bean from the Spring Application Context
    dao = (IClickerDao) applicationContext.getBean("org.sakaiproject.iclicker.dao.IClickerDao");
    if (dao == null) {
        throw new NullPointerException("DAO could not be retrieved from spring context");
    }//from w ww.j  av  a  2 s  .  com

    // load up the test data preloader from spring
    tdp = (FakeDataPreload) applicationContext.getBean("org.sakaiproject.iclicker.logic.test.FakeDataPreload");
    if (tdp == null) {
        throw new NullPointerException("FakeDataPreload could not be retrieved from spring context");
    }

    // init the class if needed

    // check the preloaded data
    Assert.assertTrue("Error preloading data", dao.countAll(ClickerRegistration.class) > 0);

    // preload data if desired
    dao.save(item);
    dao.save(item2);
}

From source file:com.datatorrent.lib.io.HttpOutputOperatorTest.java

@Test
public void testHttpOutputNode() throws Exception {

    final List<String> receivedMessages = new ArrayList<String>();
    Handler handler = new AbstractHandler() {
        @Override/*from   ww w  . j a v  a  2 s  .  c o m*/
        @Consumes({ MediaType.APPLICATION_JSON })
        public void handle(String string, Request rq, HttpServletRequest request, HttpServletResponse response)
                throws IOException, ServletException {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            IOUtils.copy(request.getInputStream(), bos);
            receivedMessages.add(new String(bos.toByteArray()));
            response.setContentType("text/html");
            response.setStatus(HttpServletResponse.SC_OK);
            response.getWriter().println("<h1>Thanks</h1>");
            ((Request) request).setHandled(true);
            receivedMessage = true;
        }
    };

    Server server = new Server(0);
    server.setHandler(handler);
    server.start();

    String url = "http://localhost:" + server.getConnectors()[0].getLocalPort() + "/somecontext";
    System.out.println("url: " + url);

    HttpOutputOperator<Object> node = new HttpOutputOperator<Object>();
    node.setResourceURL(new URI(url));

    node.setup(null);

    Map<String, String> data = new HashMap<String, String>();
    data.put("somekey", "somevalue");
    node.input.process(data);

    // Wait till the message is received or a maximum timeout elapses
    int timeoutMillis = 10000;
    while (!receivedMessage && timeoutMillis > 0) {
        timeoutMillis -= 20;
        Thread.sleep(20);
    }

    Assert.assertEquals("number requests", 1, receivedMessages.size());
    System.out.println(receivedMessages.get(0));
    JSONObject json = new JSONObject(data);
    Assert.assertTrue("request body " + receivedMessages.get(0),
            receivedMessages.get(0).contains(json.toString()));

    receivedMessages.clear();
    String stringData = "stringData";
    node.input.process(stringData);
    Assert.assertEquals("number requests", 1, receivedMessages.size());
    Assert.assertEquals("request body " + receivedMessages.get(0), stringData, receivedMessages.get(0));

    node.teardown();
    server.stop();
}

From source file:net.carinae.dev.async.TasksIntegrationTest.java

/**
 * Schedules a simple task for 10 seconds in the future and waits for 5
 * minutes for it to be executed.//w ww  .  j a  va 2  s.  c o m
 */
@Test
public void testScheduledSimpleTask() throws InterruptedException {

    String data = "" + System.nanoTime();

    scheduleSimpleTask(data);

    // Now, try to read from the database
    int tries = 0;
    while (tries < 300 && pollDummyEntity(data)) {
        Thread.sleep(1000); // 1 second
        tries++;
    }

    Assert.assertTrue("Scheduled task didn't execute in 5 minutes time", tries < 300);
}

From source file:net.padaf.preflight.TestIsartorValidationFromClasspath.java

@Test()
public void validate() throws Exception {
    ValidationResult result = null;/*from   ww w .  jav  a2  s  .co  m*/
    try {
        InputStream input = this.getClass().getResourceAsStream(path);
        ByteArrayDataSource bds = new ByteArrayDataSource(input);
        result = validator.validate(bds);
        Assert.assertFalse(path + " : Isartor file should be invalid (" + path + ")", result.isValid());
        Assert.assertTrue(path + " : Should find at least one error", result.getErrorsList().size() > 0);
        // could contain more than one error
        boolean found = false;
        for (ValidationError error : result.getErrorsList()) {
            if (error.getErrorCode().equals(this.expectedError)) {
                found = true;
            }
            if (isartorResultFile != null) {
                String log = path.replace(".pdf", "") + "#" + error.getErrorCode() + "#" + error.getDetails()
                        + "\n";
                isartorResultFile.write(log.getBytes());
            }
        }

        if (result.getErrorsList().size() > 1) {
            if (!found) {
                StringBuilder message = new StringBuilder(100);
                message.append(path).append(" : Invalid error code returned. Expected ");
                message.append(this.expectedError).append(", found ");
                for (ValidationError error : result.getErrorsList()) {
                    message.append(error.getErrorCode()).append(" ");
                }
                Assert.fail(message.toString());
            }
        } else {
            Assert.assertEquals(path + " : Invalid error code returned.", this.expectedError,
                    result.getErrorsList().get(0).getErrorCode());
        }
    } catch (ValidationException e) {
        throw new Exception(path + " :" + e.getMessage(), e);
    } finally {
        if (result != null) {
            result.closePdf();
        }
    }
}