@Test public void rulesCreatedWithoutNameMustRetainComputedNameAfterDeserialisation() throws Exception { assertThat( serialiseAndDeserialise( indexRegular ).getName(), is( "index_1" ) ); assertThat( serialiseAndDeserialise( indexUnique ).getName(), is( "index_2" ) ); assertThat( serialiseAndDeserialise( indexCompositeRegular ).getName(), is( "index_1" ) ); assertThat( serialiseAndDeserialise( indexCompositeUnique ).getName(), is( "index_2" ) ); assertThat( serialiseAndDeserialise( indexBigComposite ).getName(), is( "index_1" ) ); assertThat( serialiseAndDeserialise( constraintExistsLabel ).getName(), is( "constraint_1" ) ); assertThat( serialiseAndDeserialise( constraintUniqueLabel ).getName(), is( "constraint_2" ) ); assertThat( serialiseAndDeserialise( constraintNodeKeyLabel ).getName(), is( "constraint_2" ) ); assertThat( serialiseAndDeserialise( constraintExistsRelType ).getName(), is( "constraint_2" ) ); assertThat( serialiseAndDeserialise( constraintCompositeLabel ).getName(), is( "constraint_1" ) ); assertThat( serialiseAndDeserialise( constraintCompositeRelType ).getName(), is( "constraint_2" ) ); }
void addSchemaRule( SchemaRule rule ) { if ( rule instanceof ConstraintRule ) { ConstraintRule constraintRule = (ConstraintRule) rule; constraintRuleById.put( constraintRule.getId(), constraintRule ); constraints.add( constraintSemantics.readConstraint( constraintRule ) ); } else if ( rule instanceof StoreIndexDescriptor ) { CapableIndexDescriptor index = indexProviderMap.withCapabilities( (StoreIndexDescriptor) rule ); indexDescriptorById.put( index.getId(), index ); SchemaDescriptor schemaDescriptor = index.schema(); indexDescriptors.put( schemaDescriptor, index ); indexDescriptorsByName.put( rule.getName(), index ); for ( int entityTokenId : schemaDescriptor.getEntityTokenIds() ) { Set<CapableIndexDescriptor> forLabel = indexDescriptorsByLabel.getIfAbsentPut( entityTokenId, HashSet::new ); forLabel.add( index ); } for ( int propertyId : index.schema().getPropertyIds() ) { List<CapableIndexDescriptor> indexesForProperty = indexByProperty.getIfAbsentPut( propertyId, ArrayList::new ); indexesForProperty.add( index ); } } }
@Test public void rulesCreatedWithNameMustRetainGivenNameAfterDeserialisation() throws Exception { String name = "custom_rule"; assertThat( serialiseAndDeserialise( namedForLabel( name, LABEL_ID, PROPERTY_ID_1 ).withId( RULE_ID ) ).getName(), is( name ) ); assertThat( serialiseAndDeserialise( namedUniqueForLabel( name, LABEL_ID, PROPERTY_ID_1 ).withIds( RULE_ID_2, RULE_ID ) ).getName(), is( name ) ); assertThat( serialiseAndDeserialise( namedForLabel( name, LABEL_ID, PROPERTY_ID_1, PROPERTY_ID_2 ).withId( RULE_ID ) ).getName(), is( name ) ); assertThat( serialiseAndDeserialise( namedUniqueForLabel( name, LABEL_ID, PROPERTY_ID_1, PROPERTY_ID_2 ).withIds( RULE_ID_2, RULE_ID ) ).getName(), is( name ) ); assertThat( serialiseAndDeserialise( namedForLabel( name, LABEL_ID, IntStream.range(1, 200).toArray() ).withId( RULE_ID ) ).getName(), is( name ) ); assertThat( serialiseAndDeserialise( ConstraintRule.constraintRule( RULE_ID, ConstraintDescriptorFactory.existsForLabel( LABEL_ID, PROPERTY_ID_1 ), name ) ).getName(), is( name ) ); assertThat( serialiseAndDeserialise( ConstraintRule.constraintRule( RULE_ID_2, ConstraintDescriptorFactory.uniqueForLabel( LABEL_ID, PROPERTY_ID_1 ), RULE_ID, name ) ).getName(), is( name ) ); assertThat( serialiseAndDeserialise( ConstraintRule.constraintRule( RULE_ID_2, ConstraintDescriptorFactory.nodeKeyForLabel( LABEL_ID, PROPERTY_ID_1 ), RULE_ID, name ) ).getName(), is( name ) ); assertThat( serialiseAndDeserialise( ConstraintRule.constraintRule( RULE_ID_2, ConstraintDescriptorFactory.existsForRelType( REL_TYPE_ID, PROPERTY_ID_1 ), name ) ).getName(), is( name ) ); assertThat( serialiseAndDeserialise( ConstraintRule.constraintRule( RULE_ID, ConstraintDescriptorFactory.existsForLabel( LABEL_ID, PROPERTY_ID_1, PROPERTY_ID_2 ), name ) ).getName(), is( name ) ); assertThat( serialiseAndDeserialise( ConstraintRule.constraintRule( RULE_ID_2, ConstraintDescriptorFactory.existsForRelType( REL_TYPE_ID, PROPERTY_ID_1, PROPERTY_ID_2 ), name ) ).getName(), is( name ) ); }
@Test public void rulesCreatedWithNullNameMustRetainComputedNameAfterDeserialisation() throws Exception { assertThat( serialiseAndDeserialise( forLabel( LABEL_ID, PROPERTY_ID_1 ).withId( RULE_ID ) ).getName(), is( "index_1" ) ); assertThat( serialiseAndDeserialise( uniqueForLabel( LABEL_ID, PROPERTY_ID_1 ).withIds( RULE_ID_2, RULE_ID ) ).getName(), is( "index_2" ) ); assertThat( serialiseAndDeserialise( forLabel( LABEL_ID, PROPERTY_ID_1, PROPERTY_ID_2 ).withId( RULE_ID ) ).getName(), is( "index_1" ) ); assertThat( serialiseAndDeserialise( uniqueForLabel( LABEL_ID, PROPERTY_ID_1, PROPERTY_ID_2 ).withIds( RULE_ID_2, RULE_ID ) ).getName(), is( "index_2" ) ); assertThat( serialiseAndDeserialise( forLabel( LABEL_ID, IntStream.range(1, 200).toArray() ).withId( RULE_ID ) ).getName(), is( "index_1" ) ); String name = null; assertThat( serialiseAndDeserialise( ConstraintRule.constraintRule( RULE_ID, ConstraintDescriptorFactory.existsForLabel( LABEL_ID, PROPERTY_ID_1 ), name ) ).getName(), is( "constraint_1" ) ); assertThat( serialiseAndDeserialise( ConstraintRule.constraintRule( RULE_ID_2, ConstraintDescriptorFactory.uniqueForLabel( LABEL_ID, PROPERTY_ID_1 ), RULE_ID, name ) ).getName(), is( "constraint_2" ) ); assertThat( serialiseAndDeserialise( ConstraintRule.constraintRule( RULE_ID_2, ConstraintDescriptorFactory.nodeKeyForLabel( LABEL_ID, PROPERTY_ID_1 ), RULE_ID, name ) ).getName(), is( "constraint_2" ) ); assertThat( serialiseAndDeserialise( ConstraintRule.constraintRule( RULE_ID_2, ConstraintDescriptorFactory.existsForRelType( REL_TYPE_ID, PROPERTY_ID_1 ), name ) ).getName(), is( "constraint_2" ) ); assertThat( serialiseAndDeserialise( ConstraintRule.constraintRule( RULE_ID, ConstraintDescriptorFactory.existsForLabel( LABEL_ID, PROPERTY_ID_1, PROPERTY_ID_2 ), name ) ).getName(), is( "constraint_1" ) ); assertThat( serialiseAndDeserialise( ConstraintRule.constraintRule( RULE_ID_2, ConstraintDescriptorFactory.existsForRelType( REL_TYPE_ID, PROPERTY_ID_1, PROPERTY_ID_2 ), name ) ).getName(), is( "constraint_2" ) ); }
void addSchemaRule( SchemaRule rule ) { if ( rule instanceof ConstraintRule ) { ConstraintRule constraintRule = (ConstraintRule) rule; constraintRuleById.put( constraintRule.getId(), constraintRule ); constraints.add( constraintSemantics.readConstraint( constraintRule ) ); } else if ( rule instanceof StoreIndexDescriptor ) { CapableIndexDescriptor index = indexProviderMap.withCapabilities( (StoreIndexDescriptor) rule ); indexDescriptorById.put( index.getId(), index ); SchemaDescriptor schemaDescriptor = index.schema(); indexDescriptors.put( schemaDescriptor, index ); indexDescriptorsByName.put( rule.getName(), index ); for ( int entityTokenId : schemaDescriptor.getEntityTokenIds() ) { Set<CapableIndexDescriptor> forLabel = indexDescriptorsByLabel.getIfAbsentPut( entityTokenId, HashSet::new ); forLabel.add( index ); } for ( int propertyId : index.schema().getPropertyIds() ) { List<CapableIndexDescriptor> indexesForProperty = indexByProperty.getIfAbsentPut( propertyId, ArrayList::new ); indexesForProperty.add( index ); } } }