Example usage for junit.framework Assert assertNull

List of usage examples for junit.framework Assert assertNull

Introduction

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

Prototype

static public void assertNull(Object object) 

Source Link

Document

Asserts that an object is null.

Usage

From source file:com.ebay.cloud.cms.query.service.QueryPaginationByIdTest.java

@Test
public void testQueryIter00() {
    raptorContext.removeSortOn();//  w  ww. jav a2s  .  c o m
    String room = "Room";
    MetaClass metaClass = raptorMetaService.getMetaClass(room);
    PersistenceContext persistenceContext = createRaptorPersistentContext();
    BsonEntity entity = new BsonEntity(metaClass);
    final int CREATE_COUNT = 101;
    for (int i = 0; i < CREATE_COUNT; i++) {
        entity.removeField(InternalFieldEnum.ID.getName());
        entity.getNode().remove("_id");
        persistenceService.create(entity, persistenceContext);
    }
    long TOTAL_COUNT = 0;
    {
        QueryContext context = newQueryContext(RAPTOR_REPO, RAPTOR_MAIN_BRANCH_ID);
        context.setPaginationMode(PaginationMode.ID_BASED);
        context.setCountOnly(true);
        IQueryResult result = queryService.query(room, context);
        TOTAL_COUNT = result.getCount();
    }

    String queryStr = "Room";
    // clear skip/limit
    raptorContext.getCursor().setHint(-1);
    raptorContext.getCursor().setSkips(null);
    raptorContext.getCursor().setJoinCursorValues(null);
    raptorContext.getCursor().setSingleCursorValue(null);
    raptorContext.getCursor().setLimits(new int[] { CREATE_COUNT / 2 });
    raptorContext.setPaginationMode(PaginationMode.ID_BASED);
    IQueryResult result = queryService.query(queryStr, raptorContext);
    Assert.assertNull(result.getNextCursor().getJoinCursorValues());
    IEntity cursorValue = result.getNextCursor().getSingleCursorValue();
    int[] nextLimits = result.getNextCursor().getLimits();
    Assert.assertEquals(CREATE_COUNT / 2, nextLimits[0]);
    int fetchCount = 0;
    int count = 1;
    fetchCount = fetchCount + result.getEntities().size();
    while (result.hasMoreResults()) {
        Assert.assertFalse(result.getNextCursor().isJoinCursor());
        cursorValue = result.getNextCursor().getSingleCursorValue();
        Assert.assertNotNull(cursorValue);
        nextLimits = result.getNextCursor().getLimits();
        Assert.assertEquals(CREATE_COUNT / 2, nextLimits[0]);
        raptorContext.setCursor(result.getNextCursor());
        result = queryService.query(queryStr, raptorContext);
        fetchCount = fetchCount + result.getEntities().size();
        count++;
    }
    Assert.assertEquals(3, count);
    Assert.assertEquals(TOTAL_COUNT, fetchCount);
}

From source file:com.test.onesignal.MainOneSignalClassRunner.java

@Test
public void testPostNotification() throws Exception {
    OneSignalInit();/*from  w w w.j a v a2 s  . c  o  m*/

    OneSignal.PostNotificationResponseHandler handler = new OneSignal.PostNotificationResponseHandler() {
        @Override
        public void onSuccess(JSONObject response) {
            postNotificationSuccess = response;
        }

        @Override
        public void onFailure(JSONObject response) {
            postNotificationFailure = response;
        }
    };

    // Not testing input here, just that HTTP 200 fires a success.
    OneSignal.postNotification("{}", handler);
    threadAndTaskWait();
    Assert.assertNotNull(postNotificationSuccess);
    Assert.assertNull(postNotificationFailure);
    postNotificationSuccess = postNotificationFailure = null;

    ShadowOneSignalRestClient.nextSuccessResponse = "{\"id\":\"\",\"recipients\":0,\"errors\":[\"All included players are not subscribed\"]}";
    OneSignal.postNotification("{}", handler);
    Assert.assertNull(postNotificationSuccess);
    Assert.assertNotNull(postNotificationFailure);
}

From source file:fragment.web.AbstractConnectorControllerTest.java

