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 testRegisterFailNative() throws Throwable { final Container container = new Container(); Context context = getInstrumentation().getTargetContext(); final SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context.getApplicationContext()); final String handle = "handle"; String registrationId = "registrationId"; MobileServiceClient client = new MobileServiceClient(appUrl, appKey, context); client = client.withFilter(getUpsertFailTestFilter(registrationId)); final MobileServicePush push = client.getPush(); forceRefreshSync(push, handle);/*from www . j a v a 2s.c o m*/ try { push.register(handle, new String[] { "tag1" }).get(); fail("Expected Exception RegistrationGoneException"); } catch (Exception exception) { if (exception instanceof ExecutionException) { container.exception = (Exception) exception.getCause(); } else { container.exception = exception; } if (!(container.exception instanceof RegistrationGoneException)) { fail("Expected Exception RegistrationGoneException"); } Assert.assertNull(sharedPreferences .getString(STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + DEFAULT_REGISTRATION_NAME, null)); } }
From source file:net.authorize.api.controller.test.ApiCoreTestBase.java
protected static <Q extends ANetApiRequest, S extends ANetApiResponse, T extends ApiOperationBase<Q, S>> void validateSuccess( T controller, S response) {// ww w . j a v a2 s.c o m Assert.assertEquals(MessageTypeEnum.OK, controller.getResultCode()); Assert.assertNull(controller.getErrorResponse()); Assert.assertNotNull(response); displayResponse(response, "Success Messages"); }
From source file:org.openmrs.module.paperrecord.PaperRecordServiceComponentTest.java
@Test public void testRequestPaperRecordWhenDuplicateRequestShouldUpdateLocation() { // all these are from the standard test dataset Patient patient = patientService.getPatient(2); Location medicalRecordLocation = locationService.getLocation(1); Location requestLocation = locationService.getLocation(3); Location anotherRequestLocation = locationService.getLocation(2); 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, anotherRequestLocation); // there should still only be one paper record request, but with the new location 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(2), 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()); }
From source file:com.ebay.cloud.cms.query.service.QueryPaginationByIdTest.java
@Test public void testQueryIterSkip05_embed() { String oid = null;/*from www. j av a 2 s. com*/ String secondVersionId = null; { QueryContext context = newQueryContext(DEPLOY_REPO, IBranch.DEFAULT_BRANCH); context.setAllowFullTableScan(true); IQueryResult result = queryService.query("Manifest{*}.versions{*}", context); oid = result.getEntities().get(0).getId(); secondVersionId = ((IEntity) result.getEntities().get(0).getFieldValues("versions").get(1)).getId(); } // oid: 4fbdaccec681643199735a5b // secondVersionId: // Manifest!4fbdaccec681643199735a5b!versions!4fbdaccec681643199735a5e String query = "Manifest{*}.versions{*}"; QueryContext qc = newQueryContext(DEPLOY_REPO, IBranch.DEFAULT_BRANCH); qc.setPaginationMode(PaginationMode.ID_BASED); qc.setAllowFullTableScan(true); qc.getCursor().setJoinCursorValues(Arrays.asList(oid, secondVersionId)); qc.setSourceIP("127.0.0.1"); IQueryResult result = queryService.query(query, qc); Assert.assertEquals(0, result.getEntities().size()); Assert.assertFalse(result.hasMoreResults()); Assert.assertNull(result.getNextCursor()); }
From source file:com.couchbase.lite.AttachmentsTest.java
@SuppressWarnings("unchecked") public void testPutAttachment() throws CouchbaseLiteException { String testAttachmentName = "test_attachment"; BlobStore attachments = database.getAttachments(); attachments.deleteBlobs();//from www. j a va 2 s. co m Assert.assertEquals(0, attachments.count()); // Put a revision that includes an _attachments dict: byte[] attach1 = "This is the body of attach1".getBytes(); String base64 = Base64.encodeBytes(attach1); Map<String, Object> attachment = new HashMap<String, Object>(); attachment.put("content_type", "text/plain"); attachment.put("data", base64); Map<String, Object> attachmentDict = new HashMap<String, Object>(); attachmentDict.put(testAttachmentName, attachment); Map<String, Object> properties = new HashMap<String, Object>(); properties.put("foo", 1); properties.put("bar", false); properties.put("_attachments", attachmentDict); RevisionInternal rev1 = database.putRevision(new RevisionInternal(properties, database), null, false); // Examine the attachment store: Assert.assertEquals(1, attachments.count()); // Get the revision: RevisionInternal gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(Database.TDContentOptions.class)); Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); 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> expectAttachmentDict = new HashMap<String, Object>(); expectAttachmentDict.put(testAttachmentName, innerDict); Assert.assertEquals(expectAttachmentDict, gotAttachmentDict); // Update the attachment directly: byte[] attachv2 = "Replaced body of attach".getBytes(); boolean gotExpectedErrorCode = false; BlobStoreWriter blobWriter = new BlobStoreWriter(database.getAttachments()); blobWriter.appendData(attachv2); blobWriter.finish(); try { database.updateAttachment(testAttachmentName, blobWriter, "application/foo", AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev1.getDocId(), null); } catch (CouchbaseLiteException e) { gotExpectedErrorCode = (e.getCBLStatus().getCode() == Status.CONFLICT); } Assert.assertTrue(gotExpectedErrorCode); gotExpectedErrorCode = false; try { database.updateAttachment(testAttachmentName, blobWriter, "application/foo", AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev1.getDocId(), "1-bogus"); } catch (CouchbaseLiteException e) { gotExpectedErrorCode = (e.getCBLStatus().getCode() == Status.CONFLICT); } Assert.assertTrue(gotExpectedErrorCode); gotExpectedErrorCode = false; RevisionInternal rev2 = null; try { rev2 = database.updateAttachment(testAttachmentName, blobWriter, "application/foo", AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev1.getDocId(), rev1.getRevId()); } catch (CouchbaseLiteException e) { gotExpectedErrorCode = true; } Assert.assertFalse(gotExpectedErrorCode); Assert.assertEquals(rev1.getDocId(), rev2.getDocId()); Assert.assertEquals(2, rev2.getGeneration()); // Get the updated revision: RevisionInternal gotRev2 = database.getDocumentWithIDAndRev(rev2.getDocId(), rev2.getRevId(), EnumSet.noneOf(Database.TDContentOptions.class)); attachmentDict = (Map<String, Object>) gotRev2.getProperties().get("_attachments"); innerDict = new HashMap<String, Object>(); innerDict.put("content_type", "application/foo"); innerDict.put("digest", "sha1-mbT3208HI3PZgbG4zYWbDW2HsPk="); innerDict.put("length", 23); innerDict.put("stub", true); innerDict.put("revpos", 2); expectAttachmentDict.put(testAttachmentName, innerDict); Assert.assertEquals(expectAttachmentDict, attachmentDict); // Delete the attachment: gotExpectedErrorCode = false; try { database.updateAttachment("nosuchattach", null, null, AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev2.getDocId(), rev2.getRevId()); } catch (CouchbaseLiteException e) { gotExpectedErrorCode = (e.getCBLStatus().getCode() == Status.NOT_FOUND); } Assert.assertTrue(gotExpectedErrorCode); gotExpectedErrorCode = false; try { database.updateAttachment("nosuchattach", null, null, AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, "nosuchdoc", "nosuchrev"); } catch (CouchbaseLiteException e) { gotExpectedErrorCode = (e.getCBLStatus().getCode() == Status.NOT_FOUND); } Assert.assertTrue(gotExpectedErrorCode); RevisionInternal rev3 = database.updateAttachment(testAttachmentName, null, null, AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev2.getDocId(), rev2.getRevId()); Assert.assertEquals(rev2.getDocId(), rev3.getDocId()); Assert.assertEquals(3, rev3.getGeneration()); // Get the updated revision: RevisionInternal gotRev3 = database.getDocumentWithIDAndRev(rev3.getDocId(), rev3.getRevId(), EnumSet.noneOf(Database.TDContentOptions.class)); attachmentDict = (Map<String, Object>) gotRev3.getProperties().get("_attachments"); Assert.assertNull(attachmentDict); database.close(); }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.EnhancedPushTests.java
public void testRegisterFailTemplate() throws Throwable { final Container container = new Container(); Context context = getInstrumentation().getTargetContext(); final SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context.getApplicationContext()); final String handle = "handle"; final String templateName = "templateName"; String registrationId = "registrationId"; MobileServiceClient client = new MobileServiceClient(appUrl, appKey, context); client = client.withFilter(getUpsertFailTestFilter(registrationId)); final MobileServicePush push = client.getPush(); forceRefreshSync(push, handle);//from www .j a v a2s. c om try { push.registerTemplate(handle, templateName, "{ }", new String[] { "tag1" }).get(); fail("Expected Exception RegistrationGoneException"); } catch (Exception exception) { if (exception instanceof ExecutionException) { container.exception = (Exception) exception.getCause(); } else { container.exception = exception; } if (!(container.exception instanceof RegistrationGoneException)) { fail("Expected Exception RegistrationGoneException"); } Assert.assertNull(sharedPreferences .getString(STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + DEFAULT_REGISTRATION_NAME, null)); } }
From source file:org.slc.sli.dashboard.unit.manager.CustomizationAssemblyFactoryTest.java
/** * Test getting a component for a test// w w w . j a v a2 s. c o m */ @Test public void testDataComponent() { ApplicationContext goodContext = new AnnotationConfigApplicationContext( new Class<?>[] { ContextConfigurationWithGoodMananger.class }); customizationAssemblyFactory.setApplicationContext(goodContext); // test good one Assert.assertEquals(simpleMaleStudentEntity, customizationAssemblyFactory.getDataComponentForTest("panel", "1", configMap.get("panel").getData())); // test an entity mapping that throws an exception Assert.assertNull(customizationAssemblyFactory.getDataComponentForTest("panelException", "1", configMap.get("panelException").getData())); // test non-existent one Config.Data fakeDataConfig = new Config.Data("fake", "fake", false, null); Assert.assertNotNull(fakeDataConfig); try { customizationAssemblyFactory.getDataComponentForTest("panel", "1", fakeDataConfig); Assert.fail("Must not be able to find fake entity reference and throw an exception"); } catch (DashboardException de) { Assert.assertEquals( "No entity mapping references found for " + fakeDataConfig.getEntityRef() + ". Fix!!!", de.getMessage()); } }
From source file:com.ebay.cloud.cms.query.service.QueryPaginationByIdTest.java
@Test public void testQueryIte_reverse() { String query = "VPool[exists @environment]{*}.parentCluster!Compute[@fqdns=~\".*.com\"]"; QueryContext qc = newQueryContext(STRATUS_REPO, IBranch.DEFAULT_BRANCH); qc.setPaginationMode(PaginationMode.ID_BASED); qc.setAllowFullTableScan(true);/*w w w .j av a 2s . co m*/ qc.getCursor().setLimits(new int[] { 1, 2 }); qc.setSourceIP("127.0.0.1"); IQueryResult result = queryService.query(query, qc); Assert.assertTrue(result.hasMoreResults()); Assert.assertNotNull(result.getNextCursor().getJoinCursorValues()); Assert.assertNull(result.getNextCursor().getSkips()); int[] nLimit = result.getNextCursor().getLimits(); int hint = result.getNextCursor().getHint(); Assert.assertEquals(0, hint); Assert.assertEquals(2, nLimit.length); Assert.assertEquals(1, nLimit[0]); Assert.assertEquals(2, nLimit[1]); int count = result.getEntities().size(); System.out.println("fetch size: " + count); int iterateCount = 1; while (result.hasMoreResults()) { iterateCount++; System.out.println("iterate round: " + iterateCount + ", next skip _oids: " + ArrayUtils.toString(result.getNextCursor().getJoinCursorValues()) + ",next limits: " + ArrayUtils.toString(result.getNextCursor().getLimits())); qc.setCursor(result.getNextCursor()); result = queryService.query(query, qc); System.out.println("fetch size: " + result.getEntities().size()); count += result.getEntities().size(); } Assert.assertEquals(11, iterateCount); QueryContext qc1 = newQueryContext(STRATUS_REPO, IBranch.DEFAULT_BRANCH); qc1.setAllowFullTableScan(true); qc.setPaginationMode(PaginationMode.ID_BASED); qc1.setSourceIP("127.0.0.1"); IQueryResult result1 = queryService.query(query, qc1); Assert.assertFalse(result1.hasMoreResults()); Assert.assertNull(result.getNextCursor()); Assert.assertTrue(count >= result1.getEntities().size()); }
From source file:com.test.onesignal.MainOneSignalClassRunner.java
@Test public void shouldSendTags() throws Exception { OneSignalInit();/* ww w . j av a 2 s.c o m*/ OneSignal.sendTags(new JSONObject("{\"test1\": \"value1\", \"test2\": \"value2\"}")); threadAndTaskWait(); Assert.assertEquals(1, ShadowOneSignalRestClient.networkCallCount); Assert.assertEquals(ONESIGNAL_APP_ID, ShadowOneSignalRestClient.lastPost.getString("app_id")); Assert.assertEquals("value1", ShadowOneSignalRestClient.lastPost.getJSONObject("tags").getString("test1")); Assert.assertEquals("value2", ShadowOneSignalRestClient.lastPost.getJSONObject("tags").getString("test2")); // Should omit sending repeated tags ShadowOneSignalRestClient.lastPost = null; OneSignal.sendTags(new JSONObject("{\"test1\": \"value1\", \"test2\": \"value2\"}")); threadAndTaskWait(); Assert.assertEquals(1, ShadowOneSignalRestClient.networkCallCount); Assert.assertNull(ShadowOneSignalRestClient.lastPost); // Should only send changed and new tags OneSignal.sendTags( new JSONObject("{\"test1\": \"value1.5\", \"test2\": \"value2\", \"test3\": \"value3\"}")); threadAndTaskWait(); Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount); JSONObject sentTags = ShadowOneSignalRestClient.lastPost.getJSONObject("tags"); Assert.assertEquals("value1.5", sentTags.getString("test1")); Assert.assertFalse(sentTags.has(("test2"))); Assert.assertEquals("value3", sentTags.getString("test3")); }
From source file:com.ebay.cloud.cms.query.service.QueryPaginationTest.java
/** * CMS-3031/*from w ww .j a v a 2s. c om*/ */ @Test public void testQueryExplanation_notControll() { String query = SERVICE_INSTANCE; QueryContext qc = newQueryContext(RAPTOR_REPO, IBranch.DEFAULT_BRANCH); qc.setRegistration(TestUtils.getDefaultDalImplementation(dataSource)); qc.setAllowFullTableScan(true); qc.setExplain(false); IQueryResult queryResult = queryService.query(query, qc); Assert.assertNull(queryResult.getExplanations()); }