List of usage examples for java.util List toString
public String toString()
From source file:org.alfresco.bm.BM000XTest.java
/** * A listener method that allows the test to check results <b>before</b> the in-memory MongoDB instance * is discarded.// w ww . ja v a2s .c o m * <p/> * Check that the exact number of results are available, as expected * * @see BMTestRunnerListener */ @Override public void testRunFinished(ApplicationContext testCtx, String test, String run) { TestRunServicesCache services = testCtx.getBean(TestRunServicesCache.class); LogService logService = testCtx.getBean(LogService.class); MongoTestDAO testDAO = services.getTestDAO(); TestService testService = services.getTestService(); ResultService resultService = services.getResultService(test, run); SessionService sessionService = services.getSessionService(test, run); assertNotNull(resultService); TestRestAPI testAPI = new TestRestAPI(testDAO, testService, logService, services); ResultsRestAPI resultsAPI = testAPI.getTestRunResultsAPI(test, run); // Let's check the results before the DB gets thrown away (we didn't make it ourselves) // Dump one of each type of event for information Set<String> eventNames = new TreeSet<String>(resultService.getEventNames()); logger.info("Showing 1 of each type of event:"); for (String eventName : eventNames) { List<EventRecord> eventRecord = resultService.getResults(eventName, 0, 1); logger.info(" " + eventRecord); assertFalse( "An event was created that has no available processor or producer: " + eventRecord + ". Use the TerminateEventProducer to absorb events.", eventRecord.toString().contains("processedBy=unknown")); } // One successful START event assertEquals("Incorrect number of start events.", 1, resultService.countResultsByEventName(Event.EVENT_NAME_START)); List<EventRecord> results = resultService.getResults(0L, Long.MAX_VALUE, false, 0, 1); if (results.size() != 1 || !results.get(0).getEvent().getName().equals(Event.EVENT_NAME_START)) { Assert.fail(Event.EVENT_NAME_START + " failed: \n" + results.toString()); } /* * 'start' = 1 result * 'scheduleProcesses' = 2 results * 'executeProcess' = 200 results * Sessions = 200 */ assertEquals("Incorrect number of event names: " + eventNames, 3, eventNames.size()); assertEquals("Incorrect number of events: " + "scheduleProcesses", 2, resultService.countResultsByEventName("scheduleProcesses")); assertEquals("Incorrect number of events: " + "executeProcess", 200, resultService.countResultsByEventName("executeProcess")); // 203 events in total assertEquals("Incorrect number of results.", 203, resultService.countResults()); // Check that we got the failure rate correct ~30% long failures = resultService.countResultsByFailure(); assertEquals("Failure rate out of bounds. ", 60.0, (double) failures, 15.0); // Get the summary CSV results for the time period and check some of the values String summary = BMTestRunner.getResultsCSV(resultsAPI); logger.info(summary); assertTrue(summary.contains(",,scheduleProcesses, 2,")); assertTrue(summary.contains(",,executeProcess, 200,")); // Get the chart results and check String chartData = resultsAPI.getTimeSeriesResults(0L, "seconds", 1, 10, true); if (logger.isDebugEnabled()) { logger.debug("BM000X chart data: \n" + chartData); } // Check that we have 10.0 processes per second; across 10s, we should get 100 events assertTrue("Expected 10 processes per second.", chartData.contains("\"num\" : 100 , \"numPerSec\" : 10.0")); // Check the session data assertEquals("All sessions should be closed: ", 0L, sessionService.getActiveSessionsCount()); assertEquals("All sessions should be used: ", 200L, sessionService.getAllSessionsCount()); // Check the log messages DBCursor logs = logService.getLogs(null, test, run, LogLevel.INFO, null, null, 0, 500); try { assertEquals("Incorrect number of log messages for this test run. ", 6, logs.size()); logger.debug("Log messages for " + test + "." + "." + run); while (logs.hasNext()) { DBObject log = logs.next(); Date time = (Date) log.get("time"); String msg = (String) log.get("msg"); logger.debug(" " + " >>> " + time + " >>> " + msg); } } finally { logs.close(); } }
From source file:eu.planets_project.tb.impl.services.mockups.workflow.WorkflowDroidXCDLExtractorComparator.java
/** * Runs the XCDLComparator on two given xcdls and returns the comparison result. * @param xcdl1/*from w w w. j a v a 2 s . c om*/ * @param xcdl2 * @return * @throws Exception */ private String runXCDLComparator(String xcdl1, String xcdl2) throws Exception { URL url = null; try { url = new URL(URL_XCDLCOMPARATOR); Service service = Service.create(url, new QName(PlanetsServices.NS, Compare.NAME)); Compare comparator = service.getPort(Compare.class); //the service call and it's result DigitalObject x1 = new DigitalObject.Builder(Content.byValue(xcdl1.getBytes())).build(); DigitalObject x2 = new DigitalObject.Builder(Content.byValue(xcdl2.getBytes())).build(); List<Property> result = comparator.compare(x1, x2, null).getProperties(); if (result == null) { throw new Exception("XCDL comparison failed - please check service logs for details"); } return result.toString(); } catch (MalformedURLException e) { e.printStackTrace(); throw e; } }
From source file:com.ucuenca.pentaho.plugin.step.ontologymapping.OntoMapData.java
/** * Query DB Table data and load into the TableView * @param tableView Dialog TableView/*from ww w. j a va 2 s . c o m*/ * @param tableName DB table name * @return total number of queried rows * @throws Exception */ public int queryTable(TableView tableView, String tableName) throws Exception { ColumnInfo[] columns = tableView.getColumns(); List<String> tableFields = new ArrayList<String>(); for (ColumnInfo column : columns) tableFields.add(column.getName().toUpperCase().replaceAll(" ", "_")); Object[] pk = new Object[] { this.getTransName().toUpperCase(), this.getStepName().toUpperCase() }; ResultSet rs = DatabaseLoader .executeQuery("SELECT " + tableFields.toString().substring(1, tableFields.toString().length() - 1) + " FROM " + tableName + " WHERE TRANSID = ? AND STEPID = ?", pk); tableView.removeAll(); int row = 0; while (rs.next()) { if (row == 0) { TableItem item = tableView.table.getItem(row); int count = 1; while (count <= tableFields.size()) { item.setText(count, rs.getString(count)); count++; } } else { List<String> values = new ArrayList<String>(); int count = 1; while (count <= tableFields.size()) { values.add(rs.getString(count)); count++; } tableView.add(values.toArray(new String[values.size()])); } row++; } tableView.setRowNums(); tableView.optWidth(true); return row; }
From source file:com.redhat.lightblue.crud.mongo.IterateAndUpdate.java
@Override public void update(CRUDOperationContext ctx, DBCollection collection, EntityMetadata md, CRUDUpdateResponse response, DBObject query) { LOGGER.debug("iterateUpdate: start"); LOGGER.debug("Computing the result set for {}", query); DBCursor cursor = null;/*from w w w .jav a2 s. c o m*/ int docIndex = 0; int numFailed = 0; try { ctx.getFactory().getInterceptors().callInterceptors(InterceptPoint.PRE_CRUD_UPDATE_RESULTSET, ctx); cursor = new FindCommand(collection, query, null).execute(); LOGGER.debug("Found {} documents", cursor.count()); ctx.getFactory().getInterceptors().callInterceptors(InterceptPoint.POST_CRUD_UPDATE_RESULTSET, ctx); // read-update-write while (cursor.hasNext()) { DBObject document = cursor.next(); boolean hasErrors = false; LOGGER.debug("Retrieved doc {}", docIndex); DocCtx doc = ctx.addDocument(translator.toJson(document)); doc.setOutputDocument(doc.copy()); // From now on: doc contains the old copy, and doc.getOutputDocument contains the new copy if (updater.update(doc.getOutputDocument(), md.getFieldTreeRoot(), Path.EMPTY)) { LOGGER.debug("Document {} modified, updating", docIndex); PredefinedFields.updateArraySizes(nodeFactory, doc.getOutputDocument()); LOGGER.debug("Running constraint validations"); validator.clearErrors(); validator.validateDoc(doc.getOutputDocument()); List<Error> errors = validator.getErrors(); if (errors != null && !errors.isEmpty()) { ctx.addErrors(errors); hasErrors = true; LOGGER.debug("Doc has errors"); } errors = validator.getDocErrors().get(doc.getOutputDocument()); if (errors != null && !errors.isEmpty()) { doc.addErrors(errors); hasErrors = true; LOGGER.debug("Doc has data errors"); } if (!hasErrors) { List<Path> paths = roleEval.getInaccessibleFields_Update(doc.getOutputDocument(), doc); LOGGER.debug("Inaccesible fields during update={}" + paths); if (paths != null && !paths.isEmpty()) { doc.addError(Error.get("update", CrudConstants.ERR_NO_FIELD_UPDATE_ACCESS, paths.toString())); hasErrors = true; } } if (!hasErrors) { try { ctx.getFactory().getInterceptors().callInterceptors(InterceptPoint.PRE_CRUD_UPDATE_DOC, ctx, doc); DBObject updatedObject = translator.toBson(doc.getOutputDocument()); translator.addInvisibleFields(document, updatedObject, md); WriteResult result = new SaveCommand(collection, updatedObject).execute(); doc.setOperationPerformed(Operation.UPDATE); LOGGER.debug("Number of rows affected : ", result.getN()); ctx.getFactory().getInterceptors().callInterceptors(InterceptPoint.POST_CRUD_UPDATE_DOC, ctx, doc); } catch (Exception e) { LOGGER.warn("Update exception for document {}: {}", docIndex, e); doc.addError(Error.get(MongoCrudConstants.ERR_UPDATE_ERROR, e.toString())); hasErrors = true; } } } else { LOGGER.debug("Document {} was not modified", docIndex); } if (hasErrors) { LOGGER.debug("Document {} has errors", docIndex); numFailed++; doc.setOutputDocument(errorProjector.project(doc.getOutputDocument(), nodeFactory)); } else { if (projector != null) { LOGGER.debug("Projecting document {}", docIndex); doc.setOutputDocument(projector.project(doc.getOutputDocument(), nodeFactory)); } } docIndex++; } } finally { if (cursor != null) { cursor.close(); } } response.setNumUpdated(docIndex); response.setNumFailed(numFailed); }
From source file:smellminer.engine.JFreeChartDemo.java
/** * Creates a sample dataset./* ww w .j av a 2 s. c om*/ * * @return A sample dataset. */ public DefaultBoxAndWhiskerCategoryDataset createSampleDataset() { final int seriesCount = 3; final int categoryCount = 4; final int entityCount = 22; final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); for (int i = 0; i < seriesCount; i++) { for (int j = 0; j < categoryCount; j++) { final List list = new ArrayList(); // add some values... for (int k = 0; k < entityCount; k++) { final double value1 = 10.0 + Math.random() * 3; list.add(new Double(value1)); final double value2 = 11.25 + Math.random(); // concentrate values in the middle list.add(new Double(value2)); } LOGGER.debug("Adding series " + i); LOGGER.debug(list.toString()); dataset.add(list, "Series " + i, " Type " + j); } } return dataset; }
From source file:at.ac.tuwien.auto.iotsys.gateway.connectors.knx.KNXDeviceLoaderImpl.java
public ArrayList<Connector> initDevices(ObjectBroker objectBroker) { setConfiguration(devicesConfig);//from ww w . j a v a 2 s .co m objectBroker.getConfigDb().prepareDeviceLoader(getClass().getName()); ArrayList<Connector> connectors = new ArrayList<Connector>(); List<JsonNode> connectorsFromDb = objectBroker.getConfigDb().getConnectors("knx"); int connectorsSize = 0; if (connectorsFromDb.size() <= 0) { Object knxConnectors = devicesConfig.getProperty("knx.connector.name"); if (knxConnectors != null) { connectorsSize = 1; } if (knxConnectors instanceof Collection<?>) { connectorsSize = ((Collection<?>) knxConnectors).size(); } } else connectorsSize = connectorsFromDb.size(); for (int connector = 0; connector < connectorsSize; connector++) { HierarchicalConfiguration subConfig = devicesConfig.configurationAt("knx.connector(" + connector + ")"); Object knxConfiguredDevices = subConfig.getProperty("device.type");// just to get the number of devices String connectorId = ""; String connectorName = subConfig.getString("name"); String routerIP = subConfig.getString("router.ip"); int routerPort = subConfig.getInteger("router.port", 3671); String localIP = subConfig.getString("localIP"); Boolean enabled = subConfig.getBoolean("enabled", false); try { connectorId = connectorsFromDb.get(connector).get("_id").asText(); connectorName = connectorsFromDb.get(connector).get("name").asText(); enabled = connectorsFromDb.get(connector).get("enabled").asBoolean(); routerIP = connectorsFromDb.get(connector).get("routerHostname").asText(); routerPort = connectorsFromDb.get(connector).get("routerPort").asInt(); localIP = connectorsFromDb.get(connector).get("localIP").asText(); } catch (Exception e) { log.info("Cannot fetch configuration from Database, using devices.xml"); } if (enabled) { try { KNXConnector knxConnector = new KNXConnector(routerIP, routerPort, localIP); knxConnector.setName(connectorName); knxConnector.setTechnology("knx"); knxConnector.setEnabled(enabled); //knxConnector.connect(); connectors.add(knxConnector); int numberOfDevices = 0; List<Device> devicesFromDb = objectBroker.getConfigDb().getDevices(connectorId); if (connectorsFromDb.size() <= 0) { if (knxConfiguredDevices != null) { numberOfDevices = 1; // there is at least one // device. } if (knxConfiguredDevices instanceof Collection<?>) { Collection<?> knxDevices = (Collection<?>) knxConfiguredDevices; numberOfDevices = knxDevices.size(); } } else numberOfDevices = devicesFromDb.size(); log.info( numberOfDevices + " KNX devices found in configuration for connector " + connectorName); for (int i = 0; i < numberOfDevices; i++) { String type = subConfig.getString("device(" + i + ").type"); List<Object> address = subConfig.getList("device(" + i + ").address"); String addressString = address.toString(); String ipv6 = subConfig.getString("device(" + i + ").ipv6"); String href = subConfig.getString("device(" + i + ").href"); String name = subConfig.getString("device(" + i + ").name"); String displayName = subConfig.getString("device(" + i + ").displayName"); Boolean historyEnabled = subConfig.getBoolean("device(" + i + ").historyEnabled", false); Boolean groupCommEnabled = subConfig.getBoolean("device(" + i + ").groupCommEnabled", false); Integer historyCount = subConfig.getInt("device(" + i + ").historyCount", 0); Boolean refreshEnabled = subConfig.getBoolean("device(" + i + ").refreshEnabled", false); Device deviceFromDb; try { deviceFromDb = devicesFromDb.get(i); type = deviceFromDb.getType(); addressString = deviceFromDb.getAddress(); String subAddr[] = addressString.substring(1, addressString.length() - 1).split(", "); address = Arrays.asList((Object[]) subAddr); ipv6 = deviceFromDb.getIpv6(); href = deviceFromDb.getHref(); name = deviceFromDb.getName(); displayName = deviceFromDb.getDisplayName(); historyEnabled = deviceFromDb.isHistoryEnabled(); groupCommEnabled = deviceFromDb.isGroupcommEnabled(); refreshEnabled = deviceFromDb.isRefreshEnabled(); historyCount = deviceFromDb.getHistoryCount(); } catch (Exception e) { } // Transition step: comment when done Device d = new Device(type, ipv6, addressString, href, name, displayName, historyCount, historyEnabled, groupCommEnabled, refreshEnabled); objectBroker.getConfigDb().prepareDevice(connectorName, d); if (type != null && address != null) { int addressCount = address.size(); try { Constructor<?>[] declaredConstructors = Class.forName(type) .getDeclaredConstructors(); for (int k = 0; k < declaredConstructors.length; k++) { if (declaredConstructors[k].getParameterTypes().length == addressCount + 1) { // constructor // that // takes // the // KNX // connector // and // group // address // as // argument Object[] args = new Object[address.size() + 1]; // first arg is KNX connector args[0] = knxConnector; for (int l = 1; l <= address.size(); l++) { try { String adr = (String) address.get(l - 1); if (adr == null || adr.equals("null")) { args[l] = null; } else { args[l] = new GroupAddress(adr); } } catch (KNXFormatException e) { e.printStackTrace(); } } try { // create a instance of the // specified KNX device Obj knxDevice = (Obj) declaredConstructors[k].newInstance(args); knxDevice.setHref(new Uri( URLEncoder.encode(connectorName, "UTF-8") + "/" + href)); if (name != null && name.length() > 0) { knxDevice.setName(name); } if (displayName != null && displayName.length() > 0) { knxDevice.setDisplayName(displayName); } if (ipv6 != null) { objectBroker.addObj(knxDevice, ipv6); } else { objectBroker.addObj(knxDevice); } myObjects.add(knxDevice); knxDevice.initialize(); if (historyEnabled != null && historyEnabled) { if (historyCount != null && historyCount != 0) { objectBroker.addHistoryToDatapoints(knxDevice, historyCount); } else { objectBroker.addHistoryToDatapoints(knxDevice); } } if (groupCommEnabled) { objectBroker.enableGroupComm(knxDevice); } if (refreshEnabled != null && refreshEnabled) { objectBroker.enableObjectRefresh(knxDevice); } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } } catch (SecurityException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } } catch (Exception e) { e.printStackTrace(); } } } return connectors; }
From source file:org.jfree.chart.demo.BoxAndWhiskerDemo.java
/** * Creates a sample dataset./* w w w. j av a2 s.co m*/ * * @return A sample dataset. */ private BoxAndWhiskerCategoryDataset createSampleDataset() { final int seriesCount = 3; final int categoryCount = 4; final int entityCount = 22; final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); for (int i = 0; i < seriesCount; i++) { for (int j = 0; j < categoryCount; j++) { final List list = new ArrayList(); // add some values... for (int k = 0; k < entityCount; k++) { final double value1 = 10.0 + Math.random() * 3; list.add(new Double(value1)); final double value2 = 11.25 + Math.random(); // concentrate values in the middle list.add(new Double(value2)); } LOGGER.debug("Adding series " + i); LOGGER.debug(list.toString()); dataset.add(list, "Series " + i, " Type " + j); } } return dataset; }
From source file:org.o3project.ocnrm.lib.flow.OduFlowCreatorTest.java
/** * Test method for//from www.j a va 2s. c o m * {@link org.o3project.ocnrm.lib.flow.OduFlowCreator#createFlow()} */ @Test public void testCreateFlowWithJsonProcessingException() throws Exception { Logger dummyLogger = mock(Logger.class); Field field = target.getClass().getSuperclass().getSuperclass().getDeclaredField("logger"); field.setAccessible(true); field.set(target, dummyLogger); JSONParser parser = mock(JSONParser.class); PowerMockito.whenNew(JSONParser.class).withNoArguments().thenReturn(parser); OptFlow flow = new OptFlow(); flow.setTerminationPointPairs(new ArrayList<TerminationPoints>()); PowerMockito.doThrow(mock(JsonProcessingException.class)).when(parser).convertToJson(anyList(), eq(seqNo)); List<String> result = target.createFlow(flow, data, seqNo); assertThat(result.toString(), is("[]")); verify(dummyLogger, times(1)).error(seqNo + "\t" + "JsonProcessingException occured."); }
From source file:edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringRDFService.java
private String showSortedRILs(List<RowIndexedLiteral> candidatesForRemoval) { List<String> langstrings = new ArrayList<String>(); for (RowIndexedLiteral ril : candidatesForRemoval) { langstrings.add(ril.getLiteral().getLanguage()); }// ww w . j a va 2 s . co m return langstrings.toString(); }
From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftExporterBeanTest.java
@Test public void testBadSingleChannel() throws Exception { final Experiment experiment = makeGoodExperiment(); final Hybridization h = experiment.getHybridizations().iterator().next(); final RawArrayData rawData = new RawArrayData(); final ProtocolApplication pa = new ProtocolApplication(); rawData.setName("raw-array-data2"); rawData.getHybridizations().add(h);//from ww w . ja v a 2 s . c o m final Protocol p = this.vocab.getProtocol("data processing", null); p.setDescription("data proc desc"); pa.setProtocol(p); rawData.getProtocolApplications().add(pa); h.getRawDataCollection().add(rawData); final List<String> result = this.bean.validateForExport(experiment); assertEquals(result.toString(), 0, result.size()); }