@Test
@DirtiesContext/*ww  w. j ava 2  s. c  o m*/
public void testfetchAccountConfigurationsParamsWithoutEditor() {
    map = new ModelMap();
    ServiceInstance serviceInstance = serviceInstanceDao.find(1L);
    ConnectorConfigurationManager configurationManager = EasyMock
            .createMock(ConnectorConfigurationManager.class);
    ReflectionTestUtils.setField(controller, "connectorConfigurationManager", configurationManager);
    EasyMock.expect(configurationManager.getInstance(serviceInstance.getUuid())).andReturn(serviceInstance)
            .anyTimes();
    EasyMock.expect(configurationManager.getJspPath(serviceInstance.getService())).andReturn(null).anyTimes();
    EasyMock.replay(configurationManager);
    String result = controller.fetchAccountConfigurationsParams(serviceInstance.getUuid(),
            "51e89159-9257-4340-8396-944658ba2e4a", map, request);
    Assert.assertEquals("enable.service", result);
    Assert.assertEquals(map.get("tnc"), "");
    Assert.assertNull(map.get("accountConfigEditor"));
}

From source file:org.openmrs.module.paperrecord.PaperRecordServiceComponentTest.java

@Test
public void testMarkPaperRecordsAsMergedShouldMergeExistingPaperRecordRequests() throws Exception {

    Location paperRecordLocation = locationService.getLocation(1);
    Location someLocation = locationService.getLocation(2);
    Location anotherLocation = locationService.getLocation(3);

    Patient patient1 = patientService.getPatient(2);
    Patient patient2 = patientService.getPatient(6);

    // create a couple paper records
    PaperRecord paperRecord1 = paperRecordService.createPaperRecord(patient1, paperRecordLocation);
    PaperRecord paperRecord2 = paperRecordService.createPaperRecord(patient2, paperRecordLocation);

    // first, create a couple record requests
    PaperRecordRequest request1 = paperRecordService
            .requestPaperRecord(patient1, paperRecordLocation, someLocation).get(0);
    PaperRecordRequest request2 = paperRecordService
            .requestPaperRecord(patient2, paperRecordLocation, anotherLocation).get(0);
    request2.updateStatus(PaperRecordRequest.Status.SENT);
    paperRecordService.savePaperRecordRequest(request2);
    PaperRecordRequest request3 = paperRecordService
            .requestPaperRecord(patient2, paperRecordLocation, anotherLocation).get(0);

    Assert.assertEquals(2, paperRecordService.getOpenPaperRecordRequestsToCreate().size()); // sanity checks
    Assert.assertNull(paperRecordService.getMostRecentSentPaperRecordRequest(paperRecord1));
    Assert.assertNotNull(paperRecordService.getMostRecentSentPaperRecordRequest(paperRecord2));

    // now create the merge request & then mark it as merged
    paperRecordService.markPaperRecordsForMerge(paperRecord1, paperRecord2);
    PaperRecordMergeRequest mergeRequest = paperRecordService
            .getOpenPaperRecordMergeRequests(paperRecordLocation).get(0);
    paperRecordService.markPaperRecordsAsMerged(mergeRequest);

    // there should be no outstanding cretae requests (since we just cancel them)
    Assert.assertEquals(0, paperRecordService.getOpenPaperRecordRequestsToCreate().size());

    // the sent request should have been moved to the other paper record
    Assert.assertNotNull(paperRecordService.getMostRecentSentPaperRecordRequest(paperRecord1));
    Assert.assertNull(paperRecordService.getMostRecentSentPaperRecordRequest(paperRecord2));

}

From source file:com.test.onesignal.GenerateNotificationRunner.java

@Test
@Config(sdk = 21)/*from w w w  .  ja  v a 2  s .com*/
public void notificationExtenderServiceOverridePropertiesWithSummary() throws Exception {
    testNotificationExtenderServiceOverridePropertiesWithSummary();

    Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
    Iterator<Map.Entry<Integer, PostedNotification>> postedNotifsIterator = postedNotifs.entrySet().iterator();

    // Test - First notification should be the summary with the custom sound set.
    PostedNotification postedSummaryNotification = postedNotifsIterator.next().getValue();
    Assert.assertNotSame(Notification.DEFAULT_SOUND,
            postedSummaryNotification.notif.flags & Notification.DEFAULT_SOUND);
    Assert.assertEquals("content://media/internal/audio/media/32",
            postedSummaryNotification.notif.sound.toString());

    // Test - individual notification 1 should not play a sound
    PostedNotification notification = postedNotifsIterator.next().getValue();
    Assert.assertNotSame(Notification.DEFAULT_SOUND, notification.notif.flags & Notification.DEFAULT_SOUND);
    Assert.assertNull(notification.notif.sound);

    // Test - individual notification 2 should not play a sound
    notification = postedNotifsIterator.next().getValue();
    Assert.assertNotSame(Notification.DEFAULT_SOUND, notification.notif.flags & Notification.DEFAULT_SOUND);
    Assert.assertNull(notification.notif.sound);
}

