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:my.adam.smo.EncryptionTest.java

@Test
public void symetricEncryptionShortMessage() {
    ApplicationContext clientContext = new ClassPathXmlApplicationContext("Context.xml");
    SymmetricEncryptionBox box = clientContext.getBean(SymmetricEncryptionBox.class);
    int plainTextLength = 3;

    byte[] plainText = new byte[plainTextLength];
    random.nextBytes(plainText);/*w w w . j  a v a 2s .  c  o m*/

    byte[] cryptogram = box.encrypt(plainText);
    Assert.assertFalse("plain text leaked!!!", Arrays.equals(plainText,
            Arrays.copyOfRange(cryptogram, SymmetricEncryptionBox.ivLength, cryptogram.length)));

    byte[] decrypted = box.decrypt(cryptogram);
    Assert.assertTrue("unable to decrypt", Arrays.equals(plainText, decrypted));
}

From source file:mx.com.adolfogarcia.popularmovies.data.TestUtilities.java

/**
 * Inserts the values returned by {@link #createMadMaxMovieValues()} into
 * the movie database./*from   w w w .  j av  a  2s.  c  o m*/
 *
 * @param context the {@link Context} used to access the database.
 * @return the row id of the insertion.
 */
static long insertMadMaxMovieValues(Context context) {
    MovieDbHelper dbHelper = new MovieDbHelper(context);
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    ContentValues testValues = TestUtilities.createMadMaxMovieValues();

    long rowId;
    rowId = db.insert(CachedMovieEntry.TABLE_NAME, null, testValues);
    Assert.assertTrue("Row was successfully inserted", rowId != -1);
    return rowId;
}

From source file:com.ibm.cloud.appid.android.LicenseCheck.java

