@Override public DataResponse<Iterable<TestResult>> search(TestResultRequest request) { Component component = componentRepository.findOne(request.getComponentId()); if (!component.getCollectorItems().containsKey(CollectorType.Test)) { return new DataResponse<>(null, 0L); } List<TestResult> result = new ArrayList<>(); for (CollectorItem item : component.getCollectorItems().get(CollectorType.Test)) { QTestResult testResult = new QTestResult("testResult"); BooleanBuilder builder = new BooleanBuilder(); builder.and(testResult.collectorItemId.eq(item.getId())); if (request.validStartDateRange()) { builder.and( testResult.startTime.between(request.getStartDateBegins(), request.getStartDateEnds())); } if (request.validEndDateRange()) { builder.and( testResult.endTime.between(request.getEndDateBegins(), request.getEndDateEnds())); } if (request.validDurationRange()) { builder.and( testResult.duration.between( request.getDurationGreaterThan(), request.getDurationLessThan())); } if (!request.getTypes().isEmpty()) { builder.and(testResult.testCapabilities.any().type.in(request.getTypes())); } if (request.getMax() == null) { result.addAll( Lists.newArrayList( testResultRepository.findAll(builder.getValue(), testResult.timestamp.desc()))); } else { PageRequest pageRequest = new PageRequest(0, request.getMax(), Sort.Direction.DESC, "timestamp"); result.addAll( Lists.newArrayList( testResultRepository.findAll(builder.getValue(), pageRequest).getContent())); } } // One collector per Type. get(0) is hardcoded. if (!CollectionUtils.isEmpty(component.getCollectorItems().get(CollectorType.Test)) && (component.getCollectorItems().get(CollectorType.Test).get(0) != null)) { Collector collector = collectorRepository.findOne( component.getCollectorItems().get(CollectorType.Test).get(0).getCollectorId()); if (collector != null) { return new DataResponse<>( pruneToDepth(result, request.getDepth()), collector.getLastExecuted()); } } return new DataResponse<>(null, 0L); }
@Test public void useCase_exampleTableWithComment_case1() { storyElement = new StoryElement(localizedStepSupport, 17, GIVEN1); String rawContent = storyElement.getContent(); ContentWithIgnorableEmitter emitter = new ContentWithIgnorableEmitter(RegexUtils.COMMENT_PATTERN, rawContent); String input = emitter.contentWithoutIgnorables(); int offset = 0; WeightChain chain = parametrizedStep.calculateWeightChain(input); List<String> chainTokens = chain.tokenize(); for (int i = 0; i < chainTokens.size(); i++) { org.jbehave.eclipse.editor.step.ParametrizedStep.Token pToken = parametrizedStep.getToken(i); // be aware that the token length can be shorter than the content length // because content can also contain comment :) String content = chainTokens.get(i); if (pToken.isIdentifier) { emitter.emitNext(offset, content.length(), collector, "I"); } else { emitter.emitNext(offset, content.length(), collector, "D"); } offset += content.length(); } assertThat(collector.emittedList.size(), equalTo(6)); assertThat(collector.applyOn(rawContent, false), equalTo(rawContent)); assertThat(collector.applyOn(rawContent, true), equalTo(EXPECTED1)); }
/** * Test. * * @throws IOException e */ @Test public void testPeriodeNonTout() throws IOException { // counter avec période non TOUT et des requêtes collector.collectWithoutErrors(javaInformationsList); final String requestName = "test 1"; counter.bindContext(requestName, "complete test 1", null, -1); sqlCounter.addRequest("sql1", 10, 10, false, -1); counter.addRequest(requestName, 0, 0, false, 1000); counter.addRequest("test2", 1000, 500, false, 1000); counter.addRequest("test3", 10000, 500, true, 10000); collector.collectWithoutErrors(javaInformationsList); final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.SEMAINE, writer); htmlReport.toHtml("message 6", null); assertNotEmptyAndClear(writer); // période personnalisée final HtmlReport htmlReportRange = new HtmlReport( collector, null, javaInformationsList, Range.createCustomRange(new Date(), new Date()), writer); htmlReportRange.toHtml("message 6", null); assertNotEmptyAndClear(writer); }
/** * Test. * * @throws IOException e */ @Test public void testRootContexts() throws IOException { HtmlReport htmlReport; // addRequest pour que CounterRequestContext.getCpuTime() soit appelée counter.addRequest("first request", 100, 100, false, 1000); TestCounter.bindRootContexts("first request", counter, 3); sqlCounter.bindContext("sql", "sql", null, -1); htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); htmlReport.toHtml("message a", null); assertNotEmptyAndClear(writer); final Counter myCounter = new Counter("http", null); final Collector collector2 = new Collector("test 2", Arrays.asList(myCounter)); myCounter.bindContext("my context", "my context", null, -1); htmlReport = new HtmlReport(collector2, null, javaInformationsList, Period.SEMAINE, writer); htmlReport.toHtml("message b", null); assertNotEmptyAndClear(writer); final HtmlCounterRequestContextReport htmlCounterRequestContextReport = new HtmlCounterRequestContextReport( collector2.getRootCurrentContexts(collector2.getCounters()), null, new ArrayList<ThreadInformations>(), false, 500, writer); htmlCounterRequestContextReport.toHtml(); assertNotEmptyAndClear(writer); }
private void writeDurationAndOverhead() throws DocumentException { final long displayDuration = System.currentTimeMillis() - start; final String tmp = "\n\n" + getString("temps_derniere_collecte") + ": " + collector.getLastCollectDuration() + ' ' + getString("ms") + '\n' + getString("temps_affichage") + ": " + displayDuration + ' ' + getString("ms") + '\n' + getString("Estimation_overhead_memoire") + ": < " + (collector.getEstimatedMemorySize() / 1024 / 1024 + 1) + ' ' + getString("Mo") + '\n' + getString("Usage_disque") + ": " + (collector.getDiskUsage() / 1024 / 1024 + 1) + ' ' + getString("Mo"); final String string; if (Parameters.JAVAMELODY_VERSION != null) { string = tmp + "\n\n" + "JavaMelody " + Parameters.JAVAMELODY_VERSION; } else { string = tmp; } addToDocument(new Phrase(string, cellFont)); }
private void writeGraphDetails() throws IOException, DocumentException { if (collector.isStopped()) { return; } final PdfPTable jrobinTable = new PdfPTable(1); jrobinTable.setHorizontalAlignment(Element.ALIGN_CENTER); jrobinTable.setWidthPercentage(100); jrobinTable.getDefaultCell().setBorder(0); if (largeGraphs != null) { // si les graphiques ont été préinitialisés (en Swing) alors on les utilise for (final byte[] imageData : largeGraphs.values()) { final Image image = Image.getInstance(imageData); jrobinTable.addCell(image); } } else { final Collection<JRobin> counterJRobins = collector.getDisplayedCounterJRobins(); if (counterJRobins.isEmpty()) { return; } for (final JRobin jrobin : counterJRobins) { // la hauteur de l'image est prévue pour qu'il n'y ait pas de graph seul sur une page final Image image = Image.getInstance(jrobin.graph(range, LARGE_GRAPH_WIDTH, LARGE_GRAPH_HEIGHT)); jrobinTable.addCell(image); } } newPage(); addToDocument(jrobinTable); newPage(); }
private String buildSummary() { final String tmp; if (range.getPeriod() == Period.TOUT) { final String startDate = I18N.createDateAndTimeFormat().format(collector.getCounters().get(0).getStartDate()); tmp = getFormattedString( "Statistiques", "JavaMelody", I18N.getCurrentDateAndTime(), startDate, collector.getApplication()); } else { tmp = getFormattedString( "Statistiques_sans_depuis", "JavaMelody", I18N.getCurrentDateAndTime(), collector.getApplication()); } if (javaInformationsList.get(0).getContextDisplayName() != null) { return tmp + " (" + javaInformationsList.get(0).getContextDisplayName() + ')'; } return tmp; }
private FileCopyDetails expectActionExecutedWhenFileVisited() { final Collector<FileCopyDetails> collectDetails = collector(); final Action<FileCopyDetails> action = context.mock(Action.class, "action1"); context.checking( new Expectations() { { Sequence seq = context.sequence("seq"); one(delegate).visitSpec(spec); inSequence(seq); allowing(spec).getAllCopyActions(); will(returnValue(toList(action))); one(action).execute(with(notNullValue(FileCopyDetails.class))); inSequence(seq); will(collectTo(collectDetails)); one(delegate).visitFile(with(not(sameInstance(details)))); inSequence(seq); } }); visitor.visitSpec(spec); visitor.visitFile(details); FileCopyDetails copyDetails = collectDetails.get(); return copyDetails; }
public void testNegativeScores() throws Exception { // The Top*Collectors previously filtered out documents with <= scores. This // behavior has changed. This test checks that if PositiveOnlyScoresFilter // wraps one of these collectors, documents with <= 0 scores are indeed // filtered. int numPositiveScores = 0; for (int i = 0; i < scores.length; i++) { if (scores[i] > 0) { ++numPositiveScores; } } Scorer s = new SimpleScorer(); TopDocsCollector tdc = TopScoreDocCollector.create(scores.length, true); Collector c = new PositiveScoresOnlyCollector(tdc); c.setScorer(s); while (s.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) { c.collect(0); } TopDocs td = tdc.topDocs(); ScoreDoc[] sd = td.scoreDocs; assertEquals(numPositiveScores, td.totalHits); for (int i = 0; i < sd.length; i++) { assertTrue("only positive scores should return: " + sd[i].score, sd[i].score > 0); } }
@Override public void map(LongWritable key, Text value, TupleMRContext context, Collector collector) throws IOException, InterruptedException { user.set("name", "Pere"); user.set("money", 100); user.set("my_country", "ES"); collector.write(user); user.set("name", "Iván"); user.set("my_country", "ES"); user.set("money", 50); collector.write(user); user.set("my_country", "FR"); user.set("money", 150); user.set("name", "Eric"); collector.write(user); country.set("country", "ES"); country.set("averageSalary", 1000); collector.write(country); country.set("country", "FR"); country.set("averageSalary", 1500); collector.write(country); }
/** * Test checkstyle for true negative. * * @throws Exception If something goes wrong */ @Test public void testCheckstyleTrueNegative() throws Exception { final AuditListener listener = Mockito.mock(AuditListener.class); final Collector collector = new ChecksTest.Collector(); Mockito.doAnswer(collector).when(listener).addError(Mockito.any(AuditEvent.class)); this.check("/Valid.java", listener); MatcherAssert.assertThat(collector.summary(), Matchers.equalTo("")); Mockito.verify(listener, Mockito.times(0)).addError(Mockito.any(AuditEvent.class)); }
public void testStoreCity() { String query = "select p from Product p join p.stores store where store"; List visible = getVisibleEntityNames(query.toCharArray()); Collector hcc = new Collector(); String canonicalPath = cc.getCanonicalPath(visible, "store.city"); cc.getMatchingProperties(canonicalPath, "", hcc); doTestFields(hcc.getCompletionProposals(), new String[] {"id", "name"}); }
@Override protected Collector newCollector(final ItemType firstItem) { final Properties ctx = WorkpackagesOnCommitSchedulerTemplate.this.extractCtxFromItem(firstItem); final Collector collector = new Collector(ctx); collector.setCreateOneWorkpackagePerModel( WorkpackagesOnCommitSchedulerTemplate.this.createOneWorkpackagePerModel.get()); return collector; }
private void postCollectLastCollector() { if (collector != null) { try { collector.postCollect(); collector.close(); } finally { collector = null; } } }
@Override public <T> Set<Method> getInitializerMethods(Class<T> clazz) throws MultiException { Collector collector = new Collector(); Set<Method> retVal = Utilities.findInitializerMethods(clazz, locator, collector); collector.throwIfErrors(); return retVal; }
private Collector createCollector() { CollectorRequest collectorReq = new CollectorRequest(); collectorReq.setName("JenkinsCucumberTest"); collectorReq.setCollectorType(CollectorType.Test); Collector col = collectorReq.toCollector(); col.setEnabled(true); col.setOnline(true); col.setLastExecuted(System.currentTimeMillis()); return collectorService.createCollector(col); }
@Override public <T> Method getPreDestroyMethod(Class<T> clazz) throws MultiException { Collector collector = new Collector(); Method retVal = Utilities.findPreDestroy(clazz, locator, collector); collector.throwIfErrors(); return retVal; }
@Test public void stopsAtFirstActionWhichThrowsException() { final Throwable failure = new RuntimeException("failure"); final Collector<Throwable> wrappedFailure = collector(); context.checking( new Expectations() { { allowing(task).getTaskActions(); will(returnValue(toList(action1, action2))); one(listener).beforeActions(task); inSequence(sequence); one(state).setExecuting(true); inSequence(sequence); one(state).setDidWork(true); inSequence(sequence); one(standardOutputCapture).start(); inSequence(sequence); one(action1).contextualise(executionContext); inSequence(sequence); one(action1).execute(task); will(throwException(failure)); inSequence(sequence); one(action1).contextualise(null); inSequence(sequence); one(standardOutputCapture).stop(); inSequence(sequence); one(state).executed(with(notNullValue(Throwable.class))); will(collectTo(wrappedFailure)); inSequence(sequence); one(state).setExecuting(false); inSequence(sequence); one(listener).afterActions(task); inSequence(sequence); } }); executer.execute(task, state, executionContext); assertThat(wrappedFailure.get(), instanceOf(TaskExecutionException.class)); TaskExecutionException exception = (TaskExecutionException) wrappedFailure.get(); assertThat(exception.getTask(), equalTo((Task) task)); assertThat(exception.getMessage(), equalTo("Execution failed for <task>.")); assertThat(exception.getCause(), sameInstance(failure)); }
@Override protected void collectItem(final Collector collector, final ItemType item) { collector.addItem(item); final Map<String, Object> params = extractParametersFromItem(item); if (params == null) { return; // guard against NPE } for (final Entry<String, Object> param : params.entrySet()) { collector.setParameter(param.getKey(), param.getValue()); } }
public void testBadInputAfterCursor() { Collector c = new Collector(); IHQLCodeAssist hqlEval = new HQLCodeAssist(sf); String query = "from org.hibernate.t| ;"; int caretPosition = getCaretPosition(query); hqlEval.codeComplete(query, caretPosition, c); HQLCompletionProposal[] completionProposals = c.getCompletionProposals(); assertEquals(4, completionProposals.length); }
private void doTestUnaliasedProductQuery(final String query) { Collector hcc = new Collector(); List visible = getVisibleEntityNames(query.toCharArray()); cc.getMatchingProperties(cc.getCanonicalPath(visible, "owner"), "f", hcc); HQLCompletionProposal[] completionProposals = hcc.getCompletionProposals(); // assertEquals(1, completionProposals.length); assertEquals("firstName", completionProposals[0].getSimpleName()); // hcc.clear(); cc.getMatchingProperties(cc.getCanonicalPath(visible, "owner"), "l", hcc); completionProposals = hcc.getCompletionProposals(); assertEquals(1, completionProposals.length); assertEquals("lastName", completionProposals[0].getSimpleName()); // hcc.clear(); cc.getMatchingProperties(cc.getCanonicalPath(visible, "owner"), "", hcc); // firstname, lastname, owner assertEquals(3, hcc.getCompletionProposals().length); // hcc.clear(); cc.getMatchingProperties(cc.getCanonicalPath(visible, "owner"), "g", hcc); assertEquals(0, hcc.getCompletionProposals().length); }
public void testKeywordFunction() { Collector hcc = new Collector(); cc.getMatchingKeywords("f", 2, hcc); HQLCompletionProposal[] completionProposals = hcc.getCompletionProposals(); assertEquals(4, completionProposals.length); assertEquals("alse", completionProposals[0].getCompletion()); hcc.clear(); cc.getMatchingFunctions("ma", 2, hcc); completionProposals = hcc.getCompletionProposals(); assertEquals(1, completionProposals.length); assertEquals("x", completionProposals[0].getCompletion()); hcc.clear(); cc.getMatchingKeywords("FR", 3, hcc); completionProposals = hcc.getCompletionProposals(); assertEquals(1, completionProposals.length); hcc.clear(); cc.getMatchingFunctions("MA", 2, hcc); completionProposals = hcc.getCompletionProposals(); assertEquals(1, completionProposals.length); }
@SuppressWarnings("unchecked") public String getValue() { // restart the error list for a possibly new value. errors = null; Collector collector = collectors.get(source.getClass()); if (collector == null) { throw new InvalidSourceTypeException( "No collector for the type " + source.getClass().getCanonicalName()); } return collector.collect(source); }
public void testProductOwnerAddress() { String query = "select p from Product p where p.owner."; List visible = getVisibleEntityNames(query.toCharArray()); Collector hcc = new Collector(); cc.getMatchingProperties(cc.getCanonicalPath(visible, "p.owner"), "", hcc); doTestFields(hcc.getCompletionProposals(), new String[] {"address", "firstName", "lastName"}); hcc.clear(); query = "select p from Product p where p.owner.address."; visible = getVisibleEntityNames(query.toCharArray()); cc.getMatchingProperties(cc.getCanonicalPath(visible, "p.owner.address"), "", hcc); doTestFields(hcc.getCompletionProposals(), new String[] {"id", "number", "street"}); }
/** * Find an element by ID, including or under this element. * * <p>Note that this finds the first matching ID, starting with this element. If you search down * from a different starting point, it is possible to find a different element by ID. For unique * element by ID within a Document, use {@link Document#getElementById(String)} * * @param id The ID to search for. * @return The first matching element by ID, starting with this element, or null if none found. */ public Element getElementById(String id) { Validate.notEmpty(id); Elements elements = Collector.collect(new Evaluator.Id(id), this); if (elements.size() > 0) return elements.get(0); else return null; }
private List<PdfCounterRequestContextReport> writeCurrentRequests( JavaInformations javaInformations, List<Counter> counters, List<PdfCounterReport> pdfCounterReports) throws IOException, DocumentException { final List<PdfCounterRequestContextReport> pdfCounterRequestContextReports = new ArrayList<PdfCounterRequestContextReport>(); final List<CounterRequestContext> rootCurrentContexts; if (currentRequests == null) { rootCurrentContexts = collector.getRootCurrentContexts(counters); } else { rootCurrentContexts = currentRequests; } if (rootCurrentContexts.isEmpty()) { addToDocument(new Phrase(getString("Aucune_requete_en_cours"), normalFont)); } else { final PdfCounterRequestContextReport pdfCounterRequestContextReport = new PdfCounterRequestContextReport( rootCurrentContexts, pdfCounterReports, javaInformations.getThreadInformationsList(), javaInformations.isStackTraceEnabled(), pdfDocumentFactory, getDocument()); pdfCounterRequestContextReport.toPdf(); pdfCounterRequestContextReports.add(pdfCounterRequestContextReport); } return pdfCounterRequestContextReports; }
@Test public void shouldOpenFileAndShowItsContent() { String PATH = "something.txt"; frame.setProvider(ip); collector.decorate = false; frame.setModelProcessor( new ModelProcessor() { @Override public String asUrlString(Model model) { return "" + model.ocurrencesOf(111) + ";" + model.ocurrencesOf(222); } }); window.menuItemWithPath("File", "Open").click().robot.waitForIdle(); robot().waitForIdle(); JFileChooserFixture fc = window.fileChooser("open"); fc.selectFile(new File(PATH)); fc.approve(); robot().waitForIdle(); assertEquals("2.0;1.0", frame.output.getResult()); }
@Override public void setScorer(Scorer scorer) throws IOException { // Set a ScoreCachingWrappingScorer in case the wrapped Collector will call // score() also. this.scorer = new ScoreCachingWrappingScorer(scorer); c.setScorer(this.scorer); }
@Test public void testDiscardRecord() { final MorphlineContext context = new MorphlineContext.Builder().build(); Collector collectorParent = new Collector(); Collector collectorChild = new Collector(); final Command command = new TimeFilterBuilder().build(config, collectorParent, collectorChild, context); Record record = new Record(); record.put("createdAt", "21/01/2015"); command.process(record); List<Record> records = collectorChild.getRecords(); assertThat(records.size()).isEqualTo(0); }
/** * Test. * * @throws Exception e */ @Test public void testWriteRequests() throws Exception { // NOPMD final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.SEMAINE, writer); htmlReport.writeRequestAndGraphDetail("httpHitsRate"); assertNotEmptyAndClear(writer); // writeRequestAndGraphDetail avec drill-down collector.collectWithoutErrors(javaInformationsList); // si sqlCounter reste à displayed=false, // il ne sera pas utilisé dans writeRequestAndGraphDetail sqlCounter.setDisplayed(true); final String requestName = "test 1"; counter.bindContext(requestName, "complete test 1", null, -1); servicesCounter.clear(); servicesCounter.bindContext("myservices.service1", "service1", null, -1); sqlCounter.bindContext("sql1", "complete sql1", null, -1); sqlCounter.addRequest("sql1", 5, -1, false, -1); servicesCounter.addRequest("myservices.service1", 10, 10, false, -1); servicesCounter.bindContext("myservices.service2", "service2", null, -1); servicesCounter.addRequest("myservices.service2", 10, 10, false, -1); servicesCounter.addRequest("otherservices.service3", 10, 10, false, -1); servicesCounter.addRequest("otherservices", 10, 10, false, -1); jspCounter.addRequest("jsp1", 10, 10, false, -1); counter.addRequest(requestName, 0, 0, false, 1000); collector.collectWithoutErrors(javaInformationsList); final HtmlReport toutHtmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); for (final Counter collectorCounter : collector.getCounters()) { for (final CounterRequest request : collectorCounter.getRequests()) { toutHtmlReport.writeRequestAndGraphDetail(request.getId()); assertNotEmptyAndClear(writer); toutHtmlReport.writeRequestUsages(request.getId()); assertNotEmptyAndClear(writer); } } sqlCounter.setDisplayed(false); // writeCounterSummaryPerClass toutHtmlReport.writeCounterSummaryPerClass(servicesCounter.getName(), null); String requestId = new CounterRequest("myservices", servicesCounter.getName()).getId(); toutHtmlReport.writeCounterSummaryPerClass(servicesCounter.getName(), requestId); requestId = new CounterRequest("otherservices", servicesCounter.getName()).getId(); toutHtmlReport.writeCounterSummaryPerClass(servicesCounter.getName(), requestId); toutHtmlReport.writeCounterSummaryPerClass(servicesCounter.getName(), "unknown"); }