Skip to content

Commit

Permalink
Fixed missed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Feb 24, 2017
1 parent 2acea0f commit 9217e47
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 49 deletions.
Expand Up @@ -200,7 +200,7 @@ class ErrorMessagesTest extends ExecutionEngineFunSuite with CypherSerializer {
expectError( expectError(
"CREATE CONSTRAINT ON (person:Person) ASSERT person.name IS UNIQUE", "CREATE CONSTRAINT ON (person:Person) ASSERT person.name IS UNIQUE",
String.format("Unable to create CONSTRAINT ON ( person:Person ) ASSERT person.name IS UNIQUE:%n" + String.format("Unable to create CONSTRAINT ON ( person:Person ) ASSERT person.name IS UNIQUE:%n" +
"Multiple nodes with label `Person` have property `name` = 'A':%n node(0)%n node(1)") "Both Node(0) and Node(1) have the label `Person` and property `name` = 'A'")
) )
} }


Expand Down
Expand Up @@ -42,9 +42,9 @@ public NodePropertyExistenceException( LabelSchemaDescriptor schema,
@Override @Override
public String getUserMessage( TokenNameLookup tokenNameLookup ) public String getUserMessage( TokenNameLookup tokenNameLookup )
{ {
return format( "Node(%d) with label `%s` has no value for property `%s`", return format( "Node(%d) with label `%s` must have the property `%s`",
nodeId, nodeId,
tokenNameLookup.labelGetName( schema.getLabelId() ), tokenNameLookup.labelGetName( schema.getLabelId() ),
tokenNameLookup.propertyKeyGetName( schema.getPropertyIds()[0] ) ); tokenNameLookup.propertyKeyGetName( schema.getPropertyId() ) );
} }
} }
Expand Up @@ -42,9 +42,9 @@ public RelationshipPropertyExistenceException(
@Override @Override
public String getUserMessage( TokenNameLookup tokenNameLookup ) public String getUserMessage( TokenNameLookup tokenNameLookup )
{ {
return format( "Relationship(%s) with type `%s` has no value for property `%s`", return format( "Relationship(%s) with type `%s` must have the property `%s`",
relationshipId, relationshipId,
tokenNameLookup.relationshipTypeGetName( schema.getRelTypeId() ), tokenNameLookup.relationshipTypeGetName( schema.getRelTypeId() ),
tokenNameLookup.propertyKeyGetName( schema.getPropertyIds()[0] ) ); tokenNameLookup.propertyKeyGetName( schema.getPropertyId() ) );
} }
} }
Expand Up @@ -26,29 +26,29 @@
import org.neo4j.kernel.api.TokenNameLookup; import org.neo4j.kernel.api.TokenNameLookup;
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;
import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor; import org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor;