@Test
public void testLicensesHeaders() {
    try {//  w  w  w .j a  v  a  2 s.c o  m
        List<String> missingLicenseFiles = new ArrayList<>();
        File sourceDir = new File(new File("").getAbsolutePath() + "/lib/src/main/java/com/ibm/");
        File sourceTestDir = new File(new File("").getAbsolutePath() + "/lib/src/test/java/com/ibm/");
        List<File> sourceFiles = getListFiles(sourceDir);
        List<File> testsFiles = getListFiles(sourceTestDir);
        sourceFiles.addAll(testsFiles);
        for (File file : sourceFiles) {
            FileInputStream fisTargetFile = new FileInputStream(file);
            String targetFileStr = IOUtils.toString(fisTargetFile, "UTF-8");
            if (!targetFileStr.startsWith(LICENSE)) {
                missingLicenseFiles.add(file.getPath());
            }
        }
        Assert.assertTrue(
                "The following files missing the IBM License header: " + missingLicenseFiles.toString(),
                missingLicenseFiles.isEmpty());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

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

From source file:org.sakaiproject.crudplus.dao.test.CrudPlusDaoImplTest.java

protected void onSetUpInTransaction() {
    // load the spring created dao class bean from the Spring Application Context
    dao = (CrudPlusDao) applicationContext.getBean("org.sakaiproject.crudplus.dao.CrudPlusDao");
    if (dao == null) {
        log.error("onSetUpInTransaction: DAO could not be retrieved from spring context");
    }/*from   w  ww.  java  2  s .  com*/

    // init the class if needed

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

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

From source file:eu.stratosphere.nephele.services.iomanager.IOManagerITCase.java

@After
public void afterTest() throws Exception {
    ioManager.shutdown();/* w  w  w . j a v a 2s  . c  o  m*/
    Assert.assertTrue("IO Manager has not properly shut down.", ioManager.isProperlyShutDown());

    Assert.assertTrue("Not all memory was returned to the memory manager in the test.",
            memoryManager.verifyEmpty());
    memoryManager.shutdown();
    memoryManager = null;
}

From source file:org.atemsource.atem.impl.common.attribute.PrimitiveAttributeTest.java

@Test
public void testAttributeType() {
    EntityA entity = new EntityA();
    for (String propertyName : propertyNames) {
        Assert.assertTrue("cannot find property " + propertyName, entityTypeRepository.getEntityType(entity)
                .getAttribute(propertyName) instanceof SingleAttribute);
    }/*from   w  w w  .j  a v a2s .co  m*/
}

From source file:net.sf.dynamicreports.test.jasper.chart.Pie3DChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);//ww  w . j  a v  a 2  s .  com

    JFreeChart chart = getChart("summary.chart1", 0);
    Plot plot = chart.getPlot();
    Assert.assertEquals("plot", PiePlot3D.class, plot.getClass());
    Assert.assertTrue("circular", ((PiePlot) plot).isCircular());
    Assert.assertEquals("label format", "label {0}",
            ((StandardPieSectionLabelGenerator) ((PiePlot) plot).getLabelGenerator()).getLabelFormat());
    Assert.assertEquals("legend label format", "legend label {0}",
            ((StandardPieSectionLabelGenerator) ((PiePlot) plot).getLegendLabelGenerator()).getLabelFormat());
    Assert.assertEquals("depth factor", 0.5, ((PiePlot3D) plot).getDepthFactor());

    chart = getChart("summary.chart2", 0);
    plot = chart.getPlot();
    Assert.assertNull("label format", ((PiePlot) plot).getLabelGenerator());
}

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

@Test
public void testExternalBlockCrossTask() {

    int keyCnt1 = 2;
    int valCnt1 = 1;

    // 43690 fit into memory, 43691 do not!
    int keyCnt2 = 43700;
    int valCnt2 = 1;

    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 {/*ww w .j a va 2s.co  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.wso2.ei.businessprocess.integration.tests.bpmn.rest.BPMNRestTasksTest.java

@Test(groups = { "wso2.bps.bpmn.rest" }, description = "get tasks", priority = 1, singleThreaded = true)
public void testGetTasks() throws Exception {
    String processId = null;/*from w  ww  . j  ava 2s .  c om*/
    //start one task process
    for (BPMNProcess process : workflowServiceClient.getProcesses()) {
        if (process.getKey().equals("oneTaskProcess")) {
            processId = process.getProcessId();
            workflowServiceClient.getInstanceServiceStub().startProcess(processId);
            break;
        }
    }

    HttpResponse response = BPMNTestUtils.getRequestResponse(backEndUrl + tasksUrl);
    JSONObject jsonObject = new JSONObject(EntityUtils.toString(response.getEntity()));
    Assert.assertEquals("runtime/tasks test", 200, response.getStatusLine().getStatusCode());
    Assert.assertTrue("runtime/tasks test", jsonObject.getInt("total") > 0);

    response = BPMNTestUtils.getRequestResponse(backEndUrl + tasksUrl + "?name=my+task");
    jsonObject = new JSONObject(EntityUtils.toString(response.getEntity()));
    Assert.assertEquals("runtime/tasks?name= test", "my task",
            ((JSONObject) ((JSONArray) jsonObject.get("data")).get(0)).getString("name"));

    //start another instance, which will start another task
    workflowServiceClient.getInstanceServiceStub().startProcess(processId);

    response = BPMNTestUtils.getRequestResponse(backEndUrl + tasksUrl + "?order=desc");
    jsonObject = new JSONObject(EntityUtils.toString(response.getEntity()));
    Assert.assertTrue("runtime/tasks?order=desc test",
            ((JSONObject) ((JSONArray) jsonObject.get("data")).get(0))
                    .getInt("id") > ((JSONObject) ((JSONArray) jsonObject.get("data")).get(1)).getInt("id"));

    int taskId = ((JSONObject) ((JSONArray) jsonObject.get("data")).get(0)).getInt("id");
    response = BPMNTestUtils.getRequestResponse(backEndUrl + tasksUrl + "/" + taskId);
    jsonObject = new JSONObject(EntityUtils.toString(response.getEntity()));
    Assert.assertEquals("runtime/tasks/{taskId} test", taskId, jsonObject.getInt("id"));

    //update task
    String updateBody = "{\"owner\":\"owner\", \"priority\":\"20\"}";
    response = BPMNTestUtils.putRequest(backEndUrl + tasksUrl + "/" + taskId, new JSONObject(updateBody));
    jsonObject = new JSONObject(EntityUtils.toString(response.getEntity()));
    Assert.assertEquals("PUT runtime/tasks/{taskId} test", 20, jsonObject.getInt("priority"));
    Assert.assertEquals("PUT runtime/tasks/{taskId} test", "owner", jsonObject.getString("owner"));

    //update none existing task
    response = BPMNTestUtils.putRequest(backEndUrl + tasksUrl + "/0", new JSONObject(updateBody));
    Assert.assertEquals("PUT runtime/tasks/{taskId} test", 404, response.getStatusLine().getStatusCode());

    //task actions
    String claimRequest = "{\"action\":\"claim\",\"assignee\":\"userWhoClaims\"}";
    response = BPMNTestUtils.postRequest(backEndUrl + tasksUrl + "/" + taskId, new JSONObject(claimRequest));
    Assert.assertEquals("POST runtime/tasks/{taskId}  claim test", 200,
            response.getStatusLine().getStatusCode());
    response = BPMNTestUtils.getRequestResponse(backEndUrl + tasksUrl + "/" + taskId);
    jsonObject = new JSONObject(EntityUtils.toString(response.getEntity()));
    Assert.assertEquals("POST runtime/tasks/{taskId}  claim test", "userWhoClaims",
            jsonObject.getString("assignee"));

    String delegateRequest = "{\"action\":\"delegate\",\"assignee\":\"delegatedUser\"}";
    response = BPMNTestUtils.postRequest(backEndUrl + tasksUrl + "/" + taskId, new JSONObject(delegateRequest));
    Assert.assertEquals("POST runtime/tasks/{taskId}  delegate test", 200,
            response.getStatusLine().getStatusCode());
    response = BPMNTestUtils.getRequestResponse(backEndUrl + tasksUrl + "/" + taskId);
    jsonObject = new JSONObject(EntityUtils.toString(response.getEntity()));
    Assert.assertEquals("POST runtime/tasks/{taskId}  claim test", "delegatedUser",
            jsonObject.getString("assignee"));

    //resolve
    String resolve = "{\"action\":\"resolve\"}";
    response = BPMNTestUtils.postRequest(backEndUrl + tasksUrl + "/" + taskId, new JSONObject(resolve));
    Assert.assertEquals("POST runtime/tasks/{taskId}  resolve test", 200,
            response.getStatusLine().getStatusCode());
    response = BPMNTestUtils.getRequestResponse(backEndUrl + tasksUrl + "/" + taskId);
    jsonObject = new JSONObject(EntityUtils.toString(response.getEntity()));
    Assert.assertEquals("POST runtime/tasks/{taskId}  claim test", "owner", jsonObject.getString("assignee"));

    //claim
    claimRequest = "{\"action\":\"claim\"}";
    BPMNTestUtils.postRequest(backEndUrl + tasksUrl + "/" + taskId, new JSONObject(claimRequest));

    //complete
    String complete = "{\"action\":\"complete\"}";
    response = BPMNTestUtils.postRequest(backEndUrl + tasksUrl + "/" + taskId, new JSONObject(complete));
    Assert.assertEquals("POST runtime/tasks/{taskId}  resolve test", 200,
            response.getStatusLine().getStatusCode());
    response = BPMNTestUtils.getRequestResponse(backEndUrl + tasksUrl + "/" + taskId);
    //should not exist such task
    Assert.assertEquals("POST runtime/tasks/{taskId}  claim test", 404,
            response.getStatusLine().getStatusCode());

    //delete a task
    workflowServiceClient.getInstanceServiceStub().startProcess(processId);
    String result = BPMNTestUtils.getRequest(backEndUrl + tasksUrl);
    jsonObject = new JSONObject(result);
    taskId = ((JSONObject) ((JSONArray) jsonObject.get("data")).get(0)).getInt("id");
    response = BPMNTestUtils.deleteRequest(backEndUrl + tasksUrl + "/" + taskId);
    Assert.assertEquals("DELETE runtime/tasks/{taskId}  claim test", 200,
            response.getStatusLine().getStatusCode());
    response = BPMNTestUtils.getRequestResponse(backEndUrl + tasksUrl + "/" + taskId);
    Assert.assertEquals("DELETE runtime/tasks/{taskId}  claim test", 404,
            response.getStatusLine().getStatusCode());
}