http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/MapPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/MapPropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/MapPropertySourceTest.java new file mode 100644 index 0000000..5624ed4 --- /dev/null +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/MapPropertySourceTest.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.spisupport.propertysource; + +import org.apache.tamaya.spisupport.propertysource.MapPropertySource; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import static org.assertj.core.api.Assertions.assertThat; + +public class MapPropertySourceTest { + + private Map<String,String> sourceMap; + private Properties sourceProperties; + + @Before + public void createMapAndProperties() throws Exception { + sourceMap = new HashMap<>(); + sourceMap.put("a", "AAA"); + sourceMap.put("b", "BBB"); + + sourceProperties = new Properties(); + sourceProperties.setProperty("a", "AAA"); + sourceProperties.setProperty("b", "BBB"); + } + + @Test + public void sourceWillProperlyInitializedWithMapWithoutPrefix() throws Exception { + MapPropertySource propertySource = new MapPropertySource("UT", sourceMap); + + assertThat(propertySource.getProperties()).describedAs("Should contain exactly 2 properties.") + .hasSize(2); + assertThat(propertySource.get("a")).isNotNull(); + assertThat(propertySource.get("b")).isNotNull(); + } + + @Test + public void sourceWillProperlyInitializedWithMapWithPrefix() throws Exception { + MapPropertySource propertySource = new MapPropertySource("UT", sourceMap, "pre-"); + + assertThat(propertySource.getProperties()).describedAs("Should contain exactly 2 properties.") + .hasSize(2); + assertThat(propertySource.get("pre-a")).isNotNull(); + assertThat(propertySource.get("pre-b")).isNotNull(); + } + + @Test + public void sourceWillProperlyInitializedWithPropertiesWithPrefix() throws Exception { + MapPropertySource propertySource = new MapPropertySource("UT", sourceProperties, "pre-"); + + assertThat(propertySource.getProperties()).describedAs("Should contain exactly 2 properties.") + .hasSize(2); + assertThat(propertySource.get("pre-a")).isNotNull(); + assertThat(propertySource.get("pre-b")).isNotNull(); + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesFilePropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesFilePropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesFilePropertySourceTest.java new file mode 100644 index 0000000..da51740 --- /dev/null +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesFilePropertySourceTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.spisupport.propertysource; + +import org.apache.tamaya.spisupport.propertysource.SimplePropertySource; +import org.apache.tamaya.spi.PropertySource; +import org.junit.Assert; +import org.junit.Test; + +public class PropertiesFilePropertySourceTest { + + private final SimplePropertySource testfilePropertySource = new SimplePropertySource(Thread.currentThread() + .getContextClassLoader().getResource("testfile.properties")); + private final SimplePropertySource overrideOrdinalPropertySource = new SimplePropertySource( + Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties")); + + + @Test + public void testGetOrdinal() { + Assert.assertEquals(0, testfilePropertySource.getOrdinal()); + Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL) + .getValue()), + overrideOrdinalPropertySource.getOrdinal()); + } + + + @Test + public void testGet() { + Assert.assertEquals("val3", testfilePropertySource.get("key3").getValue()); + Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5").getValue()); + Assert.assertNull(testfilePropertySource.get("nonpresentkey")); + } + + + @Test + public void testGetProperties() throws Exception { + Assert.assertEquals(5, testfilePropertySource.getProperties().size()); + Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key1")); + Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key2")); + Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key3")); + Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key4")); + Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key5")); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java new file mode 100644 index 0000000..288b8cd --- /dev/null +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.spisupport.propertysource; + +import org.apache.tamaya.ConfigException; +import org.apache.tamaya.spi.PropertyValue; +import org.junit.Test; + +import java.net.URL; + +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.endsWith; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.startsWith; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.aMapWithSize; +import static org.hamcrest.Matchers.hasEntry; + +public class SimplePropertySourceTest { + @Test + public void successfulCreationWithPropertiesFromXMLPropertiesFile() { + URL resource = getClass().getResource("/valid-properties.xml"); + + SimplePropertySource source = new SimplePropertySource(resource); + + assertThat(source, notNullValue()); + assertThat(source.getProperties(), aMapWithSize(2)); // double the size for .source values. + assertThat(source.getProperties(), hasEntry("a", PropertyValue.of("a", "b", resource.toString()))); + assertThat(source.getProperties(), hasEntry("b", PropertyValue.of("b", "1", resource.toString()))); + + } + + @Test + public void failsToCreateFromNonXMLPropertiesXMLFile() { + URL resource = getClass().getResource("/non-xml-properties.xml"); + ConfigException catchedException = null; + + try { + new SimplePropertySource(resource); + } catch (ConfigException ce) { + catchedException = ce; + } + + assertThat(catchedException.getMessage(), allOf(startsWith("Error loading properties from"), + endsWith("non-xml-properties.xml"))); + } + + @Test + public void failsToCreateFromInvalidPropertiesXMLFile() { + URL resource = getClass().getResource("/invalid-properties.xml"); + ConfigException catchedException = null; + + try { + new SimplePropertySource(resource); + } catch (ConfigException ce) { + catchedException = ce; + } + + assertThat(catchedException.getMessage(), allOf(startsWith("Error loading properties from"), + endsWith("invalid-properties.xml"))); + } + + + @Test + public void successfulCreationWithPropertiesFromSimplePropertiesFile() { + URL resource = getClass().getResource("/testfile.properties"); + + SimplePropertySource source = new SimplePropertySource(resource); + + assertThat(source, notNullValue()); + assertThat(source.getProperties(), aMapWithSize(5)); // double the size for .source values. + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java new file mode 100644 index 0000000..e67630c --- /dev/null +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.spisupport.propertysource; + +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Map; +import java.util.Properties; + +public class SystemPropertySourceTest { + + private final SystemPropertySource testPropertySource = new SystemPropertySource(); + + + @Test + public void testGetOrdinal() throws Exception { + + // test the default ordinal + Assert.assertEquals(SystemPropertySource.DEFAULT_ORDINAL, testPropertySource.getOrdinal()); + + // set the ordinal to 1001 + System.setProperty(PropertySource.TAMAYA_ORDINAL, "1001"); + Assert.assertEquals(1001, new SystemPropertySource().getOrdinal()); + // currently its not possible to change ordinal at runtime + + // reset it to not destroy other tests!! + System.clearProperty(PropertySource.TAMAYA_ORDINAL); + } + + @Test + public void testGetName() throws Exception { + Assert.assertEquals("system-properties", testPropertySource.getName()); + } + + @Test + public void testGet() throws Exception { + String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next(); + + PropertyValue property = testPropertySource.get(propertyKeyToCheck); + Assert.assertNotNull("Property '" + propertyKeyToCheck + "' is not present in " + + SystemPropertySource.class.getSimpleName(), property); + Assert.assertEquals(System.getProperty(propertyKeyToCheck), property.getValue()); + } + + @Test + public void testGetProperties() throws Exception { + checkWithSystemProperties(testPropertySource.getProperties()); + + // modify system properties + System.setProperty("test", "myTestVal"); + + checkWithSystemProperties(testPropertySource.getProperties()); + + // cleanup + System.clearProperty("test"); + } + + private void checkWithSystemProperties(Map<String,PropertyValue> toCheck) { + Properties systemEntries = System.getProperties(); + int num = 0; + for (PropertyValue propertySourceEntry : toCheck.values()) { + if(propertySourceEntry.getKey().startsWith("_")){ + continue; // meta entry + } + num ++; + Assert.assertEquals("Entry values for key '" + propertySourceEntry.getKey() + "' do not match", + systemEntries.getProperty(propertySourceEntry.getKey()), propertySourceEntry.getValue()); + } + Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()", + systemEntries.size(), num); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java new file mode 100644 index 0000000..b326abc --- /dev/null +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.spisupport.propertysource; + +import org.apache.tamaya.spisupport.propertysource.BasePropertySource; +import org.apache.tamaya.spi.PropertyValue; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * Test provider reading properties from classpath:cfg/defaults/**.properties. + */ +public class TestPropertyDefaultSource extends BasePropertySource{ + + private Map<String,PropertyValue> properties = new HashMap<>(); + + public TestPropertyDefaultSource() { + super(100); + properties.put("name",PropertyValue.of("name", "Anatole", "Test")); + properties.put("name2",PropertyValue.of("name2", "Sabine", "Test")); + properties = Collections.unmodifiableMap(properties); + } + + @Override + public String getName() { + return "default-testdata-properties"; + } + + @Override + public Map<String, PropertyValue> getProperties() { + return properties; + } + + @Override + public boolean isScannable() { + return true; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java new file mode 100644 index 0000000..46d69da --- /dev/null +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java @@ -0,0 +1,205 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.spisupport.services; + +import org.apache.tamaya.ConfigException; +import org.apache.tamaya.spi.ServiceContext; +import org.apache.tamaya.spisupport.PriorityServiceComparator; + +import javax.annotation.Priority; +import java.io.IOException; +import java.net.URL; +import java.text.MessageFormat; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * This class implements the (default) {@link ServiceContext} interface and hereby uses the JDK + * {@link ServiceLoader} to load the services required. + */ +public final class DefaultServiceContext implements ServiceContext { + private static final Logger LOG = Logger.getLogger(DefaultServiceContext.class.getName()); + /** + * List current services loaded, per class. + */ + private final ConcurrentHashMap<Class<?>, List<Object>> servicesLoaded = new ConcurrentHashMap<>(); + /** + * Singletons. + */ + private final Map<Class<?>, Object> singletons = new ConcurrentHashMap<>(); + @SuppressWarnings("rawtypes") + private Map<Class, Class> factoryTypes = new ConcurrentHashMap<>(); + + @Override + public <T> T getService(Class<T> serviceType) { + Object cached = singletons.get(serviceType); + if (cached == null) { + cached = create(serviceType); + if(cached!=null) { + singletons.put(serviceType, cached); + } + } + return serviceType.cast(cached); + } + + @Override + public <T> T create(Class<T> serviceType) { + @SuppressWarnings("unchecked") + Class<? extends T> implType = factoryTypes.get(serviceType); + if(implType==null) { + Collection<T> services = getServices(serviceType); + if (services.isEmpty()) { + return null; + } else { + return getServiceWithHighestPriority(services, serviceType); + } + } + try { + return implType.newInstance(); + } catch (Exception e) { + LOG.log(Level.SEVERE, "Failed to create instance of " + implType.getName(), e); + return null; + } + } + + /** + * Loads and registers services. + * + * @param <T> the concrete type. + * @param serviceType The service type. + * @return the items found, never {@code null}. + */ + @Override + public <T> List<T> getServices(final Class<T> serviceType) { + @SuppressWarnings("unchecked") + List<T> found = (List<T>) servicesLoaded.get(serviceType); + if (found != null) { + return found; + } + List<T> services = new ArrayList<>(); + try { + for (T t : ServiceLoader.load(serviceType)) { + services.add(t); + } + if(services.isEmpty()) { + for (T t : ServiceLoader.load(serviceType, serviceType.getClassLoader())) { + services.add(t); + } + } + Collections.sort(services, PriorityServiceComparator.getInstance()); + services = Collections.unmodifiableList(services); + } catch (ServiceConfigurationError e) { + LOG.log(Level.WARNING, + "Error loading services current type " + serviceType, e); + if(services==null){ + services = Collections.emptyList(); + } + } + @SuppressWarnings("unchecked") + final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services)); + return previousServices != null ? previousServices : services; + } + + /** + * Checks the given instance for a @Priority annotation. If present the annotation's value is evaluated. If no such + * annotation is present, a default priority of {@code 1} is returned. + * @param o the instance, not {@code null}. + * @return a priority, by default 1. + */ + public static int getPriority(Object o){ + int prio = 1; //X TODO discuss default priority + Priority priority = o.getClass().getAnnotation(Priority.class); + if (priority != null) { + prio = priority.value(); + } + return prio; + } + + /** + * @param services to scan + * @param <T> type of the service + * + * @return the service with the highest {@link Priority#value()} + * + * @throws ConfigException if there are multiple service implementations with the maximum priority + */ + private <T> T getServiceWithHighestPriority(Collection<T> services, Class<T> serviceType) { + T highestService = null; + // we do not need the priority stuff if the list contains only one element + if (services.size() == 1) { + highestService = services.iterator().next(); + this.factoryTypes.put(serviceType, highestService.getClass()); + return highestService; + } + + Integer highestPriority = null; + int highestPriorityServiceCount = 0; + + for (T service : services) { + int prio = getPriority(service); + if (highestPriority == null || highestPriority < prio) { + highestService = service; + highestPriorityServiceCount = 1; + highestPriority = prio; + } else if (highestPriority == prio) { + highestPriorityServiceCount++; + } + } + + if (highestPriorityServiceCount > 1) { + throw new ConfigException(MessageFormat.format("Found {0} implementations for Service {1} with Priority {2}: {3}", + highestPriorityServiceCount, + serviceType.getName(), + highestPriority, + services)); + } + this.factoryTypes.put(serviceType, highestService.getClass()); + return highestService; + } + + @Override + public int ordinal() { + return 1; + } + + @Override + public Enumeration<URL> getResources(String resource, ClassLoader cl) throws IOException { + if(cl==null){ + cl = Thread.currentThread().getContextClassLoader(); + } + if(cl==null){ + cl = getClass().getClassLoader(); + } + return cl.getResources(resource); + } + + @Override + public URL getResource(String resource, ClassLoader cl) { + if(cl==null){ + cl = Thread.currentThread().getContextClassLoader(); + } + if(cl==null){ + cl = getClass().getClassLoader(); + } + return cl.getResource(resource); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter new file mode 100644 index 0000000..7c62bb2 --- /dev/null +++ b/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter @@ -0,0 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy current the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +org.apache.tamaya.spisupport.CTestConverter \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext new file mode 100644 index 0000000..135caa1 --- /dev/null +++ b/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext @@ -0,0 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy current the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +org.apache.tamaya.spisupport.DefaultServiceContext http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/resources/invalid-properties.xml ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/resources/invalid-properties.xml b/code/spi-support/src/test/resources/invalid-properties.xml new file mode 100644 index 0000000..d8b10b7 --- /dev/null +++ b/code/spi-support/src/test/resources/invalid-properties.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> + <entry key="a"> + <entry key="b">1</entry> +</properties> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/resources/non-xml-properties.xml ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/resources/non-xml-properties.xml b/code/spi-support/src/test/resources/non-xml-properties.xml new file mode 100644 index 0000000..8de819a --- /dev/null +++ b/code/spi-support/src/test/resources/non-xml-properties.xml @@ -0,0 +1,18 @@ +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/resources/overrideOrdinal.properties ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/resources/overrideOrdinal.properties b/code/spi-support/src/test/resources/overrideOrdinal.properties new file mode 100644 index 0000000..c68208a --- /dev/null +++ b/code/spi-support/src/test/resources/overrideOrdinal.properties @@ -0,0 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +#overrideValue ordinal +tamaya.ordinal=16784 + +mykey1=myval1 +mykey2=myval2 +mykey3=myval3 +mykey4=myval4 +mykey5=myval5 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/resources/testfile.properties ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/resources/testfile.properties b/code/spi-support/src/test/resources/testfile.properties new file mode 100644 index 0000000..abd7ee8 --- /dev/null +++ b/code/spi-support/src/test/resources/testfile.properties @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +key1=val1 +key2=val2 +key3=val3 +key4=val4 +key5=val5 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/code/spi-support/src/test/resources/valid-properties.xml ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/resources/valid-properties.xml b/code/spi-support/src/test/resources/valid-properties.xml new file mode 100644 index 0000000..7eb51d9 --- /dev/null +++ b/code/spi-support/src/test/resources/valid-properties.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> + <entry key="a">b</entry> + <entry key="b">1</entry> +</properties> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java ---------------------------------------------------------------------- diff --git a/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java b/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java index b999cb9..aeb44ef 100644 --- a/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java +++ b/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java @@ -40,8 +40,8 @@ import static java.lang.String.format; * or {@code /META-INF/javaconfiguration.xml}. * </p> * - * @see org.apache.tamaya.core.propertysource.EnvironmentPropertySource - * @see org.apache.tamaya.core.propertysource.SystemPropertySource + * @see org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource + * @see org.apache.tamaya.spisupport.propertysource.SystemPropertySource */ public class Main { /* http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java ---------------------------------------------------------------------- diff --git a/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java b/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java index f9fb853..c993eeb 100644 --- a/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java +++ b/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java @@ -19,7 +19,7 @@ package org.apache.tamaya.examples.minimal; import org.apache.tamaya.Configuration; -import org.apache.tamaya.core.internal.DefaultConfigurationProvider; +import org.apache.tamaya.spisupport.DefaultConfigurationProvider; /** * Configuration provider that allows to set and reset a configuration http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java ---------------------------------------------------------------------- diff --git a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java index ebc054d..d21230e 100644 --- a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java +++ b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java @@ -18,7 +18,7 @@ */ package org.apache.tamaya.examples.custompropertysource; -import org.apache.tamaya.core.propertysource.BasePropertySource; +import org.apache.tamaya.spisupport.propertysource.BasePropertySource; import org.apache.tamaya.spi.PropertyValue; import java.io.IOException; http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySourceProvider.java b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySourceProvider.java index 56fecf5..0573fbd 100644 --- a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySourceProvider.java +++ b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySourceProvider.java @@ -18,7 +18,7 @@ */ package org.apache.tamaya.examples.custompropertysource; -import org.apache.tamaya.core.propertysource.SimplePropertySource; +import org.apache.tamaya.spisupport.propertysource.SimplePropertySource; import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertySourceProvider; http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/examples/11-distributed/src/main/java/org/apache/tamaya/examples/distributed/Display.java ---------------------------------------------------------------------- diff --git a/examples/11-distributed/src/main/java/org/apache/tamaya/examples/distributed/Display.java b/examples/11-distributed/src/main/java/org/apache/tamaya/examples/distributed/Display.java index fb95a07..7ba8ad2 100644 --- a/examples/11-distributed/src/main/java/org/apache/tamaya/examples/distributed/Display.java +++ b/examples/11-distributed/src/main/java/org/apache/tamaya/examples/distributed/Display.java @@ -36,8 +36,8 @@ import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.stage.Stage; import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.core.propertysource.EnvironmentPropertySource; -import org.apache.tamaya.core.propertysource.SystemPropertySource; +import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource; +import org.apache.tamaya.spisupport.propertysource.SystemPropertySource; import org.apache.tamaya.functions.ConfigurationFunctions; import org.apache.tamaya.hazelcast.HazelcastPropertySource; import org.apache.tamaya.inject.ConfigurationInjection; http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7917a9f3/examples/11-distributed/src/main/java/org/apache/tamaya/examples/distributed/DisplayManager.java ---------------------------------------------------------------------- diff --git a/examples/11-distributed/src/main/java/org/apache/tamaya/examples/distributed/DisplayManager.java b/examples/11-distributed/src/main/java/org/apache/tamaya/examples/distributed/DisplayManager.java index efd200b..c178cce 100644 --- a/examples/11-distributed/src/main/java/org/apache/tamaya/examples/distributed/DisplayManager.java +++ b/examples/11-distributed/src/main/java/org/apache/tamaya/examples/distributed/DisplayManager.java @@ -37,8 +37,8 @@ import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.stage.Stage; import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.core.propertysource.EnvironmentPropertySource; -import org.apache.tamaya.core.propertysource.SystemPropertySource; +import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource; +import org.apache.tamaya.spisupport.propertysource.SystemPropertySource; import org.apache.tamaya.functions.ConfigurationFunctions; import org.apache.tamaya.hazelcast.HazelcastPropertySource; import org.apache.tamaya.inject.ConfigurationInjection;
