Program: 47911
Project: 47911
Buggy source:
@Test public void testConditionalUpdate() throws Exception {
  Record record=createDefaultRecord();
  record.setField(fieldType1.getName(),"String_Node_Str");
  record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1.getName(),"String_Node_Str")));
  assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
  assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
  record=repository.read(record.getId());
  assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
  List<MutationCondition> conditions=new ArrayList<MutationCondition>();
  conditions.add(new MutationCondition(fieldType1.getName(),"String_Node_Str"));
  conditions.add(new MutationCondition(fieldType2.getName(),123));
  conditions.add(new MutationCondition(fieldType3.getName(),false));
  record.setField(fieldType1.getName(),"String_Node_Str");
  record=repository.update(record,conditions);
  assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
  assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
  record=repository.read(record.getId());
  assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
  record.setField(fieldType1.getName(),"String_Node_Str");
  record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1.getName(),"String_Node_Str")));
  assertEquals(ResponseStatus.UP_TO_DATE,record.getResponseStatus());
  record.setField(fieldType1.getName(),"String_Node_Str");
  record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1.getName(),"String_Node_Str")));
  assertEquals(ResponseStatus.UPDATED,record.getResponseStatus());
  record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1.getName(),"String_Node_Str")));
  assertEquals(ResponseStatus.UP_TO_DATE,record.getResponseStatus());
  record=createDefaultRecord();
  record.setField(fieldType1.getName(),"String_Node_Str");
  record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1.getName(),CompareOp.NOT_EQUAL,"String_Node_Str")));
  assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
  assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
  for (  CompareOp op : CompareOp.values()) {
    List<Integer> testValues=new ArrayList<Integer>();
switch (op) {
case LESS:
      testValues.add(123);
    testValues.add(122);
  break;
case LESS_OR_EQUAL:
testValues.add(122);
break;
case EQUAL:
testValues.add(122);
testValues.add(124);
break;
case NOT_EQUAL:
testValues.add(123);
break;
case GREATER_OR_EQUAL:
testValues.add(124);
break;
case GREATER:
testValues.add(123);
testValues.add(124);
}
for (Integer testValue : testValues) {
record.setField(fieldType2.getName(),999);
record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType2.getName(),op,testValue)));
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
assertEquals(123,record.getField(fieldType2.getName()));
}
}
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1B.getName(),CompareOp.EQUAL,"String_Node_Str",true)));
assertEquals(ResponseStatus.UPDATED,record.getResponseStatus());
assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record);
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1.getName(),CompareOp.EQUAL,null)));
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1B.getName(),CompareOp.NOT_EQUAL,null)));
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1.getName(),CompareOp.NOT_EQUAL,null)));
assertEquals(ResponseStatus.UPDATED,record.getResponseStatus());
assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record);
final QName versionField=new QName("String_Node_Str","String_Node_Str");
record=createDefaultRecord();
record.setField(fieldType2.getName(),new Integer(55));
record=repository.update(record,Collections.singletonList(new MutationCondition(versionField,CompareOp.EQUAL,new Long(2))));
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
record.setField(fieldType2.getName(),new Integer(55));
record=repository.update(record,Collections.singletonList(new MutationCondition(versionField,CompareOp.EQUAL,new Long(1))));
assertEquals(ResponseStatus.UPDATED,record.getResponseStatus());
assertEquals(new Long(2),record.getVersion());
assertEquals(new Integer(55),record.getField(fieldType2.getName()));
record=repository.newRecord();
record.setRecordType(recordType1.getName(),recordType1.getVersion());
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.create(record);
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record,Collections.singletonList(new MutationCondition(versionField,CompareOp.EQUAL,new Long(1))));
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record,Collections.singletonList(new MutationCondition(versionField,CompareOp.EQUAL,null)));
assertEquals(ResponseStatus.UPDATED,record.getResponseStatus());
record=createDefaultRecord();
record.setField(fieldType3.getName(),false);
record=repository.update(record,true,true,Collections.singletonList(new MutationCondition(fieldType3.getName(),CompareOp.EQUAL,Boolean.FALSE)));
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
record.setField(fieldType3.getName(),false);
record=repository.update(record,true,true,Collections.singletonList(new MutationCondition(fieldType3.getName(),CompareOp.EQUAL,Boolean.TRUE)));
assertEquals(ResponseStatus.UPDATED,record.getResponseStatus());
conditions=new ArrayList<MutationCondition>();
conditions.add(new MutationCondition(fieldType1.getName(),"String_Node_Str"));
conditions.add(new MutationCondition(fieldType2.getName(),124));
record.setField(fieldType3.getName(),true);
record=repository.update(record,true,true,conditions);
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
}

