genericResource = new GenericScimResource( ((GenericScimResource) resource).getObjectNode().deepCopy()); genericResource.getObjectNode()))
final List<String> values) throws ScimException return addStringValues(Path.fromString(path), values);
/** * Gets a list of String from a generic SCIM resource. If the path exists, * the JSON node at the path must be a list of String. If the path does * not exist, an empty list will be returned. * <p> * * For example: * In a GenericScimResource (gsr) representing the following resource: * <pre><code> * { * "path1": ["stringValue1", "stringValue2"] * } * </code></pre> * <p> * * getStringValueList("path1") * returns a list containing "stringValue1", "stringValue2" * <p> * * getStringValueList("bogusPath") * returns an empty list * * @param path the path to get the value from. * @return the value at the path, or an empty list. * @throws ScimException thrown if an error occurs. */ public List<String> getStringValueList(final String path) throws ScimException { return getStringValueList(Path.fromString(path)); }
String arrayValue4 = "arrayValue4"; GenericScimResource gsr = new GenericScimResource(); Assert.assertEquals(gsr.replaceValue(path1, value1). getStringValue(Path.fromString(path1)), value1); Assert.assertEquals(gsr.replaceValue(Path.fromString(path2), value2). getStringValue(path2), value2); List<String> list1 = gsr.addStringValues(path3, Lists.<String>newArrayList(arrayValue1, arrayValue2)). getStringValueList(Path.fromString(path3)); Assert.assertEquals(list1.size(), 2); Assert.assertTrue(list1.contains(arrayValue1)); Assert.assertTrue(list1.contains(arrayValue2)); List<String> list2 = gsr.addStringValues(Path.fromString(path4), Lists.<String>newArrayList(arrayValue3, arrayValue4)). getStringValueList(path4); Assert.assertEquals(list2.size(), 2); Assert.assertTrue(list2.contains(arrayValue3)); Assert.assertTrue(list2.contains(arrayValue4)); Assert.assertNull(gsr.getStringValue("bogusPath")); Assert.assertNull(gsr.getStringValue(Path.fromString("bogusPath"))); Assert.assertTrue(gsr.getStringValueList("bogusPath").isEmpty()); Assert.assertTrue(gsr.getStringValueList( Path.fromString("bogusPath")).isEmpty());
new GenericScimResource(getTestResource()); gso.replaceValue("string", JsonUtils.valueToNode("new")); gso.getObjectNode()).get(0), String.class), "new"); gso.replaceValue("array.string", JsonUtils.valueToNode("new")); gso.replaceValue("complex.array.array[id eq \"2\"].string", JsonUtils.valueToNode("new")); Path.fromString("array.string"), gso.getObjectNode()).get(0), String.class), "new"); assertEquals(JsonUtils.nodeToValue(JsonUtils.findMatchingPaths( Path.fromString("array.string"), gso.getObjectNode()).get(1), String.class), "new"); assertEquals(JsonUtils.nodeToValue(JsonUtils.findMatchingPaths( Path.fromString("complex.array.array.string"), gso.getObjectNode()).get(0), String.class), "string"); assertEquals(JsonUtils.nodeToValue(JsonUtils.findMatchingPaths( Path.fromString("complex.array.array.string"), gso.getObjectNode()).get(1), String.class), "new"); assertEquals(JsonUtils.nodeToValue(JsonUtils.findMatchingPaths( Path.fromString("complex.array.array.string"), gso.getObjectNode()).get(2), String.class), "string"); assertEquals(JsonUtils.nodeToValue(JsonUtils.findMatchingPaths( Path.fromString("complex.array.array.string"), gso.getObjectNode()).get(3), String.class), "new"); gso.replaceValue(Path.root("urn:some:extension").attribute("attribute"),
Double arrayValue4 = new Double(1.2); GenericScimResource gsr = new GenericScimResource(); Assert.assertEquals(gsr.replaceValue(path1, value1). getDoubleValue(Path.fromString(path1)), value1, 0.01); Assert.assertEquals(gsr.replaceValue(Path.fromString(path2), value2). getDoubleValue(path2), value2, 0.01); List<Double> list1 = gsr.addDoubleValues(path3, Lists.<Double>newArrayList(arrayValue1, arrayValue2)). getDoubleValueList(Path.fromString(path3)); Assert.assertEquals(list1.size(), 2); List<Double> list2 = gsr.addDoubleValues(Path.fromString(path4), Lists.<Double>newArrayList(arrayValue3, arrayValue4)). getDoubleValueList(path4); Assert.assertEquals(list2.size(), 2); Assert.assertNull(gsr.getDoubleValue("bogusPath")); Assert.assertNull(gsr.getDoubleValue(Path.fromString("bogusPath"))); Assert.assertTrue(gsr.getDoubleValueList("bogusPath").isEmpty()); Assert.assertTrue(gsr.getDoubleValueList( Path.fromString("bogusPath")).isEmpty());
Long arrayValue4 = 12L; GenericScimResource gsr = new GenericScimResource(); Assert.assertEquals(gsr.replaceValue(path1, value1). getLongValue(Path.fromString(path1)), value1); Assert.assertEquals(gsr.replaceValue(Path.fromString(path2), value2). getLongValue(path2), value2); List<Long> list1 = gsr.addLongValues(path3, Lists.<Long>newArrayList(arrayValue1, arrayValue2)). getLongValueList(Path.fromString(path3)); Assert.assertEquals(list1.size(), 2); Assert.assertTrue(list1.contains(arrayValue1)); Assert.assertTrue(list1.contains(arrayValue2)); List<Long> list2 = gsr.addLongValues(Path.fromString(path4), Lists.<Long>newArrayList(arrayValue3, arrayValue4)). getLongValueList(path4); Assert.assertEquals(list2.size(), 2); Assert.assertTrue(list2.contains(arrayValue3)); Assert.assertTrue(list2.contains(arrayValue4)); Assert.assertNull(gsr.getLongValue("bogusPath")); Assert.assertNull(gsr.getLongValue(Path.fromString("bogusPath"))); Assert.assertTrue(gsr.getLongValueList("bogusPath").isEmpty()); Assert.assertTrue(gsr.getLongValueList( Path.fromString("bogusPath")).isEmpty());
Boolean arrayValue4 = Boolean.TRUE; GenericScimResource gsr = new GenericScimResource(); Assert.assertEquals(gsr.replaceValue(path1, value1). getBooleanValue(Path.fromString(path1)), value1); Assert.assertEquals(gsr.replaceValue(Path.fromString(path2), value2). getBooleanValue(path2), value2); List<Boolean> list1 = gsr.addBooleanValues(path3, Lists.<Boolean>newArrayList(arrayValue1, arrayValue2)). getBooleanValueList(Path.fromString(path3)); Assert.assertEquals(list1.size(), 2); Assert.assertTrue(list1.contains(arrayValue1)); Assert.assertTrue(list1.contains(arrayValue2)); List<Boolean> list2 = gsr.addBooleanValues(Path.fromString(path4), Lists.<Boolean>newArrayList(arrayValue3, arrayValue4)). getBooleanValueList(path4); Assert.assertEquals(list2.size(), 2); Assert.assertTrue(list2.contains(arrayValue3)); Assert.assertTrue(list2.contains(arrayValue4)); Assert.assertNull(gsr.getBooleanValue("bogusPath")); Assert.assertNull(gsr.getBooleanValue(Path.fromString("bogusPath"))); Assert.assertTrue(gsr.getBooleanValueList("bogusPath").isEmpty()); Assert.assertTrue(gsr.getBooleanValueList( Path.fromString("bogusPath")).isEmpty());
Integer arrayValue4 = 12; GenericScimResource gsr = new GenericScimResource(); Assert.assertEquals(gsr.replaceValue(path1, value1). getIntegerValue(Path.fromString(path1)), value1); Assert.assertEquals(gsr.replaceValue(Path.fromString(path2), value2). getIntegerValue(path2), value2); List<Integer> list1 = gsr.addIntegerValues(path3, Lists.<Integer>newArrayList(arrayValue1, arrayValue2)). getIntegerValueList(Path.fromString(path3)); Assert.assertEquals(list1.size(), 2); Assert.assertTrue(list1.contains(arrayValue1)); Assert.assertTrue(list1.contains(arrayValue2)); List<Integer> list2 = gsr.addIntegerValues(Path.fromString(path4), Lists.<Integer>newArrayList(arrayValue3, arrayValue4)). getIntegerValueList(path4); Assert.assertEquals(list2.size(), 2); Assert.assertTrue(list2.contains(arrayValue3)); Assert.assertTrue(list2.contains(arrayValue4)); Assert.assertNull(gsr.getIntegerValue("bogusPath")); Assert.assertNull(gsr.getIntegerValue(Path.fromString("bogusPath"))); Assert.assertTrue(gsr.getIntegerValueList("bogusPath").isEmpty()); Assert.assertTrue(gsr.getIntegerValueList( Path.fromString("bogusPath")).isEmpty());
GenericScimResource gsr = new GenericScimResource(); Assert.assertEquals(gsr.replaceValue(path1, value1). getURIValue(Path.fromString(path1)), value1); Assert.assertEquals(gsr.replaceValue(Path.fromString(path2), value2). getURIValue(path2), value2); List<URI> list1 = gsr.addURIValues(path3, Lists.<URI>newArrayList(arrayValue1, arrayValue2)). getURIValueList(Path.fromString(path3)); Assert.assertEquals(list1.size(), 2); Assert.assertTrue(list1.contains(arrayValue1)); Assert.assertTrue(list1.contains(arrayValue2)); List<URI> list2 = gsr.addURIValues(Path.fromString(path4), Lists.<URI>newArrayList(arrayValue3, arrayValue4)). getURIValueList(path4); Assert.assertEquals(list2.size(), 2); Assert.assertTrue(list2.contains(arrayValue3)); Assert.assertTrue(list2.contains(arrayValue4)); Assert.assertEquals(gsr.replaceValue(path5, relativeUri1). getURIValue(path5), relativeUri1); Assert.assertNull(gsr.getURIValue("bogusPath")); Assert.assertNull(gsr.getURIValue(Path.fromString("bogusPath"))); Assert.assertTrue(gsr.getURIValueList("bogusPath").isEmpty()); Assert.assertTrue(gsr.getURIValueList( Path.fromString("bogusPath")).isEmpty());
Date arrayValue4 = new Date(9482087579L); GenericScimResource gsr = new GenericScimResource(); Assert.assertEquals(gsr.replaceValue(path1, value1). getDateValue(Path.fromString(path1)), value1); Assert.assertEquals(gsr.replaceValue(Path.fromString(path2), value2). getDateValue(path2), value2); List<Date> list1 = gsr.addDateValues(path3, Lists.<Date>newArrayList(arrayValue1, arrayValue2)). getDateValueList(Path.fromString(path3)); Assert.assertEquals(list1.size(), 2); Assert.assertTrue(list1.contains(arrayValue1)); Assert.assertTrue(list1.contains(arrayValue2)); List<Date> list2 = gsr.addDateValues(Path.fromString(path4), Lists.<Date>newArrayList(arrayValue3, arrayValue4)). getDateValueList(path4); Assert.assertEquals(list2.size(), 2); Assert.assertTrue(list2.contains(arrayValue3)); Assert.assertTrue(list2.contains(arrayValue4)); Assert.assertNull(gsr.getDateValue("bogusPath")); Assert.assertNull(gsr.getDateValue(Path.fromString("bogusPath"))); Assert.assertTrue(gsr.getDateValueList("bogusPath").isEmpty()); Assert.assertTrue(gsr.getDateValueList( Path.fromString("bogusPath")).isEmpty());
GenericScimResource gsr = new GenericScimResource(); Assert.assertEquals(gsr.replaceValue(path1, value1). getBinaryValue(Path.fromString(path1)), value1); Assert.assertEquals(gsr.replaceValue(path1, JsonUtils.getJsonNodeFactory().binaryNode(value1)). getBinaryValue(Path.fromString(path1)), value1); Assert.assertEquals(gsr.replaceValue(path1, JsonUtils.getJsonNodeFactory().textNode( Base64Variants.getDefaultVariant().encode(value1))). getBinaryValue(Path.fromString(path1)), value1); Assert.assertEquals(gsr.replaceValue(Path.fromString(path2), value2). getBinaryValue(path2), value2); List<byte[]> list1 = gsr.addBinaryValues(path3, Lists.<byte[]>newArrayList(arrayValue1, arrayValue2)). getBinaryValueList(Path.fromString(path3)); Assert.assertEquals(list1.size(), 2); assertByteArrayListContainsBytes(list1, arrayValue1); list1 = gsr.replaceValue(path3, JsonUtils.getJsonNodeFactory().arrayNode(). add(JsonUtils.getJsonNodeFactory().binaryNode(arrayValue1)). add(JsonUtils.getJsonNodeFactory().binaryNode(arrayValue2))). getBinaryValueList(Path.fromString(path3)); Assert.assertEquals(list1.size(), 2); assertByteArrayListContainsBytes(list1, arrayValue1);
/** * {@inheritDoc} */ @Override public void serialize(final GenericScimResource value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException { JsonUtils.getObjectWriter().writeValue(jgen, value.getObjectNode()); } }
new GenericScimResource(getTestResource()); boolean removed = gso.removeValues("array.complex.array.string"); assertEquals(removed, true); Path.fromString("array.complex.array.string"), gso.getObjectNode()); assertEquals(stringResult.size(), 0); gso = new GenericScimResource(getTestResource()); removed = gso.removeValues("array[id eq \"1\"].complex.array.string"); assertEquals(removed, true); gso.getObjectNode()); assertEquals(stringResult.size(), 0); gso = new GenericScimResource(getTestResource()); removed = gso.removeValues("array.complex.array[id eq \"1\"].string"); assertEquals(removed, true); gso.getObjectNode()); assertEquals(stringResult.size(), 0); gso = new GenericScimResource(getTestResource()); removed = gso.removeValues( "array[id eq \"1\"].complex.array[id eq \"1\"].string"); assertEquals(removed, true);
new GenericScimResource(getTestResource()); meta2.set("version", "2"); ArrayValue[] metas = new ArrayValue[] { meta1, meta2 }; gso.addValues("array", (ArrayNode) JsonUtils.valueToNode(metas)); Path.fromString("array"), gso.getObjectNode()).get(0), ArrayValue[].class)[0], meta1); assertNotEquals(JsonUtils.nodeToValue(JsonUtils.findMatchingPaths( Path.fromString("array"), gso.getObjectNode()).get(0), ArrayValue[].class)[1], meta2); assertEquals(JsonUtils.nodeToValue(JsonUtils.findMatchingPaths( Path.fromString("array"), gso.getObjectNode()).get(0), ArrayValue[].class)[2], meta1); assertEquals(JsonUtils.nodeToValue(JsonUtils.findMatchingPaths( Path.fromString("array"), gso.getObjectNode()).get(0), ArrayValue[].class)[3], meta2); gso.addValues("complex.array[id eq \"2\"]", (ArrayNode) JsonUtils.valueToNode(metas)); Path.fromString("complex.array"), gso.getObjectNode()).get(0), ArrayValue[].class).length, 4); assertNotEquals(JsonUtils.nodeToValue(JsonUtils.findMatchingPaths( Path.fromString("complex.array"), gso.getObjectNode()).get(0), ArrayValue[].class)[0], meta1); assertNotEquals(JsonUtils.nodeToValue(JsonUtils.findMatchingPaths( Path.fromString("complex.array"), gso.getObjectNode()).get(0), ArrayValue[].class)[1], meta2);
/** * {@inheritDoc} */ public GenericScimResource asGenericScimResource() { ObjectNode object = JsonUtils.valueToNode(this); return new GenericScimResource(object); }
/** * Tests that etags work properly for retrievals when a not modified * exception is thrown. * @throws ScimException in case of error. */ @Test(expectedExceptions = NotModifiedException.class) public void testIfNoneMatch_retrieveException() throws ScimException { final ScimService scimService = new ScimService(target()); GenericScimResource gsr = new GenericScimResource(); Meta meta = new Meta(); meta.setLocation(UriBuilder.fromUri(ETAG_URI).path("/123").build()); meta.setVersion("123"); gsr.setMeta(meta); scimService.retrieveRequest( UriBuilder.fromUri(ETAG_URI).path("/exception/notModified").build()). ifNoneMatch("123").invoke(GenericScimResource.class); }
"}"); GenericScimResource gso = new GenericScimResource(node); JsonUtils.getObjectWriter().writeValueAsString(gso.getMeta())); Assert.assertEquals( metaNode.get("created").asText(), ((GenericScimResource)cso).getObjectNode().path("shoeSize").asText(), "12W");
private void verifyEtagHeaders(GenericScimResource resource, boolean shouldContainIfMatch, boolean shouldContainIfNoneMatch) throws ScimException { if(shouldContainIfMatch) { List<String> ifMatchValues = resource.getStringValueList(HttpHeaders.IF_MATCH); Assert.assertNotNull(ifMatchValues); Assert.assertFalse(ifMatchValues.isEmpty()); } else { Assert.assertTrue(resource.getObjectNode(). path(HttpHeaders.IF_MATCH).isMissingNode()); } if(shouldContainIfNoneMatch) { List<String> ifNoneMatchValues = resource.getStringValueList(HttpHeaders.IF_NONE_MATCH); Assert.assertNotNull(ifNoneMatchValues); Assert.assertFalse(ifNoneMatchValues.isEmpty()); } else { Assert.assertTrue(resource.getObjectNode(). path(HttpHeaders.IF_NONE_MATCH).isMissingNode()); } }
private GenericScimResource getEtagDocument(HttpHeaders headers) throws ScimException { GenericScimResource gsr = new GenericScimResource(); if(headers.getRequestHeaders().containsKey(HttpHeaders.IF_NONE_MATCH)) { gsr.addStringValues(HttpHeaders.IF_NONE_MATCH, headers.getRequestHeader(HttpHeaders.IF_NONE_MATCH)); } if(headers.getRequestHeaders().containsKey(HttpHeaders.IF_MATCH)) { gsr.addStringValues(HttpHeaders.IF_MATCH, headers.getRequestHeader(HttpHeaders.IF_MATCH)); } lastResult = gsr; return gsr; } }