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 E83EF200CB3 for ; Mon, 26 Jun 2017 15:41:16 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id E6E86160BF8; Mon, 26 Jun 2017 13:41:16 +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 39155160BD9 for ; Mon, 26 Jun 2017 15:41:16 +0200 (CEST) Received: (qmail 18754 invoked by uid 500); 26 Jun 2017 13:41:15 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 18722 invoked by uid 99); 26 Jun 2017 13:41:15 -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; Mon, 26 Jun 2017 13:41:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0FE86E96AC; Mon, 26 Jun 2017 13:41:15 +0000 (UTC) From: geomacy To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #734: Support ConfigKey deprecated names Content-Type: text/plain Message-Id: <20170626134115.0FE86E96AC@git1-us-west.apache.org> Date: Mon, 26 Jun 2017 13:41:15 +0000 (UTC) archived-at: Mon, 26 Jun 2017 13:41:17 -0000 Github user geomacy commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/734#discussion_r124008032 --- Diff: core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationTest.java --- @@ -0,0 +1,328 @@ +/* + * 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.brooklyn.core.config; + +import static org.testng.Assert.assertEquals; + +import org.apache.brooklyn.api.entity.Entity; +import org.apache.brooklyn.api.entity.EntityInitializer; +import org.apache.brooklyn.api.entity.EntityLocal; +import org.apache.brooklyn.api.entity.EntitySpec; +import org.apache.brooklyn.api.entity.ImplementedBy; +import org.apache.brooklyn.api.location.LocationSpec; +import org.apache.brooklyn.api.policy.PolicySpec; +import org.apache.brooklyn.api.sensor.EnricherSpec; +import org.apache.brooklyn.config.ConfigKey; +import org.apache.brooklyn.core.enricher.AbstractEnricher; +import org.apache.brooklyn.core.entity.AbstractEntity; +import org.apache.brooklyn.core.entity.EntityInternal; +import org.apache.brooklyn.core.entity.internal.ConfigUtilsInternal; +import org.apache.brooklyn.core.location.AbstractLocation; +import org.apache.brooklyn.core.policy.AbstractPolicy; +import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; +import org.apache.brooklyn.core.test.entity.TestEntity; +import org.apache.brooklyn.entity.stock.BasicEntity; +import org.apache.brooklyn.test.LogWatcher; +import org.apache.brooklyn.test.LogWatcher.EventPredicates; +import org.apache.brooklyn.util.core.config.ConfigBag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableMap; + +import ch.qos.logback.classic.spi.ILoggingEvent; + +public class ConfigKeyDeprecationTest extends BrooklynAppUnitTestSupport { + + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(ConfigKeyDeprecationTest.class); + + public static final ConfigKey KEY_1 = ConfigKeys.builder(String.class, "key1") + .deprecatedNames("oldKey1", "oldKey1b") + .build(); + + @Test + public void testUsingDeprecatedName() throws Exception { + EntityInternal entity = app.addChild(EntitySpec.create(MyBaseEntity.class) + .configure("oldSuperKey1", "myval")); + EntityInternal entity2 = app.addChild(EntitySpec.create(MyBaseEntity.class) + .configure("oldSuperKey1b", "myval")); + assertEquals(entity.config().get(MyBaseEntity.SUPER_KEY_1), "myval"); + assertEquals(entity2.config().get(MyBaseEntity.SUPER_KEY_1), "myval"); + } + + @Test + public void testPrefersNonDeprecatedName() throws Exception { + EntityInternal entity = app.addChild(EntitySpec.create(MyBaseEntity.class) + .configure("superKey1", "myval") + .configure("oldSuperKey1", "mywrongval")); + assertEquals(entity.config().get(MyBaseEntity.SUPER_KEY_1), "myval"); + } + + @Test + public void testPrefersFirstDeprecatedNameIfMultiple() throws Exception { + EntityInternal entity = app.addChild(EntitySpec.create(MyBaseEntity.class) + .configure("oldSuperKey1", "myval1") --- End diff -- Maybe nicer to order these as ``` .configure("oldSuperKey1b", "myval2") .configure("oldSuperKey1", "myval1") ``` to demonstrate that the order in which they are configured here is not the determining factor; maybe even call `oldSuperKey1` something instead that is lexically greater than `oldSuperKey2` to demonstrate that it's not alphabetic either! --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---