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.transfer;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.endsWith;
20  import static org.hamcrest.Matchers.hasSize;
21  import static org.hamcrest.Matchers.is;
22  
23  import java.io.File;
24  import java.util.Arrays;
25  
26  import org.junit.Before;
27  import org.junit.Rule;
28  import org.junit.Test;
29  import org.junit.experimental.categories.Category;
30  import org.junit.rules.TemporaryFolder;
31  
32  import de.smartics.properties.api.config.domain.key.ApplicationId;
33  import de.smartics.properties.api.config.domain.key.ConfigurationKey;
34  import de.smartics.properties.api.config.domain.key.EnvironmentId;
35  import de.smartics.properties.config.transfer.filesystem.FileSystemPropertySink;
36  import de.smartics.properties.config.transfer.filesystem.PropertiesFormat;
37  import de.smartics.properties.impl.config.domain.key.envapp.EnvAppConfigurationKeyBuilder;
38  import de.smartics.properties.impl.config.domain.key.rtaware.TenantUserDefinitionConfigParser;
39  import de.smartics.properties.resource.domain.ClassPathEnvironment;
40  import de.smartics.properties.resource.filesystem.heap.FileSystemResourceHeap;
41  import de.smartics.properties.spi.config.transfer.PropertyProviderList;
42  import de.smartics.testdoc.annotations.Uut;
43  import de.smartics.testdoc.categories.type.Integration;
44  import de.smartics.util.test.io.FileTestUtils;
45  
46  /**
47   * Tests {@link FileSystemPropertySink}.
48   */
49  @Category(Integration.class)
50  public class FileSystemPropertySinkTest
51  {
52    // ********************************* Fields *********************************
53  
54    // --- constants ------------------------------------------------------------
55  
56    public static final EnvironmentId ENV = new EnvironmentId("test");
57  
58    public static final ApplicationId APP = new ApplicationId("group",
59        "artifactId", "1.0");
60  
61    public static final ConfigurationKey<?> KEY =
62        new EnvAppConfigurationKeyBuilder().withEnvironmentName(ENV.getName())
63            .withGroupId(APP.getGroupId()).withArtifactId(APP.getArtifactId())
64            .withVersion(APP.getVersion()).build();
65  
66    // --- members --------------------------------------------------------------
67  
68    @Uut
69    private FileSystemPropertySink uut;
70  
71    @Rule
72    public TemporaryFolder targetFolder = new TemporaryFolder();
73  
74    private File targetDir;
75  
76    // ****************************** Inner Classes *****************************
77  
78    // ********************************* Methods ********************************
79  
80    // --- prepare --------------------------------------------------------------
81  
82    @Before
83    public void setUp()
84    {
85      this.targetDir = targetFolder.getRoot();
86      this.uut = new FileSystemPropertySink(targetDir, PropertiesFormat.XML);
87    }
88  
89    // --- helper ---------------------------------------------------------------
90  
91    // --- tests ----------------------------------------------------------------
92  
93    @Test
94    public void storesFilesInTargetFolder()
95    {
96      final File dir = FileTestUtils.getFileFromResource("fs/jar");
97      final FileSystemResourceHeap heap = new FileSystemResourceHeap();
98      heap.addRootFolder(dir);
99      final ClassPathEnvironment env = heap.resolve();
100 
101     final PropertyProviderList list = new PropertyProviderList();
102     final TenantUserDefinitionConfigParser parser =
103         new TenantUserDefinitionConfigParser();
104     list.addPropertyDefinitions(parser, env);
105     uut.write(list);
106 
107     final File propertiesFolder =
108         new File(targetDir,
109             "de.smartics.sandbox/test-application-1-config/0.1.0");
110     assertThat(propertiesFolder.exists(), is(true));
111     final File[] files = propertiesFolder.listFiles();
112     assertThat(Arrays.asList(files), is(hasSize(4)));
113     assertThat(files[0].getName(), endsWith(".xml"));
114   }
115 }