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(boolean condition) 

Source Link

Document

Asserts that a condition is true.

Usage

From source file:com.couchbase.lite.AttachmentsTest.java

@SuppressWarnings("unchecked")
public void testAttachments() throws Exception {

    String testAttachmentName = "test_attachment";

    BlobStore attachments = database.getAttachments();

    Assert.assertEquals(0, attachments.count());
    Assert.assertEquals(new HashSet<Object>(), attachments.allKeys());

    Status status = new Status();
    Map<String, Object> rev1Properties = new HashMap<String, Object>();
    rev1Properties.put("foo", 1);
    rev1Properties.put("bar", false);
    RevisionInternal rev1 = database.putRevision(new RevisionInternal(rev1Properties, database), null, false,
            status);/*from   w  w w.  j  a  va 2  s .  co m*/

    Assert.assertEquals(Status.CREATED, status.getCode());

    byte[] attach1 = "This is the body of attach1".getBytes();
    database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1), rev1.getSequence(),
            testAttachmentName, "text/plain", rev1.getGeneration());
    Assert.assertEquals(Status.CREATED, status.getCode());

    //We must set the no_attachments column for the rev to false, as we are using an internal
    //private API call above (database.insertAttachmentForSequenceWithNameAndType) which does
    //not set the no_attachments column on revs table
    try {
        ContentValues args = new ContentValues();
        args.put("no_attachments=", false);
        database.getDatabase().update("revs", args, "sequence=?",
                new String[] { String.valueOf(rev1.getSequence()) });
    } catch (SQLException e) {
        Log.e(Database.TAG, "Error setting rev1 no_attachments to false", e);
        throw new CouchbaseLiteException(Status.INTERNAL_SERVER_ERROR);
    }

    Attachment attachment = database.getAttachmentForSequence(rev1.getSequence(), testAttachmentName);
    Assert.assertEquals("text/plain", attachment.getContentType());
    InputStream is = attachment.getContent();
    byte[] data = IOUtils.toByteArray(is);
    is.close();
    Assert.assertTrue(Arrays.equals(attach1, data));

    Map<String, Object> innerDict = new HashMap<String, Object>();
    innerDict.put("content_type", "text/plain");
    innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE=");
    innerDict.put("length", 27);
    innerDict.put("stub", true);
    innerDict.put("revpos", 1);
    Map<String, Object> attachmentDict = new HashMap<String, Object>();
    attachmentDict.put(testAttachmentName, innerDict);

    Map<String, Object> attachmentDictForSequence = database.getAttachmentsDictForSequenceWithContent(
            rev1.getSequence(), EnumSet.noneOf(Database.TDContentOptions.class));
    Assert.assertEquals(attachmentDict, attachmentDictForSequence);

    RevisionInternal gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(),
            EnumSet.noneOf(Database.TDContentOptions.class));
    Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments");
    Assert.assertEquals(attachmentDict, gotAttachmentDict);

    // Check the attachment dict, with attachments included:
    innerDict.remove("stub");
    innerDict.put("data", Base64.encodeBytes(attach1));
    attachmentDictForSequence = database.getAttachmentsDictForSequenceWithContent(rev1.getSequence(),
            EnumSet.of(Database.TDContentOptions.TDIncludeAttachments));
    Assert.assertEquals(attachmentDict, attachmentDictForSequence);

    gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(),
            EnumSet.of(Database.TDContentOptions.TDIncludeAttachments));
    gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments");
    Assert.assertEquals(attachmentDict, gotAttachmentDict);

    // Add a second revision that doesn't update the attachment:
    Map<String, Object> rev2Properties = new HashMap<String, Object>();
    rev2Properties.put("_id", rev1.getDocId());
    rev2Properties.put("foo", 2);
    rev2Properties.put("bazz", false);
    RevisionInternal rev2 = database.putRevision(new RevisionInternal(rev2Properties, database),
            rev1.getRevId(), false, status);
    Assert.assertEquals(Status.CREATED, status.getCode());

    database.copyAttachmentNamedFromSequenceToSequence(testAttachmentName, rev1.getSequence(),
            rev2.getSequence());

    // Add a third revision of the same document:
    Map<String, Object> rev3Properties = new HashMap<String, Object>();
    rev3Properties.put("_id", rev2.getDocId());
    rev3Properties.put("foo", 2);
    rev3Properties.put("bazz", false);
    RevisionInternal rev3 = database.putRevision(new RevisionInternal(rev3Properties, database),
            rev2.getRevId(), false, status);
    Assert.assertEquals(Status.CREATED, status.getCode());

    byte[] attach2 = "<html>And this is attach2</html>".getBytes();
    database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach2), rev3.getSequence(),
            testAttachmentName, "text/html", rev2.getGeneration());

    // Check the 2nd revision's attachment:
    Attachment attachment2 = database.getAttachmentForSequence(rev2.getSequence(), testAttachmentName);

    Assert.assertEquals("text/plain", attachment2.getContentType());
    InputStream is2 = attachment2.getContent();
    data = IOUtils.toByteArray(is2);
    is2.close();
    Assert.assertTrue(Arrays.equals(attach1, data));

    // Check the 3rd revision's attachment:
    Attachment attachment3 = database.getAttachmentForSequence(rev3.getSequence(), testAttachmentName);
    Assert.assertEquals("text/html", attachment3.getContentType());
    InputStream is3 = attachment3.getContent();
    data = IOUtils.toByteArray(is3);
    is3.close();
    Assert.assertTrue(Arrays.equals(attach2, data));

    Map<String, Object> attachmentDictForRev3 = (Map<String, Object>) database
            .getAttachmentsDictForSequenceWithContent(rev3.getSequence(),
                    EnumSet.noneOf(Database.TDContentOptions.class))
            .get(testAttachmentName);
    if (attachmentDictForRev3.containsKey("follows")) {
        if (((Boolean) attachmentDictForRev3.get("follows")).booleanValue() == true) {
            throw new RuntimeException("Did not expected attachment dict 'follows' key to be true");
        } else {
            throw new RuntimeException("Did not expected attachment dict to have 'follows' key");
        }
    }

    // Examine the attachment store:
    Assert.assertEquals(2, attachments.count());
    Set<BlobKey> expected = new HashSet<BlobKey>();
    expected.add(BlobStore.keyForBlob(attach1));
    expected.add(BlobStore.keyForBlob(attach2));

    Assert.assertEquals(expected, attachments.allKeys());

    database.compact(); // This clears the body of the first revision
    Assert.assertEquals(1, attachments.count());

    Set<BlobKey> expected2 = new HashSet<BlobKey>();
    expected2.add(BlobStore.keyForBlob(attach2));
    Assert.assertEquals(expected2, attachments.allKeys());
}

