mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
Fix concurrent modification check for missing modification date
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"description": "Updated description",
|
||||
"name": "admin",
|
||||
"type": "xml",
|
||||
"_embedded": {
|
||||
"members": [
|
||||
{
|
||||
"name": "user"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -8,5 +8,6 @@
|
||||
"name": "user"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"lastModified": "1970-01-01T01:00:00.00Z"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user