Fixed version (ground truth):
@Test public void testConditionalUpdate() throws Exception {
  Record record=createDefaultRecord();
  record.setField(fieldType1.getName(),"String_Node_Str");
  record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1.getName(),"String_Node_Str")));
  assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
  assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
  record=repository.read(record.getId());
  assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
  List<MutationCondition> conditions=new ArrayList<MutationCondition>();
  conditions.add(new MutationCondition(fieldType1.getName(),"String_Node_Str"));
  conditions.add(new MutationCondition(fieldType2.getName(),123));
  conditions.add(new MutationCondition(fieldType3.getName(),false));
  record.setField(fieldType1.getName(),"String_Node_Str");
  record=repository.update(record,conditions);
  assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
  assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
  record=repository.read(record.getId());
  assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
  record=createDefaultRecord();
  record.setField(fieldType1.getName(),"String_Node_Str");
  record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1.getName(),CompareOp.NOT_EQUAL,"String_Node_Str")));
  assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
  assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
  for (  CompareOp op : CompareOp.values()) {
    List<Integer> testValues=new ArrayList<Integer>();
switch (op) {
case LESS:
      testValues.add(123);
    testValues.add(122);
  break;
case LESS_OR_EQUAL:
testValues.add(122);
break;
case EQUAL:
testValues.add(122);
testValues.add(124);
break;
case NOT_EQUAL:
testValues.add(123);
break;
case GREATER_OR_EQUAL:
testValues.add(124);
break;
case GREATER:
testValues.add(123);
testValues.add(124);
}
for (Integer testValue : testValues) {
record.setField(fieldType2.getName(),999);
record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType2.getName(),op,testValue)));
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
assertEquals(123,record.getField(fieldType2.getName()));
}
}
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1B.getName(),CompareOp.EQUAL,"String_Node_Str",true)));
assertEquals(ResponseStatus.UPDATED,record.getResponseStatus());
assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record);
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1.getName(),CompareOp.EQUAL,null)));
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1B.getName(),CompareOp.NOT_EQUAL,null)));
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record,Collections.singletonList(new MutationCondition(fieldType1.getName(),CompareOp.NOT_EQUAL,null)));
assertEquals(ResponseStatus.UPDATED,record.getResponseStatus());
assertEquals("String_Node_Str",record.getField(fieldType1.getName()));
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record);
final QName versionField=new QName("String_Node_Str","String_Node_Str");
record=createDefaultRecord();
record.setField(fieldType2.getName(),new Integer(55));
record=repository.update(record,Collections.singletonList(new MutationCondition(versionField,CompareOp.EQUAL,new Long(2))));
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
record.setField(fieldType2.getName(),new Integer(55));
record=repository.update(record,Collections.singletonList(new MutationCondition(versionField,CompareOp.EQUAL,new Long(1))));
assertEquals(ResponseStatus.UPDATED,record.getResponseStatus());
assertEquals(new Long(2),record.getVersion());
assertEquals(new Integer(55),record.getField(fieldType2.getName()));
record=repository.newRecord();
record.setRecordType(recordType1.getName(),recordType1.getVersion());
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.create(record);
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record,Collections.singletonList(new MutationCondition(versionField,CompareOp.EQUAL,new Long(1))));
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
record.setField(fieldType1.getName(),"String_Node_Str");
record=repository.update(record,Collections.singletonList(new MutationCondition(versionField,CompareOp.EQUAL,null)));
assertEquals(ResponseStatus.UPDATED,record.getResponseStatus());
record=createDefaultRecord();
record.setField(fieldType3.getName(),false);
record=repository.update(record,true,true,Collections.singletonList(new MutationCondition(fieldType3.getName(),CompareOp.EQUAL,Boolean.FALSE)));
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
record.setField(fieldType3.getName(),false);
record=repository.update(record,true,true,Collections.singletonList(new MutationCondition(fieldType3.getName(),CompareOp.EQUAL,Boolean.TRUE)));
assertEquals(ResponseStatus.UPDATED,record.getResponseStatus());
conditions=new ArrayList<MutationCondition>();
conditions.add(new MutationCondition(fieldType1.getName(),"String_Node_Str"));
conditions.add(new MutationCondition(fieldType2.getName(),124));
record.setField(fieldType3.getName(),true);
record=repository.update(record,true,true,conditions);
assertEquals(ResponseStatus.CONFLICT,record.getResponseStatus());
}