From source file:com.connectsdk.service.FireTVServiceTest.java

@Test
public void testSubscribeMediaInfoShouldReturnNull() {
    Assert.assertNull(service.subscribeMediaInfo(null));
}

From source file:fragment.web.AbstractConnectorControllerTest.java

/**
 * Tests the getHandleState controller to verify whether its returning appropriate states given the tenant and service
 * instance/*from w  w  w  .java 2s .c  o m*/
 */
@Test
public void testGetHandleState() {
    Tenant tenant = createTenantWithOwner();
    ServiceInstance serviceInstance = serviceInstanceDao.find(1L);
    String handleState = controller.getHandleState(tenant, tenant.getUuid(), serviceInstance.getUuid());

    // The handle state must be null for a newly created tenant for any service instance
    Assert.assertNull(handleState);

    tenant = tenantService.getTenantByParam("id", "2", false);
    handleState = controller.getHandleState(tenant, tenant.getUuid(), serviceInstance.getUuid());

    // State should be same as the one mentioned in csv
    Assert.assertEquals(State.ACTIVE.name(), handleState);

    // State must be terminated once tenant is terminated
    tenantService.delete(tenant.getUuid(), "test deleting", null);
    handleState = controller.getHandleState(tenant, tenant.getUuid(), serviceInstance.getUuid());
    Assert.assertEquals(State.TERMINATED.name(), handleState);
}

From source file:au.com.gaiaresources.bdrs.controller.theme.ThemeControllerTest.java

@Test
public void testDownloadZip() throws Exception {
    ManagedFile mf = new ManagedFile();
    mf.setContentType("application/zip");
    mf.setFilename("testTheme.zip");
    mf.setCredit("");
    mf.setLicense("");
    mf.setDescription("");
    mf = managedFileDAO.save(mf);/*from w w  w  .  ja v  a2  s  .  co  m*/
    byte[] testTheme = createTestTheme(DEFAULT_CONFIG_VALUES);
    fileService.createFile(mf.getClass(), mf.getId(), mf.getFilename(), testTheme);

    login("root", "password", new String[] { Role.ROOT, Role.ADMIN });
    Portal portal = getRequestContext().getPortal();

    Map<String, ThemeElement> themeElementMap = new HashMap<String, ThemeElement>();
    List<ThemeElement> themeElements = new ArrayList<ThemeElement>(DEFAULT_CONFIG_VALUES.size());
    for (Map.Entry<String, String> entry : DEFAULT_CONFIG_VALUES.entrySet()) {
        ThemeElement te = new ThemeElement();
        te.setKey(entry.getKey());
        te.setDefaultValue(entry.getValue());
        te.setCustomValue(CUSTOM_CONFIG_VALUES.get(entry.getKey()));
        te.setType(ThemeElementType.TEXT);
        te = themeDAO.save(te);
        themeElements.add(te);
        themeElementMap.put(te.getKey(), te);
    }

    Theme expectedTheme = new Theme();
    expectedTheme.setActive(true);
    expectedTheme.setName("Test Theme");
    expectedTheme.setThemeFileUUID(mf.getUuid());
    expectedTheme.setCssFiles(new String[] { TEST_CSS_FILE_PATH });
    expectedTheme.setJsFiles(new String[] { TEST_JS_FILE_PATH });
    expectedTheme.setPortal(portal);
    expectedTheme.setThemeElements(themeElements);
    expectedTheme = themeDAO.save(expectedTheme);

    ZipUtils.decompressToDir(new ZipFile(fileService.getFile(mf, mf.getFilename()).getFile()),
            fileService.getTargetDirectory(expectedTheme, Theme.THEME_DIR_RAW, true));

    request.setMethod("GET");
    request.setRequestURI("/bdrs/admin/theme/downloadTheme.htm");
    request.setParameter("themeId", expectedTheme.getId().toString());

    ModelAndView mv = handle(request, response);
    Assert.assertNull(mv);
    Assert.assertEquals(testTheme.length, response.getContentLength());
    byte[] responseBytes = response.getContentAsByteArray();
    Assert.assertEquals(testTheme.length, responseBytes.length);
    /*for (int i = 0; i < testTheme.length && i < responseBytes.length; i++) {
    Assert.assertEquals("byte " + i + " of files is different", testTheme[i], responseBytes[i]);
    }*/
}

