org.yaml.snakeyaml.scanner.ScannerException Java Examples

The following examples show how to use org.yaml.snakeyaml.scanner.ScannerException. 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: YamlDataSetProducerTest.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@Test
public void testProduceDataSetUsingNotYamlStream() throws DataSetException {
    // GIVEN
    final IDataSetConsumer consumer = mock(IDataSetConsumer.class);
    final IDataSetProducer producer = new YamlDataSetProducer(jsonStream);
    producer.setConsumer(consumer);

    // WHEN
    try {
        producer.produce();
        fail("DataSetException expected");
    } catch (final DataSetException e) {
        // THEN
        assertThat(e.getCause(), instanceOf(ScannerException.class));
    }
}
 
Example #2
Source File: YamlBasedPropertiesProvider.java    From cfg4j with Apache License 2.0 6 votes vote down vote up
/**
 * Get {@link Properties} for a given {@code inputStream} treating it as a YAML file.
 *
 * @param inputStream input stream representing YAML file
 * @return properties representing values from {@code inputStream}
 * @throws IllegalStateException when unable to read properties
 */
@Override
public Properties getProperties(InputStream inputStream) {
  requireNonNull(inputStream);

  Yaml yaml = new Yaml();

  Properties properties = new Properties();

  try (Reader reader = new UnicodeReader(inputStream)) {

    Object object = yaml.load(reader);

    if (object != null) {
      Map<String, Object> yamlAsMap = convertToMap(object);
      properties.putAll(flatten(yamlAsMap));
    }

    return properties;

  } catch (IOException | ScannerException e) {
    throw new IllegalStateException("Unable to load yaml configuration from provided stream", e);
  }
}
 
Example #3
Source File: MessageManager.java    From NovaGuilds with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads messages
 *
 * @throws FatalNovaGuildsException when something goes wrong
 */
public void load() throws FatalNovaGuildsException {
	setupDirectories();

	try {
		detectLanguage();
		messages = Lang.loadConfiguration(messagesFile);

		//Fork, edit and compile NovaGuilds on your own if you want not to use the original prefix
		restorePrefix();

		prefix = Message.CHAT_PREFIX.get();
		prefixColor = ChatColor.getByChar(ChatColor.getLastColors(prefix).charAt(1));

		LoggerUtils.info("Messages loaded: " + Config.LANG_NAME.getString());
	}
	catch(ScannerException | IOException e) {
		throw new FatalNovaGuildsException("Failed to load messages", e);
	}
}
 
Example #4
Source File: YamlProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testBadResource() {
	this.processor.setResources(new ByteArrayResource("foo: bar\ncd\nspam:\n  foo: baz".getBytes()));
	assertThatExceptionOfType(ScannerException.class).isThrownBy(() ->
			this.processor.process((properties, map) -> {}))
		.withMessageContaining("line 3, column 1");
}
 
Example #5
Source File: YamlPropertiesFactoryBeanTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testBadResource() {
	YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
	factory.setResources(new ByteArrayResource(
			"foo: bar\ncd\nspam:\n  foo: baz".getBytes()));
	assertThatExceptionOfType(ScannerException.class).isThrownBy(
			factory::getObject)
		.withMessageContaining("line 3, column 1");
}
 
Example #6
Source File: YamlProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testBadResource() {
	this.processor.setResources(new ByteArrayResource("foo: bar\ncd\nspam:\n  foo: baz".getBytes()));
	this.exception.expect(ScannerException.class);
	this.exception.expectMessage("line 3, column 1");
	this.processor.process((properties, map) -> {});
}
 
Example #7
Source File: YamlPropertiesFactoryBeanTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testBadResource() {
	YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
	factory.setResources(new ByteArrayResource(
			"foo: bar\ncd\nspam:\n  foo: baz".getBytes()));
	this.exception.expect(ScannerException.class);
	this.exception.expectMessage("line 3, column 1");
	factory.getObject();
}
 
Example #8
Source File: YamlProcessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testBadResource() throws Exception {
	this.processor.setResources(new ByteArrayResource(
			"foo: bar\ncd\nspam:\n  foo: baz".getBytes()));
	this.exception.expect(ScannerException.class);
	this.exception.expectMessage("line 3, column 1");
	this.processor.process(new MatchCallback() {
		@Override
		public void process(Properties properties, Map<String, Object> map) {
		}
	});
}
 
Example #9
Source File: YamlPropertiesFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testBadResource() throws Exception {
	YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
	factory.setResources(new ByteArrayResource(
			"foo: bar\ncd\nspam:\n  foo: baz".getBytes()));
	this.exception.expect(ScannerException.class);
	this.exception.expectMessage("line 3, column 1");
	factory.getObject();
}
 
Example #10
Source File: ParseConfigException.java    From halyard with Apache License 2.0 5 votes vote down vote up
public ParseConfigException(ScannerException e) {
  Problem problem =
      new ConfigProblemBuilder(
              Problem.Severity.FATAL, "Could not parse your halconfig: " + e.getMessage())
          .build();
  getProblems().add(problem);
}
 
Example #11
Source File: ClusterDefinitionService.java    From karamel with Apache License 2.0 5 votes vote down vote up
public static YamlCluster yamlToYamlObject(String ymlString) throws KaramelException {
  try {
    Yaml yaml = new Yaml(new Constructor(YamlCluster.class));
    Object document = yaml.load(ymlString);
    return ((YamlCluster) document);
  } catch (ScannerException ex) {
    throw new KaramelException("Syntax error in the yaml!!", ex);
  }
}
 
Example #12
Source File: YAMLException.java    From restcommander with Apache License 2.0 4 votes vote down vote up
public YAMLException(ScannerException e, VirtualFile yaml) {
    super(e.getMessage() + " (in file " + yaml.relativePath() + " line " + (e.getProblemMark().getLine() + 1) + ", column " + (e.getProblemMark().getColumn() + 1) + ")", e);
    this.e = e;
    this.yaml = yaml;
}