public class UniquePropertyValueValidationException extends ConstraintValidationException public class UniquePropertyValueValidationException extends ConstraintValidationException
{ {
private final Set<IndexEntryConflictException> conflicts; private final Set<IndexEntryConflictException> conflicts;


public UniquePropertyValueValidationException( ConstraintDescriptor constraint, public UniquePropertyValueValidationException( UniquenessConstraintDescriptor constraint,
ConstraintValidationException.Phase phase, IndexEntryConflictException conflict ) ConstraintValidationException.Phase phase, IndexEntryConflictException conflict )
{ {
this( constraint, phase, Collections.singleton( conflict ) ); this( constraint, phase, Collections.singleton( conflict ) );
} }


public UniquePropertyValueValidationException( ConstraintDescriptor constraint, public UniquePropertyValueValidationException( UniquenessConstraintDescriptor constraint,
ConstraintValidationException.Phase phase, Set<IndexEntryConflictException> conflicts ) ConstraintValidationException.Phase phase, Set<IndexEntryConflictException> conflicts )
{ {
super( constraint, phase, "Existing data" ); super( constraint, phase, phase == Phase.VERIFICATION ? "Existing data" : "New data" );
this.conflicts = conflicts; this.conflicts = conflicts;
} }


public UniquePropertyValueValidationException( ConstraintDescriptor constraint, public UniquePropertyValueValidationException( UniquenessConstraintDescriptor constraint,
ConstraintValidationException.Phase phase, Throwable cause ) ConstraintValidationException.Phase phase, Throwable cause )
{ {
super( constraint, phase, "Existing data ", cause ); super( constraint, phase, phase == Phase.VERIFICATION ? "Existing data" : "New data", cause );
this.conflicts = Collections.emptySet(); this.conflicts = Collections.emptySet();
} }


Expand All @@ -62,7 +62,7 @@ public String getUserMessage( TokenNameLookup tokenNameLookup )
IndexEntryConflictException conflict = iterator.next(); IndexEntryConflictException conflict = iterator.next();
message.append( conflict.evidenceMessage( message.append( conflict.evidenceMessage(
tokenNameLookup.labelGetName( schema.getLabelId() ), tokenNameLookup.labelGetName( schema.getLabelId() ),
tokenNameLookup.propertyKeyGetName( schema.getPropertyIds()[0] ) ) ); tokenNameLookup.propertyKeyGetName( schema.getPropertyId() ) ) );
if ( iterator.hasNext() ) if ( iterator.hasNext() )
{ {
message.append( System.lineSeparator() ); message.append( System.lineSeparator() );
Expand Down
Expand Up @@ -166,7 +166,7 @@ private void validateNoExistingNodeWithLabelAndProperty(
NewIndexDescriptor index = constraint.ownedIndexDescriptor(); NewIndexDescriptor index = constraint.ownedIndexDescriptor();
assertIndexOnline( state, index ); assertIndexOnline( state, index );
int labelId = index.schema().getLabelId(); int labelId = index.schema().getLabelId();
int propertyId = index.schema().getPropertyIds()[0]; int propertyId = index.schema().getPropertyId();
state.locks().optimistic().acquireExclusive( state.locks().optimistic().acquireExclusive(
state.lockTracer(), state.lockTracer(),
INDEX_ENTRY, INDEX_ENTRY,
Expand Down Expand Up @@ -297,7 +297,7 @@ public long nodeGetFromUniqueIndexSeek(


// TODO: Support composite index, either by allowing value to be an array, or by creating a new method // TODO: Support composite index, either by allowing value to be an array, or by creating a new method
int labelId = index.schema().getLabelId(); int labelId = index.schema().getLabelId();
int propertyKeyId = index.schema().getPropertyIds()[0]; int propertyKeyId = index.schema().getPropertyId();
String stringVal = ""; String stringVal = "";
if ( null != value ) if ( null != value )
{ {
Expand Down
Expand Up @@ -34,8 +34,8 @@
import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException; import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException;
import org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException; import org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;
import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor;
import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory; import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory;
import org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor;
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor;
import org.neo4j.kernel.api.index.PropertyAccessor; import org.neo4j.kernel.api.index.PropertyAccessor;
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory;
Expand Down Expand Up @@ -91,7 +91,7 @@ public long createUniquenessConstraintIndex(
) throws TransactionFailureException, CreateConstraintFailureException, ) throws TransactionFailureException, CreateConstraintFailureException,
DropIndexFailureException, UniquePropertyValueValidationException DropIndexFailureException, UniquePropertyValueValidationException
{ {
ConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema( descriptor ); UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema( descriptor );
NewIndexDescriptor index = createConstraintIndex( descriptor ); NewIndexDescriptor index = createConstraintIndex( descriptor );
boolean success = false; boolean success = false;
boolean reacquiredSchemaLock = false; boolean reacquiredSchemaLock = false;
Expand Down Expand Up @@ -182,7 +182,7 @@ public void dropUniquenessConstraintIndex( NewIndexDescriptor descriptor )
} }
} }


private void awaitConstrainIndexPopulation( ConstraintDescriptor constraint, long indexId ) private void awaitConstrainIndexPopulation( UniquenessConstraintDescriptor constraint, long indexId )
throws InterruptedException, UniquePropertyValueValidationException throws InterruptedException, UniquePropertyValueValidationException
{ {
try try
Expand Down
Expand Up @@ -41,7 +41,7 @@ class UniqueConstraintValidationAcceptanceTest
catch catch
{ {
case e: CypherExecutionException => case e: CypherExecutionException =>
assertThat(e.getMessage, containsString( "\"key1\"=[value1]" )) assertThat(e.getMessage, containsString( "`key1` = 'value1'" ))
} }
} }


Expand All @@ -59,7 +59,7 @@ class UniqueConstraintValidationAcceptanceTest
catch catch
{ {
case e: CypherExecutionException => case e: CypherExecutionException =>
assertThat(e.getMessage, containsString( "\"key1\"=[value1]" )) assertThat(e.getMessage, containsString( "`key1` = 'value1'" ))
} }
} }


Expand All @@ -77,7 +77,7 @@ class UniqueConstraintValidationAcceptanceTest
catch catch
{ {
case e: CypherExecutionException => case e: CypherExecutionException =>
assertThat(e.getMessage, containsString( "\"key1\"=[value1]" )) assertThat(e.getMessage, containsString( "`key1` = 'value1'" ))
} }
} }


Expand All @@ -94,7 +94,7 @@ class UniqueConstraintValidationAcceptanceTest
catch catch
{ {
case e: CypherExecutionException => case e: CypherExecutionException =>
assertThat(e.getMessage, containsString( "\"key1\"=[value1]" )) assertThat(e.getMessage, containsString( "`key1` = 'value1'" ))
} }
} }


Expand Down
Expand Up @@ -207,7 +207,7 @@ case class SpecSuiteErrorHandler(typ: String, phase: String, detail: String) ext
detail should equal(INVALID_ELEMENT_ACCESS) detail should equal(INVALID_ELEMENT_ACCESS)
else if (msg.matches(".+ can not create a new node due to conflicts with( both)? existing( and missing)? unique nodes.*")) else if (msg.matches(".+ can not create a new node due to conflicts with( both)? existing( and missing)? unique nodes.*"))
detail should equal("CreateBlockedByConstraint") detail should equal("CreateBlockedByConstraint")
else if (msg.matches("Node [0-9]+ already exists with label .+ and property \".+\"=\\[.+\\]")) else if (msg.matches("Node\\([0-9]+\\) already exists with label `.+` and property `.+` = .+"))
detail should equal("CreateBlockedByConstraint") detail should equal("CreateBlockedByConstraint")
else if (msg.matches("Cannot delete node\\<\\d+\\>, because it still has relationships. To delete this node, you must first delete its relationships.")) else if (msg.matches("Cannot delete node\\<\\d+\\>, because it still has relationships. To delete this node, you must first delete its relationships."))
detail should equal(DELETE_CONNECTED_NODE) detail should equal(DELETE_CONNECTED_NODE)
Expand Down
Expand Up @@ -123,7 +123,7 @@ public void shouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsA
try try
{ {
SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction(); SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
statement.constraintDrop( constraint ); statement.constraintDrop( ConstraintDescriptorFactory.existsForSchema( constraint.schema() ) );


fail( "expected exception" ); fail( "expected exception" );
} }
Expand All @@ -143,7 +143,7 @@ public void shouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsA


Iterator<ConstraintDescriptor> constraints = statement.constraintsGetForSchema( descriptor ); Iterator<ConstraintDescriptor> constraints = statement.constraintsGetForSchema( descriptor );


assertEquals( ConstraintBoundary.map( constraint ), single( constraints ) ); assertEquals( constraint, single( constraints ) );
} }
} }
} }
Expand Up @@ -163,9 +163,8 @@ public void shouldAbortConstraintCreationWhenDuplicatesExist() throws Exception
Throwable cause = ex.getCause(); Throwable cause = ex.getCause();
assertThat( cause, instanceOf( ConstraintValidationException.class ) ); assertThat( cause, instanceOf( ConstraintValidationException.class ) );


