//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldEnforceUniquenessConstraintOnAddLabelForNumberPropertyOnNodeNotFromTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldEnforceUniquenessConstraintOnAddLabelForNumberPropertyOnNodeNotFromTransaction()
        {
            // given
            ConstrainedNode("Label1", "key1", 1);

            // when
            Transaction transaction = NewTransaction(AnonymousContext.writeToken());
            long        node        = CreateNode(transaction, "key1", 1);

            Commit();

            transaction = NewTransaction(AnonymousContext.writeToken());
            try
            {
                int label = transaction.TokenWrite().labelGetOrCreateForName("Label1");
                transaction.DataWrite().nodeAddLabel(node, label);

                fail("should have thrown exception");
            }
            // then
            catch (UniquePropertyValueValidationException e)
            {
                assertThat(e.GetUserMessage(TokenLookup(transaction)), containsString("`key1` = 1"));
            }
            Commit();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AddingUniqueNodeWithUnrelatedValueShouldNotAffectLookup()
        {
            // given
            CreateConstraint("Person", "id");

            long ourNode;
            {
                Transaction transaction = NewTransaction(AnonymousContext.writeToken());
                ourNode = CreateLabeledNode(transaction, "Person", "id", 1);
                Commit();
            }

            Transaction    transaction = NewTransaction(AnonymousContext.writeToken());
            TokenRead      tokenRead   = transaction.TokenRead();
            int            person      = tokenRead.NodeLabel("Person");
            int            propId      = tokenRead.PropertyKey("id");
            IndexReference idx         = transaction.SchemaRead().index(person, propId);

            // when
            CreateLabeledNode(transaction, "Person", "id", 2);

            // then I should find the original node
            assertThat(transaction.DataRead().lockingNodeUniqueIndexSeek(idx, exact(propId, Values.of(1))), equalTo(ourNode));
            Commit();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void roundingErrorsFromLongToDoubleShouldNotPreventTxFromCommitting() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RoundingErrorsFromLongToDoubleShouldNotPreventTxFromCommitting()
        {
            // Given
            // a node with a constrained label and a long value
            long propertyValue = 285414114323346805L;
            long firstNode     = ConstrainedNode("label1", "key1", propertyValue);

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            long node = CreateLabeledNode(transaction, "label1");

            assertNotEquals(firstNode, node);

            // When
            // a new node with the same constraint is added, with a value not equal but which would be mapped to the same double
            propertyValue++;
            // note how propertyValue is definitely not equal to propertyValue++ but they do equal if they are cast to double
            int propertyKeyId = transaction.TokenWrite().propertyKeyGetOrCreateForName("key1");

            transaction.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of(propertyValue));

            // Then
            // the commit should still succeed
            Commit();
        }
Exemple #4
0
 public static LoginContext GetLoginContextFromUserPrincipal(Principal principal)
 {
     if (principal is DelegatingPrincipal)
     {
         return((( DelegatingPrincipal )principal).LoginContext);
     }
     // If whitelisted uris can start transactions we cannot throw exception here
     //throw new IllegalArgumentException( "Tried to get access mode on illegal user principal" );
     return(AnonymousContext.none());
 }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowDataStatementAfterReadStatement() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowDataStatementAfterReadStatement()
        {
            // given
            KernelTransaction tx = kernelTransaction(AnonymousContext.write());

            tx.DataRead();

            // when / then
            tx.DataWrite();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowReadsInReadMode()
        public virtual void ShouldAllowReadsInReadMode()
        {
            // Given
            KernelTransactionImplementation tx = newTransaction(AnonymousContext.read());

            // When
            Read reads = tx.DataRead();

            // Then
            assertNotNull(reads);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowTokenReadAccessInWriteOnlyMode()
        public virtual void ShouldNotAllowTokenReadAccessInWriteOnlyMode()
        {
            // Given
            KernelTransactionImplementation tx = newTransaction(AnonymousContext.writeOnly());

            // Expect
            Exception.expect(typeof(AuthorizationViolationException));

            // When
            tx.TokenRead();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowWritesInWriteMode() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowWritesInWriteMode()
        {
            // Given
            KernelTransactionImplementation tx = newTransaction(AnonymousContext.write());

            // When
            Write writes = tx.DataWrite();

            // Then
            assertNotNull(writes);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowSchemaWritesInNoneMode() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowSchemaWritesInNoneMode()
        {
            // Given
            KernelTransactionImplementation tx = newTransaction(AnonymousContext.none());

            // Expect
            Exception.expect(typeof(AuthorizationViolationException));

            // When
            tx.SchemaWrite();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_DeleteNode() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowRemoveAndAddConflictingDataInOneTransactionDeleteNode()
        {
            // given
            long node = ConstrainedNode("Label1", "key1", "value1");

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            // when
            transaction.DataWrite().nodeDelete(node);
            CreateLabeledNode(transaction, "Label1", "key1", "value1");
            Commit();
        }
Exemple #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowNoopPropertyUpdate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void ShouldAllowNoopPropertyUpdate()
            {
                // given
                long entity = CreateConstraintAndEntity("Type1", "key1", "value1");

                Transaction transaction = NewTransaction(AnonymousContext.writeToken());

                // when
                int key = transaction.TokenWrite().propertyKeyGetOrCreateForName("key1");

                SetProperty(transaction.DataWrite(), entity, key, Values.of("value1"));

                // then should not throw exception
            }
Exemple #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowNoopLabelUpdate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void ShouldAllowNoopLabelUpdate()
            {
                // given
                long entityId = CreateConstraintAndEntity("Label1", "key1", "value1");

                Transaction transaction = NewTransaction(AnonymousContext.writeToken());

                // when
                int label = transaction.TokenWrite().labelGetOrCreateForName("Label1");

                transaction.DataWrite().nodeAddLabel(entityId, label);

                // then should not throw exception
            }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_RemoveLabel() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowRemoveAndAddConflictingDataInOneTransactionRemoveLabel()
        {
            // given
            long node = ConstrainedNode("Label1", "key1", "value1");

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            // when
            int label = transaction.TokenWrite().labelGetOrCreateForName("Label1");

            transaction.DataWrite().nodeRemoveLabel(node, label);
            CreateLabeledNode(transaction, "Label1", "key1", "value1");
            Commit();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_ChangeProperty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowRemoveAndAddConflictingDataInOneTransactionChangeProperty()
        {
            // given
            long node = ConstrainedNode("Label1", "key1", "value1");

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            // when
            int propertyKeyId = transaction.TokenWrite().propertyKeyGetOrCreateForName("key1");

            transaction.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of("value2"));
            CreateLabeledNode(transaction, "Label1", "key1", "value1");
            Commit();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_RemoveProperty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowRemoveAndAddConflictingDataInOneTransactionRemoveProperty()
        {
            // given
            long node = ConstrainedNode("Label1", "key1", "value1");

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            // when
            int key = transaction.TokenRead().propertyKey("key1");

            transaction.DataWrite().nodeRemoveProperty(node, key);
            CreateLabeledNode(transaction, "Label1", "key1", "value1");
            Commit();
        }
Exemple #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowTemporaryViolationsWithinTransactions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void ShouldAllowTemporaryViolationsWithinTransactions()
            {
                // given
                long        entity      = CreateConstraintAndEntity("Type1", "key1", "value1");
                Transaction transaction = NewTransaction(AnonymousContext.writeToken());

                // when
                int key = transaction.TokenWrite().propertyKeyGetOrCreateForName("key1");

                //remove and put back
                RemoveProperty(transaction.DataWrite(), entity, key);
                SetProperty(transaction.DataWrite(), entity, key, Values.of("value2"));

                Commit();
            }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowNoopPropertyUpdate() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowNoopPropertyUpdate()
        {
            // given
            long node = ConstrainedNode("Label1", "key1", "value1");

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            // when
            int key = transaction.TokenWrite().propertyKeyGetOrCreateForName("key1");

            transaction.DataWrite().nodeSetProperty(node, key, Values.of("value1"));

            // then should not throw exception
            Commit();
        }
Exemple #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: long createConstraintAndEntity(String type, String property, String value) throws Exception
            internal override long CreateConstraintAndEntity(string type, string property, string value)
            {
                Transaction transaction = NewTransaction(AnonymousContext.writeToken());
                int         label       = transaction.TokenWrite().labelGetOrCreateForName(type);
                long        node        = transaction.DataWrite().nodeCreate();

                transaction.DataWrite().nodeAddLabel(node, label);
                int propertyKey = transaction.TokenWrite().propertyKeyGetOrCreateForName(property);

                transaction.DataWrite().nodeSetProperty(node, propertyKey, Values.of(value));
                Commit();

                CreateConstraint(type, property);

                return(node);
            }
Exemple #19
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: long createConstraintAndEntity(String type, String property, String value) throws Exception
            internal override long CreateConstraintAndEntity(string type, string property, string value)
            {
                Transaction transaction  = NewTransaction(AnonymousContext.writeToken());
                int         relType      = transaction.TokenWrite().relationshipTypeGetOrCreateForName(type);
                long        start        = transaction.DataWrite().nodeCreate();
                long        end          = transaction.DataWrite().nodeCreate();
                long        relationship = transaction.DataWrite().relationshipCreate(start, relType, end);
                int         propertyKey  = transaction.TokenWrite().propertyKeyGetOrCreateForName(property);

                transaction.DataWrite().relationshipSetProperty(relationship, propertyKey, Values.of(value));
                Commit();

                CreateConstraint(type, property);

                return(relationship);
            }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long constrainedNode(String labelName, String propertyKey, Object propertyValue) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private long ConstrainedNode(string labelName, string propertyKey, object propertyValue)
        {
            long node;

            {
                Transaction transaction = NewTransaction(AnonymousContext.writeToken());
                int         label       = transaction.TokenWrite().labelGetOrCreateForName(labelName);
                node = transaction.DataWrite().nodeCreate();
                transaction.DataWrite().nodeAddLabel(node, label);
                int key = transaction.TokenWrite().propertyKeyGetOrCreateForName(propertyKey);
                transaction.DataWrite().nodeSetProperty(node, key, Values.of(propertyValue));
                Commit();
            }
            CreateConstraint(labelName, propertyKey);
            return(node);
        }
Exemple #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowCreationOfNonConflictingData() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void ShouldAllowCreationOfNonConflictingData()
            {
                // given
                CreateConstraintAndEntity("Type1", "key1", "value1");

                Transaction transaction = NewTransaction(AnonymousContext.writeToken());

                // when
                CreateEntity(transaction, "key1", "value1");
                CreateEntity(transaction, "Type2");
                CreateEntity(transaction, "Type1", "key1", "value2");
                CreateEntity(transaction, "Type1", "key1", "value3");

                Commit();

                // then
                assertEquals(5, EntityCount());
            }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowCreationOfNonConflictingData() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowCreationOfNonConflictingData()
        {
            // given
            ConstrainedNode("Label1", "key1", "value1");

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            // when
            CreateNode(transaction, "key1", "value1");
            CreateLabeledNode(transaction, "Label2", "key1", "value1");
            CreateLabeledNode(transaction, "Label1", "key1", "value2");
            CreateLabeledNode(transaction, "Label1", "key2", "value1");

            Commit();

            // then
            transaction = NewTransaction(AnonymousContext.writeToken());
            assertEquals("number of nodes", 5, CountNodes(transaction));
            Rollback();
        }
Exemple #23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldEnforcePropertyExistenceConstraintWhenCreatingEntityWithoutProperty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void ShouldEnforcePropertyExistenceConstraintWhenCreatingEntityWithoutProperty()
            {
                // given
                CreateConstraint("Type1", "key1");

                Transaction transaction = NewTransaction(AnonymousContext.writeToken());

                // when
                CreateEntity(transaction, "Type1");
                try
                {
                    Commit();
                    fail("should have thrown exception");
                }
                // then
                catch (ConstraintViolationTransactionFailureException e)
                {
                    Status expected = Org.Neo4j.Kernel.Api.Exceptions.Status_Schema.ConstraintValidationFailed;
                    assertThat(e.Status(), @is(expected));
                }
            }
Exemple #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldEnforceConstraintWhenRemoving() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
            public virtual void ShouldEnforceConstraintWhenRemoving()
            {
                // given
                long        entity      = CreateConstraintAndEntity("Type1", "key1", "value1");
                Transaction transaction = NewTransaction(AnonymousContext.writeToken());

                // when
                int key = transaction.TokenWrite().propertyKeyGetOrCreateForName("key1");

                RemoveProperty(transaction.DataWrite(), entity, key);
                try
                {
                    Commit();
                    fail("should have thrown exception");
                }
                // then
                catch (ConstraintViolationTransactionFailureException e)
                {
                    Status expected = Org.Neo4j.Kernel.Api.Exceptions.Status_Schema.ConstraintValidationFailed;
                    assertThat(e.Status(), @is(expected));
                }
            }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPreventConflictingDataInSameTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPreventConflictingDataInSameTransaction()
        {
            // given
            ConstrainedNode("Label1", "key1", "value1");

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            // when
            CreateLabeledNode(transaction, "Label1", "key1", "value2");
            try
            {
                CreateLabeledNode(transaction, "Label1", "key1", "value2");

                fail("expected exception");
            }
            // then
            catch (UniquePropertyValueValidationException e)
            {
                assertThat(e.GetUserMessage(TokenLookup(transaction)), containsString("`key1` = 'value2'"));
            }
            Commit();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldEnforceOnSetProperty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldEnforceOnSetProperty()
        {
            // given
            ConstrainedNode("Label1", "key1", "value1");

            Transaction transaction = NewTransaction(AnonymousContext.writeToken());

            // when
            long node = CreateLabeledNode(transaction, "Label1");

            try
            {
                int propertyKeyId = transaction.TokenWrite().propertyKeyGetOrCreateForName("key1");
                transaction.DataWrite().nodeSetProperty(node, propertyKeyId, Values.of("value1"));

                fail("should have thrown exception");
            }
            // then
            catch (UniquePropertyValueValidationException e)
            {
                assertThat(e.GetUserMessage(TokenLookup(transaction)), containsString("`key1` = 'value1'"));
            }
            Commit();
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyThatThereAreExactlyOneIndexEntryPerNodeInTheIndexes(int i, org.neo4j.helpers.collection.Pair<long[],long[]> data) throws Exception
        private void VerifyThatThereAreExactlyOneIndexEntryPerNodeInTheIndexes(int i, Pair <long[], long[]> data)
        {
            Kernel kernel = Db.DependencyResolver.resolveDependency(typeof(Kernel));

            using ([email protected] tx = kernel.BeginTransaction(@implicit, AnonymousContext.read()))
            {
                int            labelAId = tx.TokenRead().nodeLabel(LabelA(i).name());
                int            keyAId   = tx.TokenRead().propertyKey(KeyA(i));
                int            labelBId = tx.TokenRead().nodeLabel(LabelB(i).name());
                int            keyBId   = tx.TokenRead().propertyKey(KeyB(i));
                IndexReference indexA   = TestIndexDescriptorFactory.forLabel(labelAId, keyAId);
                IndexReference indexB   = TestIndexDescriptorFactory.forLabel(labelBId, keyBId);

                for (int j = 0; j < NODES_PER_INDEX; j++)
                {
                    long nodeAId = data.First()[j];
                    assertEquals(1, tx.SchemaRead().nodesCountIndexed(indexA, nodeAId, keyAId, Values.of(nodeAId)));
                    long nodeBId = data.Other()[j];
                    assertEquals(1, tx.SchemaRead().nodesCountIndexed(indexB, nodeBId, keyBId, Values.of(nodeBId)));
                }
            }
        }