List of usage examples for junit.framework Assert assertNull
static public void assertNull(Object object)
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.EnhancedPushTests.java
public void testRegisterUnregisterTemplate() throws Throwable { Context context = getInstrumentation().getTargetContext(); final SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context.getApplicationContext()); final Container container = new Container(); final String handle = "handle"; final String templateName = "templateName"; String registrationId = "registrationId"; MobileServiceClient client = new MobileServiceClient(appUrl, appKey, context); client = client.withFilter(getUpsertTestFilter(registrationId)); final MobileServicePush push = client.getPush(); forceRefreshSync(push, handle);//from w w w . j a v a2s . c o m try { TemplateRegistration registration = push .registerTemplate(handle, templateName, "{ }", new String[] { "tag1" }).get(); container.registrationId = registration.getRegistrationId(); container.storedRegistrationId = sharedPreferences .getString(STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + templateName, null); push.unregisterTemplate(templateName).get(); container.unregister = sharedPreferences .getString(STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + templateName, null); Assert.assertEquals(registrationId, container.storedRegistrationId); Assert.assertEquals(registrationId, container.registrationId); Assert.assertNull(container.unregister); } catch (Exception exception) { if (exception instanceof ExecutionException) { container.exception = (Exception) exception.getCause(); } else { container.exception = exception; } fail(container.exception.getMessage()); } }
From source file:org.sakaiproject.crudplus.logic.test.CrudPlusLogicImplTest.java
/** * Test method for {@link org.sakaiproject.crudplus.logic.impl.CrudPlusLogicImpl#removeItem(org.sakaiproject.crudplus.model.CrudPlusItem)}. *//*from w w w . ja v a 2 s . com*/ public void testRemoveItem() { // set up mock objects with return values userDirectoryService.getCurrentUser(); // expect this to be called userDirectoryServiceControl.setReturnValue(new TestUser(USER_ID)); userDirectoryServiceControl.setReturnValue(new TestUser(MAINT_USER_ID)); userDirectoryServiceControl.setReturnValue(new TestUser(ADMIN_USER_ID)); userDirectoryServiceControl.setReturnValue(new TestUser(MAINT_USER_ID)); userDirectoryServiceControl.setReturnValue(new TestUser(USER_ID)); securityService.unlock(new TestUser(USER_ID), CrudPlusLogicImpl.ITEM_WRITE_ANY, SITE_REF); securityServiceControl.setReturnValue(false, MockControl.ZERO_OR_MORE); securityService.unlock(new TestUser(MAINT_USER_ID), CrudPlusLogicImpl.ITEM_WRITE_ANY, SITE_REF); securityServiceControl.setReturnValue(true, MockControl.ZERO_OR_MORE); // activate the mock objects userDirectoryServiceControl.replay(); securityServiceControl.replay(); toolManagerControl.replay(); siteServiceControl.replay(); // mock object is needed here try { logicImpl.removeItem(adminitem); // user cannot delete this Assert.fail("Should have thrown SecurityException"); } catch (SecurityException e) { Assert.assertNotNull(e.getMessage()); log.info("Could not remove item (this is correct)"); } try { logicImpl.removeItem(adminitem); // permed user cannot delete this Assert.fail("Should have thrown SecurityException"); } catch (SecurityException e) { Assert.assertNotNull(e.getMessage()); log.info("Could not remove item (this is correct)"); } CrudPlusItem item; logicImpl.removeItem(adminitem); // admin can delete this item = logicImpl.getItemById(adminitem.getId()); Assert.assertNull(item); logicImpl.removeItem(maintitem); // permed user can delete this item = logicImpl.getItemById(maintitem.getId()); Assert.assertNull(item); logicImpl.removeItem(item1); // user can delete this item = logicImpl.getItemById(item1.getId()); Assert.assertNull(item); // verify the mock objects were used userDirectoryServiceControl.verify(); securityServiceControl.verify(); toolManagerControl.verify(); siteServiceControl.verify(); }
From source file:org.openmrs.logic.LogicServiceTest.java
/** * @see {@link LogicService#removeRule(String)} *//*from w w w . j av a 2s. co m*/ @Test(expected = LogicException.class) @Verifies(value = "should remove rule", method = "removeRule(String)") public void removeRule_shouldRemoveRule() throws Exception { LogicService logicService = Context.getLogicService(); Rule ageRule = logicService.getRule("AGE"); Assert.assertNotNull(ageRule); logicService.removeRule("AGE"); Rule afterDeleteAgeRule = logicService.getRule("AGE"); Assert.assertNull(afterDeleteAgeRule); }
From source file:org.obiba.onyx.core.etl.participant.impl.ParticipantReaderTest.java
/** * Tests processing of an appointment list where an attribute (Gender, line 3) has been assigned value that is not * allowed (i.e., is not with the attribute's "allowed value" list). Reader should not return an error as it is a * validation done in the ParticipantProcessor. * /* w ww . j a v a 2s. c o m*/ * @throws IOException if the appointment list could not be read */ @Test public void testProcessWithNotAllowedAttributeValue() throws IOException { ParticipantReaderForTest reader = createParticipantReaderForTest(1, 2, 3, false, TEST_RESOURCES_DIR + "/appointmentList_notAllowedAttributeValue.xls"); reader.open(context); List<Participant> participants = new ArrayList<Participant>(); try { while (reader.getRow() != null) { Participant participant = reader.read(); if (participant != null) participants.add(participant); } } catch (Exception e) { throw new RuntimeException(e); } Assert.assertEquals(3, participants.size()); Assert.assertEquals("Tremblay", participants.get(0).getLastName()); Assert.assertNull(participants.get(0).getGender()); Assert.assertEquals(Gender.MALE, participants.get(1).getGender()); Assert.assertEquals("Casserly", participants.get(2).getLastName()); Assert.assertEquals(Gender.FEMALE, participants.get(2).getGender()); }
From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImplTest.java
/** * //from w w w . j ava 2s .c o m * @throws Exception */ @Test public void testRetrieveTargetBlock() throws Exception { // first week of November, all blocks have visitorLimit 1 Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "5:00 PM", "MWF", CommonDateOperations.parseDatePhrase("20091102"), CommonDateOperations.parseDatePhrase("20091106"), 1); availableScheduleDao.addToSchedule(sampleOwners[0], blocks); // second week of November, all blocks have visitorLimit 2 blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "5:00 PM", "MWF", CommonDateOperations.parseDatePhrase("20091109"), CommonDateOperations.parseDatePhrase("20091113"), 2); availableScheduleDao.addToSchedule(sampleOwners[0], blocks); // third week of November, all blocks have visitorLimit 4 blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "5:00 PM", "MWF", CommonDateOperations.parseDatePhrase("20091116"), CommonDateOperations.parseDatePhrase("20091120"), 4); availableScheduleDao.addToSchedule(sampleOwners[0], blocks); // fourth week of November, all blocks have visitorLimit 20 blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "5:00 PM", "MWF", CommonDateOperations.parseDatePhrase("20091123"), CommonDateOperations.parseDatePhrase("20091127"), 20); availableScheduleDao.addToSchedule(sampleOwners[0], blocks); // wrong owner, assert returns null AvailableBlock result = availableScheduleDao.retrieveTargetBlock(sampleOwners[1], CommonDateOperations.parseDateTimePhrase("20091102-0900")); Assert.assertNull(result); // right owner, but assert time outside stored schedule returns null result = availableScheduleDao.retrieveTargetBlock(sampleOwners[0], CommonDateOperations.parseDateTimePhrase("20091101-0900")); Assert.assertNull(result); result = availableScheduleDao.retrieveTargetBlock(sampleOwners[0], CommonDateOperations.parseDateTimePhrase("20091102-0830")); Assert.assertNull(result); result = availableScheduleDao.retrieveTargetBlock(sampleOwners[0], CommonDateOperations.parseDateTimePhrase("20091102-1700")); Assert.assertNull(result); // assert proper block for a number of times Date expectedStart = CommonDateOperations.parseDateTimePhrase("20091102-0900"); Date expectedEnd = DateUtils.addMinutes(expectedStart, sampleOwners[0].getPreferredMeetingDurations().getMinLength()); result = availableScheduleDao.retrieveTargetBlock(sampleOwners[0], expectedStart); Assert.assertNotNull(result); Assert.assertEquals(1, result.getVisitorLimit()); Assert.assertEquals(expectedStart, result.getStartTime()); Assert.assertEquals(expectedEnd, result.getEndTime()); // assert retrieveTargetBlock variant with endTime expected behavior result = availableScheduleDao.retrieveTargetBlock(sampleOwners[0], expectedStart, expectedEnd); Assert.assertNotNull(result); Assert.assertEquals(1, result.getVisitorLimit()); Assert.assertEquals(expectedStart, result.getStartTime()); Assert.assertEquals(expectedEnd, result.getEndTime()); // try again with wrong end time result = availableScheduleDao.retrieveTargetBlock(sampleOwners[0], expectedStart, DateUtils.addMinutes(expectedEnd, -1)); Assert.assertNull(result); expectedStart = CommonDateOperations.parseDateTimePhrase("20091102-1200"); expectedEnd = DateUtils.addMinutes(expectedStart, sampleOwners[0].getPreferredMeetingDurations().getMinLength()); result = availableScheduleDao.retrieveTargetBlock(sampleOwners[0], expectedStart); Assert.assertNotNull(result); Assert.assertEquals(1, result.getVisitorLimit()); Assert.assertEquals(expectedStart, result.getStartTime()); Assert.assertEquals(expectedEnd, result.getEndTime()); // special case - this block butts up to the end, it'll only be minLength long expectedStart = CommonDateOperations.parseDateTimePhrase("20091102-1630"); expectedEnd = DateUtils.addMinutes(expectedStart, sampleOwners[0].getPreferredMeetingDurations().getMinLength()); result = availableScheduleDao.retrieveTargetBlock(sampleOwners[0], expectedStart); Assert.assertNotNull(result); Assert.assertEquals(1, result.getVisitorLimit()); Assert.assertEquals(expectedStart, result.getStartTime()); Assert.assertEquals(expectedEnd, result.getEndTime()); expectedStart = CommonDateOperations.parseDateTimePhrase("20091109-1200"); expectedEnd = DateUtils.addMinutes(expectedStart, sampleOwners[0].getPreferredMeetingDurations().getMinLength()); result = availableScheduleDao.retrieveTargetBlock(sampleOwners[0], expectedStart); Assert.assertNotNull(result); Assert.assertEquals(2, result.getVisitorLimit()); Assert.assertEquals(expectedStart, result.getStartTime()); Assert.assertEquals(expectedEnd, result.getEndTime()); expectedStart = CommonDateOperations.parseDateTimePhrase("20091116-1200"); expectedEnd = DateUtils.addMinutes(expectedStart, sampleOwners[0].getPreferredMeetingDurations().getMinLength()); result = availableScheduleDao.retrieveTargetBlock(sampleOwners[0], expectedStart); Assert.assertNotNull(result); Assert.assertEquals(4, result.getVisitorLimit()); Assert.assertEquals(expectedStart, result.getStartTime()); Assert.assertEquals(expectedEnd, result.getEndTime()); expectedStart = CommonDateOperations.parseDateTimePhrase("20091123-1200"); expectedEnd = DateUtils.addMinutes(expectedStart, sampleOwners[0].getPreferredMeetingDurations().getMinLength()); result = availableScheduleDao.retrieveTargetBlock(sampleOwners[0], expectedStart); Assert.assertNotNull(result); Assert.assertEquals(20, result.getVisitorLimit()); Assert.assertEquals(expectedStart, result.getStartTime()); Assert.assertEquals(expectedEnd, result.getEndTime()); }
From source file:com.ebay.cloud.cms.query.service.QueryPaginationByIdTest.java
@Test public void testQueryIterSkip02() { raptorContext.removeSortOn();//from w ww. j a va2 s . co m String oid = null; String oid_11 = null; { String query = "ServiceInstance[@name=~\"srp.*\"]{@_oid}"; QueryContext context = newQueryContext(RAPTOR_REPO, RAPTOR_MAIN_BRANCH_ID); context.setAllowFullTableScan(true); IQueryResult result = queryService.query(query, context); oid = result.getEntities().get(6).getId(); oid_11 = result.getEntities().get(10).getId(); } raptorContext.setAllowFullTableScan(true); raptorContext.setSkips(null); raptorContext.setPaginationMode(PaginationMode.ID_BASED); raptorContext.getQueryCursor().setHint(-1); raptorContext.getQueryCursor().setJoinCursorValues(Arrays.asList(null, oid, null)); // first round : String query = "ApplicationService.services[@name=~\"srp.*\"].runsOn"; raptorContext.getQueryCursor().setLimits(new int[] { 0, 0 }); IQueryResult result0 = queryService.query(query, raptorContext); Assert.assertFalse(result0.hasMoreResults()); Assert.assertEquals(3, result0.getEntities().size()); // second round : add limit raptorContext.getQueryCursor().setJoinCursorValues(Arrays.asList(null, oid)); raptorContext.setLimits(new int[] { 0, 2 }); result0 = queryService.query(query, raptorContext); Assert.assertTrue(result0.hasMoreResults()); Assert.assertEquals(2, result0.getEntities().size()); // third round : increase join oid limit based on the suggestion int nextHint = result0.getNextCursor().getHint(); Assert.assertEquals(1, nextHint); raptorContext.setCursor(result0.getNextCursor()); result0 = queryService.query(query, raptorContext); Assert.assertFalse(result0.hasMoreResults()); Assert.assertEquals(1, result0.getEntities().size()); // fourth round : increase skip/limits to bigger than the available counts raptorContext.getCursor().setJoinCursorValues(Arrays.asList(null, oid_11, "")); raptorContext.getCursor().setLimits(new int[] { 0, 0, 0 }); raptorContext.getCursor().setHint(1); IQueryResult result = queryService.query(query, raptorContext); Assert.assertFalse(result.hasMoreResults()); Assert.assertNull(result.getNextCursor()); Assert.assertEquals(0, result.getEntities().size()); }
From source file:com.test.onesignal.MainOneSignalClassRunner.java
@Test public void shouldAllowMultipleSetSubscription() throws Exception { OneSignalInit();//from ww w . j a v a 2 s . co m threadAndTaskWait(); OneSignal.setSubscription(false); threadAndTaskWait(); Assert.assertEquals(-2, ShadowOneSignalRestClient.lastPost.getInt("notification_types")); // Should not resend same value ShadowOneSignalRestClient.lastPost = null; OneSignal.setSubscription(false); Assert.assertNull(ShadowOneSignalRestClient.lastPost); OneSignal.setSubscription(true); threadAndTaskWait(); Assert.assertEquals(1, ShadowOneSignalRestClient.lastPost.getInt("notification_types")); // Should not resend same value ShadowOneSignalRestClient.lastPost = null; OneSignal.setSubscription(true); threadAndTaskWait(); Assert.assertNull(ShadowOneSignalRestClient.lastPost); }
From source file:com.couchbase.lite.LiteTestCaseWithDB.java
public static Document createDocumentWithProperties(Database db, Map<String, Object> properties) { Document doc = db.createDocument(); Assert.assertNotNull(doc);//from w ww .jav a 2 s . c o m Assert.assertNull(doc.getCurrentRevisionId()); Assert.assertNull(doc.getCurrentRevision()); Assert.assertNotNull("Document has no ID", doc.getId()); // 'untitled' docs are no longer untitled (8/10/12) try { doc.putProperties(properties); } catch (Exception e) { Log.e(TAG, "Error creating document", e); assertTrue( "can't create new document in db:" + db.getName() + " with properties:" + properties.toString(), false); } Assert.assertNotNull(doc.getId()); Assert.assertNotNull(doc.getCurrentRevisionId()); Assert.assertNotNull(doc.getUserProperties()); // should be same doc instance, since there should only ever be a single Document // instance for a given document Assert.assertEquals(db.getDocument(doc.getId()), doc); Assert.assertEquals(db.getDocument(doc.getId()).getId(), doc.getId()); return doc; }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.EnhancedPushTests.java
@SuppressWarnings("deprecation") public void testRegisterUnregisterTemplateCallback() throws Throwable { final CountDownLatch latch = new CountDownLatch(1); Context context = getInstrumentation().getTargetContext(); final SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context.getApplicationContext()); final Container container = new Container(); final String handle = "handle"; final String templateName = "templateName"; String registrationId = "registrationId"; MobileServiceClient client = new MobileServiceClient(appUrl, appKey, context); client = client.withFilter(getUpsertTestFilter(registrationId)); final MobileServicePush push = client.getPush(); forceRefreshSync(push, handle);/*w w w . j av a 2s.c om*/ push.registerTemplate(handle, templateName, "{ }", new String[] { "tag1" }, new TemplateRegistrationCallback() { @Override public void onRegister(TemplateRegistration registration, Exception exception) { if (exception != null) { container.exception = exception; latch.countDown(); } else { container.registrationId = registration.getRegistrationId(); container.storedRegistrationId = sharedPreferences .getString(STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + templateName, null); push.unregisterTemplate(templateName, new UnregisterCallback() { @Override public void onUnregister(Exception exception) { if (exception != null) { container.exception = exception; } else { container.unregister = sharedPreferences.getString( STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + templateName, null); } latch.countDown(); } }); } } }); latch.await(); // Asserts Exception exception = container.exception; if (exception != null) { fail(exception.getMessage()); } else { Assert.assertEquals(registrationId, container.storedRegistrationId); Assert.assertEquals(registrationId, container.registrationId); Assert.assertNull(container.unregister); } }
From source file:org.openmrs.module.paperrecord.PaperRecordServiceComponentTest.java
@Test public void testRequestPaperRecordWithDuplicateRequest() { // all these are from the standard test dataset Patient patient = patientService.getPatient(2); Location medicalRecordLocation = locationService.getLocation(1); Location requestLocation = locationService.getLocation(3); paperRecordService.requestPaperRecord(patient, medicalRecordLocation, requestLocation); // sanity check; make sure the record is in the database List<PaperRecordRequest> requests = paperRecordService .getOpenPaperRecordRequestsToCreate(medicalRecordLocation); Assert.assertEquals(1, requests.size()); Date dateCreated = requests.get(0).getDateCreated(); // now request the same record again paperRecordService.requestPaperRecord(patient, medicalRecordLocation, requestLocation); // there should still only be one paper record request requests = paperRecordService.getOpenPaperRecordRequestsToCreate(medicalRecordLocation); Assert.assertEquals(1, requests.size()); PaperRecordRequest request = requests.get(0); Assert.assertEquals(new Integer(2), request.getPaperRecord().getPatientIdentifier().getPatient().getId()); Assert.assertEquals(new Integer(1), request.getPaperRecord().getRecordLocation().getId()); Assert.assertEquals(new Integer(3), request.getRequestLocation().getId()); Assert.assertEquals("101", request.getPaperRecord().getPatientIdentifier().getIdentifier()); Assert.assertEquals(PaperRecordRequest.Status.OPEN, request.getStatus()); Assert.assertEquals(dateCreated, request.getDateCreated()); Assert.assertNull(request.getAssignee()); }