Example usage for junit.framework Assert assertNotNull

List of usage examples for junit.framework Assert assertNotNull

Introduction

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

Prototype

static public void assertNotNull(Object object) 

Source Link

Document

Asserts that an object isn't null.

Usage

From source file:alpha.portal.webapp.filter.LocaleFilterTest.java

/**
 * Test set locale in session when session not null.
 * /*  ww w  .  j  av  a2 s .com*/
 * @throws Exception
 *             the exception
 */
public void testSetLocaleInSessionWhenSessionNotNull() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("locale", "es");

    final MockHttpServletResponse response = new MockHttpServletResponse();
    request.setSession(new MockHttpSession(null));

    this.filter.doFilter(request, response, new MockFilterChain());

    // session not null, should result in not null
    final Locale locale = (Locale) request.getSession().getAttribute(Constants.PREFERRED_LOCALE_KEY);
    Assert.assertNotNull(locale);
    Assert.assertNotNull(LocaleContextHolder.getLocale());
    Assert.assertEquals(new Locale("es"), locale);
}

From source file:org.openxdata.server.service.impl.SettingServiceTest.java

@Test
public void getSettings_shouldReturnAllSettings() throws Exception {

    List<SettingGroup> settingGroups = settingService.getSettings();

    Assert.assertNotNull(settingGroups);
    Assert.assertEquals(4, settingGroups.size());

    for (SettingGroup settingGroup : settingGroups) {

        String name = settingGroup.getName();
        List<Setting> settings = settingGroup.getSettings();
        Assert.assertNotNull(settings);//from   www .j ava  2s.  c  o  m

        if (name.equals("General")) {
            Assert.assertEquals(1, settings.size());
        } else if (name.equals("Date")) {
            Assert.assertEquals(6, settings.size());
        } else if (name.equals("Serialization")) {
            Assert.assertEquals(3, settings.size());
        } else if (name.equals("SMS")) {
            Assert.assertEquals(5, settings.size());
        } else {
            Assert.fail("Expected Setting group name: Date, General, Serialization or SMS");
        }
    }
}

From source file:io.cloudslang.samples.StandAloneTest.java

@Test(timeout = 20000)
public void baseStandAloneTest() {
    ExecutionPlan executionPlan = createExecutionPlan();
    TriggeringProperties triggeringProperties = TriggeringProperties.create(executionPlan);
    registerEventListener(EventConstants.SCORE_FINISHED_EVENT);
    long executionId = score.trigger(triggeringProperties);

    waitForAllEventsToArrive(1);//from ww  w  .j  a v a2s  .  c  o  m
    long finishEventExecutionId = (Long) ((Map) eventQueue.get(0).getData())
            .get(EventConstants.EXECUTION_ID_CONTEXT);
    Assert.assertNotNull(finishEventExecutionId);
    Assert.assertEquals(executionId, finishEventExecutionId);
}

From source file:ejportal.webapp.action.NutzungActionTest.java

/**
 * Test remove./* w ww. jav  a2s .  co m*/
 * 
 * @throws Exception
 *             the exception
 */
public void testRemove() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    ServletActionContext.setRequest(request);
    this.action.setDelete("");
    final Nutzung nutzung = new Nutzung();
    nutzung.setNutzungId(2L);
    this.action.setNutzungId(2L);
    Assert.assertEquals("success", this.action.delete());
    Assert.assertNotNull(request.getSession().getAttribute("messages"));
}

From source file:org.alfresco.mobile.android.test.api.services.ActivityStreamServiceTest.java

/** {@inheritDoc} */
protected void initSession() {
    if (alfsession == null) {
        alfsession = createRepositorySession();
    }//w  w w. j  a va  2 s  . c om

    // Retrieve Service
    activityStreamService = alfsession.getServiceRegistry().getActivityStreamService();
    docfolderservice = alfsession.getServiceRegistry().getDocumentFolderService();

    // Check Services
    Assert.assertNotNull(alfsession.getServiceRegistry());
    Assert.assertNotNull(activityStreamService);
    Assert.assertNotNull(docfolderservice);
}

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

