You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/03/11 19:49:52 UTC
[2/3] incubator-tinkerpop git commit: Moved unit tests for
gremlin-core from gremlin-test.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
new file mode 100644
index 0000000..20a4767
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -0,0 +1,440 @@
+package org.apache.tinkerpop.gremlin.util.iterator;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IteratorUtilsTest {
+ @Test
+ public void shouldIterateSingleObject() {
+ assertIterator(IteratorUtils.of("test1"), 1);
+ }
+
+ @Test
+ public void shouldIteratePairOfObjects() {
+ assertIterator(IteratorUtils.of("test1", "test2"), 2);
+ }
+
+ @Test
+ public void shouldConvertIterableToIterator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertIterator(IteratorUtils.asIterator(iterable), iterable.size());
+ }
+
+ @Test
+ public void shouldConvertIteratorToIterator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertIterator(IteratorUtils.asIterator(iterable.iterator()), iterable.size());
+ }
+
+ @Test
+ public void shouldConvertArrayToIterator() {
+ final String[] iterable = new String[3];
+ iterable[0] = "test1";
+ iterable[1] = "test2";
+ iterable[2] = "test3";
+ assertIterator(IteratorUtils.asIterator(iterable), iterable.length);
+ }
+
+ @Test
+ public void shouldConvertThrowableToIterator() {
+ final Exception ex = new Exception("test1");
+ assertIterator(IteratorUtils.asIterator(ex), 1);
+ }
+
+ @Test
+ public void shouldConvertStreamToIterator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertIterator(IteratorUtils.asIterator(iterable.stream()), iterable.size());
+ }
+
+ @Test
+ public void shouldConvertMapToIterator() {
+ final Map<String,String> m = new HashMap<>();
+ m.put("key1", "val1");
+ m.put("key2", "val2");
+ m.put("key3", "val3");
+
+ final Iterator itty = IteratorUtils.asIterator(m);
+ for (int ix = 0; ix < m.size(); ix++) {
+ final Map.Entry entry = (Map.Entry) itty.next();
+ assertEquals("key" + (ix + 1), entry.getKey());
+ assertEquals("val" + (ix + 1), entry.getValue());
+ }
+
+ assertFalse(itty.hasNext());
+ }
+
+ @Test
+ public void shouldConvertAnythingElseToIteratorByWrapping() {
+ assertIterator(IteratorUtils.asIterator("test1"), 1);
+ }
+
+ @Test
+ public void shouldConvertIterableToList() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertIterator(IteratorUtils.asList(iterable).iterator(), iterable.size());
+ }
+
+ @Test
+ public void shouldConvertIteratorToList() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertIterator(IteratorUtils.asList(iterable.iterator()).iterator(), iterable.size());
+ }
+
+ @Test
+ public void shouldConvertArrayToList() {
+ final String[] iterable = new String[3];
+ iterable[0] = "test1";
+ iterable[1] = "test2";
+ iterable[2] = "test3";
+ assertIterator(IteratorUtils.asList(iterable).iterator(), iterable.length);
+ }
+
+ @Test
+ public void shouldConvertThrowableToList() {
+ final Exception ex = new Exception("test1");
+ assertIterator(IteratorUtils.asList(ex).iterator(), 1);
+ }
+
+ @Test
+ public void shouldConvertStreamToList() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertIterator(IteratorUtils.asList(iterable.stream()).iterator(), iterable.size());
+ }
+
+ @Test
+ public void shouldConvertMapToList() {
+ final Map<String,String> m = new HashMap<>();
+ m.put("key1", "val1");
+ m.put("key2", "val2");
+ m.put("key3", "val3");
+
+ final Iterator itty = IteratorUtils.asList(m).iterator();
+ for (int ix = 0; ix < m.size(); ix++) {
+ final Map.Entry entry = (Map.Entry) itty.next();
+ assertEquals("key" + (ix + 1), entry.getKey());
+ assertEquals("val" + (ix + 1), entry.getValue());
+ }
+
+ assertFalse(itty.hasNext());
+ }
+
+ @Test
+ public void shouldConvertAnythingElseToListByWrapping() {
+ assertIterator(IteratorUtils.asList("test1").iterator(), 1);
+ }
+
+ @Test
+ public void shouldFillFromIterator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+
+ final List<String> newList = new ArrayList<>();
+ IteratorUtils.fill(iterable.iterator(), newList);
+
+ assertIterator(newList.iterator(), iterable.size());
+ }
+
+ @Test
+ public void shouldCountEmpty() {
+ assertEquals(0, IteratorUtils.count(new ArrayList<>().iterator()));
+ }
+
+ @Test
+ public void shouldCountAll() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+
+ assertEquals(3, IteratorUtils.count(iterable.iterator()));
+ }
+
+ @Test
+ public void shouldMakeArrayListFromIterator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertIterator(IteratorUtils.list(iterable.iterator()).iterator(), iterable.size());
+ }
+
+ @Test
+ public void shouldMatchAllPositively() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertTrue(IteratorUtils.allMatch(iterable.iterator(), s -> s.startsWith("test")));
+ }
+
+ @Test
+ public void shouldMatchAllNegatively() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertFalse(IteratorUtils.allMatch(iterable.iterator(), s -> s.startsWith("test1")));
+ }
+
+ @Test
+ public void shouldMatchAnyPositively() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertTrue(IteratorUtils.anyMatch(iterable.iterator(), s -> s.startsWith("test3")));
+ }
+
+ @Test
+ public void shouldMatchAnyNegatively() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertFalse(IteratorUtils.anyMatch(iterable.iterator(), s -> s.startsWith("dfaa")));
+ }
+
+ @Test
+ public void shouldMatchNonePositively() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertTrue(IteratorUtils.noneMatch(iterable.iterator(), s -> s.startsWith("test4")));
+ }
+
+ @Test
+ public void shouldMatchNoneNegatively() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+ assertFalse(IteratorUtils.noneMatch(iterable.iterator(), s -> s.startsWith("test")));
+ }
+
+ @Test
+ public void shouldProduceMapFromIteratorUsingIdentityForValue() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+
+ final Map<String,String> m = IteratorUtils.collectMap(iterable.iterator(), k -> k.substring(4));
+ assertEquals("test1", m.get("1"));
+ assertEquals("test2", m.get("2"));
+ assertEquals("test3", m.get("3"));
+ }
+
+ @Test
+ public void shouldProduceMapFromIterator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+
+ final Map<String,String> m = IteratorUtils.collectMap(iterable.iterator(), k -> k.substring(4), v -> v.substring(0, 4));
+ assertEquals("test", m.get("1"));
+ assertEquals("test", m.get("2"));
+ assertEquals("test", m.get("3"));
+ }
+
+ @Test
+ public void shouldProduceMapFromIteratorUsingGrouping() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+
+ final Map<String,List<String>> m1 = IteratorUtils.groupBy(iterable.iterator(), i -> i.substring(4));
+ assertEquals("test1", m1.get("1").get(0));
+ assertEquals(1, m1.get("1").size());
+ assertEquals("test2", m1.get("2").get(0));
+ assertEquals(1, m1.get("2").size());
+ assertEquals("test3", m1.get("3").get(0));
+ assertEquals(1, m1.get("3").size());
+ assertEquals(3, m1.size());
+
+ final Map<String,List<String>> m2 = IteratorUtils.groupBy(iterable.iterator(), i -> i.substring(0,4));
+ assertEquals("test1", m2.get("test").get(0));
+ assertEquals("test2", m2.get("test").get(1));
+ assertEquals("test3", m2.get("test").get(2));
+ assertEquals(3, m2.get("test").size());
+ assertEquals(1, m2.size());
+ }
+
+ @Test
+ public void shouldApplyMapOverIterator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("1");
+ iterable.add("2");
+ iterable.add("3");
+
+ assertIterator(IteratorUtils.map(iterable.iterator(), s -> "test" + s), 3);
+ }
+
+ @Test
+ public void shouldApplyMapOverIterable() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("1");
+ iterable.add("2");
+ iterable.add("3");
+
+ assertIterator(IteratorUtils.map(iterable, s -> "test" + s).iterator(), 3);
+ }
+
+ @Test
+ public void shouldFilterAllFromIterator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+
+ assertIterator(IteratorUtils.filter(iterable.iterator(), s -> s.startsWith("dfaa")), 0);
+ }
+
+ @Test
+ public void shouldFilterNoneFromIterator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+
+ assertIterator(IteratorUtils.filter(iterable.iterator(), s -> s.startsWith("test")), 3);
+ }
+
+ @Test
+ public void shouldFilterSomeFromIterator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+
+ assertIterator(IteratorUtils.filter(iterable.iterator(), s -> s.equals("test1")), 1);
+ }
+
+ @Test
+ public void shouldFilterAllFromIterable() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+
+ assertIterator(IteratorUtils.filter(iterable, s -> s.startsWith("dfaa")).iterator(), 0);
+ }
+
+ @Test
+ public void shouldFilterNoneFromIterable() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+
+ assertIterator(IteratorUtils.filter(iterable, s -> s.startsWith("test")).iterator(), 3);
+ }
+
+ @Test
+ public void shouldFilterSomeFromIterable() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("test1");
+ iterable.add("test2");
+ iterable.add("test3");
+
+ assertIterator(IteratorUtils.filter(iterable, s -> s.equals("test1")).iterator(), 1);
+ }
+
+ @Test
+ public void shouldConcatIterators() {
+ final List<String> iterable1 = new ArrayList<>();
+ iterable1.add("test1");
+ iterable1.add("test2");
+ iterable1.add("test3");
+
+ final List<String> iterable2 = new ArrayList<>();
+ iterable2.add("test4");
+ iterable2.add("test5");
+ iterable2.add("test6");
+
+ assertIterator(IteratorUtils.concat(iterable1.iterator(), iterable2.iterator()), 6);
+ }
+
+ @Test
+ public void shouldReduceFromIteratorWithBinaryOperator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("1");
+ iterable.add("2");
+ iterable.add("3");
+
+ assertEquals("test123", IteratorUtils.reduce(iterable.iterator(), "test", (a, b) -> a + b));
+ }
+
+ @Test
+ public void shouldReduceFromIterableWithBinaryOperator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("1");
+ iterable.add("2");
+ iterable.add("3");
+
+ assertEquals("test123", IteratorUtils.reduce(iterable, "test", (a,b) -> a + b));
+ }
+
+ @Test
+ public void shouldReduceFromIterator() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("1");
+ iterable.add("2");
+ iterable.add("3");
+
+ assertEquals(new Integer(16), IteratorUtils.reduce(iterable.iterator(), 10, (accumulator, val) -> accumulator + Integer.parseInt(val)));
+ }
+
+ @Test
+ public void shouldReduceFromIterable() {
+ final List<String> iterable = new ArrayList<>();
+ iterable.add("1");
+ iterable.add("2");
+ iterable.add("3");
+
+ assertEquals(new Integer(16), IteratorUtils.reduce(iterable, 10, (accumulator, val) -> accumulator + Integer.parseInt(val)));
+ }
+
+ public <S> void assertIterator(final Iterator<S> itty, final int size) {
+ for (int ix = 0; ix < size; ix++) {
+ assertEquals("test" + (ix + 1), itty.next());
+ }
+
+ assertFalse(itty.hasNext());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/TraversalStrategiesTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/TraversalStrategiesTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/TraversalStrategiesTest.java
deleted file mode 100644
index f18cba3..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/TraversalStrategiesTest.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.process;
-
-import org.apache.tinkerpop.gremlin.process.graph.traversal.strategy.AbstractTraversalStrategy;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static org.junit.Assert.*;
-
-/**
- * @author Matthias Broecheler (me@matthiasb.com)
- */
-public class TraversalStrategiesTest {
-
- /**
- * Tests that {@link org.apache.tinkerpop.gremlin.process.TraversalStrategies#sortStrategies(java.util.List)}
- * works as advertised. This class defines a bunch of dummy strategies which define an order. It is verified
- * that the right order is being returned.
- */
- @Test
- public void testTraversalStrategySorting() {
- TraversalStrategy
- a = new StrategyA(),
- b = new StrategyB(),
- c = new StrategyC(),
- d = new StrategyD(),
- e = new StrategyE(),
- k = new StrategyK();
-
- List<TraversalStrategy> s;
-
- //Dependency well defined
- s = Stream.of(b, a)
- .collect(Collectors.toList());
- TraversalStrategies.sortStrategies(s);
- assertEquals(2, s.size());
- assertEquals(a, s.get(0));
- assertEquals(b, s.get(1));
-
- //No dependency
- s = Stream.of(c, a)
- .collect(Collectors.toList());
- TraversalStrategies.sortStrategies(s);
- assertEquals(2, s.size());
- assertEquals(c, s.get(0));
- assertEquals(a, s.get(1));
-
- //Dependency well defined
- s = Stream.of(c, a, b)
- .collect(Collectors.toList());
- TraversalStrategies.sortStrategies(s);
- assertEquals(3, s.size());
- assertEquals(a, s.get(0));
- assertEquals(b, s.get(1));
- assertEquals(c, s.get(2));
-
- //Circular dependency => throws exception
- s = Stream.of(c, k, a, b)
- .collect(Collectors.toList());
- try {
- TraversalStrategies.sortStrategies(s);
- fail();
- } catch (IllegalStateException ex) {
- assertTrue(ex.getMessage().toLowerCase().contains("cyclic"));
- }
-
- //Dependency well defined
- s = Stream.of(d, c, a, e, b)
- .collect(Collectors.toList());
- TraversalStrategies.sortStrategies(s);
- assertEquals(5, s.size());
- assertEquals(a, s.get(0));
- assertEquals(b, s.get(1));
- assertEquals(d, s.get(2));
- assertEquals(c, s.get(3));
- assertEquals(e, s.get(4));
-
- //Circular dependency => throws exception
- s = Stream.of(d, c, k, a, e, b)
- .collect(Collectors.toList());
- try {
- TraversalStrategies.sortStrategies(s);
- fail();
- } catch (IllegalStateException ex) {
- assertTrue(ex.getMessage().toLowerCase().contains("cyclic"));
- }
- }
-
-
- public static class StrategyA extends DummyStrategy {
-
- @Override
- public Set<Class<? extends TraversalStrategy>> applyPrior() {
- return Collections.EMPTY_SET;
- }
-
- @Override
- public Set<Class<? extends TraversalStrategy>> applyPost() {
- return Stream.of(StrategyB.class).collect(Collectors.toSet());
- }
-
- }
-
- public static class StrategyB extends DummyStrategy {
-
- @Override
- public Set<Class<? extends TraversalStrategy>> applyPrior() {
- return Stream.of(StrategyA.class).collect(Collectors.toSet());
- }
-
- @Override
- public Set<Class<? extends TraversalStrategy>> applyPost() {
- return Stream.of(StrategyC.class).collect(Collectors.toSet());
- }
-
- }
-
- public static class StrategyC extends DummyStrategy {
-
- }
-
- public static class StrategyD extends DummyStrategy {
-
- @Override
- public Set<Class<? extends TraversalStrategy>> applyPrior() {
- return Stream.of(StrategyB.class).collect(Collectors.toSet());
- }
-
- @Override
- public Set<Class<? extends TraversalStrategy>> applyPost() {
- return Stream.of(StrategyC.class).collect(Collectors.toSet());
- }
-
- }
-
- public static class StrategyE extends DummyStrategy {
-
- @Override
- public Set<Class<? extends TraversalStrategy>> applyPrior() {
- return Stream.of(StrategyC.class).collect(Collectors.toSet());
- }
-
- }
-
- public static class StrategyK extends DummyStrategy {
-
- @Override
- public Set<Class<? extends TraversalStrategy>> applyPrior() {
- return Stream.of(StrategyC.class).collect(Collectors.toSet());
- }
-
- @Override
- public Set<Class<? extends TraversalStrategy>> applyPost() {
- return Stream.of(StrategyA.class).collect(Collectors.toSet());
- }
-
- }
-
- private static class DummyStrategy extends AbstractTraversalStrategy {
-
- @Override
- public void apply(Traversal.Admin<?, ?> traversal) {
- //Do nothing
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/filter/ConjunctionStepTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/filter/ConjunctionStepTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/filter/ConjunctionStepTest.java
deleted file mode 100644
index 541511f..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/filter/ConjunctionStepTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter;
-
-import org.apache.tinkerpop.gremlin.process.graph.traversal.GraphTraversal;
-import org.apache.tinkerpop.gremlin.process.graph.util.HasContainer;
-import org.apache.tinkerpop.gremlin.structure.Compare;
-import org.junit.Test;
-
-import java.util.Iterator;
-
-import static org.apache.tinkerpop.gremlin.process.graph.traversal.__.*;
-import static org.junit.Assert.*;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class ConjunctionStepTest {
-
- @Test
- public void shouldGetHasContainers() {
- final GraphTraversal.Admin<?, ?> traversal = and(has("name"), has("age", Compare.gt, 30).or(has("lang", "java"))).asAdmin();
- assertTrue(((ConjunctionStep) traversal.getStartStep()).isConjunctionHasTree());
- final ConjunctionStep.ConjunctionTree conjunctionTree = (((ConjunctionStep<?>) traversal.getStartStep()).getConjunctionHasTree());
- final Iterator<ConjunctionStep.ConjunctionTree.Entry> iterator = conjunctionTree.iterator();
- //System.out.println(conjunctionTree);
- ConjunctionStep.ConjunctionTree.Entry entry = iterator.next();
- assertTrue(entry.isHasContainer());
- assertEquals("name", entry.<HasContainer>getValue().key);
- //
- entry = iterator.next();
- assertTrue(entry.isHasContainer());
- assertEquals("age", entry.<HasContainer>getValue().key);
- assertEquals(Compare.gt, entry.<HasContainer>getValue().predicate);
- assertEquals(30, entry.<HasContainer>getValue().value);
- //
- entry = iterator.next();
- assertTrue(entry.isConjunctionTree());
- assertFalse(entry.<ConjunctionStep.ConjunctionTree>getValue().isAnd());
- entry = entry.<ConjunctionStep.ConjunctionTree>getValue().iterator().next();
- assertTrue(entry.isHasContainer());
- assertEquals("lang", entry.<HasContainer>getValue().key);
- assertEquals(Compare.eq, entry.<HasContainer>getValue().predicate);
- assertEquals("java", entry.<HasContainer>getValue().value);
- }
-
- @Test
- public void shouldNotGetHasContainers() {
- final GraphTraversal.Admin<?, ?> traversal = and(has("name"), has("age", Compare.gt, 30).or(has("lang", "java"), out().has("name","josh"))).asAdmin();
- assertFalse(((ConjunctionStep) traversal.getStartStep()).isConjunctionHasTree());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategyTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategyTest.java
deleted file mode 100644
index 1ec2c6f..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategyTest.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package org.apache.tinkerpop.gremlin.process.graph.traversal.strategy;
-
-import org.apache.tinkerpop.gremlin.process.Traversal;
-import org.apache.tinkerpop.gremlin.process.TraversalEngine;
-import org.apache.tinkerpop.gremlin.process.TraversalStrategies;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.__;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.HasTraversalStep;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.RangeGlobalStep;
-import org.apache.tinkerpop.gremlin.process.traversal.DefaultTraversalStrategies;
-import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
-import org.apache.tinkerpop.gremlin.structure.Compare;
-import org.apache.tinkerpop.gremlin.structure.Contains;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.runners.Enclosed;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.BiPredicate;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.*;
-
-/**
- * @author Daniel Kuppitz (http://gremlin.guru)
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-@RunWith(Enclosed.class)
-public class RangeByIsCountStrategyTest {
-
- @RunWith(Parameterized.class)
- public static class StandardTest extends AbstractRangeByIsCountStrategyTest {
-
- @Parameterized.Parameters(name = "{0}")
- public static Iterable<Object[]> data() {
- return generateTestParameters();
- }
-
- @Parameterized.Parameter(value = 0)
- public String name;
-
- @Parameterized.Parameter(value = 1)
- public BiPredicate predicate;
-
- @Parameterized.Parameter(value = 2)
- public Object value;
-
- @Parameterized.Parameter(value = 3)
- public long expectedHighRange;
-
- @Before
- public void setup() {
- this.traversalEngine = mock(TraversalEngine.class);
- when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.STANDARD);
- }
-
- @Test
- public void shouldApplyStrategy() {
- doTest(predicate, value, expectedHighRange);
- }
- }
-
- @RunWith(Parameterized.class)
- public static class ComputerTest extends AbstractRangeByIsCountStrategyTest {
-
- @Parameterized.Parameters(name = "{0}")
- public static Iterable<Object[]> data() {
- return generateTestParameters();
- }
-
- @Parameterized.Parameter(value = 0)
- public String name;
-
- @Parameterized.Parameter(value = 1)
- public BiPredicate predicate;
-
- @Parameterized.Parameter(value = 2)
- public Object value;
-
- @Parameterized.Parameter(value = 3)
- public long expectedHighRange;
-
- @Before
- public void setup() {
- this.traversalEngine = mock(TraversalEngine.class);
- when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.COMPUTER);
- }
-
- @Test
- public void shouldApplyStrategy() {
- doTest(predicate, value, expectedHighRange);
- }
- }
-
- public static class SpecificComputerTest extends AbstractRangeByIsCountStrategyTest {
-
- @Before
- public void setup() {
- this.traversalEngine = mock(TraversalEngine.class);
- when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.COMPUTER);
- }
-
- @Test
- public void nestedCountEqualsNullShouldLimitToOne() {
- final AtomicInteger counter = new AtomicInteger(0);
- final Traversal traversal = __.out().has(__.outE("created").count().is(0));
- applyRangeByIsCountStrategy(traversal);
-
- final HasTraversalStep hasStep = TraversalHelper.getStepsOfClass(HasTraversalStep.class, traversal.asAdmin()).stream().findFirst().get();
- final Traversal nestedTraversal = (Traversal) hasStep.getLocalChildren().get(0);
- TraversalHelper.getStepsOfClass(RangeGlobalStep.class, nestedTraversal.asAdmin()).stream().forEach(step -> {
- assertEquals(0, step.getLowRange());
- assertEquals(1, step.getHighRange());
- counter.incrementAndGet();
- });
- assertEquals(1, counter.get());
- }
- }
-
- private static abstract class AbstractRangeByIsCountStrategyTest {
-
- protected TraversalEngine traversalEngine;
-
- void applyRangeByIsCountStrategy(final Traversal traversal) {
- final TraversalStrategies strategies = new DefaultTraversalStrategies();
- strategies.addStrategies(RangeByIsCountStrategy.instance());
-
- traversal.asAdmin().setStrategies(strategies);
- traversal.asAdmin().applyStrategies();
- traversal.asAdmin().setEngine(traversalEngine);
- }
-
- public void doTest(final BiPredicate predicate, final Object value, final long expectedHighRange) {
- final AtomicInteger counter = new AtomicInteger(0);
- final Traversal traversal = __.out().count().is(predicate, value);
- applyRangeByIsCountStrategy(traversal);
-
- final List<RangeGlobalStep> steps = TraversalHelper.getStepsOfClass(RangeGlobalStep.class, traversal.asAdmin());
- assertEquals(1, steps.size());
-
- steps.forEach(step -> {
- assertEquals(0, step.getLowRange());
- assertEquals(expectedHighRange, step.getHighRange());
- counter.incrementAndGet();
- });
-
- assertEquals(1, counter.intValue());
- }
-
- static Iterable<Object[]> generateTestParameters() {
-
- return Arrays.asList(new Object[][]{
- {"countEqualsNullShouldLimitToOne", Compare.eq, 0l, 1l},
- {"countNotEqualsFourShouldLimitToFive", Compare.neq, 4l, 5l},
- {"countLessThanOrEqualThreeShouldLimitToFour", Compare.lte, 3l, 4l},
- {"countLessThanThreeShouldLimitToThree", Compare.lt, 3l, 3l},
- {"countGreaterThanTwoShouldLimitToThree", Compare.gt, 2l, 3l},
- {"countGreaterThanOrEqualTwoShouldLimitToTwo", Compare.gte, 2l, 2l},
- {"countInsideTwoAndFourShouldLimitToFour", Compare.inside, Arrays.asList(2l, 4l), 4l},
- {"countOutsideTwoAndFourShouldLimitToFive", Compare.outside, Arrays.asList(2l, 4l), 5l},
- {"countWithinTwoSixFourShouldLimitToSeven", Contains.within, Arrays.asList(2l, 6l, 4l), 7l},
- {"countWithoutTwoSixFourShouldLimitToSix", Contains.without, Arrays.asList(2l, 6l, 4l), 6l}});
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/TimeLimitedStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/TimeLimitedStrategyTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/TimeLimitedStrategyTest.java
deleted file mode 100644
index f9d16c0..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/TimeLimitedStrategyTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package org.apache.tinkerpop.gremlin.process.graph.traversal.strategy;
-
-import org.apache.tinkerpop.gremlin.process.Traversal;
-import org.apache.tinkerpop.gremlin.process.TraversalStrategies;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.__;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.TimeLimitStep;
-import org.apache.tinkerpop.gremlin.process.traversal.DefaultTraversalStrategies;
-import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class TimeLimitedStrategyTest {
-
- @Test
- public void shouldAddTimeLimitStepIfNotPresent() {
- final Traversal t = __.out();
-
- final TimeLimitedStrategy s = new TimeLimitedStrategy(100);
- final TraversalStrategies strategies = new DefaultTraversalStrategies();
- strategies.addStrategies(s);
- t.asAdmin().setStrategies(strategies);
-
- t.asAdmin().applyStrategies();
-
- assertEquals(TimeLimitStep.class, t.asAdmin().getEndStep().getClass());
- }
-
- @Test
- public void shouldNotAddTimeLimitStepIfAlreadyPresentAtEnd() {
- final Traversal t = __.out().timeLimit(100);
-
- final TimeLimitedStrategy s = new TimeLimitedStrategy(100);
- final TraversalStrategies strategies = new DefaultTraversalStrategies();
- strategies.addStrategies(s);
- t.asAdmin().setStrategies(strategies);
-
- t.asAdmin().applyStrategies();
-
- assertEquals(1, TraversalHelper.getStepsOfAssignableClass(TimeLimitStep.class, t.asAdmin()).stream().count());
- assertEquals(TimeLimitStep.class, t.asAdmin().getEndStep().getClass());
- }
-
- @Test
- public void shouldAddTimeLimitStepIfAlreadyPresentInMiddle() {
- final Traversal t = __.out().timeLimit(100).out();
-
- final TimeLimitedStrategy s = new TimeLimitedStrategy(100);
- final TraversalStrategies strategies = new DefaultTraversalStrategies();
- strategies.addStrategies(s);
- t.asAdmin().setStrategies(strategies);
-
- t.asAdmin().applyStrategies();
-
- assertEquals(TimeLimitStep.class, t.asAdmin().getEndStep().getClass());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/util/TreeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/util/TreeTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/util/TreeTest.java
deleted file mode 100644
index abbeadb..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/util/TreeTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.process.graph.util;
-
-import org.junit.Test;
-
-import java.util.AbstractMap;
-import java.util.Arrays;
-import java.util.Map;
-
-import static org.junit.Assert.*;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class TreeTest {
-
- @Test
- public void shouldProvideValidDepths() {
- Tree<String> tree = new Tree<String>();
- tree.put("marko", new Tree<String>(TreeTest.createTree("a", new Tree<String>("a1", "a2")), TreeTest.createTree("b", new Tree<String>("b1", "b2", "b3"))));
- tree.put("josh", new Tree<String>("1", "2"));
-
- assertEquals(0, tree.getObjectsAtDepth(0).size());
- assertEquals(2, tree.getObjectsAtDepth(1).size());
- assertEquals(4, tree.getObjectsAtDepth(2).size());
- assertEquals(5, tree.getObjectsAtDepth(3).size());
- assertEquals(0, tree.getObjectsAtDepth(4).size());
- assertEquals(0, tree.getObjectsAtDepth(5).size());
-
- assertEquals(2, tree.get("josh").size());
- assertEquals(0, tree.get("marko").get("b").get("b1").size());
- assertEquals(3, tree.get("marko").get("b").size());
- assertNull(tree.get("marko").get("c"));
- }
-
- @Test
- public void shouldProvideValidLeaves() {
- Tree<String> tree = new Tree<String>();
- tree.put("marko", new Tree<String>(TreeTest.createTree("a", new Tree<String>("a1", "a2")), TreeTest.createTree("b", new Tree<String>("b1", "b2", "b3"))));
- tree.put("josh", new Tree<String>("1", "2"));
-
- assertEquals(7, tree.getLeafTrees().size());
- for (Tree<String> t : tree.getLeafTrees()) {
- assertEquals(1, t.keySet().size());
- final String key = t.keySet().iterator().next();
- assertTrue(Arrays.asList("a1", "a2", "b1", "b2", "b3", "1", "2").contains(key));
- }
-
- assertEquals(7, tree.getLeafObjects().size());
- for (String s : tree.getLeafObjects()) {
- assertTrue(Arrays.asList("a1", "a2", "b1", "b2", "b3", "1", "2").contains(s));
- }
- }
-
- @Test
- public void shouldMergeTreesCorrectly() {
- Tree<String> tree1 = new Tree<>();
- tree1.put("1", new Tree<String>(TreeTest.createTree("1_1", new Tree<String>("1_1_1")), TreeTest.createTree("1_2", new Tree<String>("1_2_1"))));
- Tree<String> tree2 = new Tree<>();
- tree2.put("1", new Tree<String>(TreeTest.createTree("1_1", new Tree<String>("1_1_1")), TreeTest.createTree("1_2", new Tree<String>("1_2_2"))));
-
- Tree<String> mergeTree = new Tree<>();
- mergeTree.addTree(tree1);
- mergeTree.addTree(tree2);
-
- assertEquals(1, mergeTree.size());
- assertEquals(0, mergeTree.getObjectsAtDepth(0).size());
- assertEquals(1, mergeTree.getObjectsAtDepth(1).size());
- assertEquals(2, mergeTree.getObjectsAtDepth(2).size());
- assertEquals(3, mergeTree.getObjectsAtDepth(3).size());
- assertTrue(mergeTree.getObjectsAtDepth(3).contains("1_1_1"));
- assertTrue(mergeTree.getObjectsAtDepth(3).contains("1_2_1"));
- assertTrue(mergeTree.getObjectsAtDepth(3).contains("1_2_2"));
- }
-
- private static <T> Map.Entry<T, Tree<T>> createTree(T key, Tree<T> tree) {
- return new AbstractMap.SimpleEntry<>(key, tree);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/util/BulkSetTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/util/BulkSetTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/util/BulkSetTest.java
deleted file mode 100644
index 74766ef..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/util/BulkSetTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.process.util;
-
-import org.junit.Test;
-
-import java.util.Iterator;
-import java.util.Random;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class BulkSetTest {
-
- @Test
- public void shouldHaveProperCountAndNotOutOfMemoryException() {
- final Set<Boolean> list = new BulkSet<>();
- final Random random = new Random();
- for (int i = 0; i < 10000000; i++) {
- list.add(random.nextBoolean());
- }
- assertEquals(10000000, list.size());
- }
-
- @Test
- public void shouldHaveCorrectBulkCounts() {
- final BulkSet<String> set = new BulkSet<>();
- set.add("marko");
- set.add("matthias");
- set.add("marko", 7);
- set.add("stephen");
- set.add("stephen");
- assertEquals(8, set.get("marko"));
- assertEquals(1, set.get("matthias"));
- assertEquals(2, set.get("stephen"));
- final Iterator<String> iterator = set.iterator();
- for (int i = 0; i < 11; i++) {
- if (i < 8)
- assertEquals("marko", iterator.next());
- else if (i < 9)
- assertEquals("matthias", iterator.next());
- else
- assertEquals("stephen", iterator.next());
- }
- assertEquals(11, set.size());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/util/TraversalHelperTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/util/TraversalHelperTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/util/TraversalHelperTest.java
deleted file mode 100644
index 6706c48..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/util/TraversalHelperTest.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.process.util;
-
-import org.apache.tinkerpop.gremlin.process.Step;
-import org.apache.tinkerpop.gremlin.process.Traversal;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.__;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.HasStep;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.LambdaFilterStep;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.PropertiesStep;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.sideEffect.IdentityStep;
-import org.apache.tinkerpop.gremlin.process.traversal.DefaultTraversal;
-import org.apache.tinkerpop.gremlin.process.traversal.engine.StandardTraversalEngine;
-import org.apache.tinkerpop.gremlin.process.traversal.step.EmptyStep;
-import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
-import org.apache.tinkerpop.gremlin.structure.PropertyType;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import static org.apache.tinkerpop.gremlin.process.graph.traversal.__.*;
-import static org.junit.Assert.*;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-
-public class TraversalHelperTest {
-
- @Test
- public void shouldCorrectlyTestIfReversible() {
- assertTrue(TraversalHelper.isReversible(out().asAdmin()));
- assertTrue(TraversalHelper.isReversible(outE().inV().asAdmin()));
- assertTrue(TraversalHelper.isReversible(in().in().asAdmin()));
- assertTrue(TraversalHelper.isReversible(inE().outV().outE().inV().asAdmin()));
- assertTrue(TraversalHelper.isReversible(outE().has("since").inV().asAdmin()));
- assertTrue(TraversalHelper.isReversible(outE().as("x").asAdmin()));
- assertFalse(TraversalHelper.isReversible(__.as("a").outE().back("a").asAdmin()));
- }
-
- @Test
- public void shouldChainTogetherStepsWithNextPreviousInALinkedListStructure() {
- Traversal.Admin traversal = new DefaultTraversal<>(new Object());
- traversal.asAdmin().addStep(new IdentityStep(traversal));
- traversal.asAdmin().addStep(new HasStep(traversal, null));
- traversal.asAdmin().addStep(new LambdaFilterStep(traversal, traverser -> true));
- validateToyTraversal(traversal);
- }
-
- @Test
- public void shouldAddStepsCorrectly() {
- Traversal.Admin traversal = new DefaultTraversal<>(new Object());
- traversal.asAdmin().addStep(0, new LambdaFilterStep(traversal, traverser -> true));
- traversal.asAdmin().addStep(0, new HasStep(traversal, null));
- traversal.asAdmin().addStep(0, new IdentityStep(traversal));
- validateToyTraversal(traversal);
-
- traversal = new DefaultTraversal<>(new Object());
- traversal.asAdmin().addStep(0, new IdentityStep(traversal));
- traversal.asAdmin().addStep(1, new HasStep(traversal, null));
- traversal.asAdmin().addStep(2, new LambdaFilterStep(traversal, traverser -> true));
- validateToyTraversal(traversal);
- }
-
- @Test
- public void shouldRemoveStepsCorrectly() {
- Traversal.Admin traversal = new DefaultTraversal<>(new Object());
- traversal.asAdmin().addStep(new IdentityStep(traversal));
- traversal.asAdmin().addStep(new HasStep(traversal, null));
- traversal.asAdmin().addStep(new LambdaFilterStep(traversal, traverser -> true));
-
- traversal.asAdmin().addStep(new PropertiesStep(traversal, PropertyType.VALUE, "marko"));
- traversal.asAdmin().removeStep(3);
- validateToyTraversal(traversal);
-
- traversal.asAdmin().addStep(0, new PropertiesStep(traversal, PropertyType.PROPERTY, "marko"));
- traversal.asAdmin().removeStep(0);
- validateToyTraversal(traversal);
-
- traversal.asAdmin().removeStep(1);
- traversal.asAdmin().addStep(1, new HasStep(traversal, null));
- validateToyTraversal(traversal);
- }
-
- private static void validateToyTraversal(final Traversal traversal) {
- assertEquals(traversal.asAdmin().getSteps().size(), 3);
-
- assertEquals(IdentityStep.class, traversal.asAdmin().getSteps().get(0).getClass());
- assertEquals(HasStep.class, traversal.asAdmin().getSteps().get(1).getClass());
- assertEquals(LambdaFilterStep.class, traversal.asAdmin().getSteps().get(2).getClass());
-
- // IDENTITY STEP
- assertEquals(EmptyStep.class, ((Step) traversal.asAdmin().getSteps().get(0)).getPreviousStep().getClass());
- assertEquals(HasStep.class, ((Step) traversal.asAdmin().getSteps().get(0)).getNextStep().getClass());
- assertEquals(LambdaFilterStep.class, ((Step) traversal.asAdmin().getSteps().get(0)).getNextStep().getNextStep().getClass());
- assertEquals(EmptyStep.class, ((Step) traversal.asAdmin().getSteps().get(0)).getNextStep().getNextStep().getNextStep().getClass());
-
- // HAS STEP
- assertEquals(IdentityStep.class, ((Step) traversal.asAdmin().getSteps().get(1)).getPreviousStep().getClass());
- assertEquals(EmptyStep.class, ((Step) traversal.asAdmin().getSteps().get(1)).getPreviousStep().getPreviousStep().getClass());
- assertEquals(LambdaFilterStep.class, ((Step) traversal.asAdmin().getSteps().get(1)).getNextStep().getClass());
- assertEquals(EmptyStep.class, ((Step) traversal.asAdmin().getSteps().get(1)).getNextStep().getNextStep().getClass());
-
- // FILTER STEP
- assertEquals(HasStep.class, ((Step) traversal.asAdmin().getSteps().get(2)).getPreviousStep().getClass());
- assertEquals(IdentityStep.class, ((Step) traversal.asAdmin().getSteps().get(2)).getPreviousStep().getPreviousStep().getClass());
- assertEquals(EmptyStep.class, ((Step) traversal.asAdmin().getSteps().get(2)).getPreviousStep().getPreviousStep().getPreviousStep().getClass());
- assertEquals(EmptyStep.class, ((Step) traversal.asAdmin().getSteps().get(2)).getNextStep().getClass());
-
- assertEquals(3, traversal.asAdmin().getSteps().size());
- }
-
- @Test
- public void shouldTruncateLongName() {
- Step s = Mockito.mock(Step.class);
- Mockito.when(s.toString()).thenReturn("0123456789");
- assertEquals("0123...", TraversalHelper.getShortName(s, 7));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/CompareTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/CompareTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/CompareTest.java
deleted file mode 100644
index 81546f5..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/CompareTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.util.Arrays;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-@RunWith(Parameterized.class)
-public class CompareTest {
-
- @Parameterized.Parameters(name = "{0}.test({1},{2}) = {3}")
- public static Iterable<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {Compare.eq, null, null, true},
- {Compare.eq, null, 1, false},
- {Compare.eq, 1, null, false},
- {Compare.eq, 1, 1, true},
- {Compare.eq, "1", "1", true},
- {Compare.eq, 100, 99, false},
- {Compare.eq, 100, 101, false},
- {Compare.eq, "z", "a", false},
- {Compare.eq, "a", "z", false},
- {Compare.neq, null, null, false},
- {Compare.neq, null, 1, true},
- {Compare.neq, 1, null, true},
- {Compare.neq, 1, 1, false},
- {Compare.neq, "1", "1", false},
- {Compare.neq, 100, 99, true},
- {Compare.neq, 100, 101, true},
- {Compare.neq, "z", "a", true},
- {Compare.neq, "a", "z", true},
- {Compare.gt, null, null, false},
- {Compare.gt, null, 1, false},
- {Compare.gt, 1, null, false},
- {Compare.gt, 1, 1, false},
- {Compare.gt, "1", "1", false},
- {Compare.gt, 100, 99, true},
- {Compare.gt, 100, 101, false},
- {Compare.gt, "z", "a", true},
- {Compare.gt, "a", "z", false},
- {Compare.lt, null, null, false},
- {Compare.lt, null, 1, false},
- {Compare.lt, 1, null, false},
- {Compare.lt, 1, 1, false},
- {Compare.lt, "1", "1", false},
- {Compare.lt, 100, 99, false},
- {Compare.lt, 100, 101, true},
- {Compare.lt, "z", "a", false},
- {Compare.lt, "a", "z", true},
- {Compare.gte, null, null, false},
- {Compare.gte, null, 1, false},
- {Compare.gte, 1, null, false},
- {Compare.gte, 1, 1, true},
- {Compare.gte, "1", "1", true},
- {Compare.gte, 100, 99, true},
- {Compare.gte, 100, 101, false},
- {Compare.gte, "z", "a", true},
- {Compare.gte, "a", "z", false},
- {Compare.lte, null, null, false},
- {Compare.lte, null, 1, false},
- {Compare.lte, 1, null, false},
- {Compare.lte, 1, 1, true},
- {Compare.lte, "1", "1", true},
- {Compare.lte, 100, 99, false},
- {Compare.lte, 100, 101, true},
- {Compare.lte, "z", "a", false},
- {Compare.lte, "a", "z", true}
- });
- }
-
- @Parameterized.Parameter(value = 0)
- public Compare compare;
-
- @Parameterized.Parameter(value = 1)
- public Object first;
-
- @Parameterized.Parameter(value = 2)
- public Object second;
-
- @Parameterized.Parameter(value = 3)
- public boolean expected;
-
- @Test
- public void shouldTest() {
- assertEquals(expected, compare.test(first, second));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/FeaturesConventionTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/FeaturesConventionTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/FeaturesConventionTest.java
deleted file mode 100644
index 1e7f97b..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/FeaturesConventionTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure;
-
-import org.apache.tinkerpop.gremlin.structure.util.FeatureDescriptor;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-
-import static org.junit.Assert.*;
-
-/**
- * All features should be prefixed with the word "supports" and return boolean. Furthermore, all should have an
- * FeatureDescriptor annotation with a "name" that represents the suffix after "supports" in the same case as the
- * method. A String name of the feature should be supplied as a public static variable and be equal to the value
- * of the "name" in all upper case.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-@RunWith(Parameterized.class)
-public class FeaturesConventionTest {
- private static final String FEATURE_METHOD_PREFIX = "supports";
- private static final String FEATURE_FIELD_PREFIX = "FEATURE_";
-
- private static final String ERROR_FIELD = "Feature [%s] must have a field declared with the name of the feature as 'public static final'";
-
- @Parameterized.Parameters(name = "{0}.test()")
- public static Iterable<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {Graph.Features.EdgeFeatures.class},
- {Graph.Features.EdgePropertyFeatures.class},
- {Graph.Features.GraphFeatures.class},
- {Graph.Features.VariableFeatures.class},
- {Graph.Features.PropertyFeatures.class},
- {Graph.Features.VertexFeatures.class}
- });
- }
-
- @Parameterized.Parameter(value = 0)
- public Class<?> featuresClass;
-
- @Test
- public void shouldFollowConventionsForFeatures() {
- Arrays.asList(featuresClass.getMethods()).stream()
- .filter(FeaturesConventionTest::chooseFeatureMethod)
- .forEach(FeaturesConventionTest::assertFeatureConvention);
- }
-
- private static String convertToUnderscore(final String text) {
- final String regex = "([a-z])([A-Z])";
- final String replacement = "$1_$2";
- final String underscored = text.replaceAll(regex, replacement);
- return underscored.substring(0, underscored.length());
- }
-
- private static boolean chooseFeatureMethod(Method m) {
- return m.getName().startsWith(FEATURE_METHOD_PREFIX) && !m.getName().equals(FEATURE_METHOD_PREFIX);
- }
-
- private static void assertFeatureConvention(final Method m) {
- final FeatureDescriptor annotation = m.getAnnotation(FeatureDescriptor.class);
- final Class featuresClass = m.getDeclaringClass();
-
- // all "features" need an annotation
- assertNotNull(annotation);
-
- // needs to match pattern of "support" followed by "name" value in annotation
- assertEquals(m.getName(), FEATURE_METHOD_PREFIX + annotation.name());
-
- try {
- final Field f = featuresClass.getField(FEATURE_FIELD_PREFIX + convertToUnderscore(annotation.name()).toUpperCase());
- assertEquals(annotation.name(), f.get(null));
- } catch (Exception e) {
- fail(String.format(ERROR_FIELD, annotation.name()));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/GraphHiddenTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/GraphHiddenTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/GraphHiddenTest.java
deleted file mode 100644
index 215715e..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/GraphHiddenTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class GraphHiddenTest {
-
- @Test
- public void shouldHandleSystemKeyManipulationCorrectly() {
- String key = "key";
- assertFalse(Graph.Hidden.isHidden(key));
- assertTrue(Graph.Hidden.isHidden(Graph.Hidden.hide(key)));
- assertEquals(Graph.Hidden.hide("").concat(key), Graph.Hidden.hide(key));
- for (int i = 0; i < 10; i++) {
- key = Graph.Hidden.hide(key);
- }
- assertTrue(Graph.Hidden.isHidden(key));
- assertEquals(Graph.Hidden.hide("key"), key);
- assertEquals("key", Graph.Hidden.unHide(key));
- for (int i = 0; i < 10; i++) {
- key = Graph.Hidden.unHide(key);
- }
- assertFalse(Graph.Hidden.isHidden(key));
- assertEquals("key", key);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
deleted file mode 100644
index 21bc5bc..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure.io.gryo;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertNotSame;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class GryoMapperTest {
- @Test
- public void shouldGetMostRecentVersion() {
- final GryoMapper.Builder b = GryoMapper.build();
- assertNotSame(b, GryoMapper.build());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9f6fa242/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
deleted file mode 100644
index aa9b8b4..0000000
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
+++ /dev/null
@@ -1,450 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure.util;
-
-import org.apache.tinkerpop.gremlin.process.T;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Element;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Property;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.javatuples.Pair;
-import org.junit.Test;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Stream;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class ElementHelperTest {
-
- @Test
- public void shouldValidatePropertyAndNotAllowNullValue() {
- try {
- ElementHelper.validateProperty("test", null);
- fail("Should fail as property value cannot be null");
- } catch (IllegalArgumentException iae) {
- assertEquals(Property.Exceptions.propertyValueCanNotBeNull().getMessage(), iae.getMessage());
- }
- }
-
- @Test
- public void shouldValidatePropertyAndNotAllowNullKey() {
- try {
- ElementHelper.validateProperty(null, "test");
- fail("Should fail as property key cannot be null");
- } catch (IllegalArgumentException iae) {
- assertEquals(Property.Exceptions.propertyKeyCanNotBeNull().getMessage(), iae.getMessage());
- }
- }
-
- @Test
- public void shouldValidatePropertyAndNotAllowEmptyKey() {
- try {
- ElementHelper.validateProperty("", "test");
- fail("Should fail as property key cannot be empty");
- } catch (IllegalArgumentException iae) {
- assertEquals(Property.Exceptions.propertyKeyCanNotBeEmpty().getMessage(), iae.getMessage());
- }
- }
-
- @Test
- public void shouldHaveValidProperty() {
- ElementHelper.validateProperty("aKey", "value");
- }
-
- @Test
- public void shouldAllowEvenNumberOfKeyValues() {
- try {
- ElementHelper.legalPropertyKeyValueArray("aKey", "test", "no-value-for-this-one");
- fail("Should fail as there is an odd number of key-values");
- } catch (IllegalArgumentException iae) {
- assertEquals(Element.Exceptions.providedKeyValuesMustBeAMultipleOfTwo().getMessage(), iae.getMessage());
- }
- }
-
- @Test
- public void shouldNotAllowEvenNumberOfKeyValuesAndInvalidKeys() {
- try {
- ElementHelper.legalPropertyKeyValueArray("aKey", "test", "value-for-this-one", 1, 1, "none");
- fail("Should fail as there is an even number of key-values, but a bad key");
- } catch (IllegalArgumentException iae) {
- assertEquals(Element.Exceptions.providedKeyValuesMustHaveALegalKeyOnEvenIndices().getMessage(), iae.getMessage());
- }
- }
-
- @Test
- public void shouldAllowEvenNumberOfKeyValuesAndValidKeys() {
- ElementHelper.legalPropertyKeyValueArray("aKey", "test", "value-for-this-one", 1, "1", "none");
- }
-
- @Test
- public void shouldFindTheIdValueAlone() {
- assertEquals(123l, ElementHelper.getIdValue(T.id, 123l).get());
- }
-
- @Test
- public void shouldFindTheIdValueInSet() {
- assertEquals(123l, ElementHelper.getIdValue("test", 321, T.id, 123l, "testagain", "that").get());
- }
-
- @Test
- public void shouldNotFindAnIdValue() {
- assertFalse(ElementHelper.getIdValue("test", 321, "xyz", 123l, "testagain", "that").isPresent());
- }
-
- @Test(expected = NullPointerException.class)
- public void shouldNotFindAnIdValueBecauseItIsNull() {
- ElementHelper.getIdValue("test", 321, T.id, null, "testagain", "that");
- }
-
- @Test
- public void shouldFindTheLabelValueAlone() {
- assertEquals("friend", ElementHelper.getLabelValue(T.label, "friend").get());
- }
-
- @Test
- public void shouldFindTheLabelValueInSet() {
- assertEquals("friend", ElementHelper.getLabelValue("test", 321, T.label, "friend", "testagain", "that").get());
- }
-
- @Test
- public void shouldNotFindTheLabelValue() {
- assertFalse(ElementHelper.getLabelValue("test", 321, "xyz", "friend", "testagain", "that").isPresent());
- }
-
- @Test(expected = ClassCastException.class)
- public void shouldNotFindTheLabelBecauseItIsNotString() {
- ElementHelper.getLabelValue("test", 321, T.label, 4545, "testagain", "that");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void shouldFailCauseNullLabelsAreNotAllowed() {
- ElementHelper.getLabelValue("test", 321, T.label, null, "testagain", "that");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void shouldFailCauseSystemLabelsAreNotAllowed() {
- ElementHelper.getLabelValue("test", 321, T.label, Graph.Hidden.hide("systemLabel"), "testagain", "that");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void shouldFailCauseEmptyLabelsAreNotAllowed() {
- ElementHelper.getLabelValue("test", 321, T.label, "", "testagain", "that");
- }
-
- @Test
- public void shouldAttachKeyValuesButNotLabelsOrId() {
- final Element mockElement = mock(Element.class);
- ElementHelper.attachProperties(mockElement, "test", 123, T.id, 321, T.label, "friends");
- verify(mockElement, times(1)).property("test", 123);
- verify(mockElement, times(0)).property(T.id.getAccessor(), 321);
- verify(mockElement, times(0)).property(T.label.getAccessor(), "friends");
- }
-
- @Test(expected = ClassCastException.class)
- public void shouldFailTryingToAttachNonStringKey() {
- final Element mockElement = mock(Element.class);
- ElementHelper.attachProperties(mockElement, "test", 123, 321, "test");
- }
-
- @Test
- public void shouldFailTryingToAttachKeysToNullElement() {
- try {
- ElementHelper.attachProperties(null, "test", 123, 321, "test");
- fail("Should throw exception since the element argument is null");
- } catch (IllegalArgumentException iae) {
- assertEquals(Graph.Exceptions.argumentCanNotBeNull("element").getMessage(), iae.getMessage());
- }
- }
-
- /*@Test
- public void shouldFailElementAreEqualTestBecauseFirstArgumentIsNull() {
- try {
- ElementHelper.areEqual((Element) null, "some object");
- fail("Should throw exception since the first argument is null");
- } catch (IllegalArgumentException iae) {
- assertEquals(Graph.Exceptions.argumentCanNotBeNull("a").getMessage(), iae.getMessage());
- }
- }
-
- @Test
- public void shouldFailElementAreEqualTestBecauseSecondArgumentIsNull() {
- final Element mockElement = mock(Element.class);
- try {
- ElementHelper.areEqual(mockElement, null);
- fail("Should throw exception since the second argument is null");
- } catch (IllegalArgumentException iae) {
- assertEquals(Graph.Exceptions.argumentCanNotBeNull("b").getMessage(), iae.getMessage());
- }
- }*/
-
- @Test
- public void shouldDetermineElementsAreEqualAsTheyAreSameObject() {
- final Element mockElement = mock(Element.class);
- assertTrue(ElementHelper.areEqual(mockElement, mockElement));
- }
-
- @Test
- public void shouldDetermineElementsAreNotEqualAsAIsVertexAndBIsEdge() {
- final Element mockVertex = mock(Vertex.class);
- final Element mockEdge = mock(Edge.class);
- assertFalse(ElementHelper.areEqual(mockVertex, mockEdge));
- }
-
- @Test
- public void shouldDetermineElementsAreNotEqualAsBIsVertexAndAIsEdge() {
- final Element mockVertex = mock(Vertex.class);
- final Element mockEdge = mock(Edge.class);
- assertFalse(ElementHelper.areEqual(mockEdge, mockVertex));
- }
-
- @Test
- public void shouldDetermineVerticesAreEqual() {
- final Element mockVertexA = mock(Vertex.class);
- final Element mockVertexB = mock(Vertex.class);
- when(mockVertexA.id()).thenReturn("1");
- when(mockVertexB.id()).thenReturn("1");
- assertTrue(ElementHelper.areEqual(mockVertexA, mockVertexB));
- }
-
- @Test
- public void shouldDetermineVerticesAreNotEqual() {
- final Element mockVertexA = mock(Vertex.class);
- final Element mockVertexB = mock(Vertex.class);
- when(mockVertexA.id()).thenReturn("1");
- when(mockVertexB.id()).thenReturn("2");
- assertFalse(ElementHelper.areEqual(mockVertexA, mockVertexB));
- }
-
- @Test
- public void shouldDetermineEdgesAreEqual() {
- final Element mockEdgeA = mock(Edge.class);
- final Element mockEdgeB = mock(Edge.class);
- when(mockEdgeA.id()).thenReturn("1");
- when(mockEdgeB.id()).thenReturn("1");
- assertTrue(ElementHelper.areEqual(mockEdgeA, mockEdgeB));
- }
-
- @Test
- public void shouldDetermineEdgesAreNotEqual() {
- final Element mockEdgeA = mock(Edge.class);
- final Element mockEdgeB = mock(Edge.class);
- when(mockEdgeA.id()).thenReturn("1");
- when(mockEdgeB.id()).thenReturn("2");
- assertFalse(ElementHelper.areEqual(mockEdgeA, mockEdgeB));
- }
-
- @Test
- public void shouldFailPropertyAreEqualTestBecauseFirstArgumentIsNull() {
- try {
- ElementHelper.areEqual((Property) null, "some object");
- fail("Should throw exception since the first argument is null");
- } catch (IllegalArgumentException iae) {
- assertEquals(Graph.Exceptions.argumentCanNotBeNull("a").getMessage(), iae.getMessage());
- }
- }
-
- @Test
- public void shouldFailPropertyAreEqualTestBecauseSecondArgumentIsNull() {
- final Property mockProperty = mock(Property.class);
- try {
- ElementHelper.areEqual(mockProperty, null);
- fail("Should throw exception since the second argument is null");
- } catch (IllegalArgumentException iae) {
- assertEquals(Graph.Exceptions.argumentCanNotBeNull("b").getMessage(), iae.getMessage());
- }
- }
-
- @Test
- public void shouldFailPropertyAreEqualTestBecauseSecondArgumentIsNotProperty() {
- final Property mockProperty = mock(Property.class);
- assertFalse(ElementHelper.areEqual(mockProperty, "i'm a string"));
- }
-
- @Test
- public void shouldDeterminePropertiesAreEqualAsTheyAreSameObject() {
- final Property mockProperty = mock(Property.class);
- assertTrue(ElementHelper.areEqual(mockProperty, mockProperty));
- }
-
- @Test
- public void shouldDeterminePropertiesAreEqualAsTheyAreBothEmpty() {
- final Property mockPropertyA = mock(Property.class);
- final Property mockPropertyB = mock(Property.class);
- when(mockPropertyA.isPresent()).thenReturn(false);
- when(mockPropertyB.isPresent()).thenReturn(false);
- assertTrue(ElementHelper.areEqual(mockPropertyA, mockPropertyB));
- }
-
- @Test
- public void shouldDeterminePropertiesAreNotEqualAsAIsEmptyAndBIsNot() {
- final Property mockPropertyA = mock(Property.class);
- final Property mockPropertyB = mock(Property.class);
- when(mockPropertyA.isPresent()).thenReturn(false);
- when(mockPropertyB.isPresent()).thenReturn(true);
- assertFalse(ElementHelper.areEqual(mockPropertyA, mockPropertyB));
- }
-
- @Test
- public void shouldDeterminePropertiesAreNotEqualAsBIsEmptyAndAIsNot() {
- final Property mockPropertyA = mock(Property.class);
- final Property mockPropertyB = mock(Property.class);
- when(mockPropertyA.isPresent()).thenReturn(true);
- when(mockPropertyB.isPresent()).thenReturn(false);
- assertFalse(ElementHelper.areEqual(mockPropertyA, mockPropertyB));
- }
-
- @Test
- public void shouldDeterminePropertiesAreEqual() {
- final Property mockPropertyA = mock(Property.class);
- final Property mockPropertyB = mock(Property.class);
- final Element mockElement = mock(Element.class);
- when(mockPropertyA.isPresent()).thenReturn(true);
- when(mockPropertyB.isPresent()).thenReturn(true);
- when(mockPropertyA.element()).thenReturn(mockElement);
- when(mockPropertyB.element()).thenReturn(mockElement);
- when(mockPropertyA.key()).thenReturn("k");
- when(mockPropertyB.key()).thenReturn("k");
- when(mockPropertyA.value()).thenReturn("v");
- when(mockPropertyB.value()).thenReturn("v");
-
- assertTrue(ElementHelper.areEqual(mockPropertyA, mockPropertyB));
- }
-
- @Test
- public void shouldDeterminePropertiesAreNotEqualWhenElementsAreDifferent() {
- final Property mockPropertyA = mock(Property.class);
- final Property mockPropertyB = mock(Property.class);
- final Element mockElement = mock(Element.class);
- final Element mockElementDifferent = mock(Element.class);
- when(mockPropertyA.isPresent()).thenReturn(true);
- when(mockPropertyB.isPresent()).thenReturn(true);
- when(mockPropertyA.element()).thenReturn(mockElement);
- when(mockPropertyB.element()).thenReturn(mockElementDifferent);
- when(mockPropertyA.key()).thenReturn("k");
- when(mockPropertyB.key()).thenReturn("k");
- when(mockPropertyA.value()).thenReturn("v");
- when(mockPropertyB.value()).thenReturn("v");
-
- assertFalse(ElementHelper.areEqual(mockPropertyA, mockPropertyB));
- }
-
- @Test
- public void shouldDeterminePropertiesAreNotEqualWhenKeysAreDifferent() {
- final Property mockPropertyA = mock(Property.class);
- final Property mockPropertyB = mock(Property.class);
- final Element mockElement = mock(Element.class);
- when(mockPropertyA.isPresent()).thenReturn(true);
- when(mockPropertyB.isPresent()).thenReturn(true);
- when(mockPropertyA.element()).thenReturn(mockElement);
- when(mockPropertyB.element()).thenReturn(mockElement);
- when(mockPropertyA.key()).thenReturn("k");
- when(mockPropertyB.key()).thenReturn("k1");
- when(mockPropertyA.value()).thenReturn("v");
- when(mockPropertyB.value()).thenReturn("v");
-
- assertFalse(ElementHelper.areEqual(mockPropertyA, mockPropertyB));
- }
-
- @Test
- public void shouldDeterminePropertiesAreNotEqualWhenValuesAreDifferent() {
- final Property mockPropertyA = mock(Property.class);
- final Property mockPropertyB = mock(Property.class);
- final Element mockElement = mock(Element.class);
- when(mockPropertyA.isPresent()).thenReturn(true);
- when(mockPropertyB.isPresent()).thenReturn(true);
- when(mockPropertyA.element()).thenReturn(mockElement);
- when(mockPropertyB.element()).thenReturn(mockElement);
- when(mockPropertyA.key()).thenReturn("k");
- when(mockPropertyB.key()).thenReturn("k");
- when(mockPropertyA.value()).thenReturn("v");
- when(mockPropertyB.value()).thenReturn("v1");
-
- assertFalse(ElementHelper.areEqual(mockPropertyA, mockPropertyB));
- }
-
- @Test
- public void shouldExtractKeys() {
- final Set<String> keys = ElementHelper.getKeys("test1", "something", "test2", "something else");
- assertTrue(keys.contains("test1"));
- assertTrue(keys.contains("test2"));
- }
-
- @Test
- public void shouldGetPairs() {
- final List<Pair<String, Object>> pairs = ElementHelper.asPairs("1", "this", "2", 6l, "3", "other", "4", 1);
- assertEquals(4, pairs.size());
- assertEquals("1", pairs.get(0).getValue0());
- assertEquals("this", pairs.get(0).getValue1());
- assertEquals("2", pairs.get(1).getValue0());
- assertEquals(6l, pairs.get(1).getValue1());
- assertEquals("3", pairs.get(2).getValue0());
- assertEquals("other", pairs.get(2).getValue1());
- assertEquals("4", pairs.get(3).getValue0());
- assertEquals(1, pairs.get(3).getValue1());
- }
-
- @Test
- public void shouldGetMap() {
- final Map<String, Object> map = ElementHelper.asMap("1", "this", "2", 6l, "3", "other", "4", 1);
- assertEquals(4, map.size());
- assertEquals("this", map.get("1"));
- assertEquals(6l, map.get("2"));
- assertEquals("other", map.get("3"));
- assertEquals(1, map.get("4"));
- }
-
- @Test
- public void shouldRemoveAKey() {
- final Optional<Object[]> kvs = ElementHelper.remove("2", "1", "this", "2", 6l, "3", "other", "4", 1);
- assertEquals(6, kvs.get().length);
- assertTrue(Stream.of(kvs.get()).noneMatch(kv -> kv.equals("2") || kv.equals(6l)));
- }
-
- @Test
- public void shouldRemoveAKeyAndReturnEmpty() {
- final Optional<Object[]> kvs = ElementHelper.remove("1", "1", "this");
- assertEquals(Optional.empty(), kvs);
- }
-
- @Test
- public void shouldUpsertKeyValueByAddingIt() {
- final Object[] oldKvs = new Object[]{"k", "v"};
- final Object[] newKvs = ElementHelper.upsert(oldKvs, "k1", "v1");
- assertEquals(4, newKvs.length);
- assertEquals("k1", newKvs[2]);
- assertEquals("v1", newKvs[3]);
- }
-
- @Test
- public void shouldUpsertKeyValueByUpdatingIt() {
- final Object[] oldKvs = new Object[]{"k", "v", "k1", "v0"};
- final Object[] newKvs = ElementHelper.upsert(oldKvs, "k1", "v1");
- assertEquals(4, newKvs.length);
- assertEquals("v1", newKvs[3]);
- }
-}