use of org.neo4j.kernel.impl.api.operations.SchemaReadOperations in project neo4j by neo4j.
the class OperationsFacadeTest method testThrowExceptionWhenDuplicateUniqueIndexFound.
@Test
public void testThrowExceptionWhenDuplicateUniqueIndexFound() throws SchemaRuleNotFoundException, DuplicateSchemaRuleException {
SchemaReadOperations readOperations = setupSchemaReadOperations();
NewIndexDescriptor index = NewIndexDescriptorFactory.forSchema(SchemaBoundary.map(descriptor));
Mockito.when(readOperations.uniqueIndexesGetForLabel(Mockito.any(KernelStatement.class), Mockito.eq(descriptor.getLabelId()))).thenReturn(Iterators.iterator(index, index));
TokenNameLookup tokenNameLookup = getDefaultTokenNameLookup();
expectedException.expect(DuplicateSchemaRuleException.class);
expectedException.expect(new KernelExceptionUserMessageMatcher<>(tokenNameLookup, "Multiple constraint indexs found for :Label1(Prop1)."));
operationsFacade.uniqueIndexGetForLabelAndPropertyKey(descriptor);
}
use of org.neo4j.kernel.impl.api.operations.SchemaReadOperations in project neo4j by neo4j.
the class OperationsFacadeTest method setupSchemaReadOperations.
private SchemaReadOperations setupSchemaReadOperations() {
SchemaReadOperations readOperations = Mockito.mock(SchemaReadOperations.class);
Mockito.when(statementOperationParts.schemaReadOperations()).thenReturn(readOperations);
return readOperations;
}
use of org.neo4j.kernel.impl.api.operations.SchemaReadOperations in project neo4j by neo4j.
the class OperationsFacadeTest method testThrowExceptionWhenUniqueIndexNotFound.
@Test
public void testThrowExceptionWhenUniqueIndexNotFound() throws SchemaRuleNotFoundException, DuplicateSchemaRuleException {
SchemaReadOperations readOperations = setupSchemaReadOperations();
TokenNameLookup tokenNameLookup = getDefaultTokenNameLookup();
Mockito.when(readOperations.uniqueIndexesGetForLabel(Mockito.any(KernelStatement.class), anyInt())).thenReturn(Iterators.emptyIterator());
expectedException.expect(SchemaRuleNotFoundException.class);
expectedException.expect(new KernelExceptionUserMessageMatcher<>(tokenNameLookup, "No constraint index was found for :Label1(Prop1)."));
operationsFacade.uniqueIndexGetForLabelAndPropertyKey(descriptor);
}
use of org.neo4j.kernel.impl.api.operations.SchemaReadOperations in project neo4j by neo4j.
the class IndexTxStateUpdaterTest method setup.
@Before
public void setup() {
state = mock(KernelStatement.class);
txState = mock(TransactionState.class);
when(state.txState()).thenReturn(txState);
SchemaReadOperations schemaReadOps = mock(SchemaReadOperations.class);
when(schemaReadOps.indexesGetAll(state)).thenAnswer(x -> filter(GENERAL, indexes.iterator()));
when(schemaReadOps.uniqueIndexesGetAll(state)).thenAnswer(x -> filter(UNIQUE, indexes.iterator()));
when(schemaReadOps.indexesGetForLabel(state, labelId1)).thenAnswer(x -> filter(GENERAL, filter(hasLabel(labelId1), indexes.iterator())));
when(schemaReadOps.uniqueIndexesGetForLabel(state, labelId1)).thenAnswer(x -> filter(UNIQUE, filter(hasLabel(labelId1), indexes.iterator())));
when(schemaReadOps.indexesGetForLabel(state, labelId2)).thenAnswer(x -> filter(GENERAL, filter(hasLabel(labelId2), indexes.iterator())));
when(schemaReadOps.uniqueIndexesGetForLabel(state, labelId2)).thenAnswer(x -> filter(UNIQUE, filter(hasLabel(labelId2), indexes.iterator())));
PrimitiveIntSet labels = Primitive.intSet();
labels.add(labelId1);
labels.add(labelId2);
Cursor<NodeItem> nodeItemCursor = StubCursors.asNodeCursor(0, labels);
nodeItemCursor.next();
node = nodeItemCursor.get();
PrimitiveIntSet defaultPropertyIds = PrimitiveIntCollections.asSet(new int[] { propId1, propId2, propId3 });
EntityReadOperations readOps = mock(EntityReadOperations.class);
when(readOps.nodeGetPropertyKeys(state, node)).thenReturn(defaultPropertyIds);
when(readOps.nodeGetProperties(state, node)).thenAnswer(p -> StubCursors.asPropertyCursor(Property.property(propId1, "hi1"), Property.property(propId2, "hi2"), Property.property(propId3, "hi3")));
when(readOps.nodeGetProperty(state, node, propId1)).thenReturn("hi1");
when(readOps.nodeGetProperty(state, node, propId2)).thenReturn("hi2");
when(readOps.nodeGetProperty(state, node, propId3)).thenReturn("hi3");
indexTxUpdater = new IndexTxStateUpdater(schemaReadOps, readOps);
}
Aggregations