org.yaml.snakeyaml.constructor.ConstructorException Java Examples

The following examples show how to use org.yaml.snakeyaml.constructor.ConstructorException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApplyStatesActionResult.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @return Optional with list of state results or empty
 */
public Optional<List<StateResult>> getResult() {
    Yaml yaml = new Yaml();
    List<StateResult> result = new LinkedList<>();
    try {
        @SuppressWarnings("unchecked")
        Map<String, Map<String, Object>> payload = yaml.loadAs(getOutputContents(), Map.class);
        payload.entrySet().stream().forEach(e -> {
            result.add(new StateResult(e));
        });
    }
    catch (ConstructorException ce) {
        return Optional.empty();
    }
    return Optional.of(result);
}
 
Example #2
Source File: PrimitiveArrayTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testStringCharArray() {
    Yaml yaml = new Yaml();

    try {
        yaml.load(pkg + ".CharArr [ [ abcd ] ]");
        fail("Expected exception.");
    } catch (Exception e) {
        assertEquals(ConstructorException.class, e.getClass());
        assertEquals("Invalid node Character: 'abcd'; length: 4", e.getCause().getMessage());
    }
}
 
Example #3
Source File: StatementTest.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
private void assertNoMarkerFile(final Path markerFile, final String yaml) {
    Exception expected = null;
    try {
        final var cfg = StatementConfiguration.empty();
        cfg.overrideWith(new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)), false);
    } catch (Exception e) {
        // delay test for later
        expected = e;
    }

    assertFalse(Files.isRegularFile(markerFile), "Marker file must not exist");
    assertNotNull(expected);
    assertThat(expected, IsInstanceOf.instanceOf(ConstructorException.class));
}
 
Example #4
Source File: StatementTest.java    From enmasse with Apache License 2.0 5 votes vote down vote up
private void assertNoMarkerFile(final Path markerFile, final String yaml) {
    Exception expected = null;
    try {
        var cfg = StatementConfiguration.empty();
        cfg.overrideWith(new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)), false);
    } catch (Exception e) {
        // delay test for later
        expected = e;
    }

    assertFalse(isRegularFile(markerFile), "Marker file must not exist");
    assertNotNull(expected);
    assertThat(expected, instanceOf(ConstructorException.class));
}
 
Example #5
Source File: YamlsTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testSafeYaml() throws Exception {
    assertFalse(BrooklynSystemProperties.YAML_TYPE_INSTANTIATION.isEnabled(),
            "Set property to false (or do not set at all): " + BrooklynSystemProperties.YAML_TYPE_INSTANTIATION.getPropertyName());

    try {
        Yamls.parseAll("!!java.util.Date\n" +
                "date: 25\n" +
                "month: 12\n" +
                "year: 2016");
        Asserts.shouldHaveFailedPreviously("Expected exception: " + ConstructorException.class.getCanonicalName());
    } catch(ConstructorException e) {
        Asserts.expectedFailureContains(e, "could not determine a constructor");
    }
}