Ejemplo n.º 1
0
 private void putProperty(EntityKey entityKey, Node node, TupleOperation operation) {
   try {
     node.setProperty(operation.getColumn(), operation.getValue());
   } catch (ConstraintViolationException e) {
     String message = e.getMessage();
     if (message.contains("already exists")) {
       throw log.mustNotInsertSameEntityTwice(String.valueOf(operation), e);
     } else {
       throw log.constraintViolation(entityKey, String.valueOf(operation), e);
     }
   }
 }
  @Test
  public void shouldEnforceUniquenessConstraintOnSetProperty() throws Exception {
    // given
    constrainedNode("Label1", "key1", "value1");

    newTransaction();

    // when
    Node node = db.createNode(label("Label1"));
    try {
      node.setProperty("key1", "value1");

      fail("should have thrown exception");
    }
    // then
    catch (ConstraintViolationException e) {
      assertThat(e.getMessage(), containsString("\"key1\"=[value1]"));
    }
  }
  @Test
  public void shouldPreventConflictingDataInSameTransaction() throws Exception {
    // given
    constrainedNode("Label1", "key1", "value1");

    newTransaction();

    // when
    db.createNode(label("Label1")).setProperty("key1", "value2");
    try {
      db.createNode(label("Label1")).setProperty("key1", "value2");

      fail("expected exception");
    }
    // then
    catch (ConstraintViolationException e) {
      assertThat(e.getMessage(), containsString("\"key1\"=[value2]"));
    }
  }