@Before
public void initDB() {

    this.userAccountDao = this.applicationContext.getBean(IUserAccountDao.class);
    this.testUserAccount = this.applicationContext.getBean("testUserAccount", UserAccount.class);
    this.dataSource = this.applicationContext.getBean(SingleConnectionDataSource.class);
    DBManager manager = this.applicationContext.getBean(DBManager.class);

    try {/*from   w  w w  .  j  a va2  s .  c  o  m*/
        manager.initInternalDB();
        Long id = this.userAccountDao.saveUserAccount(testUserAccount);
        Assert.assertNotNull(id);
    } catch (SQLException e) {
        log.error(e.getMessage(), e);
        Assert.fail(e.getMessage());
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        Assert.fail(e.getMessage());
    }
}

From source file:org.atemsource.atem.impl.json.ArrayTypeImplTest.java

@Test
public void testMetaType() {
    EntityTypeBuilder builder = jsonRepository.createBuilder("test");
    builder.addSingleAttribute("text", String.class);
    EntityType<?> entityType = builder.createEntityType();
    Assert.assertNotNull(entityType.getAttribute("text").getMetaType());
}

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

/**
 * in DatabaseAttachment_Tests.m/*from   ww  w  . j  ava2 s .co m*/
 * - (void) test10_Attachments
 */
