Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/734#discussion_r124001663
  
    --- Diff: 
core/src/test/java/org/apache/brooklyn/core/config/ConfigKeyDeprecationRebindTest.java
 ---
    @@ -0,0 +1,373 @@
    +/*
    + * 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 static org.testng.Assert.assertFalse;
    +import static org.testng.Assert.assertTrue;
    +
    +import java.io.File;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.util.List;
    +
    +import org.apache.brooklyn.api.entity.Application;
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.entity.EntitySpec;
    +import org.apache.brooklyn.api.entity.ImplementedBy;
    +import org.apache.brooklyn.api.objs.BrooklynObjectType;
    +import org.apache.brooklyn.config.ConfigKey;
    +import org.apache.brooklyn.core.enricher.AbstractEnricher;
    +import org.apache.brooklyn.core.entity.AbstractApplication;
    +import org.apache.brooklyn.core.entity.EntityInternal;
    +import org.apache.brooklyn.core.feed.AbstractFeed;
    +import org.apache.brooklyn.core.location.AbstractLocation;
    +import org.apache.brooklyn.core.mgmt.rebind.AbstractRebindHistoricTest;
    +import org.apache.brooklyn.core.policy.AbstractPolicy;
    +import org.testng.annotations.Test;
    +
    +import com.google.common.base.Joiner;
    +import com.google.common.base.Predicates;
    +import com.google.common.collect.Iterables;
    +
    +public class ConfigKeyDeprecationRebindTest extends 
AbstractRebindHistoricTest {
    +
    +    @Test
    +    public void testUsingDeprecatedName() throws Exception {
    +        MyApp entity = app().addChild(EntitySpec.create(MyApp.class)
    +                .configure("oldKey1", "myval"));
    +        assertEquals(entity.config().get(MyApp.KEY_1), "myval");
    +        
    +        rebind();
    +        
    +        Entity newEntity = 
mgmt().getEntityManager().getEntity(entity.getId());
    +        assertEquals(newEntity.config().get(MyApp.KEY_1), "myval");
    +        
    +        // Expect the persisted state of the entity to have used the 
non-deprecated name.
    +        String allLines = 
getPersistanceFileContents(BrooklynObjectType.ENTITY, newEntity.getId());
    +        assertFalse(allLines.contains("oldKey1"), "contains 'oldKey1', 
allLines="+allLines);
    +        assertTrue(allLines.contains("key1"), "contains 'key1', 
allLines="+allLines);
    +    }
    +    
    +    /**
    +     * Created with:
    +     * <pre>
    +     * {@code
    +     * Entity app = 
mgmt().getEntityManager().createEntity(EntitySpec.create(MyApp.class)
    +     *         .configure("oldKey1", "myval"));
    +     * }
    +     * </pre>
    +     */
    +    @Test
    +    public void testEntityPersistedWithDeprecatedKeyName() throws 
Exception {
    +        String appId = "pps2ttgijb";
    +        addMemento(BrooklynObjectType.ENTITY, "config-deprecated-key", 
appId);
    +        rebind();
    +        
    +        Entity newApp = mgmt().getEntityManager().getEntity(appId);
    +        assertEquals(newApp.config().get(MyApp.KEY_1), "myval");
    +        
    +        // Expect the persisted state to have been re-written with the new 
key value.
    +        switchOriginalToNewManagementContext();
    +        rebind();
    +        
    +        String allLines = 
getPersistanceFileContents(BrooklynObjectType.ENTITY, appId);
    +        assertFalse(allLines.contains("oldKey1"), "should not contain 
'oldKey1', allLines="+allLines);
    +        assertTrue(allLines.contains("<key1>"), "should contain '<key1>', 
allLines="+allLines);
    +    }
    +
    +    /**
    +     * Created with:
    +     * <pre>
    +     * {@code
    +     * Entity app = 
mgmt().getEntityManager().createEntity(EntitySpec.create(MyApp.class)
    +     *         .configure("oldFlagKey2", "myval"));
    +     * }
    +     * </pre>
    +     */
    +    @Test
    +    public void testEntityPersistedWithSetFromFlagNameOnKey() throws 
Exception {
    +        String appId = "ug77ek2tkd";
    +        addMemento(BrooklynObjectType.ENTITY, 
"config-deprecated-flagNameOnKey", appId);
    +        rebind();
    +        
    +        Entity newApp = mgmt().getEntityManager().getEntity(appId);
    +        assertEquals(newApp.config().get(MyApp.KEY_2), "myval");
    +        
    +        // Expect the persisted state to have been re-written with the new 
key value.
    +        switchOriginalToNewManagementContext();
    +        rebind();
    +        
    +        String allLines = 
getPersistanceFileContents(BrooklynObjectType.ENTITY, appId);
    +        assertFalse(allLines.contains("oldFlagKey2"), "should not contain 
'oldFlagKey2', allLines="+allLines);
    --- End diff --
    
    not sure I understand this test; the original persisted state already does 
not contain `oldFlagKey2`.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to