From source file:org.ocpsoft.rewrite.prettyfaces.encoding.URLEncodingTest.java

@Test
public void testURLDecoding() throws Exception {
    browser.get(getBaseURL() + getContextPath() + "/encoding/Vra?ar?dis=Fooo Bar");
    Assert.assertTrue(browser.getPageSource().contains("/encoding/Vra%C4%8Dar?dis=Fooo+Bar"));
    Assert.assertTrue(browser.getPageSource().contains("beanPathText=Vra?ar"));
    Assert.assertTrue(browser.getPageSource().contains("beanQueryText=Fooo Bar"));
}

From source file:org.openmrs.web.controller.provider.ProviderFormControllerTest.java

/**
 * @verifies set attributes to void if the values is not set
 * @see org.openmrs.web.controller.provider.ProviderFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      String, String, String, String, org.openmrs.Provider,
 *      org.springframework.validation.BindingResult, org.springframework.ui.ModelMap)
 *///w  w w  .  j a  va 2 s.  c  om
@Test
public void onSubmit_shouldSetAttributesToVoidIfTheValueIsNotSet() throws Exception {
    executeDataSet(PROVIDERS_ATTRIBUTES_XML);
    Provider provider = Context.getProviderService().getProvider(1);
    ProviderAttributeType providerAttributeType = Context.getProviderService().getProviderAttributeType(1);
    providerAttributeType.setName("provider type");
    MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
    //If value is not set then void all the attributes.
    mockHttpServletRequest.setParameter("attribute." + providerAttributeType.getId() + ".existing[1]", "");
    BindException errors = new BindException(provider, "provider");
    ProviderFormController providerFormController = (ProviderFormController) applicationContext
            .getBean("providerFormController");
    providerFormController.onSubmit(mockHttpServletRequest, "save", null, null, null, provider, errors,
            createModelMap(providerAttributeType));
    Assert.assertEquals(1, provider.getAttributes().size());
    Assert.assertTrue(((ProviderAttribute) (provider.getAttributes().toArray()[0])).isVoided());

}

From source file:cz.incad.kramerius.document.DocumentServiceTest.java

@Test
public void testDocumentServiceFromPid() throws IOException, ParserConfigurationException, SAXException,
        LexerException, ProcessSubtreeException, SecurityException, NoSuchMethodException, OutOfRangeException {
    Injector injector = _DocumentServiceTestPrepare.prepareInjector("20", true);

    DocumentService docService = injector.getInstance(DocumentService.class);
    PreparedDocument doc = docService.buildDocumentAsFlat(PATHS_MAPPING.get(DataPrepare.DROBNUSTKY_PIDS[0]),
            "uuid:4a7ec660-af36-11dd-a782-000d606f5dc6", 3, new int[] { 300, 300 });

    List<AbstractPage> pages = doc.getPages();
    Assert.assertTrue(pages.size() == 3);

    String[] relsExtOrder = new String[] { "uuid:4a7ec660-af36-11dd-a782-000d606f5dc6",
            "uuid:4314ab50-b03b-11dd-89db-000d606f5dc6", "uuid:4a80c230-af36-11dd-ace4-000d606f5dc6" };
    for (int i = 0; i < relsExtOrder.length; i++) {
        AbstractPage page = pages.get(i);
        String pid = relsExtOrder[i];
        Assert.assertEquals(pid, page.getUuid());
    }/* w ww . j  a v  a 2  s.  c  om*/
}