Java 类org.yaml.snakeyaml.constructor.ConstructorException 实例源码

项目:cloud-slang    文件:ParserExceptionHandler.java   
public String getErrorMessage(Throwable e) {
    String errorMessage = e.getMessage();
    if (e instanceof ScannerException &&
            (errorMessage.startsWith(MAPPING_VALUES_NOT_ALLOWED_HERE_ERROR) ||
                    errorMessage.startsWith(SCANNING_A_SIMPLE_KEY_ERROR))) {
        errorMessage += KEY_VALUE_PAIR_MISSING_OR_INDENTATION_PROBLEM_MSG;
    } else if (e instanceof ConstructorException && errorMessage.startsWith(CANNOT_CREATE_PROPERTY_ERROR)) {
        if (errorMessage.contains(UNABLE_TO_FIND_PROPERTY_ERROR)) {
            //parse for undefined property name
            String truncatedErrorMessage = errorMessage.substring(errorMessage.indexOf(TRUNCATION_BEGINNING),
                    errorMessage.indexOf(TRUNCATION_END));
            String undefinedProperty = truncatedErrorMessage.substring(truncatedErrorMessage.indexOf("\'") + 1,
                    truncatedErrorMessage.lastIndexOf("\'"));
            errorMessage += "Property \'" + undefinedProperty + "\' is not supported by CloudSlang. Check that \'" +
                    undefinedProperty + "\' is indented properly.";

        } else if (errorMessage.contains(MAP_CONSTRUCTOR_NOT_FOUND_ERROR)) {
            errorMessage += KEY_VALUE_PAIR_MISSING_OR_INDENTATION_PROBLEM_MSG;
        }
    }
    return errorMessage;
}
项目:snake-yaml    文件:PrimitiveArrayTest.java   
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());
    }
}
项目:playdoh    文件:YamlModelReaderTest.java   
@Test
public void testYamlThrowsConstructorExceptionShouldThrowIllegalArgumentException() {
    Yaml mockYaml = mock(Yaml.class);
    when(mockYaml.loadAs(anyString(), Matchers.<Class<Object>>anyObject())).thenThrow(ConstructorException.class);
    reader.setYaml(mockYaml);

    reader.read(User.class);
}
项目:snakeyaml    文件:PrimitiveArrayTest.java   
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());
    }
}
项目:kalibro    文件:SettingsAcceptanceTest.java   
@Test
public void shouldThrowExceptionWhenCannotLoadSettings() throws IOException {
    shouldLoadWithError(FileNotFoundException.class);

    FileUtils.writeStringToFile(settingsFile, "something weird");
    shouldLoadWithError(ConstructorException.class);

    settings.save();
    settingsFile.setReadable(false);
    shouldLoadWithError(FileNotFoundException.class);
}
项目:OpenChatAlytics    文件:YamlUtilsTest.java   
@Test(expected = ConstructorException.class)
public void testReadYamlFromResource_badResource() {
    YamlUtils.readChatAlyticsConfig("config/bad-config.yaml");
}
项目:srcdeps-core    文件:YamlConfigurationIoTest.java   
@Test(expected = ConstructorException.class)
public void readBadVersion() throws ConfigurationException, UnsupportedEncodingException, IOException {
    try (Reader in = new InputStreamReader(getClass().getResourceAsStream("/srcdeps-bad-version.yaml"), "utf-8")) {
        new YamlConfigurationIo().read(in);
    }
}