@Test public void root_context_can_be_referred_in_predicate() { List<Double> prices = using(conf).parse(JSON_DOCUMENT).read("store.book[?(@.display-price <= $.max-price)].display-price", List.class); assertThat(prices).containsAll(asList(8.95D, 8.99D)); }
@Test public void searchBranchStatistics_on_many_branches() { ComponentDto project = db.components().insertMainBranch(); List<String> branchUuids = new ArrayList<>(); List<Tuple> expectedResult = new ArrayList<>(); IntStream.range(0, 15).forEach(i -> { ComponentDto branch = db.components().insertProjectBranch(project); addIssues(branch, 1 + i, 2 + i, 3 + i); expectedResult.add(tuple(branch.uuid(), 1L + i, 2L + i, 3L + i)); branchUuids.add(branch.uuid()); }); List<BranchStatistics> branchStatistics = underTest.searchBranchStatistics(project.uuid(), branchUuids); assertThat(branchStatistics) .extracting(BranchStatistics::getBranchUuid, BranchStatistics::getBugs, BranchStatistics::getVulnerabilities, BranchStatistics::getCodeSmells) .hasSize(15) .containsAll(expectedResult); }
@Test public void select_by_projects_with_high_number_of_projects() { List<String> projectUuids = new ArrayList<>(); for (int i = 0; i < 350; i++) { ComponentDto project = ComponentTesting.newPrivateProjectDto(organization, Integer.toString(i)); dbClient.componentDao().insert(dbSession, project); projectUuids.add(project.uuid()); GroupPermissionDto dto = new GroupPermissionDto() .setOrganizationUuid(group.getOrganizationUuid()) .setGroupId(group.getId()) .setRole(USER) .setResourceId(project.getId()); dbClient.groupPermissionDao().insert(dbSession, dto); } dbSession.commit(); assertThat(underTest.selectByUuids(dbClient, dbSession, projectUuids)) .hasSize(350) .extracting(IndexPermissions::getProjectUuid) .containsAll(projectUuids); }
.contains(uuids3) .contains(dto5.getUuid()) .containsAll(tasks.stream().map(CeTask::getUuid).collect(Collectors.toList()));
public PermissionInfoAssert hasPerm(Permission... permissions) { List<String> hasPerm = actual.asMap().entrySet().stream().filter(p -> p.getValue() == true).map(e -> e.getKey().getName()) .collect(Collectors.toList()); List<String> mustHave = Arrays.asList(permissions).stream().map(e -> e.getName()).collect(Collectors.toList()); assertThat(hasPerm).containsAll(mustHave); return this; }
public void waitUntilReceived(long seconds) { logger.info("Expecting to receive {} messages", expectedMessages.size()); await().atMost(adjust(new Duration(seconds, TimeUnit.SECONDS))).until(() -> assertThat(receivedRequests.size()).isGreaterThanOrEqualTo(expectedMessages.size())); synchronized (receivedRequests) { assertThat(receivedRequests.stream().map(LoggedRequest::getBodyAsString).collect(toList())).containsAll(expectedMessages); } }
public void waitUntilReceived(long seconds) { logger.info("Expecting to receive {} messages", expectedMessages.size()); await().atMost(adjust(new Duration(seconds, TimeUnit.SECONDS))).until(() -> assertThat(receivedRequests.size()).isGreaterThanOrEqualTo(expectedMessages.size())); synchronized (receivedRequests) { assertThat(receivedRequests.stream().map(LoggedRequest::getBodyAsString).collect(toList())).containsAll(expectedMessages); } }
@Test public void multiNodeWithPlacementLifecycle() { PrestoCluster prestoCluster = new PrestoCluster(slider, hdfsClient, sliderConfDirPath, "resources-multinode.json", APP_CONFIG_TEST_TEMPLATE); prestoCluster.withPrestoCluster(() -> { prestoCluster.assertThatPrestoIsUpAndRunning(workersCount()); assertThatAllProcessesAreRunning(prestoCluster); assertThatPrestoYarnContainersUsesCgroup(prestoCluster); // check placement policy Assertions.assertThat(prestoCluster.getCoordinatorHost()).contains(master); Assertions.assertThat(prestoCluster.getWorkerHosts()).containsAll(workers); assertThatApplicationIsStoppable(prestoCluster); }); }
@Test public void testGenerateExplodedTestMethodsForShouldCallTestGeneratorWithFoundDataProviderMethodAndAddResult() { // Given: doReturn(asList(dataProviderMethod)).when(underTest).getDataProviderMethods(testMethod); List<FrameworkMethod> explodedMethods = new ArrayList<FrameworkMethod>(); explodedMethods.add(mock(FrameworkMethod.class)); explodedMethods.add(mock(FrameworkMethod.class)); doReturn(explodedMethods).when(testGenerator).generateExplodedTestMethodsFor(testMethod, dataProviderMethod); // When: List<FrameworkMethod> result = underTest.generateExplodedTestMethodsFor(asList(testMethod)); // Then: assertThat(result).hasSize(2).containsAll(explodedMethods); verify(testGenerator).generateExplodedTestMethodsFor(testMethod, dataProviderMethod); verifyNoMoreInteractions(testGenerator); }
@SuppressWarnings("unchecked") @Test public void itShufflesConsistentlyWithConstantRandom() { when(interpreter.getRandom()).thenReturn(new ConstantZeroRandomNumberGenerator()); List<String> before = Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9"); List<String> after = (List<String>) filter.filter(before, interpreter); assertThat(before).isSorted(); assertThat(after).containsAll(before); assertThat(after).containsExactly("2", "3", "4", "5", "6", "7", "8", "9", "1"); }
@SuppressWarnings("unchecked") @Test public void itShufflesConsistentlyWithConstantRandom() { when(interpreter.getRandom()).thenReturn(new ConstantZeroRandomNumberGenerator()); List<String> before = Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9"); List<String> after = (List<String>) filter.filter(before, interpreter); assertThat(before).isSorted(); assertThat(after).containsAll(before); assertThat(after).containsExactly("2", "3", "4", "5", "6", "7", "8", "9", "1"); }
@SuppressWarnings("unchecked") @Test public void itShufflesItems() { when(interpreter.getRandom()).thenReturn(ThreadLocalRandom.current()); List<String> before = Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9"); List<String> after = (List<String>) filter.filter(before, interpreter); assertThat(before).isSorted(); assertThat(after).containsAll(before); try { assertThat(after).isSorted(); failBecauseExceptionWasNotThrown(AssertionError.class); } catch (AssertionError e) { assertThat(e).hasMessageContaining("is not sorted"); } }
@Test public void testGetDataProviderMethodShouldReturnFirstNotEmptyListIfResolveStrategyIsAggregateAllMatchesAndMultipleResolversWouldMatch() { // Given: final DataProviderMethodResolver resolver2 = mock(DataProviderMethodResolver.class); final DataProviderMethodResolver resolver3 = mock(DataProviderMethodResolver.class); final List<FrameworkMethod> expected2 = Arrays.asList(mock(FrameworkMethod.class), mock(FrameworkMethod.class)); final List<FrameworkMethod> expected3 = Arrays.asList(mock(FrameworkMethod.class)); doReturn(useDataProvider).when(testMethod).getAnnotation(UseDataProvider.class); doReturn(new Class<?>[] { DataProviderMethodResolver.class, DataProviderMethodResolver.class, DataProviderMethodResolver.class }) .when(useDataProvider).resolver(); doReturn(ResolveStrategy.AGGREGATE_ALL_MATCHES).when(useDataProvider).resolveStrategy(); doReturn(dataProviderMethodResolver, resolver2, resolver3).when(underTest).getResolverInstanceInt(any(Class.class)); doReturn(emptyList()).when(dataProviderMethodResolver).resolve(testMethod, useDataProvider); doReturn(expected2).when(resolver2).resolve(testMethod, useDataProvider); doReturn(expected3).when(resolver3).resolve(testMethod, useDataProvider); // When: List<FrameworkMethod> result = underTest.getDataProviderMethods(testMethod); // Then: assertThat(result).hasSize(3).containsAll(expected2).containsAll(expected3); assertThat(underTest.dataProviderMethods).containsEntry(testMethod, result); }
@SuppressWarnings("unchecked") @Test public void itShufflesItems() { when(interpreter.getRandom()).thenReturn(ThreadLocalRandom.current()); List<String> before = Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9"); List<String> after = (List<String>) filter.filter(before, interpreter); assertThat(before).isSorted(); assertThat(after).containsAll(before); try { assertThat(after).isSorted(); failBecauseExceptionWasNotThrown(AssertionError.class); } catch (AssertionError e) { assertThat(e).hasMessageContaining("is not sorted"); } }
@Test public void aggregationsOnDifferentNodes() throws Exception { String[] columnNames = {"n.lastName", "type(r)", "collect(m.name)"}; String cypher = "MATCH (n:Person)-[r]->(m:Interest) RETURN n.lastName, type(r), collect(m.name)"; List<Map<String, Object>> cypherResults = submitAndGet(cypher); assertThat(cypherResults) .hasSize(2) .extracting(columnNames) .usingElementComparator(ignoreOrderInCollections()) .containsAll(extract(cypherResults, byName(columnNames))) .containsExactlyInAnyOrder( tuple("Andresen", "LIKES", asList("Video", "Video", "Music")), tuple("Haugland", "LIKES", asList("Video")) ); }
@Test @SuppressWarnings("unchecked") public void onePivotOneAggregation() throws Exception { String[] columnNames = {"n.lastName", "c1"}; String cypher = "MATCH (n:Person) RETURN\n" + "n.lastName," + "collect(n.firstName) AS c1;"; List<Map<String, Object>> cypherResults = submitAndGet(cypher); assertThat(cypherResults) .extracting(Map::keySet) .allSatisfy(columns -> assertThat(columns).containsExactly(columnNames)); assertThat(cypherResults) .hasSize(4) .extracting(columnNames) .usingElementComparator(ignoreOrderInCollections()) .containsAll(extract(cypherResults, byName(columnNames))) .containsExactlyInAnyOrder( tuple("Andresen", asList("Erik", "Erik", "Erik", "Lars")), tuple("Lehtinen", asList("Olavi")), tuple("Haugland", asList("Martin")), tuple("Pedersen", asList("Erlend")) ); }
@Test public void aggregationsOnly() throws Exception { String[] columnNames = {"count(n1)", "count(n2)"}; String cypher = "MATCH (n1)-[r]->(n2) RETURN count(n1), count(n2)"; List<Map<String, Object>> cypherResults = submitAndGet(cypher); assertThat(cypherResults) .hasSize(1) .extracting(columnNames) .usingElementComparator(ignoreOrderInCollections()) .containsAll(extract(cypherResults, byName(columnNames))) .containsExactlyInAnyOrder( tuple(22L, 22L) ); }
@Test public void labelPredicate() throws Exception { String[] columnNames = {"isPerson", "count"}; String cypher = "MATCH (n)\n" + "RETURN (n:Person) AS isPerson, count(*) AS count"; List<Map<String, Object>> cypherResults = submitAndGet(cypher); assertThat(cypherResults) .hasSize(2) .extracting(columnNames) .usingElementComparator(ignoreOrderInCollections()) .containsAll(extract(cypherResults, byName(columnNames))) .containsExactlyInAnyOrder( tuple(true, 7L), tuple(false, 11L) ); }
@Test public void distinct() throws Exception { String[] columnNames = {"n.lastName", "type(r)"}; String cypher = "MATCH ()-[r]->(n:Person) RETURN DISTINCT n.lastName, type(r)"; List<Map<String, Object>> cypherResults = submitAndGet(cypher); assertThat(cypherResults) .hasSize(3) .extracting(columnNames) .usingElementComparator(ignoreOrderInCollections()) .containsAll(extract(cypherResults, byName(columnNames))) .containsExactlyInAnyOrder( tuple("Andresen", "KNOWS"), tuple("Pedersen", "KNOWS"), tuple("Lehtinen", "KNOWS") ); }
@Test public void multiple() throws Exception { String[] columnNames = {"type(r)", "count"}; String cypher = "MATCH ()-[r]->() RETURN count(r) AS count, type(r)"; List<Map<String, Object>> cypherResults = submitAndGet(cypher); assertThat(cypherResults) .hasSize(4) .extracting(columnNames) .usingElementComparator(ignoreOrderInCollections()) .containsAll(extract(cypherResults, byName(columnNames))) .containsExactlyInAnyOrder( tuple("IS_LOCATED_IN", 6L), tuple("LIKES", 4L), tuple("KNOWS", 6L), tuple("IS_PART_OF", 6L) ); }