Package org.springframework.core.io

Examples of org.springframework.core.io.ByteArrayResource


    });
  }

  @Test
  public void integerKeyBehaves() {
    this.processor.setResources(new ByteArrayResource(
        "foo: bar\n1: bar".getBytes()));
    this.processor.process(new MatchCallback() {
      @Override
      public void process(Properties properties, Map<String, Object> map) {
        assertEquals("bar", properties.get("[1]"));
View Full Code Here


    });
  }

  @Test
  public void integerDeepKeyBehaves() {
    this.processor.setResources(new ByteArrayResource(
        "foo:\n  1: bar".getBytes()));
    this.processor.process(new MatchCallback() {

      @Override
      public void process(Properties properties, Map<String, Object> map) {
View Full Code Here

    assertEquals(0, this.factory.getObject().size());
  }

  @Test
  public void testGetObject() throws Exception {
    this.factory.setResources(new ByteArrayResource[] {new ByteArrayResource(
        "foo: bar".getBytes())});
    assertEquals(1, this.factory.getObject().size());
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testOverrideAndremoveDefaults() throws Exception {
    this.factory.setResources(new ByteArrayResource[] {
        new ByteArrayResource("foo:\n  bar: spam".getBytes()),
        new ByteArrayResource("foo:\n  spam: bar".getBytes())});
    assertEquals(1, this.factory.getObject().size());
    assertEquals(2,
        ((Map<String, Object>) this.factory.getObject().get("foo")).size());
  }
View Full Code Here

      @Override
      public InputStream getInputStream() throws IOException {
        throw new IOException("planned");
      }
    }, new ByteArrayResource("foo:\n  spam: bar".getBytes()));
    assertEquals(1, this.factory.getObject().size());
  }
View Full Code Here

    assertEquals(1, this.factory.getObject().size());
  }

  @Test
  public void testMapWithPeriodsInKey() throws Exception {
    this.factory.setResources(new ByteArrayResource[] {new ByteArrayResource(
        "foo:\n  ? key1.key2\n  : value".getBytes())});
    Map<String, Object> map = this.factory.getObject();
    assertEquals(1, map.size());
    assertTrue(map.containsKey("foo"));
    Object object = map.get("foo");
View Full Code Here

    assertEquals("value", sub.get("key1.key2"));
  }

  @Test(expected = ParserException.class)
  public void testDuplicateKey() throws Exception {
    this.factory.setResources(new ByteArrayResource[] {new ByteArrayResource(
        "mymap:\n  foo: bar\nmymap:\n  bar: foo".getBytes())});
    this.factory.getObject().get("mymap");
  }
View Full Code Here

  @Override
  protected Resource readInternal(Class<? extends Resource> clazz, HttpInputMessage inputMessage)
      throws IOException, HttpMessageNotReadableException {

    byte[] body = StreamUtils.copyToByteArray(inputMessage.getBody());
    return new ByteArrayResource(body);
  }
View Full Code Here

    // Must now report back as having been modified
    assertTrue("ResourceScriptSource must report back as being modified if the underlying File resource is reporting a changed lastModified time.", scriptSource.isModified());
  }

  public void testLastModifiedWorksWithResourceThatDoesNotSupportFileBasedAccessAtAll() throws Exception {
    Resource resource = new ByteArrayResource(new byte[0]);
    ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
    assertTrue("ResourceScriptSource must start off in the 'isModified' state (it obviously isn't).", scriptSource.isModified());
    scriptSource.getScriptAsString();
    assertFalse("ResourceScriptSource must not report back as being modified if the underlying File resource is not reporting a changed lastModified time.", scriptSource.isModified());
    // Must now continue to report back as not having been modified 'cos the Resource does not support access as a File (and so the lastModified date cannot be determined).
View Full Code Here

  public ExpectedException exception = ExpectedException.none();

  @Test
  public void testLoadResource() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource(
        "foo: bar\nspam:\n  foo: baz".getBytes()));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo"), equalTo("bar"));
    assertThat(properties.getProperty("spam.foo"), equalTo("baz"));
  }
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.