You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2019/09/10 23:30:58 UTC
[incubator-tamaya-sandbox] 01/01: Added missing license headers.
This is an automated email from the ASF dual-hosted git repository.
anatole pushed a commit to branch 0.4-incubating-vote-RC4
in repository https://gitbox.apache.org/repos/asf/incubator-tamaya-sandbox.git
commit ad67bcb15ff0797ebbc50bc7017501b2caa9a028
Author: Anatole Tresch <at...@gmail.com>
AuthorDate: Wed Sep 11 01:25:50 2019 +0200
Added missing license headers.
---
.travis.yml | 16 ++
README.md | 17 +++
jodatime/pom.xml | 2 +-
.../org/apache/tamaya/metamodel/CachedFilter.java | 40 ++++-
.../org/apache/tamaya/metamodel/MaskFilter.java | 23 ---
.../org/apache/tamaya/metamodel/MetaContext.java | 2 +-
.../org/apache/tamaya/metamodel/SecuredFilter.java | 60 ++++----
.../metamodel/internal/ComponentFactory.java | 17 ---
.../apache/tamaya/metamodel/CachedFilterTest.java | 160 ++++++++++++++++++++
.../metamodel/EnabledPropertySourceTest.java | 92 ++++++++++++
.../{MaskFilterTest.java => HideFilterTest.java} | 50 +------
.../org/apache/tamaya/metamodel/MapFilterTest.java | 90 ++++++++++++
.../apache/tamaya/metamodel/MaskFilterTest.java | 14 +-
.../tamaya/metamodel/MetaConfigurationTest.java | 65 ++++++++
.../apache/tamaya/metamodel/MetaContextTest.java | 163 +++++++++++++++++++++
.../apache/tamaya/metamodel/SecuredFilterTest.java | 147 +++++++++++++++++++
.../tamaya/metamodel/TestContextInializer.java | 32 ++++
.../metamodel/spi/ItemFactoryManagerTest.java | 85 +++++++++++
....apache.tamaya.metamodel.spi.ContextInitializer | 19 +++
19 files changed, 964 insertions(+), 130 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index a545c25..0b9f026 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +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 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.
language: java
jdk:
- openjdk8
diff --git a/README.md b/README.md
index 6f338b8..4125beb 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,20 @@
+<!--
+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.
+-->
# Apache Tamaya (incubating) Sandbox
This is the sandbox of [Apache Tamaya](https://tamaya.incubator.apache.org).
diff --git a/jodatime/pom.xml b/jodatime/pom.xml
index 3d21d20..995c9c8 100644
--- a/jodatime/pom.xml
+++ b/jodatime/pom.xml
@@ -25,7 +25,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-sandbox</artifactId>
- <version>0.4-incubating-SNAPSHOT</version>
+ <version>0.5-incubating-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
index 73f1388..5119eb9 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
@@ -24,6 +24,7 @@ import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertyValue;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
@@ -37,7 +38,8 @@ public class CachedFilter implements PropertyFilter{
private String matches;
private Map<String, CachedEntry> cachedEntries = new ConcurrentHashMap<>();
private int maxSize = -1;
- private long timeout = TimeUnit.MINUTES.toMillis(5);
+ private TimeUnit timeUnit = TimeUnit.MINUTES;
+ private long timeout = 5;
/**
* Factory for configuring immutable property filter.
@@ -68,6 +70,33 @@ public class CachedFilter implements PropertyFilter{
return this;
}
+ public CachedFilter setTimeout(long timeout){
+ this.timeout = timeout;
+ return this;
+ }
+
+ public CachedFilter setTimeUnit(TimeUnit timeUnit){
+ this.timeUnit = Objects.requireNonNull(timeUnit);
+ return this;
+ }
+
+ public TimeUnit getTimeUnit(){
+ return timeUnit;
+ }
+
+ public long getTimeout(){
+ return timeout;
+ }
+
+ public CachedFilter setMaxSize(int maxSize){
+ this.maxSize = maxSize;
+ return this;
+ }
+
+ public int getMaxSize(){
+ return maxSize;
+ }
+
@Override
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
if(matches !=null){
@@ -85,17 +114,17 @@ public class CachedFilter implements PropertyFilter{
* @return
*/
private PropertyValue resolveCachedEntry(PropertyValue value) {
- if(maxSize>0 && maxSize<=this.cachedEntries.size()){
+ if(maxSize>0 && maxSize<this.cachedEntries.size()){
return value;
}
CachedEntry ce = cachedEntries.get(value.getKey());
if(ce==null || !ce.isValid()){
if(value!=null) {
- ce = new CachedEntry(value, System.currentTimeMillis() + timeout);
+ ce = new CachedEntry(value, System.currentTimeMillis() + timeUnit.toMillis(timeout));
this.cachedEntries.put(value.getKey(), ce);
}
}
- return value;
+ return ce.value;
}
@Override
@@ -105,6 +134,7 @@ public class CachedFilter implements PropertyFilter{
", cache-getNumChilds=" + cachedEntries.size() +
", max-getNumChilds=" + maxSize +
", timeout=" + timeout +
+ ", timeUnit=" + timeUnit +
'}';
}
@@ -121,7 +151,7 @@ public class CachedFilter implements PropertyFilter{
}
public boolean isValid(){
- return System.currentTimeMillis() > ttl;
+ return System.currentTimeMillis() < ttl;
}
}
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
index b92be5d..82b71b7 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MaskFilter.java
@@ -36,7 +36,6 @@ import java.util.Map;
public class MaskFilter implements PropertyFilter{
private String matches;
- private List<String> roles = new ArrayList<>();
private String mask = "*****";
private boolean filterSingleValues;
private boolean filterAllValues = true;
@@ -71,27 +70,6 @@ public class MaskFilter implements PropertyFilter{
return this;
}
- public List<String> getRoles() {
- return roles;
- }
-
- public MaskFilter setRoles(List<String> roles) {
- this.roles.clear();
- for(String role:roles) {
- this.roles.add(role.trim());
- }
- return this;
- }
-
- public MaskFilter setRoles(String... roles) {
- return setRoles(Arrays.asList(roles));
- }
-
- public MaskFilter setRoles(String roles){
- setRoles(roles.split(","));
- return this;
- }
-
public String getMask() {
return mask;
}
@@ -134,7 +112,6 @@ public class MaskFilter implements PropertyFilter{
return "MaskFilter{" +
"matches='" + matches + '\'' +
", mask='" + mask + '\'' +
- ", roles='" + roles + '\'' +
", filterAllValues='" + filterAllValues + '\'' +
", filterSingleValues='" + filterSingleValues + '\'' +
'}';
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
index d4bf5b5..d41fe0b 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/MetaContext.java
@@ -209,7 +209,7 @@ public final class MetaContext {
*/
public boolean checkPropertiesArePresent(String... keys){
for(String key:keys) {
- if (getProperty(key, null) == null) {
+ if (!getProperty(key, null).isPresent()) {
return false;
}
}
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
index e49b170..4f43d47 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/SecuredFilter.java
@@ -24,10 +24,8 @@ import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertyValue;
-import javax.security.auth.Subject;
-import java.security.AccessController;
-import java.security.Principal;
-import java.util.Map;
+import java.util.*;
+import java.util.function.Supplier;
import java.util.logging.Logger;
/**
@@ -40,8 +38,8 @@ public class SecuredFilter implements PropertyFilter{
private static final Logger LOG = Logger.getLogger(SecuredFilter.class.getName());
private String matches;
- private String roles;
- private String[]rolesArray;
+ private Set<String> roles = new HashSet<>();
+ private Supplier<Set<String>> roleSupplier = () -> null;
private SecurePolicy policy = SecurePolicy.HIDE;
/**
@@ -73,13 +71,16 @@ public class SecuredFilter implements PropertyFilter{
return this;
}
- public String getRoles() {
- return roles;
+ public Set<String> getRoles() {
+ return Collections.unmodifiableSet(roles);
}
- public SecuredFilter setRoles(String roles) {
- this.roles = roles;
- this.rolesArray = roles.split(",");
+ public SecuredFilter setRoles(String... roles) {
+ return setRoles(Arrays.asList(roles));
+ }
+
+ public SecuredFilter setRoles(Collection<String> roles) {
+ this.roles.addAll(roles);
return this;
}
@@ -92,6 +93,14 @@ public class SecuredFilter implements PropertyFilter{
return this;
}
+ public Supplier<Set<String>> getRoleSupplier() {
+ return roleSupplier;
+ }
+
+ public void setRoleSupplier(Supplier<Set<String>> roleSupplier) {
+ this.roleSupplier = Objects.requireNonNull(roleSupplier);
+ }
+
@Override
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
if(matches !=null){
@@ -99,24 +108,25 @@ public class SecuredFilter implements PropertyFilter{
return value;
}
}
- Subject s = javax.security.auth.Subject.getSubject(AccessController.getContext());
- for(Principal principal:s.getPrincipals()){
- for(String role:rolesArray) {
- if(principal.getName().equals(role)){
+ Set<String> assignedRoles = this.roleSupplier.get();
+ if(assignedRoles!=null) {
+ for (String role : this.roles) {
+ if (assignedRoles.contains(role)) {
return value;
}
}
+ switch (policy) {
+ case THROW_EXCPETION:
+ throw new ConfigException("Unauthorized access to '" + value.getKey() + "', not in " + roles);
+ case WARN_ONLY:
+ LOG.warning("Unauthorized access to '" + value.getKey() + "', not in " + roles);
+ return value;
+ case HIDE:
+ default:
+ return null;
+ }
}
- switch(policy){
- case THROW_EXCPETION:
- throw new ConfigException("Unauthorized access to '"+value.getKey()+"', not in " + roles);
- case WARN_ONLY:
- LOG.warning("Unauthorized access to '"+value.getKey()+"', not in " + roles);
- return value;
- case HIDE:
- default:
- return null;
- }
+ return value;
}
@Override
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentFactory.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentFactory.java
index 59d4b69..9cf492a 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentFactory.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/internal/ComponentFactory.java
@@ -80,23 +80,6 @@ public final class ComponentFactory<T> {
return comp;
}
-// public Collection<T> loadInstances(NodeList nodeList) {
-// List<T> items = new ArrayList<>();
-// for(int i=0;i<nodeList.getLength();i++){
-// Node node = nodeList.item(i);
-// if(node.getNodeName().equals("filter")){
-// String type = node.getNodeValue();
-// try {
-// T item = getComponent(type);
-// ComponentConfigurator.configure(item, node);
-// items.addPropertyValue(item);
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// }
-// }
-// return items;
-// }
@Override
public String toString() {
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/CachedFilterTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/CachedFilterTest.java
new file mode 100644
index 0000000..d3696aa
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/CachedFilterTest.java
@@ -0,0 +1,160 @@
+/*
+ * 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.metamodel;
+
+import org.apache.tamaya.spi.PropertyValue;
+import org.junit.Test;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class CachedFilterTest {
+
+ @Test
+ public void getSetMatches() {
+ CachedFilter filter = new CachedFilter();
+ assertThat(filter.getMatches()).isNull();
+ filter.setMatches("foo");
+ assertThat(filter.getMatches()).isNotNull().isEqualTo("foo");
+ }
+
+ @Test
+ public void getSetMaxSize() {
+ CachedFilter filter = new CachedFilter();
+ assertThat(filter.getMaxSize()).isEqualTo(-1);
+ filter.setMaxSize(10);
+ assertThat(filter.getMaxSize()).isEqualTo(10);
+ }
+
+ @Test
+ public void getSetTimeout() {
+ CachedFilter filter = new CachedFilter();
+ assertThat(filter.getTimeout()).isEqualTo(5);
+ filter.setTimeout(10);
+ assertThat(filter.getTimeout()).isEqualTo(10);
+ }
+
+ @Test
+ public void getSetTineUnit() {
+ CachedFilter filter = new CachedFilter();
+ assertThat(filter.getTimeUnit()).isEqualTo(TimeUnit.MINUTES);
+ assertThat(filter.setTimeUnit(TimeUnit.HOURS)).isSameAs(filter);
+ assertThat(filter.getTimeUnit()).isEqualTo(TimeUnit.HOURS);
+ }
+
+ @Test
+ public void filterNullProperty() {
+ CachedFilter filter = new CachedFilter();
+ PropertyValue val = filter.filterProperty(null, null);
+ assertThat(val).isNull();
+ }
+
+ @Test
+ public void filterExceedingProperty() {
+ CachedFilter filter = new CachedFilter();
+ filter.setMatches(".*");
+ filter.setMaxSize(1);
+ PropertyValue val = PropertyValue.createValue("a", "b");
+ PropertyValue cached = filter.filterProperty(val, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ PropertyValue val2 = PropertyValue.createValue("a", "b2");
+ cached = filter.filterProperty(val2, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ // exceeding property is not cached anymore
+ val = PropertyValue.createValue("b", "b");
+ cached = filter.filterProperty(val, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ val2 = PropertyValue.createValue("b", "b2");
+ cached = filter.filterProperty(val2, null);
+ assertThat(cached).isNotNull().isEqualTo(val2);
+ }
+
+ @Test
+ public void filterWithTimeout() throws InterruptedException {
+ CachedFilter filter = new CachedFilter();
+ filter.setMatches(".*");
+ filter.setTimeout(50).setTimeUnit(TimeUnit.MILLISECONDS);
+ PropertyValue val = PropertyValue.createValue("a", "b");
+ PropertyValue cached = filter.filterProperty(val, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ PropertyValue val2 = PropertyValue.createValue("a", "b2");
+ cached = filter.filterProperty(val2, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ // After timeout cache entry is renewed...
+ Thread.sleep(100L);
+ val = PropertyValue.createValue("a", "b3");
+ cached = filter.filterProperty(val, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ val2 = PropertyValue.createValue("a", "b4");
+ cached = filter.filterProperty(val2, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ }
+
+ @Test
+ public void filterMacthingProperty() {
+ CachedFilter filter = new CachedFilter();
+ filter.setMatches("a");
+ PropertyValue val = PropertyValue.createValue("a", "b");
+ PropertyValue cached = filter.filterProperty(val, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ PropertyValue val2 = PropertyValue.createValue("a", "b2");
+ cached = filter.filterProperty(val2, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ }
+
+ @Test
+ public void filterMacthingPropertyExpression() {
+ CachedFilter filter = new CachedFilter();
+ filter.setMatches("a.*");
+ PropertyValue val = PropertyValue.createValue("a", "b");
+ PropertyValue cached = filter.filterProperty(val, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ PropertyValue val2 = PropertyValue.createValue("a", "b2");
+ cached = filter.filterProperty(val2, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+
+ val = PropertyValue.createValue("a2", "b");
+ cached = filter.filterProperty(val, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ val2 = PropertyValue.createValue("a2", "b2");
+ cached = filter.filterProperty(val2, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+
+ val = PropertyValue.createValue("b", "b");
+ cached = filter.filterProperty(val, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ val2 = PropertyValue.createValue("b", "b2");
+ cached = filter.filterProperty(val2, null);
+ assertThat(cached).isNotNull().isEqualTo(val2);
+ }
+
+ @Test
+ public void filterNonMacthingProperty() {
+ CachedFilter filter = new CachedFilter();
+ filter.setMatches("b");
+ PropertyValue val = PropertyValue.createValue("a", "b");
+ PropertyValue cached = filter.filterProperty(val, null);
+ assertThat(cached).isNotNull().isEqualTo(val);
+ PropertyValue val2 = PropertyValue.createValue("a", "b2");
+ cached = filter.filterProperty(val2, null);
+ assertThat(cached).isNotNull().isEqualTo(val2);
+ }
+}
\ No newline at end of file
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/EnabledPropertySourceTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/EnabledPropertySourceTest.java
new file mode 100644
index 0000000..282e75a
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/EnabledPropertySourceTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.metamodel;
+
+import org.apache.tamaya.spisupport.propertysource.SystemPropertySource;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class EnabledPropertySourceTest {
+
+ private SystemPropertySource systemPropertySource = new SystemPropertySource();
+ private EnabledPropertySource enabledPropertySource = new EnabledPropertySource(
+ systemPropertySource, "true"
+ );
+
+ @Test
+ public void calculateEnabled() {
+ assertThat(enabledPropertySource.calculateEnabled()).isTrue();
+ enabledPropertySource = new EnabledPropertySource(
+ systemPropertySource, "false"
+ );
+ assertThat(enabledPropertySource.calculateEnabled()).isFalse();
+ }
+
+ @Test
+ public void setEnabled() {
+ enabledPropertySource.setEnabled(false);
+ assertThat(enabledPropertySource.isEnabled());
+ enabledPropertySource.setEnabled(true);
+ assertThat(enabledPropertySource.isEnabled());
+
+ }
+
+ @Test
+ public void getOrdinal() {
+ assertThat(enabledPropertySource.getOrdinal()).isEqualTo(systemPropertySource.getOrdinal());
+
+ }
+
+ @Test
+ public void getName() {
+ assertThat(enabledPropertySource.getName()).isEqualTo(systemPropertySource.getName());
+ }
+
+ @Test
+ public void get() {
+ assertThat(enabledPropertySource.get("java.version")).isEqualTo(systemPropertySource.get("java.version"));
+ enabledPropertySource.setEnabled(false);
+ assertThat(enabledPropertySource.get("java.version")).isNull();
+ }
+
+ @Test
+ public void getProperties() {
+ assertThat(enabledPropertySource.getProperties()).isEqualTo(systemPropertySource.getProperties());
+ enabledPropertySource.setEnabled(false);
+ assertThat(enabledPropertySource.getProperties()).isEmpty();
+ }
+
+ @Test
+ public void isScannable() {
+ assertThat(enabledPropertySource.isScannable()).isTrue();
+ }
+
+ @Test
+ public void testToString() {
+ assertThat(enabledPropertySource.toString()).isNotNull().isEqualTo("EnabledPropertySource{\n" +
+ " enabled=true\n" +
+ " wrapped=SystemPropertySource{ defaultOrdinal=1000\n" +
+ " ordinal=null\n" +
+ " disabled=false\n" +
+ " name='system-properties'\n" +
+ "}}");
+ }
+}
\ No newline at end of file
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/MaskFilterTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/HideFilterTest.java
similarity index 53%
copy from metamodel/src/test/java/org/apache/tamaya/metamodel/MaskFilterTest.java
copy to metamodel/src/test/java/org/apache/tamaya/metamodel/HideFilterTest.java
index 9d30b49..9e9a294 100644
--- a/metamodel/src/test/java/org/apache/tamaya/metamodel/MaskFilterTest.java
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/HideFilterTest.java
@@ -23,74 +23,34 @@ import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyValue;
import org.junit.Test;
-import java.util.Arrays;
import java.util.Collections;
import static org.assertj.core.api.Assertions.assertThat;
-public class MaskFilterTest {
+public class HideFilterTest {
+
+ private HideFilter filter = new HideFilter();
@Test
public void getSetMatches() {
- MaskFilter filter = new MaskFilter();
filter.setMatches("*.SEC");
assertThat(filter.getMatches()).isNotNull().isEqualTo("*.SEC");
}
@Test
- public void getSetRoles() {
- MaskFilter filter = new MaskFilter();
- filter.setRoles("a", "b");
- assertThat(Arrays.asList("a", "b")).isEqualTo(filter.getRoles());
-
- filter = new MaskFilter();
- filter.setRoles(Arrays.asList("a", "b"));
- assertThat(Arrays.asList("a", "b")).isEqualTo(filter.getRoles());
- }
-
- @Test
- public void getSetMask() {
- MaskFilter filter = new MaskFilter();
- filter.setMask("*");
- assertThat(filter.getMask()).isEqualTo("*");
- }
-
- @Test
- public void setGetFilterAllValues() {
- MaskFilter filter = new MaskFilter();
- filter.setFilterAllValues(true);
- assertThat(filter.isFilterAllValues()).isTrue();
- }
-
- @Test
- public void setGetFilterSingleValues() {
- MaskFilter filter = new MaskFilter();
- filter.setFilterSingleValues(true);
- assertThat(filter.isFilterSingleValues()).isTrue();
- }
-
-
- @Test
public void filterProperty() {
- MaskFilter filter = new MaskFilter();
filter.setMatches(".*\\.SEC");
assertThat(filter.getMatches()).isEqualTo(".*\\.SEC");
PropertyValue value = PropertyValue.createValue("foo.SEC", "someValue");
PropertyValue filtered = filter.filterProperty(value,
new FilterContext(value, Collections.emptyMap(), ConfigurationContext.EMPTY));
- assertThat(filtered).isNotNull();
- assertThat(filtered.getValue()).isNotNull().isEqualTo("*****");
+ assertThat(filtered).isNull();
}
@Test
public void testToString() {
- MaskFilter filter = new MaskFilter();
filter.setMatches(".*\\.SEC");
- filter.setMask("*****");
- filter.setFilterSingleValues(true);
- filter.setMask("123");
- assertThat(filter.toString()).isEqualTo("MaskFilter{matches='.*\\.SEC', mask='123', roles='[]', filterAllValues='true', " +
- "filterSingleValues='true'}");
+ assertThat(filter.toString()).isEqualTo("HideFilter{matches='.*\\.SEC'}");
}
}
\ No newline at end of file
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/MapFilterTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/MapFilterTest.java
new file mode 100644
index 0000000..f1218ac
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/MapFilterTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.metamodel;
+
+import org.apache.tamaya.spi.PropertyValue;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class MapFilterTest {
+
+ private MapFilter filter = new MapFilter();
+
+ @Test
+ public void getSetTarget() {
+ assertThat(filter.getTarget()).isNull();
+ filter.setTarget("target:");
+ assertThat(filter.getTarget()).isEqualTo("target:");
+ }
+
+ @Test
+ public void getSetCutoff() {
+ assertThat(filter.getCutoff()).isNull();
+ filter.setCutoff("cutoff");
+ assertThat(filter.getCutoff()).isEqualTo("cutoff");
+ }
+
+ @Test
+ public void getSetMatches() {
+ filter.setMatches("*.SEC");
+ assertThat(filter.getMatches()).isNotNull().isEqualTo("*.SEC");
+ }
+
+ @Test
+ public void filterProperty_NoMap() {
+ PropertyValue pv = PropertyValue.createValue("k", "v");
+ PropertyValue value = filter.filterProperty(pv, null);
+ assertThat(value).isNotNull().isEqualTo(pv);
+ }
+
+ @Test
+ public void filterProperty_Mapped() {
+ PropertyValue pv = PropertyValue.createValue("k", "v");
+ filter.setTarget("a:");
+ PropertyValue value = filter.filterProperty(pv, null);
+ assertThat(value).isNotNull().isEqualTo(PropertyValue.createValue("a:k", "v"));
+ }
+
+ @Test
+ public void filterProperty_Cutoff() {
+ PropertyValue pv = PropertyValue.createValue("a.b:k", "v");
+ filter.setCutoff("a.b:");
+ PropertyValue value = filter.filterProperty(pv, null);
+ assertThat(value).isNotNull().isEqualTo(PropertyValue.createValue("k", "v"));
+ }
+
+ @Test
+ public void filterProperty_CutoffAndTarget() {
+ PropertyValue pv = PropertyValue.createValue("a.b:k", "v");
+ filter.setCutoff("a.b:");
+ filter.setTarget("new.");
+ PropertyValue value = filter.filterProperty(pv, null);
+ assertThat(value).isNotNull().isEqualTo(PropertyValue.createValue("new.k", "v"));
+ }
+
+
+ @Test
+ public void testToString() {
+ assertThat(filter.toString()).isNotNull().isEqualTo("MapFilter{target='null', cutoff='null', matches='null'}");
+ filter.setTarget("tgt").setCutoff("cutoff").setMatches("matches");
+ assertThat(filter.toString()).isNotNull().isEqualTo("MapFilter{target='tgt', cutoff='cutoff', matches='matches'}");
+ }
+}
\ No newline at end of file
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/MaskFilterTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/MaskFilterTest.java
index 9d30b49..fa96d47 100644
--- a/metamodel/src/test/java/org/apache/tamaya/metamodel/MaskFilterTest.java
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/MaskFilterTest.java
@@ -39,17 +39,6 @@ public class MaskFilterTest {
}
@Test
- public void getSetRoles() {
- MaskFilter filter = new MaskFilter();
- filter.setRoles("a", "b");
- assertThat(Arrays.asList("a", "b")).isEqualTo(filter.getRoles());
-
- filter = new MaskFilter();
- filter.setRoles(Arrays.asList("a", "b"));
- assertThat(Arrays.asList("a", "b")).isEqualTo(filter.getRoles());
- }
-
- @Test
public void getSetMask() {
MaskFilter filter = new MaskFilter();
filter.setMask("*");
@@ -90,7 +79,6 @@ public class MaskFilterTest {
filter.setMask("*****");
filter.setFilterSingleValues(true);
filter.setMask("123");
- assertThat(filter.toString()).isEqualTo("MaskFilter{matches='.*\\.SEC', mask='123', roles='[]', filterAllValues='true', " +
- "filterSingleValues='true'}");
+ assertThat(filter.toString()).isEqualTo("MaskFilter{matches='.*\\.SEC', mask='123', filterAllValues='true', filterSingleValues='true'}");
}
}
\ No newline at end of file
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/MetaConfigurationTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/MetaConfigurationTest.java
new file mode 100644
index 0000000..4664267
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/MetaConfigurationTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.metamodel;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationBuilder;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MetaConfigurationTest {
+
+ @Test
+ public void configure() {
+ Configuration config = Configuration.current();
+ MetaConfiguration.configure();
+ Configuration config2 = Configuration.current();
+ assertThat(config).isNotEqualTo(config2);
+ }
+
+ @Test
+ public void configure_with_URL() {
+ Configuration config = Configuration.current();
+ MetaConfiguration.configure(getClass().getResource("/integrationTests/empty-config.conf"));
+ Configuration config2 = Configuration.current();
+ assertThat(config).isNotEqualTo(config2);
+ assertThat(config2.getContext().getPropertySources()).isEmpty();
+ assertThat(config2.getContext().getPropertyConverters()).isEmpty();
+ assertThat(config2.getContext().getPropertyFilters()).isEmpty();
+ }
+
+ @Test
+ public void createConfigBuilder() {
+ ConfigurationBuilder builder = MetaConfiguration.createConfigBuilder(
+ getClass().getResource("/integrationTests/empty-config.conf"));
+ assertThat(builder).isNotNull();
+ assertThat(builder.getPropertySources()).isEmpty();
+ assertThat(builder.getPropertyConverter()).isEmpty();
+ assertThat(builder.getPropertyFilters()).isEmpty();
+ }
+
+ @Test
+ public void createConfiguration() {
+ Configuration config = MetaConfiguration.createConfiguration(getClass().getResource("/integrationTests/empty-config.conf"));
+ assertThat(config.getContext().getPropertySources()).isEmpty();
+ assertThat(config.getContext().getPropertyConverters()).isEmpty();
+ assertThat(config.getContext().getPropertyFilters()).isEmpty();
+ }
+}
\ No newline at end of file
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/MetaContextTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/MetaContextTest.java
new file mode 100644
index 0000000..a165409
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/MetaContextTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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.metamodel;
+
+import org.junit.Test;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Optional;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class MetaContextTest {
+
+ @Test
+ public void getInstance() {
+ assertThat(MetaContext.getInstance()).isNotNull();
+ }
+
+ @Test
+ public void getId() {
+ assertThat(MetaContext.getInstance().getId()).isNotNull().isNotEmpty();
+ }
+
+ @Test
+ public void initialize() {
+ MetaContext meta = new MetaContext();
+ meta.initialize();
+ assertThat(meta.getProperty("key", String.class)).isEqualTo(Optional.of("value"));
+ }
+
+ @Test
+ public void initialize_WithClassLoader() {
+ MetaContext meta = new MetaContext();
+ meta.initialize(new URLClassLoader(new URL[0]));
+ assertThat(meta.getProperty("key", String.class)).isEqualTo(Optional.of("value"));
+ }
+
+ @Test
+ public void combineWith() {
+ MetaContext meta = new MetaContext();
+ meta.initialize();
+ MetaContext meta2 = new MetaContext();
+ meta2.setProperty("foo", String.class, "bar");
+ meta.initialize(new URLClassLoader(new URL[0]));
+ MetaContext meta3 = meta.combineWith(meta2);
+ assertThat(meta3.getProperty("key", String.class)).isEqualTo(Optional.of("value"));
+ assertThat(meta3.getProperty("foo", String.class)).isEqualTo(Optional.of("bar"));
+ assertThat(meta2.getProperty("key", String.class)).isEqualTo(Optional.empty());
+ assertThat(meta.getProperty("foo", String.class)).isEqualTo(Optional.empty());
+ }
+
+ @Test
+ public void getStringProperty() {
+ assertThat(MetaContext.getInstance().getProperty("key", String.class)).isEqualTo(Optional.of("value"));
+ }
+
+ @Test
+ public void getBooleanProperty() {
+ assertThat(MetaContext.getInstance().getProperty("boolean", boolean.class)).isEqualTo(Optional.of(true));
+ }
+
+ @Test
+ public void getNumberProperty() {
+ assertThat(MetaContext.getInstance().getProperty("int", Number.class)).isEqualTo(Optional.of(Integer.valueOf(1)));
+ }
+
+ @Test
+ public void getProperty() {
+ assertThat(MetaContext.getInstance().getProperty("key", String.class)).isNotNull();
+ }
+
+ @Test
+ public void setStringProperty() {
+ MetaContext.getInstance().setStringProperty("a", "b");
+ assertThat(MetaContext.getInstance().getProperty("key", String.class)).isEqualTo(Optional.of("value"));
+ assertThat(MetaContext.getInstance().getProperty("a", String.class)).isEqualTo(Optional.of("b"));
+ }
+
+ @Test
+ public void setBooleanProperty() {
+ assertThat(MetaContext.getInstance().getProperty("boolean", Boolean.class)).isEqualTo(Optional.of(true));
+ }
+
+ @Test
+ public void setNumberProperty() {
+ assertThat(MetaContext.getInstance().getProperty("int", Number.class)).isEqualTo(Optional.of(Integer.valueOf(1)));
+ }
+
+ @Test
+ public void setProperty() {
+ MetaContext.getInstance().setProperty("test", String.class, "testValue");
+ assertThat(MetaContext.getInstance().getProperty("test", String.class)).isEqualTo(Optional.of("testValue"));
+ }
+
+ @Test
+ public void setPropertyIfAbsent() {
+ MetaContext.getInstance().setPropertyIfAbsent("test", String.class, "testValue");
+ assertThat(MetaContext.getInstance().getProperty("test", String.class)).isEqualTo(Optional.of("testValue"));
+ MetaContext.getInstance().setPropertyIfAbsent("test", String.class, "testValue2");
+ assertThat(MetaContext.getInstance().getProperty("test", String.class)).isEqualTo(Optional.of("testValue"));
+ }
+
+ @Test
+ public void checkPropertiesArePresent() {
+ assertThat(MetaContext.getInstance().checkPropertiesArePresent()).isTrue();
+ assertThat(MetaContext.getInstance().checkPropertiesArePresent("boolean", "int", "key")).isTrue();
+ assertThat(MetaContext.getInstance().checkPropertiesArePresent("boolean", "boolean")).isTrue();
+ assertThat(MetaContext.getInstance().checkPropertiesArePresent("boolean", "int", "foo")).isFalse();
+ assertThat(MetaContext.getInstance().checkPropertiesArePresent("foo")).isFalse();
+ }
+
+ @Test
+ public void getProperties() {
+ assertThat(MetaContext.getInstance().getProperties())
+ .containsEntry("int", 1)
+ .containsEntry("boolean", true)
+ .containsEntry("key", "value");
+ }
+
+ @Test
+ public void testEquals() {
+ MetaContext meta = new MetaContext();
+ meta.initialize();
+ MetaContext meta2 = new MetaContext();
+ meta2.initialize();
+ assertThat(meta).isNotEqualTo(meta2);
+ }
+
+ @Test
+ public void testHashCode() {
+ MetaContext meta = new MetaContext();
+ meta.initialize();
+ MetaContext meta2 = new MetaContext();
+ meta2.initialize();
+ assertThat(meta.hashCode()).isNotEqualTo(meta2.hashCode());
+ }
+
+ @Test
+ public void testToString() {
+ assertThat(MetaContext.getInstance().toString()).isNotNull()
+ .contains("properties={boolean=true, test=testValue")
+ .contains("float=23.45, key=value, int=1")
+ .contains("MetaContext");
+ }
+}
\ No newline at end of file
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/SecuredFilterTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/SecuredFilterTest.java
new file mode 100644
index 0000000..58576f6
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/SecuredFilterTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.metamodel;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.functions.Supplier;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyValue;
+import org.junit.Test;
+
+import java.security.Security;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class SecuredFilterTest {
+
+ private Set<String> testRoles = new HashSet<>(Collections.singletonList("test"));
+
+ @Test
+ public void getSetMatches() {
+ SecuredFilter filter = new SecuredFilter();
+ filter.setMatches("*.SEC");
+ assertThat(filter.getMatches()).isNotNull().isEqualTo("*.SEC");
+ }
+
+ @Test
+ public void getSetRoleSupplier() {
+ Supplier<Set<String>> testSupplier = () -> testRoles;
+ SecuredFilter filter = new SecuredFilter();
+ assertThat(filter.getRoleSupplier()).isNotNull();
+ assertThat(filter.getRoleSupplier().get()).isNull();
+ filter.setRoleSupplier(testSupplier);
+ assertThat(filter.getRoleSupplier()).isEqualTo(testSupplier);
+ }
+
+ @Test
+ public void getSetRoles() {
+ SecuredFilter filter = new SecuredFilter();
+ filter.setRoles("myrole");
+ assertThat(filter.getRoles()).containsExactly("myrole");
+ }
+
+ @Test
+ public void setGetPolicy() {
+ SecuredFilter filter = new SecuredFilter();
+ filter.setPolicy(SecuredFilter.SecurePolicy.HIDE);
+ assertThat(filter.getPolicy()).isEqualTo(SecuredFilter.SecurePolicy.HIDE);
+ }
+
+ @Test
+ public void filterProperty_Hide() {
+ SecuredFilter filter = new SecuredFilter();
+ filter.setRoleSupplier(() -> testRoles);
+ filter.setRoles("test2");
+ filter.setPolicy(SecuredFilter.SecurePolicy.HIDE);
+ filter.setMatches(".*\\.SEC");
+ assertThat(filter.getMatches()).isEqualTo(".*\\.SEC");
+ PropertyValue value = PropertyValue.createValue("foo.SEC", "someValue");
+ PropertyValue filtered = filter.filterProperty(value,
+ new FilterContext(value, Collections.emptyMap(), ConfigurationContext.EMPTY));
+ assertThat(filtered).isNull();
+ }
+
+ @Test
+ public void filterProperty_ThrowException_matching() {
+ SecuredFilter filter = new SecuredFilter();
+ filter.setRoleSupplier(() -> testRoles);
+ filter.setRoles("test");
+ filter.setPolicy(SecuredFilter.SecurePolicy.THROW_EXCPETION);
+ filter.setMatches(".*\\.SEC");
+ assertThat(filter.getMatches()).isEqualTo(".*\\.SEC");
+ PropertyValue value = PropertyValue.createValue("foo.SEC", "someValue");
+ assertThat(filter.filterProperty(value,
+ new FilterContext(value, Collections.emptyMap(), ConfigurationContext.EMPTY)))
+ .isEqualTo(value);
+ }
+
+ @Test(expected = ConfigException.class)
+ public void filterProperty_ThrowException() {
+ SecuredFilter filter = new SecuredFilter();
+ filter.setRoleSupplier(() -> testRoles);
+ filter.setRoles("test2");
+ filter.setPolicy(SecuredFilter.SecurePolicy.THROW_EXCPETION);
+ filter.setMatches(".*\\.SEC");
+ assertThat(filter.getMatches()).isEqualTo(".*\\.SEC");
+ PropertyValue value = PropertyValue.createValue("foo.SEC", "someValue");
+ filter.filterProperty(value,
+ new FilterContext(value, Collections.emptyMap(), ConfigurationContext.EMPTY));
+ }
+
+ @Test
+ public void filterProperty_Warn() {
+ SecuredFilter filter = new SecuredFilter();
+ filter.setRoleSupplier(() -> testRoles);
+ filter.setRoles("test2");
+ filter.setPolicy(SecuredFilter.SecurePolicy.WARN_ONLY);
+ filter.setMatches(".*\\.SEC");
+ assertThat(filter.getMatches()).isEqualTo(".*\\.SEC");
+ PropertyValue value = PropertyValue.createValue("foo.SEC", "someValue");
+ PropertyValue filtered = filter.filterProperty(value,
+ new FilterContext(value, Collections.emptyMap(), ConfigurationContext.EMPTY));
+ assertThat(filtered).isNotNull();
+ assertThat(filtered.getValue()).isNotNull().isEqualTo("someValue");
+ }
+
+ @Test
+ public void filterProperty_NoRoleSupplier() {
+ SecuredFilter filter = new SecuredFilter();
+ filter.setRoles("test");
+ filter.setPolicy(SecuredFilter.SecurePolicy.THROW_EXCPETION);
+ filter.setMatches(".*\\.SEC");
+ PropertyValue value = PropertyValue.createValue("foo.SEC", "someValue");
+ assertThat(filter.filterProperty(value,
+ new FilterContext(value, Collections.emptyMap(), ConfigurationContext.EMPTY)))
+ .isEqualTo(value);
+ }
+
+ @Test
+ public void testToString() {
+ SecuredFilter filter = new SecuredFilter();
+ filter.setMatches(".*\\.SEC");
+ filter.setPolicy(SecuredFilter.SecurePolicy.HIDE);
+ assertThat(filter.toString()).isEqualTo("SecuredFilter{matches='.*\\.SEC', roles='[]', policy='HIDE'}");
+ }
+}
\ No newline at end of file
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/TestContextInializer.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/TestContextInializer.java
new file mode 100644
index 0000000..f290b0b
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/TestContextInializer.java
@@ -0,0 +1,32 @@
+/*
+ * 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.metamodel;
+
+import org.apache.tamaya.metamodel.spi.ContextInitializer;
+
+public class TestContextInializer implements ContextInitializer {
+ @Override
+ public void initializeContext(MetaContext metaContext) {
+ metaContext.setProperty("key", String.class, "value");
+ metaContext.setProperty("int", Integer.class, Integer.valueOf(1));
+ metaContext.setProperty("float", Float.class, 23.45F);
+ metaContext.setProperty("boolean", Boolean.class, true);
+
+ }
+}
diff --git a/metamodel/src/test/java/org/apache/tamaya/metamodel/spi/ItemFactoryManagerTest.java b/metamodel/src/test/java/org/apache/tamaya/metamodel/spi/ItemFactoryManagerTest.java
new file mode 100644
index 0000000..29c8206
--- /dev/null
+++ b/metamodel/src/test/java/org/apache/tamaya/metamodel/spi/ItemFactoryManagerTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.metamodel.spi;
+
+import org.apache.tamaya.metamodel.internal.factories.SysPropertiesFactory;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class ItemFactoryManagerTest {
+
+ @Test
+ public void getInstance() {
+ assertThat(ItemFactoryManager.getInstance()).isNotNull();
+ }
+
+ @Test
+ public void getType() {
+ assertThat(ItemFactoryManager.getType(PropertyValue.createObject())).isNull();
+ assertThat(ItemFactoryManager.getType(PropertyValue.createObject().setValue("type", "test")))
+ .isNotNull().isEqualTo("test");
+ assertThat(ItemFactoryManager.getType(PropertyValue.createObject().setValue("class", "test")))
+ .isNotNull().isEqualTo("test");
+ }
+
+ @Test
+ public void getFactories() {
+ assertThat(ItemFactoryManager.getInstance().getFactories(PropertySource.class))
+ .isNotEmpty()
+ .hasSize(9);
+ }
+
+ @Test
+ public void getFactory() {
+ ItemFactory ifact = new SysPropertiesFactory();
+ assertThat(ItemFactoryManager.getInstance().getFactory(PropertySource.class, ifact.getName()))
+ .isNotNull();
+ }
+
+ @Test
+ public void registerItemFactory() {
+ ItemFactory ifact = new ItemFactory(){
+ @Override
+ public String getName() {
+ return "foo";
+ }
+
+ @Override
+ public Class getType() {
+ return String.class;
+ }
+
+ @Override
+ public Object create(Map parameters) {
+ return Collections.emptyMap();
+ }
+ };
+ ItemFactoryManager.getInstance().registerItemFactory(ifact);
+ assertThat(ItemFactoryManager.getInstance().getFactory(String.class, ifact.getName()))
+ .isNotNull()
+ .isEqualTo(ifact);
+ }
+}
\ No newline at end of file
diff --git a/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ContextInitializer b/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ContextInitializer
new file mode 100644
index 0000000..5eefb34
--- /dev/null
+++ b/metamodel/src/test/resources/META-INF/services/org.apache.tamaya.metamodel.spi.ContextInitializer
@@ -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 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.
+#
+org.apache.tamaya.metamodel.TestContextInializer
\ No newline at end of file