List of usage examples for junit.framework Assert assertTrue
static public void assertTrue(boolean condition)
From source file:org.apache.bigtop.bigpetstore.qstream.TestLoadGen.java
/** * This is a generic test that our server wrappers etc are okay. * The code paths it exersizes aren't necessarily used via the * prime purpose of the app as of the march 1 2015. * @throws Exception//from ww w. j av a 2 s. c o m */ @org.junit.Test public void testUtilsParameters() throws Exception { final String bind = "localhost"; final int port = 8129; final String ctx = "/"; final String rsp = "This is the response..."; SimpleHttpServer server = new SimpleHttpServer(port); List<NameValuePair> params = new java.util.ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("json", "{\"a\":\"json\"}")); params.add(new BasicNameValuePair("abc", "123")); HttpResponse r = Utils.get("localhost:8129", "", params); System.out.println(r); String contents = org.apache.commons.io.IOUtils.toString(r.getEntity().getContent()); System.out.println(contents); /** * Use responseLine() to test that the lines in the http response * which originate from the above parameters are returned exactly. */ Assert.assertTrue(contents.contains(SimpleHttpServer.responseLine("abc", "123"))); Assert.assertTrue(contents.contains(SimpleHttpServer.responseLine("json", "%7B%22a%22%3A%22json%22%7D"))); server.stop(); }
From source file:com.espertech.esper.multithread.StmtDatabaseJoinCallable.java
public Object call() throws Exception { try {//from w w w. ja va2s . c o m // Add assertListener SupportMTUpdateListener assertListener = new SupportMTUpdateListener(); ThreadLogUtil.trace("adding listeners ", assertListener); stmt.addListener(assertListener); for (int loop = 0; loop < numRepeats; loop++) { int intPrimitive = loop % 10 + 1; Object eventS0 = makeEvent(intPrimitive); engine.getEPRuntime().sendEvent(eventS0); // Should have received one that's mine, possible multiple since the statement is used by other threads boolean found = false; EventBean[] events = assertListener.getNewDataListFlattened(); for (EventBean theEvent : events) { Object s0Received = theEvent.get("s0"); Map s1Received = (Map) theEvent.get("s1"); if ((s0Received == eventS0) || (s1Received.get("myvarchar").equals(MYVARCHAR_VALUES[intPrimitive - 1]))) { found = true; } } if (!found) { } Assert.assertTrue(found); assertListener.reset(); } } catch (AssertionFailedError ex) { log.fatal("Assertion error in thread " + Thread.currentThread().getId(), ex); return false; } catch (Exception ex) { log.fatal("Error in thread " + Thread.currentThread().getId(), ex); return false; } return true; }
From source file:com.gisgraphy.helper.StringHelperTest.java
@Test public void TransformStringForIlikeIndexation() { char delimiter = '-'; String transformedString = StringHelper.transformStringForPartialWordIndexation("it s ok;", delimiter); String[] splited = transformedString.split(String.valueOf(" ")); List<String> list = Arrays.asList(splited); //s ok, s o, it s, t s o, t s, it s ok, ok, it s o, it, t s ok Assert.assertEquals(/*from w ww .ja v a 2 s . co m*/ "There is not the number of words expected, maybe there is duplicate, or single char are indexed but should not, or ..., here is the tansformed string :" + transformedString, 10, list.size()); Assert.assertTrue(list.contains("it-s-ok")); Assert.assertTrue(list.contains("it")); Assert.assertTrue(list.contains("it-s")); Assert.assertTrue(list.contains("it-s-o")); Assert.assertTrue(list.contains("t-s")); Assert.assertTrue(list.contains("t-s-o")); Assert.assertTrue(list.contains("t-s-ok")); Assert.assertTrue(list.contains("s-o")); Assert.assertTrue(list.contains("s-ok")); Assert.assertTrue(list.contains("ok")); }
From source file:org.adroitlogic.ultraesb.rest.HttpPathPatternTest.java
@Test public void testPathParam() throws Exception { // Get the new customer logger.debug("*** GET the account detail echo **"); HttpGet httpget = new HttpGet(REST_URL); HttpResponse response = client.execute(httpget); String payload = EntityUtils.toString(response.getEntity()); logger.debug("Received payload is : {}", payload); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertTrue(payload.contains("<customerId>1234</customerId>")); Assert.assertTrue(payload.contains("<accountId>456</accountId>")); }
From source file:com.lillicoder.newsblurry.util.FileLogger.java
/** * Gets a {@link File} object for the given filename. If the indicated * file already exists, it will be overwritten by a new file. The returned file * lives in this app's external cache directory by default (when external * media is not available, the internal cache is used instead). * @param filename Filename of the file to get. * @return {@link File} object for the given filename. *///from w ww . j a v a 2 s. co m private File getLogFile(String filename) { Assert.assertTrue(!TextUtils.isEmpty(filename)); // Use cache directory so that files are removed on uninstall. Context context = this.getContext(); // Check for external media availability. If available, // write to that directory. Otherwise get the internal cache // directory and write there. File rootDirectory; if (this.isExternalStorageAvailable()) rootDirectory = context.getExternalCacheDir(); else rootDirectory = context.getCacheDir(); // If the file to write already exists, delete it. File logFile = new File(rootDirectory, filename); if (logFile.exists()) logFile.delete(); return logFile; }
From source file:cz.fi.muni.pa165.dao.AlbumDaoImplementationTest.java
@Test public void findAll() { albumDao.create(albumOne);/*from w ww. j ava 2 s .c o m*/ albumDao.create(albumTwo); List<Album> albums = albumDao.findAll(); Assert.assertEquals(2, albums.size()); Assert.assertTrue(albums.contains(albumOne)); Assert.assertTrue(albums.contains(albumTwo)); }
From source file:io.cloudslang.engine.queue.services.QueueDispatcherServiceTest.java
@Test public void testPollEmptyResult() throws Exception { Date now = new Date(); List<ExecutionMessage> msg = new ArrayList<>(); when(executionQueueService.poll("workerId", 5, ExecStatus.ASSIGNED)).thenReturn(msg); List<ExecutionMessage> result = queueDispatcherService.poll("workerId", 5); Assert.assertTrue(result.isEmpty()); }
From source file:com.connectsdk.service.WebOSTVServiceTest.java
@Test public void testCapabilitiesForVersion5() { Mockito.when(serviceDescription.getVersion()).thenReturn("5.0.0"); Assert.assertTrue(service.hasCapabilities(PlaylistControl.JumpToTrack, PlaylistControl.Next, PlaylistControl.Previous, WebAppLauncher.Any, MediaControl.Any)); }
From source file:com.amazonaws.http.AmazonHttpClientRequestTimeoutTest.java
@Test(timeout = 10 * 1000) public void testRequestTimeoutDisabled() { ProblematicServer server = new ProblematicServer(ProblematicServer.ServerIssue.UNRESPONSIVE); server.startServer();/*w ww . java2 s. c o m*/ String localhostEndpoint = "http://localhost:" + server.getPort(); Request<?> request = new EmptyHttpRequest(localhostEndpoint, HttpMethodName.GET); AmazonHttpClient httpClient = new AmazonHttpClient( new ClientConfiguration().withSocketTimeout(1 * 1000).withRequestTimeout(0).withMaxErrorRetry(0)); try { httpClient.execute(request, new NullResponseHandler(), new NullErrorResponseHandler(), new ExecutionContext()); Assert.fail("Client-side socket read timeout is expected!"); } catch (AmazonClientException e) { Assert.assertTrue(e.getCause() instanceof SocketTimeoutException); /* The internal request timer should not have been instantiated. */ ScheduledThreadPoolExecutor httpRequestTimer = httpClient.getHttpRequestTimer().getExecutor(); Assert.assertNull(httpRequestTimer); } server.stopServer(); httpClient.shutdown(); }
From source file:com.indeed.lsmtree.recordlog.TestRecordLogDirectoryQuickly.java
public void testWithDeletedFirstFile() throws Exception { final com.indeed.util.serialization.Serializer serializer = new StringSerializer(); final CompressionCodec codec = new SnappyCodec(); RecordLogDirectory<String> recordLogDir = new RecordLogDirectory.Builder(dir, serializer, codec).build(); final RecordLogDirectory.Writer writer = RecordLogDirectory.Writer.create(dir, serializer, codec, 100); for (int i = 0; i < 10; i++) { writer.append(String.valueOf(i)); }//w w w . ja v a 2 s .c o m Thread.sleep(1000); for (int i = 0; i < 10; i++) { writer.append(String.valueOf(i)); } writer.close(); recordLogDir.close(); recordLogDir = new RecordLogDirectory.Builder(dir, serializer, codec).build(); assertEquals(0, recordLogDir.getMinSegmentNum(dir)); Assert.assertEquals(20, countBlocks(recordLogDir.reader())); final File firstFile = new File(dir, "000/000/000000000.rec"); BlockCompressedRecordFile<String> bcrf = new BlockCompressedRecordFile.Builder(firstFile, serializer, codec) .setBlockSize(RecordLogDirectory.DEFAULT_BLOCK_SIZE) .setRecordIndexBits(RecordLogDirectory.DEFAULT_RECORD_INDEX_BITS) .setPadBits(RecordLogDirectory.DEFAULT_PAD_BITS).build(); final int firstFileBlockCount = countBlocks(bcrf.reader()); Assert.assertTrue(firstFile.delete()); final RecordLogDirectory<String> recordLogDir2 = new RecordLogDirectory.Builder(dir, serializer, codec) .build(); Assert.assertEquals(20 - firstFileBlockCount, countBlocks(recordLogDir2.reader(recordLogDir2.getAddress(1)))); }