Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 Objectos, Fábrica de Software LTDA.
   *
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
   * use this file except in compliance with the License. You may obtain a copy of
   * the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  * License for the specific language governing permissions and limitations under
  * the License.
  */
 package br.com.objectos.way.etc;
 
 import static br.com.objectos.way.base.testing.WayMatchers.equalTo;
 import static br.com.objectos.way.base.testing.WayMatchers.hasContentsEqualTo;
 import static org.hamcrest.MatcherAssert.assertThat;
 
 import java.io.File;
 import java.util.List;
 
 

Author(s):
marcio.endo@objectos.com.br (Marcio Endo)
 
 public class WayEtcResourcesTest {
 
   private File dir;
 
   public void setUp() {
      = new File("/tmp/wetc/resources");
   }
 
   public void clean() {
     .mkdirs();
     Directories.rm_rf();
   }
 
   public void copy() {
     WayEtc.resourcesAt()
         .copyTo();
 
     List<Fileres = Directories.listFiles();
     assertThat(res.size(), equalTo(0));
   }
 
   public void copy_selection() {
     WayEtc.resourcesAt()
         .add("/tmpl/etc/user")
         .copyTo();
 
     List<Fileres = Directories.listFiles();
     assertThat(res.size(), equalTo(1));
 
     File r0 = res.get(0);
     assertThat(r0.getPath(), equalTo("/tmp/wetc/resources/tmpl/etc/user"));
     assertThat(r0hasContentsEqualTo("/tmpl/etc/user"));
   }
 
   public void copy_file_list() {
     WayEtc.resourcesAt()
         .addFromListAt("/resources-file-list.txt")
         .copyTo();
 
     List<Fileres = Directories.listFiles();
     assertThat(res.size(), equalTo(2));
 
     assertThat(res.get(0).getPath(), equalTo("/tmp/wetc/resources/tmpl/etc/host"));
     assertThat(res.get(1).getPath(), equalTo("/tmp/wetc/resources/tmpl/etc/user"));
   }
 
   public void copy_selection_and_file_list() {
     WayEtc.resourcesAt()
         .addFromListAt("/resources-file-list.txt")
         .add("/tmpl/conf.d/service")
         .copyTo();
 
     List<Fileres = Directories.listFiles();
     assertThat(res.size(), equalTo(3));
 
     assertThat(res.get(0).getPath(), equalTo("/tmp/wetc/resources/tmpl/conf.d/service"));
     assertThat(res.get(1).getPath(), equalTo("/tmp/wetc/resources/tmpl/etc/host"));
     assertThat(res.get(2).getPath(), equalTo("/tmp/wetc/resources/tmpl/etc/user"));
   }
 
   public void copy_with_basedir() {
    WayEtc.resourcesAt("/tmpl")
        .add("/conf.d/service")
        .add("/etc/host")
        .add("/etc/user")
        .copyTo();
    List<Fileres = Directories.listFiles();
    assertThat(res.size(), equalTo(3));
    assertThat(res.get(0).getPath(), equalTo("/tmp/wetc/resources/conf.d/service"));
    assertThat(res.get(1).getPath(), equalTo("/tmp/wetc/resources/etc/host"));
    assertThat(res.get(2).getPath(), equalTo("/tmp/wetc/resources/etc/user"));
  }
  public void filter_contents() {
    Global global = .;
    WayEtc.resourcesAt()
        .add("/tmpl/etc/user")
        .evalWith(global)
        .copyTo();
    List<Fileres = Directories.listFiles();
    assertThat(res.size(), equalTo(1));
    File r0 = res.get(0);
    assertThat(r0.getPath(), equalTo("/tmp/wetc/resources/tmpl/etc/user"));
    assertThat(r0hasContentsEqualTo("/eval/etc/user"));
  }
  public void filter_contents_with_list() {
    Global global = .;
    WayEtc.resourcesAt()
        .addFromListAt("/resources-file-list.txt")
        .evalWith(global)
        .only("/tmpl/etc/host")
        .copyTo();
    List<Fileres = Directories.listFiles();
    assertThat(res.size(), equalTo(2));
    assertThat(res.get(0), hasContentsEqualTo("/eval/etc/host"));
    assertThat(res.get(1), hasContentsEqualTo("/tmpl/etc/user"));
  }
New to GrepCode? Check out our FAQ X