From source file:com.ebay.cloud.cms.query.service.QueryPaginationByIdTest.java

private void queryAndIterate(long TOTAL_COUNT, String query, QueryContext queryContext, Set<String> allIds,
        int step) throws Exception {
    queryContext.getCursor().setLimits(null);
    queryContext.getCursor().setSingleCursorValue(null);

    Set<String> fetchedIds = new HashSet<String>();
    IQueryResult result;/* w ww.  j  av  a2 s  .c o  m*/
    int fetchCount = 0;
    queryContext.getCursor().setLimits(new int[] { step });
    result = queryService.query(query, queryContext);
    List<String> repeatedIds = new ArrayList<String>();
    do {
        for (IEntity e : result.getEntities()) {
            if (fetchedIds.contains(e.getId())) {
                repeatedIds.add(e.getId());
            } else {
                fetchedIds.add(e.getId());
            }
            fetchCount++;
        }
        if (result.hasMoreResults()) {
            Assert.assertNotNull(result.getNextCursor());
            Assert.assertNull(result.getNextCursor().getSortOn());
            Assert.assertNull(result.getNextCursor().getJoinCursorValues());
            Assert.assertFalse(result.getNextCursor().isJoinCursor());
            queryContext.setCursor(result.getNextCursor());
            result = queryService.query(query, queryContext);
        } else {
            break;
        }
    } while (true);

    Set<String> missedIds = CollectionUtils.diffSet(allIds, fetchedIds);
    Assert.assertEquals("Missed Entity ids : " + missedIds, 0, missedIds.size());
    System.out.println(" repeated entity ids: " + new ObjectMapper().writeValueAsString(repeatedIds));
    if (TOTAL_COUNT != fetchCount) {
        Assert.fail(" repeated entity ids: " + new ObjectMapper().writeValueAsString(repeatedIds));
    }
    Assert.assertEquals(TOTAL_COUNT, fetchCount);
    Assert.assertEquals(0, repeatedIds.size());
    Assert.assertEquals(TOTAL_COUNT, fetchedIds.size());
    //        Assert.assertEquals(2, queryIterationCount);
    fetchedIds.clear();
    fetchCount = 0;
}

From source file:com.ebay.cloud.cms.query.service.QueryPaginationByIdTest.java

@Test
public void testSortOn_fieldProperty() {
    String query = SERVICE_INSTANCE + "{@_oid, @manifestRef.$_length}";
    // create service instance data
    raptorContext.getCursor().setSkips(null);
    raptorContext.getCursor().setLimits(null);
    raptorContext.setPaginationMode(PaginationMode.ID_BASED);
    raptorContext.getCursor().addSortOn("manifestRef._length");
    raptorContext.getCursor().setJoinCursorValues(null);
    raptorContext.getCursor().setSingleCursorValue(null);
    raptorContext.getCursor().setLimits(new int[] { 1 });
    IQueryResult result = queryService.query(query, raptorContext);
    Assert.assertTrue(result.hasMoreResults());
    Assert.assertEquals(1, result.getEntities().size());
    IEntity oldEntity = result.getEntities().get(0);
    Integer oldLength = (Integer) oldEntity.getFieldProperty("manifestRef", "_length");

    raptorContext.setCursor(result.getNextCursor());
    result = queryService.query(query, raptorContext);
    Assert.assertTrue(result.hasMoreResults());
    int nullToNotNull = 0;
    for (IEntity e : result.getEntities()) {
        Integer curLength = (Integer) e.getFieldProperty("manifestRef", "_length");
        if (curLength == null) {
            Assert.assertNull(oldLength);
        } else if (oldLength == null) {
            nullToNotNull++;/*w  w w  .  j a v a  2s. c  o m*/
        } else {
            Assert.assertTrue(curLength >= oldLength);
        }
        // swap
        oldLength = curLength;
    }
}