1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
48
49 @Category(Integration.class)
50 public class FileSystemPropertySinkTest
51 {
52
53
54
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
67
68 @Uut
69 private FileSystemPropertySink uut;
70
71 @Rule
72 public TemporaryFolder targetFolder = new TemporaryFolder();
73
74 private File targetDir;
75
76
77
78
79
80
81
82 @Before
83 public void setUp()
84 {
85 this.targetDir = targetFolder.getRoot();
86 this.uut = new FileSystemPropertySink(targetDir, PropertiesFormat.XML);
87 }
88
89
90
91
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 }