@Transactional(readOnly = true) @Test public void testGetWidgetDefinitionsByCategory() throws IOException, Exception { SecurityContext securityContext = SecurityContextHolder.getContext(); securityContext.setAuthentication(auth); MultiMap widgetDefinitionsByCategoryMap = uIService.getWidgetDefinitionsByCategory(); Assert.notNull(widgetDefinitionsByCategoryMap); // Assert.isTrue(widgetDefinitionsByCategoryMap.size() == 3); // Assert.isTrue(widgetDefinitionsByCategoryMap.values().size() == 4); org.junit.Assert.assertTrue( "testGetWidgetDefinitionsByCategory() widgetDefinitionsByCategoryMap.size() failed test, " + "expected value 3, actually got: " + widgetDefinitionsByCategoryMap.size(), widgetDefinitionsByCategoryMap.size() == 4); org.junit.Assert.assertTrue( "testGetWidgetDefinitionsByCategory() widgetDefinitionsByCategoryMap.values().size() failed test, " + "expected value 4, actually got: " + widgetDefinitionsByCategoryMap.values().size(), widgetDefinitionsByCategoryMap.values().size() >= 5); securityContext.setAuthentication(null); }
/** * Indexes a set of reports, using Start and End tags output is a list of entries of the form: A: * time1,time2,time3 * * <p>If no matches, will return an empty array */ @SuppressWarnings("unchecked") public static Text[] indexGraph(Map<String, Report> reports) { org.apache.commons.collections.MultiMap index = new org.apache.commons.collections.MultiHashMap(); // map from start tag to opIds of nodes containing the ends for (Map.Entry<String, Report> report : reports.entrySet()) { Report start = report.getValue(); List<String> starts = start.get("Start"); if (starts != null) { for (String s : starts) { Report end = findMatchingEnd(reports, start, s); if (end == null) continue; List<String> endTL = end.get("Timestamp"); List<String> staTL = start.get("Timestamp"); if (staTL != null && endTL != null && staTL.size() > 0 && endTL.size() > 0) { // FIXME: perhaps parse more cleverly? double startT = Double.parseDouble(staTL.get(0)); double endT = Double.parseDouble(endTL.get(0)); Long diff = new Long((long) (1000 * (endT - startT))); index.put(s, diff); } } } } Text[] out = new Text[index.size()]; int i = 0; for (Object k : index.keySet()) { StringBuilder sb = new StringBuilder(); sb.append(k.toString()); sb.append(' '); Collection coll = (Collection) index.get(k); for (Object v : coll) { assert v instanceof Long : "how did a non-Long get into my collection?"; sb.append(v.toString()); sb.append(","); } sb.deleteCharAt(sb.length() - 1); Text t = new Text(sb.toString()); out[i++] = t; } return out; }