private void assertSerializeAndDeserializeConstraintRule( ConstraintRule constraintRule ) throws MalformedSchemaRuleException { ConstraintRule deserialized = assertConstraintRule( serialiseAndDeserialise( constraintRule ) ); assertThat( deserialized.getId(), equalTo( constraintRule.getId() ) ); assertThat( deserialized.getConstraintDescriptor(), equalTo( constraintRule.getConstraintDescriptor() ) ); assertThat( deserialized.schema(), equalTo( constraintRule.schema() ) ); }
public MandatoryProperties( StoreAccess storeAccess ) { this.storeAccess = storeAccess; SchemaStorage schemaStorage = new SchemaStorage( storeAccess.getSchemaStore() ); for ( ConstraintRule rule : constraintsIgnoringMalformed( schemaStorage ) ) { if ( rule.getConstraintDescriptor().enforcesPropertyExistence() ) { rule.schema().processWith( constraintRecorder ); } } }
private void assertParseNodeKeyConstraintRule( String serialized, String name ) throws MalformedSchemaRuleException { // GIVEN long ruleId = 1; int propertyKey = 3; int labelId = 55; long ownedIndexId = 2; NodeKeyConstraintDescriptor constraint = ConstraintDescriptorFactory.nodeKeyForLabel( labelId, propertyKey ); byte[] bytes = decodeBase64( serialized ); // WHEN ConstraintRule deserialized = assertConstraintRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized.getConstraintDescriptor(), equalTo( constraint ) ); assertThat( deserialized.schema(), equalTo( constraint.schema() ) ); assertThat( deserialized.getOwnedIndex(), equalTo( ownedIndexId ) ); assertThat( deserialized.getName(), is( name ) ); }
private void assertParseRelationshipPropertyExistsRule( String serialized, String name ) throws Exception { // GIVEN long ruleId = 51; int propertyKey = 6119; int relTypeId = 8512; ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForRelType( relTypeId, propertyKey ); byte[] bytes = decodeBase64( serialized ); // WHEN ConstraintRule deserialized = assertConstraintRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized.getConstraintDescriptor(), equalTo( constraint ) ); assertThat( deserialized.schema(), equalTo( constraint.schema() ) ); assertException( deserialized::getOwnedIndex, IllegalStateException.class ); assertThat( deserialized.getName(), is( name ) ); }
private void assertParseUniqueConstraintRule( String serialized, String name ) throws MalformedSchemaRuleException { // GIVEN long ruleId = 1; int propertyKey = 3; int labelId = 55; long ownedIndexId = 2; UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel( labelId, propertyKey ); byte[] bytes = decodeBase64( serialized ); // WHEN ConstraintRule deserialized = assertConstraintRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized.getConstraintDescriptor(), equalTo( constraint ) ); assertThat( deserialized.schema(), equalTo( constraint.schema() ) ); assertThat( deserialized.getOwnedIndex(), equalTo( ownedIndexId ) ); assertThat( deserialized.getName(), is( name ) ); }
private void assertParseNodePropertyExistsRule( String serialized, String name ) throws Exception { // GIVEN long ruleId = 87; int propertyKey = 51; int labelId = 45; ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForLabel( labelId, propertyKey ); byte[] bytes = decodeBase64( serialized ); // WHEN ConstraintRule deserialized = assertConstraintRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized.getConstraintDescriptor(), equalTo( constraint ) ); assertThat( deserialized.schema(), equalTo( constraint.schema() ) ); assertException( deserialized::getOwnedIndex, IllegalStateException.class ); assertThat( deserialized.getName(), is( name ) ); }
@Test public void shouldCreateNodeKeyConstraint() { // GIVEN ConstraintDescriptor descriptor = nodeKeyForLabel( LABEL_ID, PROPERTY_ID_1 ); ConstraintRule constraintRule = ConstraintRule.constraintRule( RULE_ID, descriptor ); // THEN assertThat( constraintRule.getId(), equalTo( RULE_ID ) ); assertThat( constraintRule.schema(), equalTo( descriptor.schema() ) ); assertThat( constraintRule.getConstraintDescriptor(), equalTo( descriptor ) ); assertException( constraintRule::getOwnedIndex, IllegalStateException.class ); }
@Test public void shouldCreateUniquenessConstraint() { // GIVEN ConstraintDescriptor descriptor = ConstraintDescriptorFactory.uniqueForLabel( LABEL_ID, PROPERTY_ID_1 ); ConstraintRule constraintRule = ConstraintRule.constraintRule( RULE_ID, descriptor ); // THEN assertThat( constraintRule.getId(), equalTo( RULE_ID ) ); assertThat( constraintRule.schema(), equalTo( descriptor.schema() ) ); assertThat( constraintRule.getConstraintDescriptor(), equalTo( descriptor ) ); assertException( constraintRule::getOwnedIndex, IllegalStateException.class ); }
@Test public void shouldCreateExistenceConstraint() { // GIVEN ConstraintDescriptor descriptor = existsForLabel( LABEL_ID, PROPERTY_ID_1 ); ConstraintRule constraintRule = ConstraintRule.constraintRule( RULE_ID, descriptor ); // THEN assertThat( constraintRule.getId(), equalTo( RULE_ID ) ); assertThat( constraintRule.schema(), equalTo( descriptor.schema() ) ); assertThat( constraintRule.getConstraintDescriptor(), equalTo( descriptor ) ); assertException( constraintRule::getOwnedIndex, IllegalStateException.class ); }
@Test public void shouldListConstraintsForSchema() { // Given ConstraintRule rule1 = uniquenessConstraintRule( 0, 1, 1, 0 ); ConstraintRule rule2 = uniquenessConstraintRule( 1, 2, 1, 0 ); ConstraintRule rule3 = nodePropertyExistenceConstraintRule( 2, 1, 2 ); SchemaCache cache = newSchemaCache(); cache.addSchemaRule( rule1 ); cache.addSchemaRule( rule2 ); cache.addSchemaRule( rule3 ); // When Set<ConstraintDescriptor> listed = asSet( cache.constraintsForSchema( rule3.schema() ) ); // Then assertEquals( singleton( rule3.getConstraintDescriptor() ), listed ); }