@SuppressWarnings("unchecked")
public void testAttachments() throws Exception {
    BlobStore attachments = database.getAttachmentStore();
    Assert.assertEquals(0, attachments.count());
    Assert.assertEquals(new HashSet<Object>(), attachments.allKeys());

    // Add a revision and an attachment to it:
    Status status = new Status(Status.OK);
    byte[] attach1 = "This is the body of attach1".getBytes();
    Map<String, Object> props = new HashMap<String, Object>();
    props.put("foo", 1);
    props.put("bar", false);
    props.put("_attachments", getAttachmentsDict(attach1, "attach", "text/plain", false));
    RevisionInternal rev1 = database.putRevision(new RevisionInternal(props), null, false, status);
    Assert.assertEquals(Status.CREATED, status.getCode());

    AttachmentInternal att = database.getAttachment(rev1, "attach");
    Assert.assertNotNull(att);
    Log.i(TAG, new String(att.getContent()));
    Assert.assertTrue(Arrays.equals(attach1, att.getContent()));
    Assert.assertEquals("text/plain", att.getContentType());
    Assert.assertEquals(AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, att.getEncoding());

    // Check the attachment dict:
    Map<String, Object> itemDict = new HashMap<String, Object>();
    itemDict.put("content_type", "text/plain");
    itemDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE=");
    itemDict.put("length", 27);
    itemDict.put("stub", true);
    itemDict.put("revpos", 1);
    Map<String, Object> attachmentDict = new HashMap<String, Object>();
    attachmentDict.put("attach", itemDict);
    RevisionInternal gotRev1 = database.getDocument(rev1.getDocID(), rev1.getRevID(), true);
    Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments");
    Assert.assertEquals(attachmentDict, gotAttachmentDict);

    // Check the attachment dict, with attachments included:
    itemDict.remove("stub");
    itemDict.put("data", Base64.encodeBytes(attach1));
    gotRev1 = database.getDocument(rev1.getDocID(), rev1.getRevID(), true);
    RevisionInternal expandedRev = gotRev1.copy();
    Assert.assertTrue(database.expandAttachments(expandedRev, 0, false, true, status));
    Assert.assertEquals(attachmentDict, expandedRev.getAttachments());

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

    // Add a third revision of the same document:
    byte[] attach2 = "<html>And this is attach2</html>".getBytes();
    props = new HashMap<String, Object>();
    props.put("_id", rev2.getDocID());
    props.put("foo", 2);
    props.put("bazz", false);
    props.put("_attachments", getAttachmentsDict(attach2, "attach", "text/html", false));
    RevisionInternal rev3 = database.putRevision(new RevisionInternal(props), rev2.getRevID(), false, status);
    Assert.assertEquals(Status.CREATED, status.getCode());

    // Check the 2nd revision's attachment:
    att = database.getAttachment(rev2, "attach");
    Assert.assertNotNull(att);
    Assert.assertEquals("text/plain", att.getContentType());
    Assert.assertEquals(AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, att.getEncoding());
    Assert.assertTrue(Arrays.equals(attach1, att.getContent()));

    expandedRev = rev2.copy();
    Assert.assertTrue(database.expandAttachments(expandedRev, 2, false, true, status));
    attachmentDict = new HashMap<String, Object>();
    itemDict = new HashMap<String, Object>();
    itemDict.put("stub", true);
    itemDict.put("revpos", 1);
    attachmentDict.put("attach", itemDict);
    Assert.assertEquals(attachmentDict, expandedRev.getAttachments());

    // Check the 3rd revision's attachment:
    att = database.getAttachment(rev3, "attach");
    Assert.assertNotNull(att);
    Assert.assertEquals("text/html", att.getContentType());
    Assert.assertEquals(AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, att.getEncoding());
    Assert.assertTrue(Arrays.equals(attach2, att.getContent()));

    expandedRev = rev3.copy();
    Assert.assertTrue(database.expandAttachments(expandedRev, 2, false, true, status));
    attachmentDict = new HashMap<String, Object>();
    itemDict = new HashMap<String, Object>();
    itemDict.put("content_type", "text/html");
    itemDict.put("data", "PGh0bWw+QW5kIHRoaXMgaXMgYXR0YWNoMjwvaHRtbD4=");
    itemDict.put("digest", "sha1-s14XRTXlwvzYfjo1t1u0rjB+ZUA=");
    itemDict.put("length", 32);
    itemDict.put("revpos", 3);
    attachmentDict.put("attach", itemDict);
    Map<String, Object> data = expandedRev.getAttachments();
    Assert.assertEquals(attachmentDict, expandedRev.getAttachments());

    // 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:gov.nih.nci.ncicb.tcga.dcc.common.webservice.WebServiceUtilFastTest.java

/**
 * Check that the given {@link WebApplicationException} is a <code>ValidationErrors</code> response with the expected values.
 *
 * @param response the {@link Response} to check
 * @param expectedStatusCode the expected status code
 * @param expectedInvalidValue the expected invalid value
 * @param expectedErrorMessage the expected error message
 * @param expectedMediaType the expected media type
 *//*from  ww  w  .  j  a  v a  2  s. co m*/
public static void checkValidationErrorsResponse(final Response response, final int expectedStatusCode,
        final String expectedInvalidValue, final String expectedErrorMessage, final String expectedMediaType) {

    Assert.assertEquals(expectedStatusCode, response.getStatus());

    final Object entity = response.getEntity();
    Assert.assertEquals(ValidationErrors.class, entity.getClass());
    final ValidationErrors validationErrors = (ValidationErrors) entity;
    Assert.assertNotNull(validationErrors);

    final List<ValidationErrors.ValidationError> validationErrorList = validationErrors.getValidationError();
    Assert.assertNotNull(validationErrorList);
    Assert.assertEquals(1, validationErrorList.size());

    final ValidationErrors.ValidationError validationError = validationErrorList.get(0);
    Assert.assertNotNull(validationError);
    Assert.assertEquals(expectedInvalidValue, validationError.getInvalidValue());
    Assert.assertEquals(expectedErrorMessage, validationError.getErrorMessage());

    final MultivaluedMap<String, Object> multivaluedMap = response.getMetadata();
    Assert.assertNotNull(multivaluedMap);

    final Object contentType = multivaluedMap.get("Content-Type");
    Assert.assertNotNull(contentType);
    assertTrue(contentType instanceof LinkedList);

    final LinkedList linkedList = (LinkedList) contentType;
    Assert.assertEquals(1, linkedList.size());
    Assert.assertEquals(expectedMediaType, linkedList.get(0).toString());
}

From source file:net.krautchan.data.KCThread.java

public synchronized void addPosting(KCPosting posting) {
    if (null == kcNummer) {
        kcNummer = posting.getKcNummer();
    }//from  w  ww .  jav  a2  s  . c o  m
    if (null == firstPostDate) {
        firstPostDate = posting.getCreated();
        makeDigest(posting);
    }
    if (null == this.getUri()) {
        this.setUri(posting.getUri());
    }
    if (null == this.getDbId()) {
        this.setDbId((long) this.getUri().hashCode());
    }
    if (null == digest) {
        makeDigest(posting);
    }
    lastPostDate = posting.getCreated();
    Long id = posting.getDbId();
    if (!postings.containsKey(id)) {
        posting.setThreadDbId(this.getDbId());
        postings.put(id, posting);
    }
    if ((null != previousLastKcNum) && (previousLastKcNum < posting.getKcNummer())) {
        previousLastKcNum = posting.getKcNummer();
    }
    Assert.assertNotNull(this.getDbId());
}