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 29D28200C3E for ; Tue, 21 Mar 2017 23:09:56 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 28BD9160B90; Tue, 21 Mar 2017 22:09:56 +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 2ADCB160B6E for ; Tue, 21 Mar 2017 23:09:55 +0100 (CET) Received: (qmail 67450 invoked by uid 500); 21 Mar 2017 22:09:54 -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 67441 invoked by uid 99); 21 Mar 2017 22:09:54 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Mar 2017 22:09:54 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id EABBF181327 for ; Tue, 21 Mar 2017 22:09:53 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.568 X-Spam-Level: X-Spam-Status: No, score=-3.568 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_NEUTRAL=0.652, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id bA9N32RDAgGr for ; Tue, 21 Mar 2017 22:09:51 +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 84B5A60CD9 for ; Tue, 21 Mar 2017 22:09:50 +0000 (UTC) Received: (qmail 67378 invoked by uid 99); 21 Mar 2017 22:09:49 -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; Tue, 21 Mar 2017 22:09:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 88EC0DFB0E; Tue, 21 Mar 2017 22:09:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: plexus@apache.org To: commits@tamaya.incubator.apache.org Date: Tue, 21 Mar 2017 22:09:52 -0000 Message-Id: <521b4f300ad14d1a938158e98aa6837d@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [4/4] incubator-tamaya-extensions git commit: [TAMAYA-244] Wrote tests for EnrichedPropertySource. archived-at: Tue, 21 Mar 2017 22:09:56 -0000 [TAMAYA-244] Wrote tests for EnrichedPropertySource. Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/2f124694 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/2f124694 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/2f124694 Branch: refs/heads/master Commit: 2f124694a58fbe65652f90c44ded8f68b9518f70 Parents: 19553ad Author: Oliver B. Fischer Authored: Tue Mar 21 23:09:35 2017 +0100 Committer: Oliver B. Fischer Committed: Tue Mar 21 23:09:35 2017 +0100 ---------------------------------------------------------------------- .../functions/EnrichedPropertySourceTest.java | 250 +++++++++++++++++++ .../functions/FilteredPropertySourceTest.java | 1 + .../functions/InMemoryPropertySource.java | 4 +- 3 files changed, 254 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2f124694/modules/functions/src/test/java/org/apache/tamaya/functions/EnrichedPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/EnrichedPropertySourceTest.java b/modules/functions/src/test/java/org/apache/tamaya/functions/EnrichedPropertySourceTest.java new file mode 100644 index 0000000..563a986 --- /dev/null +++ b/modules/functions/src/test/java/org/apache/tamaya/functions/EnrichedPropertySourceTest.java @@ -0,0 +1,250 @@ +/* + * 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.functions; + +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; +import org.junit.Test; + +import javax.management.RuntimeMBeanException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static java.util.Collections.EMPTY_MAP; +import static org.apache.tamaya.functions.MethodNotMockedAnswer.NOT_MOCKED_ANSWER; +import static org.apache.tamaya.spi.PropertyValue.of; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +public class EnrichedPropertySourceTest { + + /* + * Tests for getName() + */ + + @Test + public void getNameReturnsTheNameOfTheBaseConfiguration() { + PropertySource propertySource = mock(PropertySource.class, NOT_MOCKED_ANSWER); + doReturn("abc").when(propertySource).getName(); + + EnrichedPropertySource sut = new EnrichedPropertySource(propertySource, EMPTY_MAP, false); + + String name = sut.getName(); + + assertThat(name).isEqualTo("abc"); + } + + + /* + * Tests for getOrdinal() + */ + + @Test + public void getOrdinalReturnsTheValueOfTheBaseConfiguration() { + PropertySource propertySource = mock(PropertySource.class, NOT_MOCKED_ANSWER); + doReturn(13).when(propertySource).getOrdinal(); + + EnrichedPropertySource sut = new EnrichedPropertySource(propertySource, EMPTY_MAP, false); + + int ordinal = sut.getOrdinal(); + + assertThat(ordinal).isEqualTo(13); + } + + /* + * Tests for EnrichedPropertySource(PropertySource, Map, boolean) + */ + + /* + * Tests for get(String) + */ + + @Test + public void getReturnsAdditional() { + InMemoryPropertySource base = new InMemoryPropertySource(); + + base.setName("name").add("a", "1").add("b", "2").add("c", "3").add("d", "4"); + + Map additions = new HashMap<>(); + additions.put("e", "9"); + additions.put("f", "11"); + + EnrichedPropertySource sut = new EnrichedPropertySource(base, additions, false); + + PropertyValue result = sut.get("e"); + + assertThat(result).isNotNull().isNotNull().isEqualTo(of("e", "9", "name")); + } + + @Test + public void getReturnsOverriddenValue() { + InMemoryPropertySource base = new InMemoryPropertySource(); + + base.setName("name").add("a", "1").add("b", "2").add("c", "3").add("d", "4"); + + Map additions = new HashMap<>(); + additions.put("b", "9"); + additions.put("d", "11"); + + EnrichedPropertySource sut = new EnrichedPropertySource(base, additions, true); + + PropertyValue result = sut.get("b"); + + assertThat(result).isNotNull().isEqualTo(of("b", "9", "name")); + } + + @Test + public void getReturnsGivenValueWhichIsNotOverridden() { + InMemoryPropertySource base = new InMemoryPropertySource(); + + base.setName("name").add("a", "1").add("b", "2").add("c", "3").add("d", "4"); + + Map additions = new HashMap<>(); + additions.put("b", "9"); + additions.put("d", "11"); + + EnrichedPropertySource sut = new EnrichedPropertySource(base, additions, true); + + PropertyValue result = sut.get("a"); + + assertThat(result).isNotNull().isEqualTo(of("a", "1", "name")); + } + + @Test + public void getPropertiesReturnsNotOverriddenValue() { + InMemoryPropertySource base = new InMemoryPropertySource(); + + base.setName("name").add("a", "1").add("b", "2").add("c", "3").add("d", "4"); + + Map additions = new HashMap<>(); + additions.put("b", "9"); + additions.put("d", "11"); + + EnrichedPropertySource sut = new EnrichedPropertySource(base, additions, false); + + PropertyValue result = sut.get("b"); + + assertThat(result).isNotNull().isEqualTo(of("b", "2", "name")); + } + + + /* + * Tests for getProperties() + */ + + @Test + public void getPropertiesReturnsAllAdditionalToo() { + InMemoryPropertySource base = new InMemoryPropertySource(); + + base.setName("name").add("a", "1").add("b", "2").add("c", "3").add("d", "4"); + + Map additions = new HashMap<>(); + additions.put("e", "9"); + additions.put("f", "11"); + + EnrichedPropertySource sut = new EnrichedPropertySource(base, additions, false); + + Map properties = sut.getProperties(); + + assertThat(properties).isNotNull().isNotEmpty() + .containsEntry("a", of("a", "1", "name")) + .containsEntry("b", of("b", "2", "name")) + .containsEntry("c", of("c", "3", "name")) + .containsEntry("d", of("d", "4", "name")) + .containsEntry("e", of("e", "9", "name")) + .containsEntry("f", of("f", "11", "name")) + .hasSize(6); + } + + @Test + public void getPropertiesReturnsAllWithOverriddenValues() { + InMemoryPropertySource base = new InMemoryPropertySource(); + + base.setName("name").add("a", "1").add("b", "2").add("c", "3").add("d", "4"); + + Map additions = new HashMap<>(); + additions.put("b", "9"); + additions.put("d", "11"); + + EnrichedPropertySource sut = new EnrichedPropertySource(base, additions, true); + + Map properties = sut.getProperties(); + + assertThat(properties).isNotNull().isNotEmpty() + .containsEntry("a", of("a", "1", "name")) + .containsEntry("b", of("b", "9", "name")) + .containsEntry("c", of("c", "3", "name")) + .containsEntry("d", of("d", "11", "name")) + .hasSize(4); + + } + + @Test + public void getPropertiesReturnsAllNoOverriddenValues() { + InMemoryPropertySource base = new InMemoryPropertySource(); + + base.setName("name").add("a", "1").add("b", "2").add("c", "3").add("d", "4"); + + Map additions = new HashMap<>(); + additions.put("b", "9"); + additions.put("d", "11"); + + EnrichedPropertySource sut = new EnrichedPropertySource(base, additions, false); + + Map properties = sut.getProperties(); + + assertThat(properties).isNotNull().isNotEmpty() + .containsEntry("a", of("a", "1", "name")) + .containsEntry("b", of("b", "2", "name")) + .containsEntry("c", of("c", "3", "name")) + .containsEntry("d", of("d", "4", "name")) + .hasSize(4); + } + + /* + * Tests for isScannable() + */ + + @Test + public void isScannableReturnsTheValueOfTheBaseConfigurationWhichIsTrue() { + PropertySource propertySource = mock(PropertySource.class, NOT_MOCKED_ANSWER); + doReturn(true).when(propertySource).isScannable(); + + EnrichedPropertySource sut = new EnrichedPropertySource(propertySource, EMPTY_MAP, false); + + boolean isScannable = sut.isScannable(); + + assertThat(isScannable).isEqualTo(true); + } + + @Test + public void isScannableReturnsTheValueOfTheBaseConfigurationWhichIsFalse() { + PropertySource propertySource = mock(PropertySource.class, NOT_MOCKED_ANSWER); + doReturn(false).when(propertySource).isScannable(); + + EnrichedPropertySource sut = new EnrichedPropertySource(propertySource, EMPTY_MAP, false); + + boolean isScannable = sut.isScannable(); + + assertThat(isScannable).isEqualTo(false); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2f124694/modules/functions/src/test/java/org/apache/tamaya/functions/FilteredPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/FilteredPropertySourceTest.java b/modules/functions/src/test/java/org/apache/tamaya/functions/FilteredPropertySourceTest.java index 677711d..e86cbc5 100644 --- a/modules/functions/src/test/java/org/apache/tamaya/functions/FilteredPropertySourceTest.java +++ b/modules/functions/src/test/java/org/apache/tamaya/functions/FilteredPropertySourceTest.java @@ -34,6 +34,7 @@ public class FilteredPropertySourceTest { /* * Tests for getName() */ + @Test public void getNameReturnsTheNameOfTheBaseConfiguration() { PropertySource propertySource = mock(PropertySource.class, NOT_MOCKED_ANSWER); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2f124694/modules/functions/src/test/java/org/apache/tamaya/functions/InMemoryPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/InMemoryPropertySource.java b/modules/functions/src/test/java/org/apache/tamaya/functions/InMemoryPropertySource.java index f927ca6..5f9b236 100644 --- a/modules/functions/src/test/java/org/apache/tamaya/functions/InMemoryPropertySource.java +++ b/modules/functions/src/test/java/org/apache/tamaya/functions/InMemoryPropertySource.java @@ -44,8 +44,10 @@ public class InMemoryPropertySource implements PropertySource { return name; } - public void setName(String name) { + public InMemoryPropertySource setName(String name) { this.name = name; + + return this; } @Override