String expectedMessage = String expectedMessage = String.format(
String.format( "Multiple nodes with label `%s` have property `%s` = '%s':%n node(%d)%n node(%d)", "Both Node(%d) and Node(%d) have the label `Foo` and property `name` = 'foo'", node1, node2 );
"Foo", "name", "foo", node1, node2 );
String actualMessage = userMessage( (ConstraintValidationException) cause ); String actualMessage = userMessage( (ConstraintValidationException) cause );
assertEquals( expectedMessage, actualMessage ); assertEquals( expectedMessage, actualMessage );
} }
Expand Down
Expand Up @@ -26,23 +26,15 @@
import org.neo4j.SchemaHelper; import org.neo4j.SchemaHelper;
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.RelationshipType;
import org.neo4j.helpers.collection.Iterators; import org.neo4j.helpers.collection.Iterators;
import org.neo4j.kernel.api.schema.NodePropertyDescriptor;
import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor;
import org.neo4j.kernel.api.constraints.NodePropertyConstraint;
import org.neo4j.kernel.api.constraints.NodePropertyExistenceConstraint;
import org.neo4j.kernel.api.constraints.PropertyConstraint;
import org.neo4j.kernel.api.constraints.RelationshipPropertyConstraint;
import org.neo4j.kernel.api.constraints.RelationshipPropertyExistenceConstraint;
import org.neo4j.kernel.api.constraints.UniquenessConstraint;
import org.neo4j.kernel.api.schema_new.SchemaBoundary;
import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory; import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory;
import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor; import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor;
import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory; import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory;
import org.neo4j.test.TestEnterpriseGraphDatabaseFactory; import org.neo4j.test.TestEnterpriseGraphDatabaseFactory;


