Source:
public void patchReplaceStartDataUnAuthenticatedTest() throws Exception { context.turnOffAuthorisationSystem(); Community community = CommunityBuilder.createCommunity(context).build(); Collection collection = CollectionBuilder.createCollection(context, community).build(); Item item = ItemBuilder.createItem(context, collection).build(); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2010); calendar.set(Calendar.MONTH, 5); calendar.set(Calendar.DATE, 15); Date data = calendar.getTime(); ResourcePolicy resourcePolicy = ResourcePolicyBuilder.createResourcePolicy(context) .withAction(Constants.WRITE) .withDspaceObject(item) .withStartDate(data) .withPolicyType(ResourcePolicy.TYPE_CUSTOM) .build(); context.restoreAuthSystemState(); Calendar calendar2 = Calendar.getInstance(); SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd"); calendar2.set(Calendar.YEAR, 2021); calendar2.set(Calendar.MONTH, 2); calendar2.set(Calendar.DATE, 21); Date newDate = calendar2.getTime(); List<Operation> ops = new ArrayList<Operation>(); ReplaceOperation replaceOperation = new ReplaceOperation("/startDate", formatDate.format(newDate)); ops.add(replaceOperation); String patchBody = getPatchContent(ops); getClient().perform(patch("/api/authz/resourcepolicies/" + resourcePolicy.getID()) .content(patchBody) .contentType(MediaType.APPLICATION_JSON_PATCH_JSON)) .andExpect(status().isUnauthorized()); }

Target:
public void patchReplaceStartDataUnAuthenticatedTest() throws Exception { context.turnOffAuthorisationSystem(); Community community = CommunityBuilder.createCommunity(context).build(); Collection collection = CollectionBuilder.createCollection(context, community).build(); Item item = ItemBuilder.createItem(context, collection).build(); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2010); calendar.set(Calendar.MONTH, 5); calendar.set(Calendar.DATE, 15); Date date = calendar.getTime(); ResourcePolicy resourcePolicy = ResourcePolicyBuilder.createResourcePolicy(context) .withAction(Constants.WRITE) .withDspaceObject(item) .withStartDate(date) .withPolicyType(ResourcePolicy.TYPE_CUSTOM) .build(); context.restoreAuthSystemState(); Calendar calendar2 = Calendar.getInstance(); SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd"); calendar2.set(Calendar.YEAR, 2021); calendar2.set(Calendar.MONTH, 2); calendar2.set(Calendar.DATE, 21); Date newDate = calendar2.getTime(); List<Operation> ops = new ArrayList<Operation>(); ReplaceOperation replaceOperation = new ReplaceOperation("/startDate", formatDate.format(newDate)); ops.add(replaceOperation); String patchBody = getPatchContent(ops); getClient().perform(patch("/api/authz/resourcepolicies/" + resourcePolicy.getID()) .content(patchBody) .contentType(MediaType.APPLICATION_JSON_PATCH_JSON)) .andExpect(status().isUnauthorized()); String authToken = getAuthToken(admin.getEmail(), password); getClient(authToken).perform(get("/api/authz/resourcepolicies/" + resourcePolicy.getID())) .andExpect(status().isOk()) .andExpect(jsonPath("$",Matchers.allOf( hasJsonPath("$.action", is(Constants.actionText[resourcePolicy.getAction()])), hasJsonPath("$.startDate", is(formatDate.format(date))), hasJsonPath("$.description", is(resourcePolicy.getRpDescription()))))); }