-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#87 : API: support SPI for net.cactusthorn.config.core.loader.Loader
- Loading branch information
Showing
6 changed files
with
115 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
core/src/main/resources/META-INF/services/net.cactusthorn.config.core.loader.Loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
net.cactusthorn.config.core.loader.standard.ClasspathJarManifestLoader | ||
net.cactusthorn.config.core.loader.standard.ClasspathPropertiesLoader | ||
net.cactusthorn.config.core.loader.standard.ClasspathXMLLoader | ||
net.cactusthorn.config.core.loader.standard.SystemEnvLoader | ||
net.cactusthorn.config.core.loader.standard.SystemPropertiesLoader | ||
net.cactusthorn.config.core.loader.standard.UrlPropertiesLoader | ||
net.cactusthorn.config.core.loader.standard.UrlXMLLoader |
39 changes: 39 additions & 0 deletions
39
tests/src/main/java/net/cactusthorn/config/tests/loader/SinglePropertyLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2021, Alexei Khatskevich | ||
* | ||
* Licensed under the BSD 3-Clause license. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://github.com/Gmugra/net.cactusthorn.config/blob/main/LICENSE | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package net.cactusthorn.config.tests.loader; | ||
|
||
import java.net.URI; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import net.cactusthorn.config.core.loader.Loader; | ||
|
||
public class SinglePropertyLoader implements Loader { | ||
|
||
@Override public boolean accept(URI uri) { | ||
return uri.toString().equals("single:property"); | ||
} | ||
|
||
@Override public Map<String, String> load(URI uri, ClassLoader classLoader) { | ||
Map<String, String> result = new HashMap<>(); | ||
result.put("key", "value"); | ||
return result; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
tests/src/main/resources/META-INF/services/net.cactusthorn.config.core.loader.Loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
net.cactusthorn.config.tests.loader.SinglePropertyLoader |
56 changes: 56 additions & 0 deletions
56
tests/src/test/java/net/cactusthorn/config/tests/loader/SinglePropertyLoaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2021, Alexei Khatskevich | ||
* | ||
* Licensed under the BSD 3-Clause license. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://github.com/Gmugra/net.cactusthorn.config/blob/main/LICENSE | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package net.cactusthorn.config.tests.loader; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import net.cactusthorn.config.core.ConfigFactory; | ||
import net.cactusthorn.config.core.loader.ConfigHolder; | ||
import net.cactusthorn.config.core.loader.Loader; | ||
|
||
public class SinglePropertyLoaderTest { | ||
|
||
private static final Loader LOADER = new SinglePropertyLoader(); | ||
private static final ClassLoader CL = SinglePropertyLoaderTest.class.getClassLoader(); | ||
private static final URI SPURI = URI.create("single:property"); | ||
|
||
@Test public void accept() { | ||
assertTrue(LOADER.accept(SPURI)); | ||
} | ||
|
||
@Test public void notAccept() { | ||
assertFalse(LOADER.accept(URI.create("classpath://a.properties"))); | ||
} | ||
|
||
@Test public void load() { | ||
Map<String, String> values = LOADER.load(SPURI, CL); | ||
assertEquals("value", values.get("key")); | ||
} | ||
|
||
@Test public void loadFactory() { | ||
ConfigHolder holder = ConfigFactory.builder().addSource("single:property").build().configHolder(); | ||
assertEquals("value", holder.getString("key")); | ||
} | ||
} |