import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.neo4j.helpers.collection.Iterators.asSet; import static org.neo4j.helpers.collection.Iterators.asSet;


Expand Down Expand Up @@ -72,18 +64,15 @@ public void shouldListAllConstraints()
// Then // Then
int labelId1 = labelId( label1 ); int labelId1 = labelId( label1 );
int labelId2 = labelId( label2 ); int labelId2 = labelId( label2 );
int relTypeId = relationshipTypeId( relType1 );
int propKeyId = propertyKeyId( propertyKey ); int propKeyId = propertyKeyId( propertyKey );
NodePropertyDescriptor descriptor1 = new NodePropertyDescriptor( labelId1, propKeyId );
NodePropertyDescriptor descriptor2 = new NodePropertyDescriptor( labelId2, propKeyId );

Set<PropertyConstraint> expectedConstraints = asSet(
new UniquenessConstraint( descriptor1 ),
new UniquenessConstraint( descriptor2 ),
new NodePropertyExistenceConstraint( descriptor2 ),
new RelationshipPropertyExistenceConstraint(
new RelationshipPropertyDescriptor( relationshipTypeId( relType1 ), propKeyId ) ) );


assertEquals( expectedConstraints, constraints ); assertThat( constraints, containsInAnyOrder(
ConstraintDescriptorFactory.uniqueForLabel( labelId1, propKeyId ),
ConstraintDescriptorFactory.uniqueForLabel( labelId2, propKeyId ),
ConstraintDescriptorFactory.existsForLabel( labelId2, propKeyId ),
ConstraintDescriptorFactory.existsForRelType( relTypeId, propKeyId )
) );
} }


@Test @Test
Expand Down
Expand Up @@ -37,7 +37,7 @@ class PropertyExistenceConstraintAcceptanceTest
val e = intercept[ConstraintValidationException](execute("create (node:Label1)")) val e = intercept[ConstraintValidationException](execute("create (node:Label1)"))


// THEN // THEN
e.getMessage should endWith("with label \"Label1\" must have the property \"key1\" due to a constraint") e.getMessage should endWith(" with label `Label1` must have the property `key1`")
} }


test("relationship: should enforce constraints on creation") { test("relationship: should enforce constraints on creation") {
Expand All @@ -48,7 +48,7 @@ class PropertyExistenceConstraintAcceptanceTest
val e = intercept[ConstraintValidationException](execute("create (p1:Person)-[:KNOWS]->(p2:Person)")) val e = intercept[ConstraintValidationException](execute("create (p1:Person)-[:KNOWS]->(p2:Person)"))


// THEN // THEN
e.getMessage should endWith("with type \"KNOWS\" must have the property \"since\" due to a constraint") e.getMessage should endWith("with type `KNOWS` must have the property `since`")
} }


test("node: should enforce on removing property") { test("node: should enforce on removing property") {
Expand Down

0 comments on commit 9217e47

Please sign in to comment.