View Javadoc

1   /*
2    * Copyright 2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package test.de.smartics.properties.resource.filesystem;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.is;
20  import static org.hamcrest.Matchers.not;
21  import static org.hamcrest.Matchers.endsWith;
22  import static org.hamcrest.Matchers.emptyCollectionOf;
23  
24  import java.io.File;
25  import java.net.URL;
26  import java.util.Collection;
27  
28  import org.junit.Before;
29  import org.junit.Test;
30  
31  import de.smartics.properties.resource.domain.ClassPathEnvironment;
32  import de.smartics.properties.resource.filesystem.heap.FileSystemResourceHeap;
33  import de.smartics.testdoc.annotations.Uut;
34  import de.smartics.util.test.io.FileTestUtils;
35  
36  /**
37   * Tests {@link FileSystemResourceHeap}.
38   */
39  public class FileSystemResourceHeapTest
40  {
41    // ********************************* Fields *********************************
42  
43    // --- constants ------------------------------------------------------------
44  
45    // --- members --------------------------------------------------------------
46  
47    @Uut
48    private FileSystemResourceHeap uut;
49  
50    // ****************************** Inner Classes *****************************
51  
52    // ********************************* Methods ********************************
53  
54    // --- prepare --------------------------------------------------------------
55  
56    @Before
57    public void setUp()
58    {
59      uut = new FileSystemResourceHeap();
60    }
61  
62    // --- helper ---------------------------------------------------------------
63  
64    // --- tests ----------------------------------------------------------------
65  
66    @Test
67    public void ableToDealWithNoRootDirectory()
68    {
69      final ClassPathEnvironment env = uut.resolve();
70      assertThat((Collection<URL>) env.getUrls(),
71          is(emptyCollectionOf(URL.class)));
72    }
73  
74    @Test
75    public void ableToDealWithEmptyDirectories()
76    {
77      final File dir = FileTestUtils.getFileFromResource("fs/empty");
78  
79      final FileSystemResourceHeap uut = new FileSystemResourceHeap();
80      uut.addRootFolder(dir);
81      final ClassPathEnvironment env = uut.resolve();
82      assertThat((Collection<URL>) env.getUrls(),
83          is(emptyCollectionOf(URL.class)));
84    }
85  
86    @Test
87    public void ableToDealWithJars()
88    {
89      final File dir = FileTestUtils.getFileFromResource("fs/jar");
90  
91      final FileSystemResourceHeap uut = new FileSystemResourceHeap();
92      uut.addRootFolder(dir);
93      final ClassPathEnvironment env = uut.resolve();
94      assertThat((Collection<URL>) env.getUrls(),
95          is(not(emptyCollectionOf(URL.class))));
96    }
97  
98    @Test
99    public void ableToDealWithPropertiesFolder()
100   {
101     final File dir = FileTestUtils.getFileFromResource("fs/properties");
102 
103     final FileSystemResourceHeap uut = new FileSystemResourceHeap();
104     uut.addRootFolder(dir);
105     final ClassPathEnvironment env = uut.resolve();
106     assertThat((Collection<URL>) env.getUrls(),
107         is(not(emptyCollectionOf(URL.class))));
108     assertThat(env.getUrls().get(0).toExternalForm(),
109         is(not(endsWith(".properties"))));
110   }
111 }