/** * Matches the set of entries against the given set of values. The full combinatorial of values passed in is expected in the output set. * * @param rows * Rows to check for. * @param colFs * Column families to check for. * @param colQs * Column qualifiers to check for. * @param colVs * Column visibilities to check for. * @param values * Values to check for. * @return Hamcrest matcher. */ @Factory @SuppressWarnings("unchecked") public static Matcher<Iterable<Entry<Key,Value>>> hasData(Collection<String> rows, Collection<String> colFs, Collection<String> colQs, Collection<String> colVs, Collection<String> values) { int size = rows.size() * colFs.size() * colQs.size() * colVs.size() * values.size(); ArrayList<Matcher<? super Iterable<Entry<Key,Value>>>> matchers = new ArrayList<>(size + 1); matchers.add(IsIterableWithSize.iterableWithSize(size)); for (String row : rows) { for (String colF : colFs) { for (String colQ : colQs) { for (String colV : colVs) { for (String value : values) { matchers.add(hasItems(equalToRow(row, colF, colQ, colV, value))); } } } } } return allOf(matchers); }
@Test public void testDynamicClassLoaderService() throws MalformedURLException { // this will check that the java service loader works on a classloader that is mutable RuntimeUtil.registerMavenUrlHandler(); // given ExtensibleUrlClassLoader urlClassLoader = new ExtensibleUrlClassLoader(new URL[0]); // 2 comp installer assertThat(ServiceLoader.load(ComponentInstaller.class, urlClassLoader), IsIterableWithSize.<ComponentInstaller> iterableWithSize(2)); // when urlClassLoader.addURL(new URL("mvn:org.talend.components/multiple-runtime-comp/0.18.0")); // then // 3 comp installer assertThat(ServiceLoader.load(ComponentInstaller.class, urlClassLoader), IsIterableWithSize.<ComponentInstaller> iterableWithSize(3)); }
/** * See https://github.com/SciCrunch/SciGraph/wiki/MappingToOWL#equivalence-axioms */ @Test public void testEquivalentToIntersectionOf() { Node x = getNode("http://example.org/x"); Node y = getNode("http://example.org/y"); Node z = getNode("http://example.org/z"); assertThat("equivalence is symmetric and holds between all members.", GraphUtil.getRelationships(x, y, OwlRelationships.OWL_EQUIVALENT_CLASS, false), is(IsIterableWithSize.<Relationship> iterableWithSize(1))); assertThat("equivalence is symmetric and holds between all members.", GraphUtil.getRelationships(x, z, OwlRelationships.OWL_EQUIVALENT_CLASS, false), is(IsIterableWithSize.<Relationship> iterableWithSize(1))); assertThat("equivalence is symmetric and holds between all members.", GraphUtil.getRelationships(y, z, OwlRelationships.OWL_EQUIVALENT_CLASS, false), is(IsIterableWithSize.<Relationship> iterableWithSize(1))); }
@Test public void transform_string_to_enum () { List<String> days = Lists.newArrayList( "WEDNESDAY", "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY"); Function<String, Day> valueOfFunction = Enums.valueOfFunction(Day.class); Iterable<Day> daysAsEnums = Iterables.transform(days, valueOfFunction); assertThat(daysAsEnums, IsIterableWithSize.<Day>iterableWithSize(5)); assertThat(daysAsEnums, IsIterableContainingInOrder. <Day>contains( Day.WEDNESDAY, Day.SUNDAY, Day.MONDAY, Day.TUESDAY, Day.WEDNESDAY)); }
@Test public void transform_string_to_enum_string_converter () { List<String> days = Lists.newArrayList( "WEDNESDAY", "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY"); Function<String, Day> valueOfFunction = Enums.stringConverter(Day.class); Iterable<Day> daysAsEnums = Iterables.transform(days, valueOfFunction); assertThat(daysAsEnums, IsIterableWithSize.<Day>iterableWithSize(5)); assertThat(daysAsEnums, IsIterableContainingInOrder. <Day>contains( Day.WEDNESDAY, Day.SUNDAY, Day.MONDAY, Day.TUESDAY, Day.WEDNESDAY)); }
@Test public void testZipped() throws Exception { // given // when final Iterable<Product3<String, Double, Date>> zipped = Products.zip(Collections.singleton("a"), Collections.singleton(1.0), Collections.singleton(new Date())); // then Assert.assertThat(zipped, is(IsIterableWithSize.<Product3<String, Double, Date>>iterableWithSize(1))); }
@Test public void testSubclass() { Node subclass = getNode("http://example.org/subclass"); Node superclass = getNode("http://example.org/superclass"); assertThat("classes should be labeled as such", subclass.hasLabel(OwlLabels.OWL_CLASS) && superclass.hasLabel(OwlLabels.OWL_CLASS)); assertThat("subclass should be a directed relationship", GraphUtil.getRelationships(subclass, superclass, OwlRelationships.RDFS_SUBCLASS_OF), is(IsIterableWithSize.<Relationship> iterableWithSize(1))); }
@Test public void testSubclass() { Node subp = getNode("http://example.org/subproperty"); Node superp = getNode("http://example.org/superproperty"); assertThat("subclass should be a directed relationship", GraphUtil.getRelationships(subp, superp, OwlRelationships.RDFS_SUB_PROPERTY_OF), is(IsIterableWithSize.<Relationship> iterableWithSize(1))); }
@Test public void evidenceIsAdded() { assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(5)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(1)); aspect.invoke(graph); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(6)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(3)); }
@Test public void pathsAreTranslated() { Iterable<PropertyContainer> path = newArrayList(node, relationship, otherNode); TinkerGraphUtil tgu = new TinkerGraphUtil(graph, curieUtil); tgu.addPath(path); assertThat(graph.getVertices(), is(IsIterableWithSize.<Vertex>iterableWithSize(2))); assertThat(graph.getEdges(), is(IsIterableWithSize.<Edge>iterableWithSize(1))); }
@Test public void testMultiTypedNeighborhood() { Graph graph = graphApi.getNeighbors(newHashSet(b), 1, newHashSet(new DirectedRelationshipType(OwlRelationships.RDFS_SUBCLASS_OF, Direction.INCOMING), new DirectedRelationshipType(fizz, Direction.INCOMING)), absent); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(3)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(2)); }
@Test public void multipleAncestors_areReturned() { Graph graph = graphApi.getNeighbors(newHashSet(i), 10, newHashSet(new DirectedRelationshipType(OwlRelationships.RDFS_SUBCLASS_OF, Direction.OUTGOING)), absent); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(4)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(4)); }
@Override public Void apply(Iterable<Variant> actual) { assertThat(actual, CoreMatchers.hasItem(expectedSnp1)); assertThat(actual, CoreMatchers.hasItem(expectedSnp2)); assertThat(actual, CoreMatchers.hasItem(expectedInsert)); assertThat(actual, IsIterableWithSize.<Variant>iterableWithSize(3)); return null; }
@Test public void present_instances () { List<Optional<PullRequest>> pullRequests = Lists.newArrayList(); pullRequests.add(getPullRequestUsingGuavaOptional()); pullRequests.add(Optional.of(new PullRequest("Graham", "a->b summary", "please merge"))); pullRequests.add(getPullRequestUsingGuavaOptional()); pullRequests.add(Optional.of(new PullRequest("Jesse", "c->d summary", "check code"))); Iterable<PullRequest> presentInstances = Optional.presentInstances(pullRequests); assertThat(presentInstances, IsIterableWithSize.<PullRequest>iterableWithSize(2)); }
@Test public void remove_null_from_list_guava_iterables () { List<String> strings = Lists.newArrayList( null, "www", null, "leveluplunch", "com", null); Iterable<String> filterStrings = Iterables.filter(strings, Predicates.notNull()); assertThat(filterStrings, IsIterableWithSize.<String>iterableWithSize(3)); }
@Test public void check_size_of_iterable () { List<String> cloths = Lists.newArrayList( "shirts", "shoes", "pants", "socks"); assertThat(cloths, IsIterableWithSize.<String>iterableWithSize(4)); }
@Test public void ages() { getXoManager().currentTransaction().begin(); Result<Long> result = getXoManager().createQuery("g.V('lastname','Doe').outE('FRIENDS').inV().age", Long.class) .using(Gremlin.class).execute(); assertThat(result, IsIterableWithSize.<Long> iterableWithSize(1)); getXoManager().currentTransaction().commit(); }
@Test // #61 public void findOrdersBetween() { order = orderManager.save(order); LocalDateTime dateCreated = order.getDateCreated(); Iterable<Order> result = orderManager.findBy(Interval.from(dateCreated).to(dateCreated.plusHours(1L))); assertThat(result, IsIterableWithSize.<Order> iterableWithSize(1)); assertThat(result.iterator().next(), is(order)); }
@Test // #61 public void findOrdersBetweenWhenFromToEqual() { order = orderManager.save(order); LocalDateTime dateCreated = order.getDateCreated(); Iterable<Order> result = orderManager.findBy(Interval.from(dateCreated).to(dateCreated)); assertThat(result, IsIterableWithSize.<Order> iterableWithSize(1)); assertThat(result.iterator().next(), is(order)); }
@Test // #61 public void findOrdersByOrderStatus_OPEN() { Order openOrder = new Order(user, Cash.CASH); openOrder = orderManager.save(openOrder); orderManager.save(order); orderManager.payOrder(order); Iterable<Order> openOrders = orderManager.findBy(OrderStatus.OPEN); assertThat(openOrders, IsIterableWithSize.<Order> iterableWithSize(1)); assertThat(openOrders.iterator().next(), is(openOrder)); }
@Test public void requestIsCorrectlyCreated() throws Exception { ThriftService<FrontendRequest, FrontendResponse> thriftService = createDefaultListener(); logger = new ThriftScribeLogger(thriftService, executorService); logger.log(CATEGORY, LINES); // Test request outside as otherwise an assertion could fail silently. assertEquals(request.getType(), FrontendRequestType.LOG); assertEquals(request.getLogRequest().getType(), LogRequestType.SCRIBE_DATA); assertEquals(request.getLogRequest().getScribeData().getCategory(), CATEGORY); assertThat( request.getLogRequest().getScribeData().getLines(), Matchers.allOf( hasItem(LINES.get(0)), hasItem(LINES.get(1)), IsIterableWithSize.iterableWithSize(2))); }
@Test public void testUnboundedSourceMetrics() { int numElements = 1000; String readStep = "readFromKafka"; p.apply(readStep, mkKafkaReadTransform(numElements, new ValueAsTimestampFn()).withoutMetadata()); PipelineResult result = p.run(); String splitId = "0"; MetricName elementsRead = SourceMetrics.elementsRead().getName(); MetricName elementsReadBySplit = SourceMetrics.elementsReadBySplit(splitId).getName(); MetricName bytesRead = SourceMetrics.bytesRead().getName(); MetricName bytesReadBySplit = SourceMetrics.bytesReadBySplit(splitId).getName(); MetricName backlogElementsOfSplit = SourceMetrics.backlogElementsOfSplit(splitId).getName(); MetricName backlogBytesOfSplit = SourceMetrics.backlogBytesOfSplit(splitId).getName(); MetricQueryResults metrics = result.metrics().queryMetrics( MetricsFilter.builder().build()); Iterable<MetricResult<Long>> counters = metrics.counters(); assertThat(counters, hasItem(attemptedMetricsResult( elementsRead.namespace(), elementsRead.name(), readStep, 1000L))); assertThat(counters, hasItem(attemptedMetricsResult( elementsReadBySplit.namespace(), elementsReadBySplit.name(), readStep, 1000L))); assertThat(counters, hasItem(attemptedMetricsResult( bytesRead.namespace(), bytesRead.name(), readStep, 12000L))); assertThat(counters, hasItem(attemptedMetricsResult( bytesReadBySplit.namespace(), bytesReadBySplit.name(), readStep, 12000L))); MetricQueryResults backlogElementsMetrics = result.metrics().queryMetrics( MetricsFilter.builder() .addNameFilter( MetricNameFilter.named( backlogElementsOfSplit.namespace(), backlogElementsOfSplit.name())) .build()); // since gauge values may be inconsistent in some environments assert only on their existence. assertThat(backlogElementsMetrics.gauges(), IsIterableWithSize.<MetricResult<GaugeResult>>iterableWithSize(1)); MetricQueryResults backlogBytesMetrics = result.metrics().queryMetrics( MetricsFilter.builder() .addNameFilter( MetricNameFilter.named( backlogBytesOfSplit.namespace(), backlogBytesOfSplit.name())) .build()); // since gauge values may be inconsistent in some environments assert only on their existence. assertThat(backlogBytesMetrics.gauges(), IsIterableWithSize.<MetricResult<GaugeResult>>iterableWithSize(1)); }
private <T> void assertIterableSize(Iterable<T> iterable, int size) { assertThat(iterable, IsIterableWithSize.<T>iterableWithSize(size)); }
@Test public void edgesAreMovedToLeader() { Node zfin1 = null; Node zfin2 = null; Node phenotype1 = null; Node phenotype2 = null; Node phenotype3 = null; try (Transaction tx = graphDb.beginTx()) { for (Node n : graphDb.getAllNodes()) { if (n.getProperty(NodeProperties.IRI).equals("http://www.ncbi.nlm.nih.gov/gene/ZG1")) { zfin1 = n; } if (n.getProperty(NodeProperties.IRI).equals("http://zfin.org/ZG1")) { zfin2 = n; } if (n.getProperty(NodeProperties.IRI).equals("http://purl.obolibrary.org/obo/ZP_0000001")) { phenotype1 = n; } if (n.getProperty(NodeProperties.IRI).equals("http://purl.obolibrary.org/obo/MP_0000001")) { phenotype2 = n; } if (n.getProperty(NodeProperties.IRI).equals("http://purl.obolibrary.org/obo/HP_0000001")) { phenotype3 = n; } } assertThat(zfin1.getRelationships(), IsIterableWithSize.<Relationship>iterableWithSize(6)); assertThat(zfin2.getRelationships(), IsIterableWithSize.<Relationship>iterableWithSize(6)); assertThat(phenotype1.getRelationships(), IsIterableWithSize.<Relationship>iterableWithSize(4)); assertThat(phenotype2.getRelationships(), IsIterableWithSize.<Relationship>iterableWithSize(4)); assertThat(phenotype3.getRelationships(), IsIterableWithSize.<Relationship>iterableWithSize(8)); clique.run(); assertThat(zfin2.getRelationships(), IsIterableWithSize.<Relationship>iterableWithSize(11)); assertThat(zfin1.getRelationships(), IsIterableWithSize.<Relationship>iterableWithSize(1)); assertThat(phenotype1.getRelationships(), IsIterableWithSize.<Relationship>iterableWithSize(1)); assertThat(phenotype2.getRelationships(), IsIterableWithSize.<Relationship>iterableWithSize(1)); assertThat(phenotype3.getRelationships(), IsIterableWithSize.<Relationship>iterableWithSize(14)); assertThat(zfin2.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(true)); assertThat(zfin1.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(false)); assertThat(phenotype1.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(false)); assertThat(phenotype2.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(false)); assertThat(phenotype3.hasLabel(Clique.CLIQUE_LEADER_LABEL), is(true)); tx.success(); } }
@Test public void test1Neighborhood() { Graph graph = graphApi.getNeighbors(newHashSet(b), 1, Collections.<DirectedRelationshipType>emptySet(), absent); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(4)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(3)); }
@Test public void testKNeighborhood() { Graph graph = graphApi.getNeighbors(newHashSet(b), 10, Collections.<DirectedRelationshipType>emptySet(), absent); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(5)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(4)); }
@Test public void testTypedNeighborhood() { Graph graph = graphApi.getNeighbors(newHashSet(b), 2, newHashSet(new DirectedRelationshipType(OwlRelationships.RDFS_SUBCLASS_OF, Direction.INCOMING)), absent); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(3)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(2)); }
@Test public void testSingleNodeNeighborhood() { Graph graph = graphApi.getNeighbors(newHashSet(f), 1, Collections.<DirectedRelationshipType>emptySet(), absent); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(1)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(0)); }
@Test public void inflectorAppliesCorrectly() { path.setVendorExtension("x-query", "MATCH (n) RETURN n"); TinkerGraph graph = (TinkerGraph) inflector.apply(context).getEntity(); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(6)); }
@Test public void pathsAreReturnedCorrectly() { path.setVendorExtension("x-query","MATCH (n {iri:'http://x.org/#foo'})-[path:subPropertyOf*]-(m) RETURN n, path, m"); TinkerGraph graph = (TinkerGraph) inflector.apply(context).getEntity(); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(1)); }
/** * * Matches an {@link Iterable} of the specified size. (The size may be a {@link MoxieMatchers} invocation.) * <p> * * The class argument to this method is not matched against the value passed to the mocked method; it is provided * as a convenient way of specifying the type parameter for those who wish to statically import this method. * <p> * * @param iterableClass Type of the expected iterable * @param size Desired size of the iterable (raw value or {@link MoxieMatchers} invocation) * @return <code>null</code> */ @SuppressWarnings("unchecked") static public <I extends Iterable> I iterableSize(Class<I> iterableClass, int size) { final Matcher<Integer> sizeMatcher = MatcherSyntax.singleMatcherFragment(Integer.TYPE, size); return (I) argThat(iterableClass, new IsIterableWithSize(sizeMatcher)); }