List of usage examples for junit.framework Assert assertTrue
static public void assertTrue(boolean condition)
From source file:com.couchbase.touchdb.testapp.tests.Attachments.java
@SuppressWarnings("unchecked") public void testAttachments() throws Exception { TDBlobStore attachments = database.getAttachments(); Assert.assertEquals(0, attachments.count()); Assert.assertEquals(new HashSet<Object>(), attachments.allKeys()); TDStatus status = new TDStatus(); Map<String, Object> rev1Properties = new HashMap<String, Object>(); rev1Properties.put("foo", 1); rev1Properties.put("bar", false); TDRevision rev1 = database.putRevision(new TDRevision(rev1Properties), null, false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); byte[] attach1 = "This is the body of attach1".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1), rev1.getSequence(), "attach", "text/plain", rev1.getGeneration()); Assert.assertEquals(TDStatus.CREATED, status.getCode()); TDAttachment attachment = database.getAttachmentForSequence(rev1.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment.getContentType()); byte[] data = IOUtils.toByteArray(attachment.getContentStream()); 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("attach", innerDict); Map<String, Object> attachmentDictForSequence = database .getAttachmentsDictForSequenceWithContent(rev1.getSequence(), false); Assert.assertEquals(attachmentDict, attachmentDictForSequence); TDRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(TDDatabase.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(), true); Assert.assertEquals(attachmentDict, attachmentDictForSequence); gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.of(TDDatabase.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); TDRevision rev2 = database.putRevision(new TDRevision(rev2Properties), rev1.getRevId(), false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); status = database.copyAttachmentNamedFromSequenceToSequence("attach", rev1.getSequence(), rev2.getSequence());//from w ww . j a v a 2s . com Assert.assertEquals(TDStatus.OK, status.getCode()); // 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); TDRevision rev3 = database.putRevision(new TDRevision(rev3Properties), rev2.getRevId(), false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); byte[] attach2 = "<html>And this is attach2</html>".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach2), rev3.getSequence(), "attach", "text/html", rev2.getGeneration()); Assert.assertEquals(TDStatus.CREATED, status.getCode()); // Check the 2nd revision's attachment: TDAttachment attachment2 = database.getAttachmentForSequence(rev2.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment2.getContentType()); data = IOUtils.toByteArray(attachment2.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); // Check the 3rd revision's attachment: TDAttachment attachment3 = database.getAttachmentForSequence(rev3.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/html", attachment3.getContentType()); data = IOUtils.toByteArray(attachment3.getContentStream()); Assert.assertTrue(Arrays.equals(attach2, data)); // Examine the attachment store: Assert.assertEquals(2, attachments.count()); Set<TDBlobKey> expected = new HashSet<TDBlobKey>(); expected.add(TDBlobStore.keyForBlob(attach1)); expected.add(TDBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected, attachments.allKeys()); status = database.compact(); // This clears the body of the first revision Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals(1, attachments.count()); Set<TDBlobKey> expected2 = new HashSet<TDBlobKey>(); expected2.add(TDBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected2, attachments.allKeys()); }
From source file:com.couchbase.cblite.testapp.tests.Attachments.java
@SuppressWarnings("unchecked") public void testAttachments() throws Exception { CBLBlobStore attachments = database.getAttachments(); Assert.assertEquals(0, attachments.count()); Assert.assertEquals(new HashSet<Object>(), attachments.allKeys()); CBLStatus status = new CBLStatus(); Map<String, Object> rev1Properties = new HashMap<String, Object>(); rev1Properties.put("foo", 1); rev1Properties.put("bar", false); CBLRevision rev1 = database.putRevision(new CBLRevision(rev1Properties), null, false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); byte[] attach1 = "This is the body of attach1".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1), rev1.getSequence(), "attach", "text/plain", rev1.getGeneration()); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); CBLAttachment attachment = database.getAttachmentForSequence(rev1.getSequence(), "attach", status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment.getContentType()); byte[] data = IOUtils.toByteArray(attachment.getContentStream()); 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("attach", innerDict); Map<String, Object> attachmentDictForSequence = database .getAttachmentsDictForSequenceWithContent(rev1.getSequence(), false); Assert.assertEquals(attachmentDict, attachmentDictForSequence); CBLRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(CBLDatabase.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(), true); Assert.assertEquals(attachmentDict, attachmentDictForSequence); gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.of(CBLDatabase.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); CBLRevision rev2 = database.putRevision(new CBLRevision(rev2Properties), rev1.getRevId(), false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); status = database.copyAttachmentNamedFromSequenceToSequence("attach", rev1.getSequence(), rev2.getSequence());//from www .j a v a 2 s . c o m Assert.assertEquals(CBLStatus.OK, status.getCode()); // 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); CBLRevision rev3 = database.putRevision(new CBLRevision(rev3Properties), rev2.getRevId(), false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); byte[] attach2 = "<html>And this is attach2</html>".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach2), rev3.getSequence(), "attach", "text/html", rev2.getGeneration()); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); // Check the 2nd revision's attachment: CBLAttachment attachment2 = database.getAttachmentForSequence(rev2.getSequence(), "attach", status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment2.getContentType()); data = IOUtils.toByteArray(attachment2.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); // Check the 3rd revision's attachment: CBLAttachment attachment3 = database.getAttachmentForSequence(rev3.getSequence(), "attach", status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals("text/html", attachment3.getContentType()); data = IOUtils.toByteArray(attachment3.getContentStream()); Assert.assertTrue(Arrays.equals(attach2, data)); // Examine the attachment store: Assert.assertEquals(2, attachments.count()); Set<CBLBlobKey> expected = new HashSet<CBLBlobKey>(); expected.add(CBLBlobStore.keyForBlob(attach1)); expected.add(CBLBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected, attachments.allKeys()); status = database.compact(); // This clears the body of the first revision Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals(1, attachments.count()); Set<CBLBlobKey> expected2 = new HashSet<CBLBlobKey>(); expected2.add(CBLBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected2, attachments.allKeys()); }
From source file:ru.codemine.pos.service.StoreServiceTest.java
@Test public void testStoreService() { log.info("--- ? StoreService---"); try {/* w ww . jav a 2 s .c om*/ storeService.create(store); } catch (DuplicateStoreDataException ex) { ex.printStackTrace(); } log.info(" ? ..."); Store s1 = storeService.getByName("TheTestStore"); Store unproxedS1 = storeService.unproxyStocks(s1); Assert.assertNotNull(unproxedS1); Assert.assertTrue(unproxedS1.getStocks().get(p1) == 1); log.info("...ok"); log.info(" ? ? ? ..."); store.getStocks().put(p3, 10); try { storeService.update(store); } catch (DuplicateStoreDataException ex) { ex.printStackTrace(); } Store s2 = storeService.getByName("TheTestStore"); Store unproxedS2 = storeService.unproxyStocks(s2); Assert.assertNotNull(unproxedS2); Assert.assertTrue(unproxedS2.getStocks().get(p3) == 10); log.info("...ok"); }
From source file:com.googlecode.t7mp.CommonsSetupUtilTest.java
@Test public void testCopyDirectory() throws IOException { File rootDirectory = new File(catalinaBaseDir, "root"); Assert.assertTrue(rootDirectory.mkdir()); File firstFile = File.createTempFile("first_", ".tmp", rootDirectory); File childDirectory = new File(rootDirectory, "child"); Assert.assertTrue(childDirectory.mkdir()); File secondFile = File.createTempFile("second_", ".tmp", childDirectory); File webappsDirectory = new File(catalinaBaseDir, "/webapps/"); webappsDirectory.mkdirs();/* w ww.j av a 2 s . c o m*/ File targetDirectory = new File(webappsDirectory, rootDirectory.getName()); Assert.assertTrue(targetDirectory.mkdirs()); SetupUtil setupUtil = new CommonsSetupUtil(); setupUtil.copyDirectory(rootDirectory, targetDirectory); File copiedRootDir = new File(webappsDirectory, "/root/"); Assert.assertTrue(copiedRootDir.isDirectory()); Assert.assertTrue(copiedRootDir.exists()); File copiedChildDirectory = new File(copiedRootDir, "/child/"); Assert.assertTrue(copiedChildDirectory.isDirectory()); Assert.assertTrue(copiedChildDirectory.exists()); File[] rootDirectoryFiles = copiedRootDir.listFiles(new FilesOnlyFileFilter()); Assert.assertEquals(1, rootDirectoryFiles.length); Assert.assertTrue(rootDirectoryFiles[0].getName().startsWith("first_")); File[] childDirectoryFiles = copiedChildDirectory.listFiles(new FilesOnlyFileFilter()); Assert.assertEquals(1, childDirectoryFiles.length); Assert.assertTrue(childDirectoryFiles[0].getName().startsWith("second_")); }
From source file:net.i2cat.netconf.test.TransportContentparserTest.java
@Test public void parseReplyErrorTest() throws IOException, SAXException { String messageId = "1"; String message = "Malformed XML!!!"; for (ErrorType type : ErrorType.values()) { for (ErrorTag tag : ErrorTag.values()) { for (ErrorSeverity severity : ErrorSeverity.values()) { String replyMsg = buildErrorRepy(messageId, type.toString(), tag.toString(), severity.toString(), message); parseMessage(replyMsg);// w w w . j av a2 s. c o m Reply reply = (Reply) queue.consumeById(messageId); Assert.assertNotNull(reply); Assert.assertTrue(reply.containsErrors()); Error error = reply.getErrors().get(0); Assert.assertEquals(severity, error.getSeverity()); Assert.assertEquals(type, error.getType()); Assert.assertEquals(tag, error.getTag()); Assert.assertEquals(message, error.getMessage()); } } } }
From source file:com.couchbase.lite.performance.Test16_ParallelPushReplication.java
public void testPushReplicationPerformance() throws Exception { if (!performanceTestsEnabled()) { return;/*from w ww .jav a 2 s . com*/ } long startMillis = System.currentTimeMillis(); URL remote0 = getReplicationSubURL("0"); URL remote1 = getReplicationSubURL("1"); URL remote2 = getReplicationSubURL("2"); URL remote3 = getReplicationSubURL("3"); final Replication repl0 = database.createPushReplication(remote0); repl0.setContinuous(false); if (!isSyncGateway(remote0)) { repl0.setCreateTarget(true); Assert.assertTrue(repl0.shouldCreateTarget()); } final Replication repl1 = database.createPushReplication(remote1); repl1.setContinuous(false); if (!isSyncGateway(remote1)) { repl1.setCreateTarget(true); Assert.assertTrue(repl1.shouldCreateTarget()); } final Replication repl2 = database.createPushReplication(remote2); repl2.setContinuous(false); if (!isSyncGateway(remote2)) { repl2.setCreateTarget(true); Assert.assertTrue(repl2.shouldCreateTarget()); } final Replication repl3 = database.createPushReplication(remote3); repl3.setContinuous(false); if (!isSyncGateway(remote3)) { repl3.setCreateTarget(true); Assert.assertTrue(repl3.shouldCreateTarget()); } Thread t0 = new Thread() { public void run() { try { runReplication(repl0); } catch (Exception e) { e.printStackTrace(); } } }; Thread t1 = new Thread() { public void run() { try { runReplication(repl1); } catch (Exception e) { e.printStackTrace(); } } }; Thread t2 = new Thread() { public void run() { try { runReplication(repl2); } catch (Exception e) { e.printStackTrace(); } } }; t0.start(); t1.start(); t2.start(); runReplication(repl3); Log.d(TAG, "testPusher() finished"); Log.v("PerformanceStats", TAG + "," + Long.valueOf(System.currentTimeMillis() - startMillis).toString() + "," + getNumberOfDocuments()); }
From source file:org.jasig.ssp.util.importer.job.BatchPartialUploadTest.java
@SuppressWarnings("unchecked") @Test/* ww w. ja v a 2 s . c o m*/ public void testDirectoryNoFiles() throws Exception { deleteDirectory(inputDirectoryPath); createDirectory(inputDirectoryPath); Assert.assertTrue(directoryExists(inputDirectoryPath)); JobExecution jobExecution = jobLauncherTestUtils.launchJob(); BatchStatus exitStatus = jobExecution.getStatus(); Map<String, ReportEntry> report = (Map<String, ReportEntry>) jobExecution.getExecutionContext() .get("report"); Assert.assertNull(report); Assert.assertEquals(BatchStatus.STOPPED, exitStatus); Assert.assertTrue(directoryExists(inputDirectoryPath)); }
From source file:org.apache.olingo.odata2.annotation.processor.ref.ServiceJsonTest.java
@Test public void serviceDocumentAcceptHeaderJson() throws Exception { final HttpResponse response = callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON); String body = getBody(response); Assert.assertTrue(jsonDataResponseContains(body, "Buildings")); Assert.assertTrue(jsonDataResponseContains(body, "Employees")); Assert.assertTrue(jsonDataResponseContains(body, "Managers")); Assert.assertTrue(jsonDataResponseContains(body, "Photos")); Assert.assertTrue(jsonDataResponseContains(body, "Rooms")); Assert.assertTrue(jsonDataResponseContains(body, "Teams")); }
From source file:org.apache.smscserver.test.spring.SpringConfigTest.java
public void test() throws Throwable { // FIXME: Hasan variable not expanded System.setProperty("SMSC_HOME", "./target/"); XmlBeanFactory factory = new XmlBeanFactory( new FileSystemResource("src/test/resources/spring-config/config-spring-1.xml")); DefaultSmscServer server = (DefaultSmscServer) factory.getBean("server"); Assert.assertEquals(500, server.getServerContext().getConnectionConfig().getMaxBinds()); Assert.assertEquals(124, server.getServerContext().getConnectionConfig().getMaxBindFailures()); Assert.assertEquals(125, server.getServerContext().getConnectionConfig().getBindFailureDelay()); Assert.assertEquals(4, server.getServerContext().getConnectionConfig().getMinThreads()); Assert.assertEquals(16, server.getServerContext().getConnectionConfig().getMaxThreads()); Assert.assertEquals(2, server.getServerContext().getDeliveryManagerConfig().getManagerThreads()); Assert.assertEquals(8, server.getServerContext().getDeliveryManagerConfig().getMinThreads()); Assert.assertEquals(24, server.getServerContext().getDeliveryManagerConfig().getMaxThreads()); Assert.assertEquals(1000, server.getServerContext().getSessionLockTimeout()); Map<String, Listener> listeners = server.getServerContext().getListeners(); Assert.assertEquals(3, listeners.size()); Listener listener = listeners.get("listener1"); Assert.assertNotNull(listener);//w ww . j a v a 2 s . c o m Assert.assertTrue(listener instanceof MyCustomListener); Assert.assertEquals(2223, listener.getPort()); listener = listeners.get("listener2"); Assert.assertNotNull(listener); Assert.assertTrue(listener instanceof MyCustomListener); Assert.assertEquals(2224, listener.getPort()); CommandFactory cf = server.getCommandFactory(); Assert.assertTrue(cf.getCommand(9) instanceof BindCommand); Assert.assertTrue(cf.getCommand(21) instanceof EnquireLinkCommand); Assert.assertEquals(2, server.getSmsclets().size()); Assert.assertEquals(123, ((TestSmsclet) server.getSmsclets().get("smsclet1")).getFoo()); Assert.assertEquals(223, ((TestSmsclet) server.getSmsclets().get("smsclet2")).getFoo()); Assert.assertNotNull(server.getServerContext().getMessageManager()); }