Fix concurrent modification check for missing modification date

This commit is contained in:
René Pfeuffer
2018-08-30 10:34:43 +02:00
parent f5600f60fb
commit b992ab414f
4 changed files with 36 additions and 6 deletions

View File

@@ -71,8 +71,8 @@ class SingleResourceManagerAdapter<MODEL_OBJECT extends ModelObject,
}
private boolean modelObjectWasModifiedConcurrently(MODEL_OBJECT existing, MODEL_OBJECT updated) {
return (existing.getLastModified() != null && updated.getLastModified() != null)
&& (existing.getLastModified() > updated.getLastModified());
return existing.getLastModified() != null
&& (updated.getLastModified() == null || existing.getLastModified() > updated.getLastModified());
}
public Response delete(Supplier<Optional<MODEL_OBJECT>> reader) {

View File

@@ -122,10 +122,10 @@ public class GroupRootResourceTest {
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
Group capturedGroup = groupCaptor.getValue();
assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
Group capturedGroup = groupCaptor.getValue();
assertEquals("Updated description", capturedGroup.getDescription());
}
@@ -147,7 +147,7 @@ public class GroupRootResourceTest {
}
@Test
public void updateShouldFailOnConcurrentModification() throws URISyntaxException, IOException {
public void updateShouldFailOnConcurrentModification_oldModificationDate() throws URISyntaxException, IOException {
URL url = Resources.getResource("sonia/scm/api/v2/group-test-update-concurrent-modification.json");
byte[] groupJson = Resources.toByteArray(url);
@@ -163,6 +163,23 @@ public class GroupRootResourceTest {
assertEquals(HttpServletResponse.SC_CONFLICT, response.getStatus());
}
@Test
public void updateShouldFailOnConcurrentModification_unsetModificationDate() throws URISyntaxException, IOException {
URL url = Resources.getResource("sonia/scm/api/v2/group-test-update-concurrent-modification_null_date.json");
byte[] groupJson = Resources.toByteArray(url);
MockHttpRequest request = MockHttpRequest
.put("/" + GroupRootResource.GROUPS_PATH_V2 + "admin")
.contentType(VndMediaType.GROUP)
.content(groupJson);
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_CONFLICT, response.getStatus());
}
@Test
public void shouldDeleteGroup() throws URISyntaxException {
Group group = createDummyGroup();
@@ -236,7 +253,7 @@ public class GroupRootResourceTest {
group.setName("admin");
group.setCreationDate(0L);
group.setMembers(Collections.singletonList("user"));
group.setLastModified(1234L);
group.setLastModified(3600000L);
return group;
}
}

View File

@@ -0,0 +1,12 @@
{
"description": "Updated description",
"name": "admin",
"type": "xml",
"_embedded": {
"members": [
{
"name": "user"
}
]
}
}

View File

@@ -8,5 +8,6 @@
"name": "user"
}
]
}
},
"lastModified": "1970-01-01T01:00:00.00Z"
}