Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7C1F2200BB0 for ; Sun, 30 Oct 2016 18:25:54 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 7AAFA160ADD; Sun, 30 Oct 2016 17:25:54 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F24CE160AF1 for ; Sun, 30 Oct 2016 18:25:52 +0100 (CET) Received: (qmail 78888 invoked by uid 500); 30 Oct 2016 17:25:52 -0000 Mailing-List: contact commits-help@tamaya.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tamaya.incubator.apache.org Delivered-To: mailing list commits@tamaya.incubator.apache.org Received: (qmail 78879 invoked by uid 99); 30 Oct 2016 17:25:52 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 30 Oct 2016 17:25:52 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id AAE861A00AA for ; Sun, 30 Oct 2016 17:25:51 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id agdJagw7i-32 for ; Sun, 30 Oct 2016 17:25:46 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id DB9355FAF9 for ; Sun, 30 Oct 2016 17:25:44 +0000 (UTC) Received: (qmail 78673 invoked by uid 99); 30 Oct 2016 17:25:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 30 Oct 2016 17:25:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E19BADFCE0; Sun, 30 Oct 2016 17:25:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: anatole@apache.org To: commits@tamaya.incubator.apache.org Date: Sun, 30 Oct 2016 17:25:45 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [03/10] incubator-tamaya-sandbox git commit: TAMAYA-182: Adapted modules to new builder patter changes, including tests. Fixed compile errors, or excluded modules from compilation (see root pom). archived-at: Sun, 30 Oct 2016 17:25:54 -0000 http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java b/validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java new file mode 100644 index 0000000..f6acafe --- /dev/null +++ b/validation/src/main/java/org/apache/tamaya/validation/spi/ParameterModel.java @@ -0,0 +1,242 @@ +/* + * 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.validation.spi; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.validation.ConfigModel; +import org.apache.tamaya.validation.ModelTarget; +import org.apache.tamaya.validation.Validation; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Default configuration Model for a configuration parameter. + */ +public class ParameterModel extends AbstractConfigModel { + /** Optional regular expression for validating the value. */ + private final String regEx; + /** The target type into which the value must be convertible. */ + private final Class type; + + /** + * Internal constructor. + * @param builder the builder, not null. + */ + protected ParameterModel(Builder builder) { + super(builder.owner, builder.name, builder.required, builder.description); + this.regEx = builder.regEx; + this.type = builder.type; + } + + @Override + public ModelTarget getType() { + return ModelTarget.Parameter; + } + + /** + * Get the required parameter type. + * + * @return the type. + */ + public Class getParameterType() { + return type; + } + + @Override + public Collection validate(Configuration config) { + List result = new ArrayList<>(1); + String configValue = config.get(getName()); + if (configValue == null && isRequired()) { + result.add(Validation.ofMissing(this)); + } + if (configValue != null && regEx != null) { + if (!configValue.matches(regEx)) { + result.add(Validation.ofError(this, "Config value not matching expression: " + regEx + ", was " + + configValue)); + } + } + return result; + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + b.append(getType()).append(": ").append(getName()); + if (isRequired()) { + b.append(", required: ").append(isRequired()); + } + if (regEx != null) { + b.append(", expression: ").append(regEx); + } + return b.toString(); + } + + /** + * Creates a new Builder instance. + * @param owner the owner name, not null. + * @param name the fully qualified parameter name. + * @return a new builder, never null. + */ + public static Builder builder(String owner, String name) { + return new Builder(owner, name); + } + + /** + * Creates a new ConfigModel + * @param owner the owner name, not null. + * @param name the fully qualified parameter name. + * @param required the required flag. + * @param expression an optional regular expression to validate a value. + * @return the new ConfigModel instance. + */ + public static ConfigModel of(String owner, String name, boolean required, String expression) { + return new Builder(owner, name).setRequired(required).setExpression(expression).build(); + } + + /** + * Creates a new ConfigModel + * @param owner the owner name, not null. + * @param name the fully qualified parameter name. + * @param required the required flag. + * @return the new ConfigModel instance. + */ + public static ConfigModel of(String owner, String name, boolean required) { + return new Builder(owner, name).setRequired(required).build(); + } + + /** + * Creates a new ConfigModel. The parameter will be defined as optional. + * @param owner the owner name, not null. + * @param name the fully qualified parameter name. + * @return the new ConfigModel instance. + */ + public static ConfigModel of(String owner, String name) { + return new Builder(owner, name).setRequired(false).build(); + } + + + /** + * A new Builder for creating ParameterModel instances. + */ + public static class Builder { + /** The parameter's target type. */ + private Class type; + /** The owner. */ + private String owner; + /** The fully qualified parameter name. */ + private String name; + /** The optional validation expression. */ + private String regEx; + /** The optional description. */ + private String description; + /** The required flag. */ + private boolean required; + + /** + * Creates a new Builder. + * @param owner owner, not null. + * @param name the fully qualified parameter name, not null. + */ + public Builder(String owner, String name) { + this.owner = Objects.requireNonNull(owner); + this.name = Objects.requireNonNull(name); + } + + /** + * Sets the target type. + * @param type the type, not null. + * @return the Builder for chaining + */ + public Builder setType(String type) { + try { + this.type = Class.forName(type); + } catch (ClassNotFoundException e) { + try { + this.type = Class.forName("java.ui.lang."+type); + } catch (ClassNotFoundException e2) { + Logger.getLogger(getClass().getName()).log(Level.INFO, "Failed to load parameter type: " + type, e2); + } + } + return this; + } + + /** + * Sets the required flag. + * @param required the required flag. + * @return the Builder for chaining + */ + public Builder setRequired(boolean required) { + this.required = required; + return this; + } + + /** + * Sets the optional description + * @param description the description + * @return the Builder for chaining + */ + public Builder setDescription(String description) { + this.description = description; + return this; + } + + /** + * Sets the optional validation expression + * @param expression the validation expression + * @return the Builder for chaining + */ + public Builder setExpression(String expression) { + this.regEx = expression; + return this; + } + + /** + * Sets the owner name. + * @param owner the owner name, not null. + * @return the Builder for chaining + */ + public Builder setOwner(String owner) { + this.owner = Objects.requireNonNull(owner); + return this; + } + + /** + * Sets the fully qualified parameter name. + * @param name the fully qualified parameter name, not null. + * @return the Builder for chaining + */ + public Builder setName(String name) { + this.name = Objects.requireNonNull(name); + return this; + } + + /** + * Creates a new ConfigModel with the given parameters. + * @return a new ConfigModel , never null. + */ + public ConfigModel build() { + return new ParameterModel(this); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/validation/src/main/java/org/apache/tamaya/validation/spi/SectionModel.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/spi/SectionModel.java b/validation/src/main/java/org/apache/tamaya/validation/spi/SectionModel.java new file mode 100644 index 0000000..23d9f91 --- /dev/null +++ b/validation/src/main/java/org/apache/tamaya/validation/spi/SectionModel.java @@ -0,0 +1,202 @@ +/* + * 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.validation.spi; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.validation.ConfigModel; +import org.apache.tamaya.validation.ModelTarget; +import org.apache.tamaya.validation.Validation; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Default configuration Model for a configuration section. + */ +public class SectionModel extends GroupModel { + + /** + * Creates a new builder. + * @param owner owner, not null. + * @param name the section name. + * @return a new builder instance. + */ + public static Builder builder(String owner, String name){ + return new Builder(owner, name); + } + + /** + * Creates a section validation for the given section. + * @param owner owner, not null. + * @param name the fully qualified section name + * @param required flag, if the section is required to be present. + * @return the ConfigModel instance + */ + public static ConfigModel of(String owner, String name, boolean required){ + return new Builder(owner, name).setRequired(required).build(); + } + + /** + * Creates a section validation for the given section. + * @param owner owner, not null. + * @param name the fully qualified section name + * @param required flag, if the section is required to be present. + * @param configModels additional configModels + * @return a new builder, never null. + */ + public static ConfigModel of(String owner, String name, boolean required, ConfigModel... configModels){ + return new Builder(owner, name).setRequired(required).addValidations(configModels).build(); + } + + /** + * Internal constructor. + * @param builder the builder, not null. + */ + protected SectionModel(Builder builder) { + super(builder.owner, builder.name, builder.childConfigModels); + } + + @Override + public ModelTarget getType(){ + return ModelTarget.Section; + } + + @Override + public Collection validate(Configuration config) { + Map map = config.getProperties(); + String lookupKey = getName() + '.'; + boolean present = false; + for(String key:map.keySet()){ + if(key.startsWith("_")){ + continue; + } + if(key.startsWith(lookupKey)){ + present = true; + break; + } + } + List result = new ArrayList<>(1); + if(isRequired() && !present) { + result.add(Validation.ofMissing(this)); + } + result.addAll(super.validate(config)); + return result; + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + b.append(getType()).append(": ").append(getName()); + if(isRequired()) { + b.append(", required: " ).append(isRequired()); + } + for(ConfigModel val:getValidations()){ + b.append(", ").append(val.toString()); + } + return b.toString(); + } + + /** + * Builder for setting up a AreaConfigModel instance. + */ + public static class Builder{ + /** The section owner. */ + private String owner; + /** The section name. */ + private String name; + /** The optional description. */ + private String description; + /** The required flag. */ + private boolean required; + /** The (optional) custom validations.*/ + private final List childConfigModels = new ArrayList<>(); + + /** + * Creates a new Builder. + * @param owner owner, not null. + * @param sectionName the section name, not null. + */ + public Builder(String owner, String sectionName){ + this.owner = Objects.requireNonNull(owner); + this.name = Objects.requireNonNull(sectionName); + } + + /** + * Add configModels. + * @param configModels the configModels, not null. + * @return the Builder for chaining. + */ + public Builder addValidations(ConfigModel... configModels){ + this.childConfigModels.addAll(Arrays.asList(configModels)); + return this; + } + + /** + * Add configModels. + * @param configModels the configModels, not null. + * @return the Builder for chaining. + */ + public Builder addValidations(Collection configModels){ + this.childConfigModels.addAll(configModels); + return this; + } + + /** + * Sets the required flag. + * @param required zhe flag. + * @return the Builder for chaining. + */ + public Builder setRequired(boolean required){ + this.required = required; + return this; + } + + /** + * Set the )optional) description. + * @param description the description. + * @return the Builder for chaining. + */ + public Builder setDescription(String description){ + this.description = description; + return this; + } + + /** + * Set the section name + * @param name the section name, not null. + * @return the Builder for chaining. + */ + public Builder setName(String name){ + this.name = Objects.requireNonNull(name); + return this; + } + + /** + * Build a new ConfigModel instance. + * @return the new ConfigModel instance, not null. + */ + public ConfigModel build(){ + return new SectionModel(this); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ConfigDocumentationMBean ---------------------------------------------------------------------- diff --git a/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ConfigDocumentationMBean b/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ConfigDocumentationMBean new file mode 100644 index 0000000..f41ad43 --- /dev/null +++ b/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ConfigDocumentationMBean @@ -0,0 +1,38 @@ +# +# 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. +# + +# +# 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.validation.internal.ConfigDocumentationBean \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ModelProviderSpi ---------------------------------------------------------------------- diff --git a/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ModelProviderSpi b/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ModelProviderSpi new file mode 100644 index 0000000..3866a74 --- /dev/null +++ b/validation/src/main/resources/META-INF/services/org.apache.tamaya.validation.spi.ModelProviderSpi @@ -0,0 +1,41 @@ +# +# 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. +# + +# +# 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.validation.internal.ConfiguredPropertiesModelProviderSpi +org.apache.tamaya.validation.internal.ConfiguredInlineModelProviderSpi +org.apache.tamaya.validation.internal.ConfiguredResourcesModelProviderSpi +org.apache.tamaya.validation.internal.ConfiguredTypeEventsModelProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/validation/src/test/java/org/apache/tamaya/validation/ConfigModelProviderTest.java ---------------------------------------------------------------------- diff --git a/validation/src/test/java/org/apache/tamaya/validation/ConfigModelProviderTest.java b/validation/src/test/java/org/apache/tamaya/validation/ConfigModelProviderTest.java new file mode 100644 index 0000000..dda2b67 --- /dev/null +++ b/validation/src/test/java/org/apache/tamaya/validation/ConfigModelProviderTest.java @@ -0,0 +1,68 @@ +/* + * 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.validation; + +import org.apache.tamaya.validation.spi.SectionModel; +import org.apache.tamaya.validation.spi.ParameterModel; +import org.apache.tamaya.validation.spi.GroupModel; +import org.apache.tamaya.validation.spi.ModelProviderSpi; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + + +/** + * Created by Anatole on 09.08.2015. + */ +public class ConfigModelProviderTest implements ModelProviderSpi { + + private List configModels = new ArrayList<>(1); + + public ConfigModelProviderTest(){ + configModels.add(new TestConfigModel()); + configModels = Collections.unmodifiableList(configModels); + } + + public Collection getConfigModels() { + return configModels; + } + + private static final class TestConfigModel extends GroupModel { + + public TestConfigModel(){ + super("TestConfigModel", "TestConfig", new SectionModel.Builder("TestConfigModel", + "a.test.existing").setRequired(true).build(), + ParameterModel.of("TestConfigModel", "a.test.existing.aParam", true), + ParameterModel.of("TestConfigModel", "a.test.existing.optionalParam"), + ParameterModel.of("TestConfigModel", "a.test.existing.aABCParam", false, "[ABC].*"), + new SectionModel.Builder("TestConfigModel", "a.test.notexisting").setRequired(true).build(), + ParameterModel.of("TestConfigModel", "a.test.notexisting.aParam", true), + ParameterModel.of("TestConfigModel", "a.test.notexisting.optionalParam"), + ParameterModel.of("TestConfigModel", "a.test.existing.aABCParam2", false, "[ABC].*")); + } + @Override + public String getName() { + return "TestConfigConfigModel"; + } + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/validation/src/test/java/org/apache/tamaya/validation/ValidationTests.java ---------------------------------------------------------------------- diff --git a/validation/src/test/java/org/apache/tamaya/validation/ValidationTests.java b/validation/src/test/java/org/apache/tamaya/validation/ValidationTests.java new file mode 100644 index 0000000..29c3801 --- /dev/null +++ b/validation/src/test/java/org/apache/tamaya/validation/ValidationTests.java @@ -0,0 +1,52 @@ +/* + * 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.validation; + +import org.junit.Test; + +/** + * Created by Anatole on 10.08.2015. + */ +public class ValidationTests { + + @Test + public void testDefaults(){ + System.err.println(ConfigModelManager.validate()); + } + + @Test + public void testAllValidations(){ + System.err.println(ConfigModelManager.getModels()); + } + + @Test + public void testConfigInfo(){ + System.err.println(ConfigModelManager.getConfigInfoText()); + } + + @Test + public void testAllValidationsInclUndefined(){ + System.err.println("Including UNDEFINED: \n" + ConfigModelManager.validate(true)); + } + + @Test + public void testModels(){ + System.err.println("MODELS: " +ConfigModelManager.getModels()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/validation/src/test/java/org/apache/tamaya/validation/internal/ConfigDocumentationBeanTest.java ---------------------------------------------------------------------- diff --git a/validation/src/test/java/org/apache/tamaya/validation/internal/ConfigDocumentationBeanTest.java b/validation/src/test/java/org/apache/tamaya/validation/internal/ConfigDocumentationBeanTest.java new file mode 100644 index 0000000..39bf657 --- /dev/null +++ b/validation/src/test/java/org/apache/tamaya/validation/internal/ConfigDocumentationBeanTest.java @@ -0,0 +1,108 @@ +/* + * 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.validation.internal; + +import org.apache.tamaya.validation.ModelTarget; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * Created by Anatole on 19.08.2015. + */ +public class ConfigDocumentationBeanTest { + + private final ConfigDocumentationBean mbean = new ConfigDocumentationBean(); + + @Test + public void testValidate_NoUnknowns() throws Exception { + String results = mbean.validate(false); + assertNotNull(results); + assertFalse(results.trim().isEmpty()); + assertTrue(results.contains("\"target\":\"Parameter\"")); + assertTrue(results.contains("\"result\":\"MISSING\"")); + assertFalse(results.contains("\"description\":\"Undefined key: ")); + assertFalse(results.contains(" \"result\":\"UNDEFINED\"")); + } + + @Test + public void testValidate_WithUnknowns() throws Exception { + String results = mbean.validate(true); + assertNotNull(results); + assertFalse(results.trim().isEmpty()); + // test transitive excludes of default sys properties + assertFalse(results.contains("\"name\":\"java")); + assertFalse(results.contains("\"name\":\"sun.")); + assertFalse(results.contains("\"name\":\"file.")); + // test others + assertTrue(results.contains("\"target\":\"Parameter\"")); + assertTrue(results.contains("\"target\":\"Section\"")); + assertTrue(results.contains("\"result\":\"MISSING\"")); + assertTrue(results.contains("\"description\":\"Undefined key: ")); + assertTrue(results.contains(" \"result\":\"UNDEFINED\"")); + } + + @Test + public void testGetConfigurationModel() throws Exception { + String results = mbean.getConfigurationModel(); + assertNotNull(results); + assertFalse(results.trim().isEmpty()); + assertTrue(results.contains("\"target\":\"Parameter\"")); + assertTrue(results.contains("\"name\":\"MyNumber\"")); + assertTrue(results.contains("\"name\":\"a.b.c\"")); + assertTrue(results.contains("\"required\":true")); + } + + @Test + public void testGetConfigurationModel_WithSection() throws Exception { + String results = mbean.getConfigurationModel(ModelTarget.Parameter); + assertNotNull(results); + assertFalse(results.trim().isEmpty()); + assertTrue(results.contains("\"target\":\"Parameter\"")); + assertFalse(results.contains("\"target\":\"Section\"")); + assertTrue(results.contains("\"required\":true")); + } + + @Test + public void testFindConfigurationModels() throws Exception { + String results = mbean.findConfigurationModels("a"); + assertNotNull(results); + assertFalse(results.trim().isEmpty()); + assertFalse(results.contains("\"target\":\"Parameter\"")); + assertTrue(results.contains("\"target\":\"Section\"")); + } + + @Test + public void testFindValidationModels() throws Exception { + String results = mbean.findValidationModels("a", ModelTarget.Section); + assertNotNull(results); + assertFalse(results.trim().isEmpty()); + assertFalse(results.contains("\"target\":\"Parameter\"")); + assertTrue(results.contains("\"target\":\"Section\"")); + System.out.println(results); + } + + @Test + public void testToString() throws Exception { + String toString = mbean.toString(); + System.out.println(toString); + } +} \ No newline at end of file