Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional checks in testMultiValuedAttributesWithEmptyValues() #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
import com.unboundid.scim2.common.types.PhoneNumber;
import com.unboundid.scim2.common.types.Photo;
import com.unboundid.scim2.common.utils.JsonUtils;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.IOException;
import java.math.BigDecimal;
import java.net.URI;
import java.util.Iterator;
Expand Down Expand Up @@ -1060,12 +1058,12 @@ public void sanityTest() throws Exception
* diff with. We should return no patch operations, however in previous
* iterations of this code, we would try and remove the attribute.
*
* @throws IOException if an error occurs
* @throws Exception if an error occurs
*/
@Test
public void testMultiValuedAttributesWithEmptyValues() throws IOException
public void testMultiValuedAttributesWithEmptyValues() throws Exception
{
String jsonString = "{\n" +
String jsonString1 = "{\n" +
" \"schemas\" : [ \"urn:unboundid:configuration:2.0\" ],\n" +
" \"id\" : \"userRoot2\",\n" +
" \"meta\" : {\n" +
Expand All @@ -1084,12 +1082,61 @@ public void testMultiValuedAttributesWithEmptyValues() throws IOException
" \"compactCommonParentDn\" : [ ],\n" +
" \"jeProperty\" : [ ]\n" +
"}";
ObjectNode source = JsonUtils.getObjectReader().
forType(ObjectNode.class).readValue(jsonString);
ObjectNode target = JsonUtils.getObjectReader().
forType(ObjectNode.class).readValue(jsonString);
List<PatchOperation> d = JsonUtils.diff(source, target, false);
Assert.assertEquals(d.size(), 0);
ObjectNode source1 = JsonUtils.getObjectReader().
forType(ObjectNode.class).readValue(jsonString1);
ObjectNode target1 = JsonUtils.getObjectReader().
forType(ObjectNode.class).readValue(jsonString1);

// diff() should not return any patch operations for identical resources,
// regardless of 'removeMissing' parameter.
assertEquals(JsonUtils.diff(source1, target1, false).size(), 0);
assertEquals(JsonUtils.diff(source1, target1, true).size(), 0);

String jsonString2 = "{\n" +
" \"schemas\" : [ \"urn:unboundid:configuration:2.0\" ],\n" +
" \"id\" : \"userRoot2\",\n" +
" \"meta\" : {\n" +
" \"resourceType\" : \"LocalDbBackend\",\n" +
" \"location\" : \"http://localhost:5033/config/v2/Backends/userRoot2\"\n" +
" },\n" +
" \"urn:unboundid:configuration:2.0\" : {\n" +
" \"type\" : \"LocalDbBackend\"\n" +
" },\n" +
" \"backendId\" : \"userRoot2\",\n" +
" \"backgroundPrime\" : \"false\",\n" +
" \"backupFilePermissions\" : \"700\",\n" +
" \"baseDn\" : [ ],\n" +
" \"checkpointOnCloseCount\" : \"2\",\n" +
" \"cleanerThreadWaitTime\" : \"120000\",\n" +
" \"compactCommonParentDn\" : [ ],\n" +
" \"jeProperty\" : [ ],\n" +
" \"jeProperty2\" : [ ],\n" +
" \"favoriteColors\" : [ \"purple\", \"beige\" ]\n" +
"}";

ObjectNode target2 = JsonUtils.getObjectReader().
forType(ObjectNode.class).readValue(jsonString2);

// diff() should generate a remove operation for baseDN
// and a replace operation for favoriteColors, but no
// operations for empty new jeProperty2.

List<PatchOperation> ops = JsonUtils.diff(source1, target2, true);
assertEquals(ops.size(), 2);
for (PatchOperation op : ops)
{
if (op.getOpType().equals(PatchOpType.REMOVE)) {
assertEquals("baseDn", op.getPath().toString());
}
else if (op.getOpType().equals(PatchOpType.REPLACE))
{
GenericScimResource nameAndValues = op.getValue(GenericScimResource.class);
List<String> values = nameAndValues.getStringValueList("favoriteColors");
assertEquals(values.size(), 2);
assertTrue(values.contains("purple"));
assertTrue(values.contains("beige"));
}
}
}

private void removeNullNodes(JsonNode object)
Expand Down