private List<EntityId> getEntities() { return IntStream.range(0, 10).mapToObj(i -> { return new Entity.Builder() .group(TestGroups.ENTITY) .vertex(i) .build(); }).collect(Collectors.toList()); }
private List<EntityId> getEntities(final Object vertex) { final List<Entity> entities = new ArrayList<>(); entities.add(new Entity.Builder().group(TestGroups.ENTITY).vertex(vertex).build()); entities.add(new Entity.Builder().group(TestGroups.ENTITY_2).vertex(vertex).build()); return Collections.unmodifiableList(entities); }
@Test public void shouldCompareWhenFirstElementsHasWrongGroup() { // Given final ElementPropertyComparator comparator = new ElementPropertyComparator.Builder() .groups(TestGroups.ENTITY_2) .property(TestPropertyNames.PROP_1) .comparator(new ComparatorImpl()) .build(); final Entity smallEntity = new Entity.Builder().group(TestGroups.ENTITY) .property(TestPropertyNames.PROP_1, new IntegerWrapper(1)) .build(); final Entity largeEntity = new Entity.Builder().group(TestGroups.ENTITY_2) .property(TestPropertyNames.PROP_1, new IntegerWrapper(2)) .build(); // When final int result = comparator.compare(smallEntity, largeEntity); // Then assertThat(result, greaterThan(0)); }
@Test public void shouldTransformElementUsingInlineFunction() { // Given final Function<String, Integer> function = String::length; final ElementTransformer transformer = new ElementTransformer.Builder() .select("prop1") .execute(function) .project("prop3") .build(); final Entity element = new Entity.Builder() .group("test") .property("prop1", "value") .property("prop2", 1) .build(); // When final Element result = transformer.apply(element); // Then assertEquals("prop1".length(), result.getProperty("prop3")); }
@Test public void shouldNotBeEqualOnDifferentElement() { // Given final Entity testEntity1 = new Entity.Builder() .group(TestGroups.ENTITY_3) .vertex("vertex") .property(TestPropertyNames.SET, CollectionUtil.treeSet("3")) .property(TestPropertyNames.COUNT, 3L) .build(); final Entity testEntity2 = new Entity.Builder() .group(TestGroups.ENTITY_4) .vertex("vertex") .property(TestPropertyNames.SET, CollectionUtil.treeSet("3")) .property(TestPropertyNames.COUNT, 3L) .build(); ElementJoinComparator elementJoinComparator = new ElementJoinComparator(); // When / Then assertFalse(elementJoinComparator.test(testEntity1, testEntity2)); }
@Test public void shouldNotBeEqualOnSameElementWithDifferentPropertyWithGroupBy() { // Given final Entity testEntity1 = new Entity.Builder() .group(TestGroups.ENTITY_3) .vertex("vertex") .property(TestPropertyNames.SET, CollectionUtil.treeSet("3")) .property(TestPropertyNames.COUNT, 3L) .build(); final Entity testEntity2 = new Entity.Builder() .group(TestGroups.ENTITY_3) .vertex("vertex") .property(TestPropertyNames.SET, CollectionUtil.treeSet("3")) .property(TestPropertyNames.COUNT, 5L) .build(); ElementJoinComparator elementJoinComparator = new ElementJoinComparator("count"); // When / Then assertFalse(elementJoinComparator.test(testEntity1, testEntity2)); } }
@Test public void shouldGenerateAnEmptyMap() { // Given final Object vertex = "source vertex"; final String prop1 = "property 1"; final int count = 10; final Element element = new Entity.Builder() .group(TestGroups.ENTITY) .vertex(vertex) .property(TestPropertyNames.PROP_1, prop1) .property(TestPropertyNames.COUNT, count) .build(); final MapGenerator generator = new MapGenerator(); // When final Map<String, Object> map = generator._apply(element); // Then final Map<String, Object> expectedMap = new LinkedHashMap<>(); assertEquals(expectedMap, map); } }
@Test public void shouldCompareWhenSecondElementHasMissingProperties() { // Given final ElementPropertyComparator comparator = new ElementPropertyComparator.Builder() .groups(TestGroups.ENTITY) .property(TestPropertyNames.PROP_2) .comparator(new ComparatorImpl()) .build(); final Entity smallEntity = new Entity.Builder().group(TestGroups.ENTITY) .property(TestPropertyNames.PROP_2, new IntegerWrapper(1)) .build(); final Entity largeEntity = new Entity.Builder().group(TestGroups.ENTITY) .property(TestPropertyNames.PROP_1, new IntegerWrapper(2)) .build(); // When final int result = comparator.compare(smallEntity, largeEntity); // Then assertThat(result, lessThan(0)); }
@Test public void shouldBeEqualOnSameElementWithDifferentPropertyWhenNoGroupBys() { // Given final Entity testEntity1 = new Entity.Builder() .group(TestGroups.ENTITY_3) .vertex("vertex") .property(TestPropertyNames.SET, CollectionUtil.treeSet("3")) .property(TestPropertyNames.COUNT, 3L) .build(); final Entity testEntity2 = new Entity.Builder() .group(TestGroups.ENTITY_3) .vertex("vertex") .property(TestPropertyNames.SET, CollectionUtil.treeSet("3")) .property(TestPropertyNames.COUNT, 5L) .build(); ElementJoinComparator elementJoinComparator = new ElementJoinComparator(); // When / Then assertTrue(elementJoinComparator.test(testEntity1, testEntity2)); }
@Test public void shouldBuildEntity() { // Given final String vertex = "vertex1"; final String propValue = "propValue"; // When final Entity entity = new Entity.Builder() .group(TestGroups.ENTITY) .vertex(vertex) .property(TestPropertyNames.STRING, propValue) .build(); // Then assertEquals(TestGroups.ENTITY, entity.getGroup()); assertEquals(vertex, entity.getVertex()); assertEquals(propValue, entity.getProperty(TestPropertyNames.STRING)); }
@Test public void shouldCompareWithNoProvidedComparatorInstance() { // Given final ElementPropertyComparator comparator = new ElementPropertyComparator.Builder() .groups(TestGroups.ENTITY) .property(TestPropertyNames.PROP_1) .build(); final Entity smallEntity = new Entity.Builder().group(TestGroups.ENTITY) .property(TestPropertyNames.PROP_1, 1) .build(); final Entity largeEntity = new Entity.Builder().group(TestGroups.ENTITY) .property(TestPropertyNames.PROP_1, 2) .build(); // When final int result = comparator.compare(smallEntity, largeEntity); // Then assertThat(result, lessThan(0)); }
@Test public void shouldReturnGroupFromEntity() { // Given final ExtractGroup function = new ExtractGroup(); final String group = "testGroup_2"; final Entity entity = new Entity.Builder() .vertex("1") .group(group) .build(); // When final String result = function.apply(entity); // Then assertEquals(group, result); }
@Test public void shouldBeEqualOnSameElement() { // Given final Entity testEntity1 = new Entity.Builder() .group(TestGroups.ENTITY_3) .vertex("vertex") .property(TestPropertyNames.SET, CollectionUtil.treeSet("3")) .property(TestPropertyNames.COUNT, 3L) .build(); final Entity testEntity2 = testEntity1.shallowClone(); ElementJoinComparator elementJoinComparator = new ElementJoinComparator(); // When / Then assertTrue(elementJoinComparator.test(testEntity1, testEntity2)); }
private Entity makeEntity(final String group, final Object vertex) { return new Entity.Builder().group(group).vertex(vertex).build(); } }
public static Entity getBasicEntity(final Object vertex) { return new Entity.Builder() .vertex(vertex) .group(TestGroups.ENTITY) .build(); } }
@Test public void shouldValidateWhenEntity() { // Given final Element element = new Entity.Builder() .group(TestGroups.ENTITY) .build(); // When final boolean valid = new IsEntityValidator().validate(element); // Then assertTrue(valid); }
@Override protected Entity newElement() { return new Entity.Builder().build(); }
@Test public void shouldNotValidateWhenEntity() { // Given final Element element = new Entity.Builder() .group(TestGroups.ENTITY) .build(); // When final boolean valid = new IsEdgeValidator().validate(element); // Then assertFalse(valid); } }
@Override @Test public void shouldSetAndGetFields() { // Given final Entity entity = new Entity.Builder() .group("group") .vertex("identifier") .build(); // Then assertEquals("group", entity.getGroup()); assertEquals("identifier", entity.getVertex()); }
@Test public void shouldValidateWhenEntity() { // Given final Element element = new Entity.Builder() .group(TestGroups.ENTITY) .build(); // When final boolean valid = new IsElementValidator().validate(element); // Then assertTrue(valid); }