1 package org.onap.config.type;
3 import com.google.common.collect.ImmutableMap;
5 import org.onap.config.NonConfigResource;
8 import java.net.MalformedURLException;
9 import java.net.URISyntaxException;
11 import java.nio.file.Path;
12 import java.nio.file.Paths;
15 import static org.junit.Assert.assertNull;
16 import static org.junit.Assert.assertTrue;
18 public class NonConfigResourceTest {
20 private final URL sampleUrlResource = NonConfigResourceTest.class.getResource("NonConfigResourceTest.class");
21 private final String sampleResourcePath = sampleUrlResource.getPath();
22 private final File sampleResourceFile = new File(sampleResourcePath);
25 public void testShouldLocateResourceWhenAbsPathProvided2() {
26 Map<String, String> properties = ImmutableMap.of();
27 Path actualResourcePath = NonConfigResource.create(properties::get).locate(sampleResourceFile.toString());
29 assertTrue(actualResourcePath.compareTo(sampleResourceFile.toPath()) == 0);
33 public void testShouldLocateResourceWhenPresentInFiles2() {
34 Map<String, String> properties = ImmutableMap.of();
35 NonConfigResource testedObject = NonConfigResource.create(properties::get);
36 testedObject.add(sampleResourceFile);
38 Path thisFilePath = testedObject.locate("NonConfigResourceTest.class");
40 assertTrue(thisFilePath.compareTo(sampleResourceFile.toPath()) == 0);
44 public void testShouldLocateResourceWhenNodeConfigPropertyIsSet2() throws URISyntaxException, MalformedURLException {
45 Map<String, String> properties = ImmutableMap.of("node.config.location", new File(sampleResourcePath).getParentFile().getPath());
46 NonConfigResource testedNonConfigResource = NonConfigResource.create(properties::get);
47 System.getProperties().setProperty("node.config.location", new File(sampleResourcePath).getParentFile().getPath());
48 Path thisFilePath = testedNonConfigResource.locate("NonConfigResourceTest.class");
50 assertTrue(thisFilePath.compareTo(new File(sampleResourcePath).toPath()) == 0);
54 public void testShouldLocateResourceWhenConfigPropertyIsSet2() {
55 Map<String, String> properties = ImmutableMap.of("config.location", new File(sampleResourcePath).getParentFile().getPath());
56 NonConfigResource testedNonConfigResource = NonConfigResource.create(properties::get);
57 Path thisFilePath = testedNonConfigResource.locate("NonConfigResourceTest.class");
59 assertTrue(thisFilePath.compareTo(new File(sampleResourcePath).toPath()) == 0);
63 public void testShouldLocatePathWhenResourcePresentInUrls2() throws URISyntaxException {
64 Map<String, String> properties = ImmutableMap.of();
65 NonConfigResource testedObject = NonConfigResource.create(properties::get);
66 testedObject.add(sampleUrlResource);
68 Path thisFilePath = testedObject.locate("NonConfigResourceTest.class");
70 assertTrue(thisFilePath.compareTo(Paths.get(sampleUrlResource.toURI())) == 0);
74 public void testShouldNotLocateResource2() throws URISyntaxException {
75 Map<String, String> properties = ImmutableMap.of();
76 NonConfigResource testedObject = NonConfigResource.create(properties::get);
78 Path thisFilePath = testedObject.locate("nonexistingresource");
80 assertNull(thisFilePath);