List of usage examples for junit.framework Assert assertTrue
static public void assertTrue(boolean condition)
From source file:com.gisgraphy.helper.StringHelperTest.java
@Test public void TransformStringForIlikeIndexationWithSpecialChar() { 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(// w w w .j a v a 2s . c o 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.tritsch.android.chargefinder.CFService.java
/** * <code>lockup<code> will contact the chargefinder service and will retrieve * a/the list of stations described by the parameters. * * @param pointX - x coordinates to start the search from * @param pointY - y coordinates to start the search from * @param radius - the radius from x, y to include in the search * * @return a/the list of stations that are within the radius *///from w ww .ja v a 2 s . co m public static List<CFStation> lookup(final String pointX, final String pointY, final String radius) { if (Log.isLoggable(TAG, Log.DEBUG)) Log.d(TAG, "Enter: lookup()"); Assert.assertNotNull(pointX); Assert.assertFalse(pointX.length() == 0); Assert.assertNotNull(pointY); Assert.assertFalse(pointY.length() == 0); Assert.assertNotNull(radius); Assert.assertFalse(radius.length() == 0); if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "pointX:" + pointX); if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "pointY:" + pointY); if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "radius:" + radius); if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "create the list we will return ..."); List<CFStation> stations = new ArrayList<CFStation>(); if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "create http client ..."); HttpClient httpClient = new DefaultHttpClient(); Assert.assertNotNull(httpClient); String url = "" + BASE_URL + "?point_x=" + pointX + "&point_y=" + pointY + "&radius=" + radius; if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "URL:" + url); if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "go and do it ..."); HttpResponse response = null; try { response = httpClient.execute(new HttpGet(url)); Assert.assertNotNull(response); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "process response ..."); JSONArray stationsObject = null; try { HttpEntity entity = response.getEntity(); Assert.assertNotNull(entity); String resultString = getString(entity.getContent()); Assert.assertNotNull(resultString); if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "Result:" + resultString); JSONObject resultObject = new JSONObject(resultString); Assert.assertNotNull(resultObject); stationsObject = resultObject.getJSONArray("stations"); Assert.assertNotNull(stationsObject); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "build list of stations ..."); try { for (int i = 0; i < stationsObject.length(); i++) { JSONObject station = stationsObject.getJSONObject(i); Assert.assertNotNull(station); CFStation newStation = new CFStation(); newStation.setName(station.getString("name")); newStation.setX(station.getDouble("st_x")); newStation.setY(station.getDouble("st_y")); Assert.assertTrue(stations.add(newStation)); } } catch (Exception e) { e.printStackTrace(); Assert.fail(); } if (Log.isLoggable(TAG, Log.DEBUG)) Log.d(TAG, "Leave: lookup()"); return stations; }
From source file:com.collective.celos.FileSystemStateDatabaseTest.java
@Test public void testPauseFileExistence() throws Exception { StateDatabaseConnection db = getStateDatabaseConnection(); WorkflowID workflowID = new WorkflowID("wf1"); File pauseFile = new File(getDatabaseDir(), "paused/wf1"); Assert.assertFalse(db.isPaused(workflowID)); Assert.assertFalse(pauseFile.exists()); db.setPaused(workflowID, false);//from ww w. jav a 2 s . c o m Assert.assertFalse(db.isPaused(workflowID)); Assert.assertFalse(pauseFile.exists()); db.setPaused(workflowID, true); Assert.assertTrue(pauseFile.exists()); Assert.assertTrue(db.isPaused(workflowID)); db.setPaused(workflowID, false); Assert.assertFalse(db.isPaused(workflowID)); Assert.assertFalse(pauseFile.exists()); }
From source file:com.couchbase.lite.DocumentTest.java
public void testDeleteDocument() throws CouchbaseLiteException { Document document = database.createDocument(); Map<String, Object> properties = new HashMap<String, Object>(); properties.put("foo", "foo"); properties.put("bar", Boolean.FALSE); document.putProperties(properties);// w ww. j a v a 2 s .c o m Assert.assertNotNull(document.getCurrentRevision()); String docId = document.getId(); document.delete(); Assert.assertTrue(document.isDeleted()); Document fetchedDoc = database.getExistingDocument(docId); Assert.assertNull(fetchedDoc); // query all docs and make sure we don't see that document //database.getAllDocs(new QueryOptions()); Query queryAllDocs = database.createAllDocumentsQuery(); QueryEnumerator queryEnumerator = queryAllDocs.run(); for (Iterator<QueryRow> it = queryEnumerator; it.hasNext();) { QueryRow row = it.next(); Assert.assertFalse(row.getDocument().getId().equals(docId)); } }
From source file:org.openmrs.module.printer.PrinterServiceComponentTest.java
@Test public void testShouldReturnTrueIfAnotherPrinterAlreadyHasIpAddressAssigned() { Printer differentPrinter = new Printer(); differentPrinter.setName("Another printer"); differentPrinter.setIpAddress("192.1.1.2"); // printer in test dataset has this ip differentPrinter.setType(PrinterType.LABEL); Assert.assertTrue(printerService.isIpAddressAllocatedToAnotherPrinter(differentPrinter)); }
From source file:edu.uci.ics.jung.algorithms.flows.TestEdmondsKarpMaxFlow.java
public void testSimpleFlow() { DirectedGraph<Number, Number> graph = new DirectedSparseMultigraph<Number, Number>(); Factory<Number> edgeFactory = new Factory<Number>() { int count = 0; public Number create() { return count++; }/*from www .j a v a 2s. com*/ }; Map<Number, Number> edgeCapacityMap = new HashMap<Number, Number>(); for (int i = 0; i < 6; i++) { graph.addVertex(i); } Map<Number, Number> edgeFlowMap = new HashMap<Number, Number>(); graph.addEdge(edgeFactory.create(), 0, 1, EdgeType.DIRECTED); edgeCapacityMap.put(0, 16); graph.addEdge(edgeFactory.create(), 0, 2, EdgeType.DIRECTED); edgeCapacityMap.put(1, 13); graph.addEdge(edgeFactory.create(), 1, 2, EdgeType.DIRECTED); edgeCapacityMap.put(2, 6); graph.addEdge(edgeFactory.create(), 1, 3, EdgeType.DIRECTED); edgeCapacityMap.put(3, 12); graph.addEdge(edgeFactory.create(), 2, 4, EdgeType.DIRECTED); edgeCapacityMap.put(4, 14); graph.addEdge(edgeFactory.create(), 3, 2, EdgeType.DIRECTED); edgeCapacityMap.put(5, 9); graph.addEdge(edgeFactory.create(), 3, 5, EdgeType.DIRECTED); edgeCapacityMap.put(6, 20); graph.addEdge(edgeFactory.create(), 4, 3, EdgeType.DIRECTED); edgeCapacityMap.put(7, 7); graph.addEdge(edgeFactory.create(), 4, 5, EdgeType.DIRECTED); edgeCapacityMap.put(8, 4); EdmondsKarpMaxFlow<Number, Number> ek = new EdmondsKarpMaxFlow<Number, Number>(graph, 0, 5, MapTransformer.<Number, Number>getInstance(edgeCapacityMap), edgeFlowMap, edgeFactory); ek.evaluate(); assertTrue(ek.getMaxFlow() == 23); Set<Number> nodesInS = ek.getNodesInSourcePartition(); assertEquals(4, nodesInS.size()); for (Number v : nodesInS) { Assert.assertTrue(v.intValue() != 3 && v.intValue() != 5); } Set<Number> nodesInT = ek.getNodesInSinkPartition(); assertEquals(2, nodesInT.size()); for (Number v : nodesInT) { Assert.assertTrue(v.intValue() == 3 || v.intValue() == 5); } Set<Number> minCutEdges = ek.getMinCutEdges(); int maxFlow = 0; for (Number e : minCutEdges) { Number flow = edgeFlowMap.get(e); maxFlow += flow.intValue(); } Assert.assertEquals(23, maxFlow); Assert.assertEquals(3, minCutEdges.size()); }
From source file:org.sakaiproject.iclicker.dao.IClickerDaoImplTest.java
/** * Test method for/*w w w . ja v a 2s .com*/ * {@link org.sakaiproject.iclicker.dao.impl.GenericHibernateDao#save(java.lang.Object)}. */ public void testSave() { ClickerRegistration item1 = new ClickerRegistration("New item1", ITEM_OWNER); dao.save(item1); Long itemId = item1.getId(); Assert.assertNotNull(itemId); Assert.assertTrue(dao.countAll(ClickerRegistration.class) > 8); }
From source file:BQJDBC.QueryResultTest.BQForwardOnlyResultSetFunctionTest.java
@Test public void databaseMetaDataGetTables() { //clouddb,ARTICLE_LOOKUP,starschema.net,[Ljava.lang.String;@9e8424 ResultSet result = null;/*from www. j ava2 s . c om*/ try { //Function call getColumns //catalog:null, //schemaPattern: starschema_net__clouddb, //tableNamePattern:OUTLET_LOOKUP, columnNamePattern: null //result = con.getMetaData().getTables("OUTLET_LOOKUP", null, "starschema_net__clouddb", null ); result = con.getMetaData().getColumns(null, "starschema_net__clouddb", "OUTLET_LOOKUP", null); //Function call getTables(catalog: ARTICLE_COLOR_LOOKUP, schemaPattern: null, tableNamePattern: starschema_net__clouddb, types: TABLE , VIEW , SYSTEM TABLE , SYNONYM , ALIAS , ) } catch (SQLException e) { e.printStackTrace(); Assert.fail(); } try { Assert.assertTrue(result.first()); while (!result.isAfterLast()) { String toprint = ""; toprint += result.getString(1) + " , "; toprint += result.getString(2) + " , "; toprint += result.getString(3) + " , "; toprint += result.getString(4) + " , "; toprint += result.getString(5) + " , "; toprint += result.getString(6) + " , "; toprint += result.getString(7) + " , "; toprint += result.getString(8) + " , "; toprint += result.getString(9) + " , "; toprint += result.getString(10); System.err.println(toprint); result.next(); } } catch (SQLException e) { e.printStackTrace(); Assert.fail(); } }
From source file:com.tango.logstash.flume.redis.sink.serializer.TestLogstashSerializer.java
/** * Verifies that standard headers and body are parsed correctly * @throws RedisSerializerException/*from ww w . j ava 2s. c o m*/ */ @Test public void parsingDefaultEventTest() throws RedisSerializerException { LogstashSerializer serializer = new LogstashSerializer(); byte[] body = new byte[] { '1', '2', '3', '4', '5' }; String testHost = "testhost"; String sourcePath = "/my/source/path"; String type = "mytype"; String source = "my source"; List<String> tags = new ArrayList<String>(); tags.add("one tag"); tags.add("another tag"); long now = System.currentTimeMillis(); Map<String, String> headers = new HashMap<String, String>(); headers.put(LogstashSerializer.TIMESTAMP, Long.toString(now)); headers.put(LogstashSerializer.HOST, testHost); headers.put(LogstashSerializer.SRC_PATH, sourcePath); headers.put(LogstashSerializer.TYPE, type); headers.put(LogstashSerializer.SOURCE, source); headers.put(LogstashSerializer.TAGS, StringUtils.join(tags, LogstashSerializer.DEFAULT_TAGS_SEPARATOR)); Event event = new SimpleEvent(); event.setBody(body); event.setHeaders(headers); LogstashEvent logstashEvent = serializer.convertToLogstashEvent(event); Assert.assertNotNull(logstashEvent.getMessage()); Assert.assertEquals(new String(body), logstashEvent.getMessage()); Assert.assertNotNull(logstashEvent.getTimestamp()); Assert.assertEquals(new Date(now), logstashEvent.getTimestamp()); Assert.assertNotNull(logstashEvent.getSourceHost()); Assert.assertEquals(testHost, logstashEvent.getSourceHost()); Assert.assertNotNull(logstashEvent.getSourcePath()); Assert.assertEquals(sourcePath, logstashEvent.getSourcePath()); Assert.assertNotNull(logstashEvent.getSource()); Assert.assertEquals(source, logstashEvent.getSource()); Assert.assertNotNull(logstashEvent.getType()); Assert.assertEquals(type, logstashEvent.getType()); Assert.assertNotNull(logstashEvent.getTags()); Assert.assertEquals(tags.size(), logstashEvent.getTags().size()); Assert.assertTrue(CollectionUtils.isEqualCollection(tags, logstashEvent.getTags())); Assert.assertNotNull(logstashEvent.getFields()); Assert.assertEquals(headers.size(), logstashEvent.getFields().size()); for (String key : headers.keySet()) { Assert.assertTrue(logstashEvent.getFields().containsKey(key)); Assert.assertEquals(headers.get(key), logstashEvent.getFields().get(key)); } }
From source file:com.buddycloud.mediaserver.download.DownloadAvatarTest.java
@Test public void anonymousSuccessfulDownloadParamAuth() throws Exception { Base64 encoder = new Base64(true); String authStr = BASE_USER + ":" + BASE_TOKEN; ClientResource client = new ClientResource(URL + "?auth=" + new String(encoder.encode(authStr.getBytes()))); File file = new File(TEST_OUTPUT_DIR + File.separator + "downloadedAvatar.jpg"); FileOutputStream outputStream = FileUtils.openOutputStream(file); client.get().write(outputStream);/*from www .j a v a 2 s. c om*/ Assert.assertTrue(file.exists()); // Delete downloaded file FileUtils.deleteDirectory(new File(TEST_OUTPUT_DIR)); outputStream.close(); }