Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Patouche committed Jan 31, 2021
1 parent a452dfb commit 60b49a8
Show file tree
Hide file tree
Showing 35 changed files with 1,540 additions and 533 deletions.
19 changes: 15 additions & 4 deletions TODOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,22 @@ class SampleTests {
* Entities (commons nodes & relationships) :
* [X] `ignoringIds`: Remove id to entities and create a new assertions
* [X] `havePropertyKeys`: Verify if property's entities have the expected keys
* [ ] `havePropertyType` IN PROGRESS: Verify if all property's entities have the expected type
* [ ] `havePropertyType` : Verify if all property's entities have the expected type
* [ ] `havePropertyCount`: Verify if entities have the number of properties
* [ ] `haveProperty`
* [ ] `haveProperties`
* [X] `contains`
* [ ] `haveProperty` :
* [ ] `haveProperty` :
* [ ] `haveProperty` :
* [ ] `haveProperties` :
* [X] `contains` :
* [ ] `filteredOn`
* [ ] `filteredOnPropertyExists`
* [ ] `filteredOnProperty`
* [ ]
* [ ]
* [ ]
* [ ]
* [ ]
* [ ]
* Nodes :
* [X] `haveLabels`
* [X] `Drivers.node()....`
Expand Down
237 changes: 149 additions & 88 deletions src/main/java/org/assertj/neo4j/api/beta/AbstractEntitiesAssert.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
*/
package org.assertj.neo4j.api.beta;

import org.assertj.core.util.IterableUtil;
import org.assertj.core.util.Lists;
import org.assertj.neo4j.api.beta.error.ElementsShouldHaveLabels;
import org.assertj.neo4j.api.beta.type.DataLoader;
import org.assertj.neo4j.api.beta.type.Nodes;
import org.assertj.neo4j.api.beta.type.RecordType;
import org.assertj.neo4j.api.beta.type.Relationships;
import org.assertj.neo4j.api.beta.util.Checks;
import org.assertj.neo4j.api.beta.util.NodeLabels;
import org.assertj.neo4j.api.beta.util.Wip;

import java.util.ArrayList;
import java.util.List;

/**
Expand Down Expand Up @@ -63,7 +61,7 @@ protected AbstractNodesAssert(final Class<SELF> selfType,
* @throws AssertionError if the one of the actual nodes does not contain the given label
*/
public SELF haveLabels(final String... expectedLabels) {
return haveLabels(checkArray(expectedLabels, "The labels to look for should not be null or empty"));
return haveLabels(Checks.notNullOrEmpty(expectedLabels, "The labels to look for should not be null or empty"));
}

/**
Expand All @@ -84,11 +82,9 @@ public SELF haveLabels(final String... expectedLabels) {
* @throws AssertionError if the one of the actual nodes does not contain the given label
*/
public SELF haveLabels(final Iterable<String> expectedLabels) {
if (IterableUtil.isNullOrEmpty(expectedLabels)) {
throw new IllegalArgumentException("The iterable of values to look for should not be empty");
}
final List<String> labels = Checks
.notNullOrEmpty(expectedLabels, "The iterable of values to look for should not be empty");
if (NodeLabels.haveLabels(actual, expectedLabels)) {
final ArrayList<String> labels = Lists.newArrayList(expectedLabels);
throwAssertionError(ElementsShouldHaveLabels.create(actual, labels, NodeLabels.missing(actual, labels)));
}
return myself;
Expand All @@ -102,7 +98,7 @@ public SELF haveLabels(final Iterable<String> expectedLabels) {
public ChildrenDriverRelationshipsAssert<SELF, ROOT_ASSERT> incomingRelationships(final String type) {
final List<Long> nodeIds = entityIds();
final Relationships relationships = new Relationships(this.dataLoader.getDriver(), type);
return new ChildrenDriverRelationshipsAssert<>(relationships.load(), relationships, false, myself, rootAssert)
return new ChildrenDriverRelationshipsAssert<>(relationships.load(), relationships, false, myself, toRootAssert())
.filteredOn(r -> nodeIds.contains(r.getId()))
.withParent(myself);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@
public abstract class AbstractRelationshipsAssert<SELF extends AbstractRelationshipsAssert<SELF,PARENT_ASSERT, ROOT_ASSERT>,
PARENT_ASSERT,
ROOT_ASSERT>
extends AbstractEntitiesAssert<SELF,
Relationships.DbRelationship,
PARENT_ASSERT,
ROOT_ASSERT>
implements Navigable<PARENT_ASSERT,
ROOT_ASSERT> {
extends AbstractEntitiesAssert<SELF, Relationships.DbRelationship, PARENT_ASSERT, ROOT_ASSERT>
implements Navigable<PARENT_ASSERT, ROOT_ASSERT> {
//@formatter:on

protected AbstractRelationshipsAssert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.assertj.neo4j.api.beta.type.Relationships;

import java.util.List;
import java.util.Objects;

/**
* @author patouche - 02/01/2021
Expand Down Expand Up @@ -47,17 +48,31 @@ protected ChildrenDriverRelationshipsAssert(final List<Relationships.DbRelations
ignoringIds,
factory(),
parentAssert,
rootAssert
Objects.requireNonNull(rootAssert)
);
}

private static <PARENT_ASSERT, ROOT_ASSERT> EntitiesAssertFactory<ChildrenDriverRelationshipsAssert<PARENT_ASSERT, ROOT_ASSERT>,
private static <PARENT_ASSERT, ROOT_ASSERT> EntitiesAssertFactory<ChildrenDriverRelationshipsAssert<PARENT_ASSERT
, ROOT_ASSERT>,
Relationships.DbRelationship, PARENT_ASSERT, ROOT_ASSERT> factory() {
return (entities, loader, ignoringIds, rootAssert) -> new ChildrenDriverRelationshipsAssert<>(entities, loader, ignoringIds, rootAssert.rootAssert);
return (entities, loader, ignoringIds, self) -> new ChildrenDriverRelationshipsAssert<>(
entities,
loader,
ignoringIds,
self.toRootAssert()
);
}

/** {@inheritDoc} */
@Override
public ChildrenDriverRelationshipsAssert<PARENT_ASSERT, ROOT_ASSERT> withParent(PARENT_ASSERT parentAssert) {
return new ChildrenDriverRelationshipsAssert<>(actual, dataLoader, ignoreIds, parentAssert, rootAssert);
return new ChildrenDriverRelationshipsAssert<>(actual, dataLoader, ignoreIds, parentAssert, toRootAssert());
}

/** {@inheritDoc} */
@Override
public ROOT_ASSERT toRootAssert() {
return rootAssert()
.orElseThrow(() -> new IllegalArgumentException("Root assertion shouldn't be null !"));
}
}
21 changes: 16 additions & 5 deletions src/main/java/org/assertj/neo4j/api/beta/DriverNodesAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* @author patouche - 08/11/2020
*/
public class DriverNodesAssert
public final class DriverNodesAssert
extends AbstractNodesAssert<DriverNodesAssert, DriverNodesAssert, DriverNodesAssert> {

/**
Expand All @@ -30,20 +30,31 @@ public class DriverNodesAssert
* @param nodes the nodes to assert
*/
public DriverNodesAssert(final Nodes nodes) {
this(nodes.load(), nodes,false, null);
this(nodes.load(), nodes, false, null);
}

@VisibleForTesting
protected DriverNodesAssert(final List<Nodes.DbNode> entities) {
this(entities, null, false, null);
this(entities, null, false, null);
}

private DriverNodesAssert(final List<Nodes.DbNode> entities,
final DataLoader<Nodes.DbNode> nodes,
final boolean ignoreIds,
final DriverNodesAssert parent) {
super(DriverNodesAssert.class, entities, nodes, ignoreIds, DriverNodesAssert::new, parent, rootAssert(parent));
super(
DriverNodesAssert.class,
entities,
nodes,
ignoreIds,
DriverNodesAssert::new, parent,
Navigable.rootAssert(parent)
);
}


/** {@inheritDoc}*/
@Override
public DriverNodesAssert toRootAssert() {
return rootAssert().orElse(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.assertj.neo4j.api.beta.type.DataLoader;
import org.assertj.neo4j.api.beta.type.Relationships;

import javax.xml.crypto.Data;
import java.util.List;

/**
Expand All @@ -27,27 +26,39 @@ public class DriverRelationshipsAssert
extends AbstractRelationshipsAssert<DriverRelationshipsAssert,
DriverRelationshipsAssert,
DriverRelationshipsAssert> {
//@formatter:off
//@formatter:on

/**
* Create new assertions on {@link Relationships}.
*
* @param relationships the relationships to assert
*/
public DriverRelationshipsAssert(final Relationships relationships) {
this(relationships.load(), relationships,false, null);
this(relationships.load(), relationships, false, null);
}

@VisibleForTesting
protected DriverRelationshipsAssert(final List<Relationships.DbRelationship> entities) {
this(entities, null, false,null);
this(entities, null, false, null);
}

private DriverRelationshipsAssert(final List<Relationships.DbRelationship> entities,
final DataLoader<Relationships.DbRelationship> loader,
final boolean ignorindIds,
final DriverRelationshipsAssert parent) {
super(DriverNodesAssert.class, entities, loader, ignorindIds, DriverRelationshipsAssert::new, parent, rootAssert(parent));
super(
DriverRelationshipsAssert.class,
entities,
loader,
ignorindIds,
DriverRelationshipsAssert::new,
parent,
Navigable.rootAssert(parent)
);
}

@Override
public DriverRelationshipsAssert toRootAssert() {
return rootAssert().orElse(this);
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/assertj/neo4j/api/beta/Navigable.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@
*/
package org.assertj.neo4j.api.beta;

import java.util.Optional;

/**
* @author patouche - 01/01/2021
*/
public interface Navigable<PARENT_ASSERT, ROOT_ASSERT> {



PARENT_ASSERT toParentAssert();

ROOT_ASSERT toRootAssert();

static <INST extends Navigable<PARENT, ROOT>, PARENT, ROOT> ROOT rootAssert(final INST parent) {
return Optional.ofNullable(parent).map(Navigable::toRootAssert).orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.assertj.core.util.Strings;
import org.assertj.neo4j.api.beta.type.DbEntity;
import org.assertj.neo4j.api.beta.type.RecordType;
import org.assertj.neo4j.api.beta.util.Entities;
import org.assertj.neo4j.api.beta.util.Presentations;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -29,18 +29,22 @@ public abstract class DbEntitiesMessageFactory<E extends DbEntity<E>, EXPECTED,
/**
* Creates a new <code>{@link BasicErrorMessageFactory}</code>.
*/
protected DbEntitiesMessageFactory(final RecordType recordType, final String title, final String but,
final List<E> actual, final EXPECTED expected, final List<ITEM> items,
final ItemMessageFactory<EXPECTED, ITEM> factory) {
protected DbEntitiesMessageFactory(
final RecordType recordType,
final String title,
final String but,
final List<E> actual, final EXPECTED expected,
final List<ITEM> items,
final ItemMessageFactory<EXPECTED, ITEM> factory) {
super(
"%nExpecting %s:%n"
+ " %s%n"
+ "%s:%n"
+ " %s %n"
+ " %s%n"
+ "%s:%n%n"
+ Strings.escapePercent(describeItems(expected, items, factory)),
unquotedString(recordType.pluralForm()),
Entities.outputIds(actual),
Presentations.outputIds(actual),
unquotedString(title),
expected,
unquotedString(but)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import org.assertj.neo4j.api.beta.type.Nodes.DbNode;
import org.assertj.neo4j.api.beta.type.RecordType;
import org.assertj.neo4j.api.beta.util.Entities;
import org.assertj.neo4j.api.beta.util.Presentations;

import java.util.List;

Expand All @@ -39,7 +39,7 @@ private static ItemMessageFactory<List<String>, Missing<DbNode, String>> itemFac
" - %s have missing labels: %s%n"
+ " Expected: %s%n"
+ " Actual : %s",
Entities.outputId(missing.getEntity()), missing.getData(), expected,
Presentations.outputId(missing.getEntity()), missing.getData(), expected,
missing.getEntity().getSortedLabels()
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.assertj.neo4j.api.beta.error;

import org.assertj.core.error.ErrorMessageFactory;
import org.assertj.neo4j.api.beta.type.DbEntity;
import org.assertj.neo4j.api.beta.type.RecordType;

import java.util.List;

/**
* @author patouche - 30/01/2021
*/
public class ElementsShouldHavePropertyInstanceOf<E extends DbEntity<E>>
extends DbEntitiesMessageFactory<E, Class<?>, E> {

protected ElementsShouldHavePropertyInstanceOf(RecordType recordType, List<E> actual,
String key, Class<?> expectedClass) {
super(recordType, "title", "but", actual, expectedClass, actual, (e, v) -> "TODO");
}

public static <E extends DbEntity<E>> ErrorMessageFactory create(RecordType recordType, List<E> actual,
String key, Class<?> expectedClass) {
return new ElementsShouldHavePropertyInstanceOf<>(recordType, actual, key, expectedClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.assertj.core.util.Streams;
import org.assertj.neo4j.api.beta.type.DbEntity;
import org.assertj.neo4j.api.beta.type.RecordType;
import org.assertj.neo4j.api.beta.util.Entities;
import org.assertj.neo4j.api.beta.util.Presentations;

import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -60,7 +60,7 @@ private static <E extends DbEntity<E>> ItemMessageFactory<List<String>, Missing<
" - %s have missing property keys: %s%n"
+ " Actual : <%s>%n"
+ " Expected: <%s>",
Entities.outputId(missing.getEntity()),
Presentations.outputId(missing.getEntity()),
missing.getData(),
missing.getEntity().getPropertyKeys(),
expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
import org.assertj.core.error.ErrorMessageFactory;
import org.assertj.neo4j.api.beta.type.DbEntity;
import org.assertj.neo4j.api.beta.type.DbValue;
import org.assertj.neo4j.api.beta.type.Nodes;
import org.assertj.neo4j.api.beta.type.RecordType;
import org.assertj.neo4j.api.beta.type.ValueType;
import org.assertj.neo4j.api.beta.util.Entities;
import org.assertj.neo4j.api.beta.util.Presentations;

import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -62,7 +61,7 @@ private static <E extends DbEntity<E>> ItemMessageFactory<ValueType, E> itemFact
+ " Expected: %s%n"
+ " Actual : %s%n"
+ " Value : %s",
Entities.outputId(entity),
Presentations.outputId(entity),
key,
expected,
streamValues(entity, key).findFirst().map(DbValue::getType).orElse(null),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.assertj.neo4j.api.beta.error;

import org.assertj.core.error.ErrorMessageFactory;
import org.assertj.neo4j.api.beta.type.DbEntity;
import org.assertj.neo4j.api.beta.type.RecordType;

import java.util.List;

/**
* @author patouche - 01/02/2021
*/
public class ElementsShouldHavePropertySize<E extends DbEntity<E>>
extends DbEntitiesMessageFactory<E, Integer, E> {

public ElementsShouldHavePropertySize(RecordType recordType, List<E> actual, List<E> notSatisfies, int size) {
super(recordType, "title", "but", actual, size, notSatisfies, (e, v) -> "todo");
}

public static <E extends DbEntity<E>> ErrorMessageFactory create(
RecordType recordType, List<E> actual, List<E> notSatisfies, int size) {
return new ElementsShouldHavePropertySize<>(recordType, actual, notSatisfies, size);
}
}
Loading

0 comments on commit 60b49a8

Please sign in to comment.