Package org.springframework.core.io

Examples of org.springframework.core.io.ByteArrayResource


  }

  @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();
  }
View Full Code Here


  @Test
  public void testLoadResourcesWithOverride() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(
        new ByteArrayResource("foo: bar\nspam:\n  foo: baz".getBytes()),
        new ByteArrayResource("foo:\n  bar: spam".getBytes()));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo"), equalTo("bar"));
    assertThat(properties.getProperty("spam.foo"), equalTo("baz"));
    assertThat(properties.getProperty("foo.bar"), equalTo("spam"));
  }
View Full Code Here

  }

  @Test
  public void testLoadResourcesWithInternalOverride() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource(
        "foo: bar\nspam:\n  foo: baz\nfoo: bucket".getBytes()));
    exception.expect(ParserException.class);
    factory.getObject();
  }
View Full Code Here

  @Test
  @Ignore("We can't fail on duplicate keys because the Map is created by the YAML library")
  public void testLoadResourcesWithNestedInternalOverride() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource(
        "foo:\n  bar: spam\n  foo: baz\nbreak: it\nfoo: bucket".getBytes()));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo.bar"), equalTo("spam"));
  }
View Full Code Here

  }

  @Test
  public void testLoadResourceWithMultipleDocuments() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource(
        "foo: bar\nspam: baz\n---\nfoo: bag".getBytes()));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo"), equalTo("bag"));
    assertThat(properties.getProperty("spam"), equalTo("baz"));
  }
View Full Code Here

  }

  @Test
  public void testLoadResourceWithSelectedDocuments() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource(
        "foo: bar\nspam: baz\n---\nfoo: bag\nspam: bad".getBytes()));
    factory.setDocumentMatchers(new DocumentMatcher() {
      @Override
      public MatchStatus matches(Properties properties) {
        return "bag".equals(properties.getProperty("foo")) ? MatchStatus.FOUND
View Full Code Here

  @Test
  public void testLoadResourceWithDefaultMatch() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setMatchDefault(true);
    factory.setResources(new ByteArrayResource(
        "one: two\n---\nfoo: bar\nspam: baz\n---\nfoo: bag\nspam: bad".getBytes()));
    factory.setDocumentMatchers(new DocumentMatcher() {
      @Override
      public MatchStatus matches(Properties properties) {
        if (!properties.containsKey("foo")) {
View Full Code Here

  @Test
  public void testLoadResourceWithoutDefaultMatch() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setMatchDefault(false);
    factory.setResources(new ByteArrayResource(
        "one: two\n---\nfoo: bar\nspam: baz\n---\nfoo: bag\nspam: bad".getBytes()));
    factory.setDocumentMatchers(new DocumentMatcher() {
      @Override
      public MatchStatus matches(Properties properties) {
        if (!properties.containsKey("foo")) {
View Full Code Here

  @Test
  public void testLoadResourceWithDefaultMatchSkippingMissedMatch() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setMatchDefault(true);
    factory.setResources(new ByteArrayResource(
        "one: two\n---\nfoo: bag\nspam: bad\n---\nfoo: bar\nspam: baz".getBytes()));
    factory.setDocumentMatchers(new DocumentMatcher() {
      @Override
      public MatchStatus matches(Properties properties) {
        if (!properties.containsKey("foo")) {
View Full Code Here

  }

  @Test
  public void testLoadNull() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource("foo: bar\nspam:"
        .getBytes()));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo"), equalTo("bar"));
    assertThat(properties.getProperty("spam"), equalTo(""));
  }
View Full Code Here

TOP

Related Classes of org.springframework.core.io.ByteArrayResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.