Example usage for com.fasterxml.jackson.databind.node TextNode valueOf

List of usage examples for com.fasterxml.jackson.databind.node TextNode valueOf

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node TextNode valueOf.

Prototype

public static TextNode valueOf(String paramString) 

Source Link

Usage

From source file:com.unboundid.scim2.server.utils.SchemaCheckerTestCase.java

/**
 * Test case for the allow undefined attribute options.
 *
 * @throws Exception if an error occurs.
 *///from  ww w.ja va 2  s.c  om
@Test
public void testAllowUndefinedAttributeOptions() throws Exception {
    SchemaResource coreSchema = SchemaUtils.getSchema(UserResource.class);
    SchemaResource enterpriseExtension = SchemaUtils.getSchema(EnterpriseUserExtension.class);

    ResourceTypeDefinition resourceTypeDefinition = new ResourceTypeDefinition.Builder("test", "/test")
            .setCoreSchema(coreSchema).addOptionalSchemaExtension(enterpriseExtension).build();

    SchemaChecker undefinedAttributesChecker = new SchemaChecker(resourceTypeDefinition);
    undefinedAttributesChecker.enable(SchemaChecker.Option.ALLOW_UNDEFINED_ATTRIBUTES);

    SchemaChecker undefinedSubAttributesChecker = new SchemaChecker(resourceTypeDefinition);
    undefinedSubAttributesChecker.enable(SchemaChecker.Option.ALLOW_UNDEFINED_SUB_ATTRIBUTES);

    // Core attribute is undefined
    ObjectNode coreUndefined = JsonUtils.getJsonNodeFactory().objectNode();
    coreUndefined.putArray("schemas").add("urn:ietf:params:scim:schemas:core:2.0:User")
            .add("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User");
    coreUndefined.put("userName", "test");
    coreUndefined.put("undefined", "value");

    SchemaChecker.Results results = undefinedAttributesChecker.checkCreate(coreUndefined);
    assertEquals(results.getSyntaxIssues().size(), 0, results.getSyntaxIssues().toString());

    results = undefinedSubAttributesChecker.checkCreate(coreUndefined);
    assertEquals(results.getSyntaxIssues().size(), 1, results.getSyntaxIssues().toString());
    assertTrue(containsIssueWith(results.getSyntaxIssues(), "is undefined for schema"));

    results = undefinedAttributesChecker.checkModify(Collections.singleton(
            PatchOperation.add(Path.root().attribute("undefined"), TextNode.valueOf("value"))), null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedSubAttributesChecker.checkModify(Collections.singleton(
            PatchOperation.add(Path.root().attribute("undefined"), TextNode.valueOf("value"))), null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedAttributesChecker.checkModify(
            Collections.singleton(
                    PatchOperation.replace(Path.root().attribute("undefined"), TextNode.valueOf("value"))),
            null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedSubAttributesChecker.checkModify(
            Collections.singleton(
                    PatchOperation.replace(Path.root().attribute("undefined"), TextNode.valueOf("value"))),
            null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedAttributesChecker.checkModify(
            Collections.singleton(PatchOperation.remove(Path.root().attribute("undefined"))), null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedSubAttributesChecker.checkModify(
            Collections.singleton(PatchOperation.remove(Path.root().attribute("undefined"))), null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedAttributesChecker.checkSearch(Filter.fromString("undefined eq \"value\""));
    assertEquals(results.getFilterIssues().size(), 0, results.getFilterIssues().toString());

    results = undefinedSubAttributesChecker.checkSearch(Filter.fromString("undefined eq \"value\""));
    assertEquals(results.getFilterIssues().size(), 1, results.getFilterIssues().toString());
    assertTrue(containsIssueWith(results.getFilterIssues(), "is undefined"));

    // Core sub-attribute is undefined
    ObjectNode coreSubUndefined = JsonUtils.getJsonNodeFactory().objectNode();
    coreSubUndefined.putArray("schemas").add("urn:ietf:params:scim:schemas:core:2.0:User")
            .add("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User");
    coreSubUndefined.put("userName", "test");
    coreSubUndefined.putObject("name").put("undefined", "value");

    results = undefinedAttributesChecker.checkCreate(coreSubUndefined);
    assertEquals(results.getSyntaxIssues().size(), 1, results.getSyntaxIssues().toString());
    assertTrue(containsIssueWith(results.getSyntaxIssues(), "is undefined for attribute"));

    results = undefinedSubAttributesChecker.checkCreate(coreSubUndefined);
    assertEquals(results.getSyntaxIssues().size(), 0, results.getSyntaxIssues().toString());

    results = undefinedAttributesChecker
            .checkModify(
                    Collections.singleton(PatchOperation.add(
                            Path.root().attribute("name").attribute("undefined"), TextNode.valueOf("value"))),
                    null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedSubAttributesChecker
            .checkModify(
                    Collections.singleton(PatchOperation.add(
                            Path.root().attribute("name").attribute("undefined"), TextNode.valueOf("value"))),
                    null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedAttributesChecker
            .checkModify(
                    Collections.singleton(PatchOperation.replace(
                            Path.root().attribute("name").attribute("undefined"), TextNode.valueOf("value"))),
                    null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedSubAttributesChecker
            .checkModify(
                    Collections.singleton(PatchOperation.replace(
                            Path.root().attribute("name").attribute("undefined"), TextNode.valueOf("value"))),
                    null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedAttributesChecker.checkModify(
            Collections.singleton(PatchOperation.remove(Path.root().attribute("name").attribute("undefined"))),
            null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedSubAttributesChecker.checkModify(
            Collections.singleton(PatchOperation.remove(Path.root().attribute("name").attribute("undefined"))),
            null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedAttributesChecker.checkSearch(Filter.fromString("name.undefined eq \"value\""));
    assertEquals(results.getFilterIssues().size(), 1, results.getFilterIssues().toString());
    assertTrue(containsIssueWith(results.getFilterIssues(), "is undefined"));

    results = undefinedSubAttributesChecker.checkSearch(Filter.fromString("name.undefined eq \"value\""));
    assertEquals(results.getFilterIssues().size(), 0, results.getFilterIssues().toString());

    // Extended attribute namespace is undefined
    ObjectNode extendedUndefined = JsonUtils.getJsonNodeFactory().objectNode();
    extendedUndefined.putArray("schemas").add("urn:ietf:params:scim:schemas:core:2.0:User");
    extendedUndefined.put("userName", "test");
    extendedUndefined.putObject("urn:undefined").put("undefined", "value");

    // This should still be an error since all namespaces must be defined in the
    // schemas attribute.
    results = undefinedAttributesChecker.checkCreate(extendedUndefined);
    assertEquals(results.getSyntaxIssues().size(), 1, results.getSyntaxIssues().toString());

    extendedUndefined = JsonUtils.getJsonNodeFactory().objectNode();
    extendedUndefined.putArray("schemas").add("urn:ietf:params:scim:schemas:core:2.0:User")
            .add("urn:undefined");
    extendedUndefined.put("userName", "test");
    extendedUndefined.putObject("urn:undefined").put("undefined", "value");

    results = undefinedSubAttributesChecker.checkCreate(extendedUndefined);
    assertEquals(results.getSyntaxIssues().size(), 1, results.getSyntaxIssues().toString());
    assertTrue(containsIssueWith(results.getSyntaxIssues(), "is undefined"));

    results = undefinedAttributesChecker.checkModify(Collections.singleton(
            PatchOperation.add(Path.root("urn:undefined").attribute("undefined"), TextNode.valueOf("value"))),
            null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedSubAttributesChecker.checkModify(Collections.singleton(
            PatchOperation.add(Path.root("urn:undefined").attribute("undefined"), TextNode.valueOf("value"))),
            null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedAttributesChecker
            .checkModify(
                    Collections.singleton(PatchOperation.replace(
                            Path.root("urn:undefined").attribute("undefined"), TextNode.valueOf("value"))),
                    null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedSubAttributesChecker
            .checkModify(
                    Collections.singleton(PatchOperation.replace(
                            Path.root("urn:undefined").attribute("undefined"), TextNode.valueOf("value"))),
                    null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedAttributesChecker.checkModify(
            Collections.singleton(PatchOperation.remove(Path.root("urn:undefined").attribute("undefined"))),
            null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedSubAttributesChecker.checkModify(
            Collections.singleton(PatchOperation.remove(Path.root("urn:undefined").attribute("undefined"))),
            null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedAttributesChecker.checkSearch(Filter.fromString("urn:undefined:undefined eq \"value\""));
    assertEquals(results.getFilterIssues().size(), 0, results.getFilterIssues().toString());

    results = undefinedSubAttributesChecker
            .checkSearch(Filter.fromString("urn:undefined:undefined eq \"value\""));
    assertEquals(results.getFilterIssues().size(), 1, results.getFilterIssues().toString());
    assertTrue(containsIssueWith(results.getFilterIssues(), "is undefined"));

    // Extended attribute is undefined
    extendedUndefined = JsonUtils.getJsonNodeFactory().objectNode();
    extendedUndefined.putArray("schemas").add("urn:ietf:params:scim:schemas:core:2.0:User")
            .add("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User");
    extendedUndefined.put("userName", "test");
    extendedUndefined.putObject("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User").put("undefined",
            "value");

    results = undefinedAttributesChecker.checkCreate(extendedUndefined);
    assertEquals(results.getSyntaxIssues().size(), 0, results.getSyntaxIssues().toString());

    results = undefinedSubAttributesChecker.checkCreate(extendedUndefined);
    assertEquals(results.getSyntaxIssues().size(), 1, results.getSyntaxIssues().toString());
    assertTrue(containsIssueWith(results.getSyntaxIssues(), "is undefined for schema"));

    results = undefinedAttributesChecker.checkModify(Collections.singleton(PatchOperation.add(
            Path.root("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User").attribute("undefined"),
            TextNode.valueOf("value"))), null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedSubAttributesChecker.checkModify(Collections.singleton(PatchOperation.add(
            Path.root("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User").attribute("undefined"),
            TextNode.valueOf("value"))), null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedAttributesChecker.checkModify(Collections.singleton(PatchOperation.replace(
            Path.root("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User").attribute("undefined"),
            TextNode.valueOf("value"))), null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedSubAttributesChecker.checkModify(Collections.singleton(PatchOperation.replace(
            Path.root("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User").attribute("undefined"),
            TextNode.valueOf("value"))), null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedAttributesChecker.checkModify(Collections.singleton(PatchOperation.remove(
            Path.root("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User").attribute("undefined"))),
            null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedSubAttributesChecker.checkModify(Collections.singleton(PatchOperation.remove(
            Path.root("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User").attribute("undefined"))),
            null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedAttributesChecker.checkSearch(Filter
            .fromString("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:undefined eq \"value\""));
    assertEquals(results.getFilterIssues().size(), 0, results.getFilterIssues().toString());

    results = undefinedSubAttributesChecker.checkSearch(Filter
            .fromString("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:undefined eq \"value\""));
    assertEquals(results.getFilterIssues().size(), 1, results.getFilterIssues().toString());
    assertTrue(containsIssueWith(results.getFilterIssues(), "is undefined"));

    // Extended sub-attribute is undefined
    ObjectNode extendedSubUndefined = JsonUtils.getJsonNodeFactory().objectNode();
    extendedSubUndefined.putArray("schemas").add("urn:ietf:params:scim:schemas:core:2.0:User")
            .add("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User");
    extendedSubUndefined.put("userName", "test");
    extendedSubUndefined.putObject("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User")
            .putObject("manager").put("$ref", "https://value").put("value", "value").put("undefined", "value");

    results = undefinedAttributesChecker.checkCreate(extendedSubUndefined);
    assertEquals(results.getSyntaxIssues().size(), 1, results.getSyntaxIssues().toString());
    assertTrue(containsIssueWith(results.getSyntaxIssues(), "is undefined for attribute"));

    results = undefinedSubAttributesChecker.checkCreate(extendedSubUndefined);
    assertEquals(results.getSyntaxIssues().size(), 0, results.getSyntaxIssues().toString());

    results = undefinedAttributesChecker
            .checkModify(
                    Collections
                            .singleton(PatchOperation.add(
                                    Path.root("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User")
                                            .attribute("manager").attribute("undefined"),
                                    TextNode.valueOf("value"))),
                    null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedSubAttributesChecker
            .checkModify(
                    Collections
                            .singleton(PatchOperation.add(
                                    Path.root("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User")
                                            .attribute("manager").attribute("undefined"),
                                    TextNode.valueOf("value"))),
                    null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedAttributesChecker
            .checkModify(
                    Collections
                            .singleton(PatchOperation.replace(
                                    Path.root("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User")
                                            .attribute("manager").attribute("undefined"),
                                    TextNode.valueOf("value"))),
                    null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedSubAttributesChecker
            .checkModify(
                    Collections
                            .singleton(PatchOperation.replace(
                                    Path.root("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User")
                                            .attribute("manager").attribute("undefined"),
                                    TextNode.valueOf("value"))),
                    null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedAttributesChecker.checkModify(Collections.singleton(
            PatchOperation.remove(Path.root("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User")
                    .attribute("manager").attribute("undefined"))),
            null);
    assertEquals(results.getPathIssues().size(), 1, results.getPathIssues().toString());
    assertTrue(containsIssueWith(results.getPathIssues(), "is undefined"));

    results = undefinedSubAttributesChecker.checkModify(Collections.singleton(
            PatchOperation.remove(Path.root("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User")
                    .attribute("manager").attribute("undefined"))),
            null);
    assertEquals(results.getPathIssues().size(), 0, results.getPathIssues().toString());

    results = undefinedAttributesChecker.checkSearch(Filter.fromString(
            "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:manager.undefined eq \"value\""));
    assertEquals(results.getFilterIssues().size(), 1, results.getFilterIssues().toString());
    assertTrue(containsIssueWith(results.getFilterIssues(), "is undefined"));

    results = undefinedSubAttributesChecker.checkSearch(Filter.fromString(
            "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:manager.undefined eq \"value\""));
    assertEquals(results.getFilterIssues().size(), 0, results.getFilterIssues().toString());
}

From source file:com.unboundid.scim2.common.GenericScimResource.java

/**
 * Adds or replaces a binary value in a generic SCIM resource.
 *   <p>/*from   w  w  w  .  j  a  v  a  2 s .  c o  m*/
 * For example:
 * In a GenericScimResource (gsr) representing the following resource:
 * <pre><code>
 * {
 *   "path1":"AjIzLg=="
 * }
 * </code></pre>
 *   <p>
 *   gsr.replaceValue(Path.fromString("path1"), path1value)
 *   where path1value is a byte[]
 *   would change the "path1" field to the value of the path1value
 *   variable
 *   <p>
 *
 *   gsr.replaceValue(Path.fromString("path2"), path2value)
 *   where path2value is a byte[]
 *   would add a field called "path2" with the value of the path2value
 *   variabl
 *   <p>
 *
 *   Note that in a case where multiple paths match (for example
 *   a path with a filter), all paths that match will be affected.
 *
 * @param path the path to replace the value for.
 * @param value the new value.
 * @return returns the new generic SCIM resource (this).
 * @throws ScimException thrown if an error occurs (for example
 * if the path or value is "{@code null}" or invalid).
 */
public GenericScimResource replaceValue(final Path path, final byte[] value) throws ScimException {
    return replaceValue(path, TextNode.valueOf(getStringForBinary(value)));
}

From source file:com.unboundid.scim2.common.GenericScimResource.java

/**
 * Adds binary values to an array node.  If no array node exists at the
 * specified path, a new array node will be created.
 *   <p>/*from  w w  w.  j  a  v a  2 s .co  m*/
 * For example:
 * In a GenericScimResource (gsr) representing the following resource:
 * <pre><code>
 * {
 *   "path1":[ "AjIzLg==", "AjNjLp==" ]
 * }
 * </code></pre>
 *   <p>
 *   gsr.addBinaryValues(Path.fromString("path1"), path1values)
 *   where path1Value is a List of byte[].
 *   Would add each of the items in the path1values list to the
 *   "path1" list in the generic SCIM resource
 *   <p>
 *
 *   gsr.addBinaryValues(Path.fromString("path2"), path2values)
 *   where path2values is a List of byte[].
 *   Would create a new array called "path2"
 *   <p>
 *
 *   Note that in a case where multiple paths match (for example
 *   a path with a filter), all paths that match will be affected.
 *
 * @param path the path to add the list to.
 * @param values a list containing the new values.
 * @return returns the new generic SCIM resource (this).
 * @throws ScimException thrown if an error occurs (for example
 * if the path or value is "{@code null}" or invalid).
 */
public GenericScimResource addBinaryValues(final Path path, final List<byte[]> values) throws ScimException {
    ArrayNode valuesArrayNode = JsonUtils.getJsonNodeFactory().arrayNode();
    for (byte[] value : values) {
        valuesArrayNode.add(TextNode.valueOf(getStringForBinary(value)));
    }

    return addValues(path, valuesArrayNode);
}

From source file:com.unboundid.scim2.common.GenericScimResource.java

/**
 * Adds or replaces a URI value in a generic SCIM resource.
 *   <p>/* w  ww  .  j a v  a  2s  . c om*/
 * For example:
 * In a GenericScimResource (gsr) representing the following resource:
 * <pre><code>
 * {
 *   "path1":"http://localhost:8080/uri/One"
 * }
 * </code></pre>
 *   <p>
 *   gsr.replaceValue(Path.fromString("path1"), path1value)
 *   where path1value is a URI
 *   would change the "path1" field to the value of the path1value
 *   variable
 *   <p>
 *   gsr.replaceValue(Path.fromString("path2"), path2value)
 *   where path2value is a URI
 *   would add a field called "path2" with the value of the path2value
 *   variable
 *   <p>
 *   Note that in a case where multiple paths match (for example
 *   a path with a filter), all paths that match will be affected.
 *
 * @param path the path to replace the value for.
 * @param value the new value.
 * @return returns the new generic SCIM resource (this).
 * @throws ScimException thrown if an error occurs (for example
 * if the path or value is "{@code null}" or invalid).
 */
public GenericScimResource replaceValue(final Path path, final URI value) throws ScimException {
    return replaceValue(path, TextNode.valueOf(value.toString()));
}

From source file:com.unboundid.scim2.server.utils.SchemaCheckerTestCase.java

/**
 * Test the attribute mutability constratins are checked correctly.
 *
 * @throws Exception if an error occurs.
 *//*from   ww w. ja  v a  2 s .co m*/
@Test
public void testAttributeMutability() throws Exception {
    List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();

    // Read-only attribute
    AttributeDefinition readOnly = new AttributeDefinition.Builder().setName("readOnly")
            .setType(AttributeDefinition.Type.STRING).setMutability(AttributeDefinition.Mutability.READ_ONLY)
            .build();

    // Immutable attribute
    AttributeDefinition immutable = new AttributeDefinition.Builder().setName("immutable")
            .setType(AttributeDefinition.Type.STRING).setMutability(AttributeDefinition.Mutability.IMMUTABLE)
            .build();

    attributeDefinitions.add(readOnly);
    attributeDefinitions.add(immutable);

    SchemaResource schema = new SchemaResource("urn:id:test", "test", "", attributeDefinitions);
    ResourceTypeDefinition resourceTypeDefinition = new ResourceTypeDefinition.Builder("test", "/test")
            .setCoreSchema(schema).build();
    SchemaChecker checker = new SchemaChecker(resourceTypeDefinition);

    // Can not create read-only
    ObjectNode o = JsonUtils.getJsonNodeFactory().objectNode();
    o.putArray("schemas").add("urn:id:test");
    o.put("readOnly", "value");
    SchemaChecker.Results results = checker.checkCreate(o);
    assertEquals(results.getMutabilityIssues().size(), 1, results.getMutabilityIssues().toString());
    assertTrue(containsIssueWith(results.getMutabilityIssues(), "read-only"));

    // Can not replace read-only
    results = checker.checkReplace(o, null);
    assertEquals(results.getMutabilityIssues().size(), 1, results.getMutabilityIssues().toString());
    assertTrue(containsIssueWith(results.getMutabilityIssues(), "read-only"));

    // Can not add read-only in patch
    results = checker.checkModify(Collections
            .singleton(PatchOperation.add(Path.root().attribute("readOnly"), TextNode.valueOf("value"))), null);
    assertEquals(results.getMutabilityIssues().size(), 1, results.getMutabilityIssues().toString());
    assertTrue(containsIssueWith(results.getMutabilityIssues(), "read-only"));

    // Can not remove read-only in patch
    results = checker
            .checkModify(Collections.singleton(PatchOperation.remove(Path.root().attribute("readOnly"))), null);
    assertEquals(results.getMutabilityIssues().size(), 1, results.getMutabilityIssues().toString());
    assertTrue(containsIssueWith(results.getMutabilityIssues(), "read-only"));

    // Can not replace read-only in patch
    results = checker.checkModify(
            Collections.singleton(
                    PatchOperation.replace(Path.root().attribute("readOnly"), TextNode.valueOf("value"))),
            null);
    assertEquals(results.getMutabilityIssues().size(), 1, results.getMutabilityIssues().toString());
    assertTrue(containsIssueWith(results.getMutabilityIssues(), "read-only"));

    // Can create immutable
    o = JsonUtils.getJsonNodeFactory().objectNode();
    o.putArray("schemas").add("urn:id:test");
    o.put("immutable", "value");
    results = checker.checkCreate(o);
    assertTrue(results.getMutabilityIssues().isEmpty(), results.getMutabilityIssues().toString());

    // Can replace immutable if not already present
    o = JsonUtils.getJsonNodeFactory().objectNode();
    o.putArray("schemas").add("urn:id:test");
    o.put("immutable", "value");
    results = checker.checkReplace(o, null);
    assertTrue(results.getMutabilityIssues().isEmpty(), results.getMutabilityIssues().toString());

    // Can replace if it is the same
    o = JsonUtils.getJsonNodeFactory().objectNode();
    o.putArray("schemas").add("urn:id:test");
    o.put("immutable", "value");
    results = checker.checkReplace(o, o);
    assertTrue(results.getMutabilityIssues().isEmpty(), results.getMutabilityIssues().toString());

    // Can not replace if value already present and different
    o = JsonUtils.getJsonNodeFactory().objectNode();
    o.putArray("schemas").add("urn:id:test");
    o.put("immutable", "value");
    results = checker.checkReplace(o.deepCopy().put("immutable", "newValue"), o);
    assertEquals(results.getMutabilityIssues().size(), 1, results.getMutabilityIssues().toString());
    assertTrue(containsIssueWith(results.getMutabilityIssues(), "immutable"));

    // Can add immutable in patch if not already present
    results = checker.checkModify(Collections.singleton(
            PatchOperation.add(Path.root().attribute("immutable"), TextNode.valueOf("value"))), null);
    assertTrue(results.getMutabilityIssues().isEmpty(), results.getMutabilityIssues().toString());

    // Can not replace immutable in patch if not already present
    results = checker.checkModify(
            Collections.singleton(
                    PatchOperation.replace(Path.root().attribute("immutable"), TextNode.valueOf("value"))),
            null);
    assertEquals(results.getMutabilityIssues().size(), 1, results.getMutabilityIssues().toString());
    assertTrue(containsIssueWith(results.getMutabilityIssues(), "immutable"));

    // Can not add immutable in patch if it is the same
    results = checker.checkModify(Collections
            .singleton(PatchOperation.add(Path.root().attribute("immutable"), TextNode.valueOf("value"))), o);
    assertEquals(results.getMutabilityIssues().size(), 1, results.getMutabilityIssues().toString());
    assertTrue(containsIssueWith(results.getMutabilityIssues(), "immutable"));

    // Can not replace immutable in patch if it is the same
    results = checker.checkModify(Collections.singleton(
            PatchOperation.replace(Path.root().attribute("immutable"), TextNode.valueOf("value"))), o);
    assertEquals(results.getMutabilityIssues().size(), 1, results.getMutabilityIssues().toString());
    assertTrue(containsIssueWith(results.getMutabilityIssues(), "immutable"));

    // Can not add immutable in patch if already present and different
    results = checker.checkModify(Collections.singleton(
            PatchOperation.add(Path.root().attribute("immutable"), TextNode.valueOf("newValue"))), o);
    assertEquals(results.getMutabilityIssues().size(), 2, results.getMutabilityIssues().toString());
    assertTrue(containsIssueWith(results.getMutabilityIssues(), "immutable"));

    // Can not replace immutable in patch if already present and different
    results = checker.checkModify(
            Collections.singleton(
                    PatchOperation.replace(Path.root().attribute("immutable"), TextNode.valueOf("newValue"))),
            o);
    assertEquals(results.getMutabilityIssues().size(), 2, results.getMutabilityIssues().toString());
    assertTrue(containsIssueWith(results.getMutabilityIssues(), "immutable"));

    // Can not remove immutable
    results = checker.checkModify(
            Collections.singleton(PatchOperation.remove(Path.root().attribute("immutable"))), null);
    assertEquals(results.getMutabilityIssues().size(), 1, results.getMutabilityIssues().toString());
    assertTrue(containsIssueWith(results.getMutabilityIssues(), "immutable"));
}

From source file:org.apache.james.mailbox.tika.TikaTextExtractorTest.java

@Test
public void asListOfStringShouldReturnASingletonWhenOneElement() {
    ContentAndMetadataDeserializer deserializer = new TikaTextExtractor.ContentAndMetadataDeserializer();
    List<String> listOfString = deserializer.asListOfString(TextNode.valueOf("text"));

    assertThat(listOfString).containsOnly("text");
}