brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #219: Added identity method to DSL
Date Thu, 23 Jun 2016 22:22:34 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/219#discussion_r68326200
  
    --- Diff: camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/IdentityYamlTest.java
---
    @@ -0,0 +1,82 @@
    +/*
    +uniqueSshConnection * 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.camp.brooklyn;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.testng.Assert;
    +import org.testng.annotations.Test;
    +
    +import com.google.common.collect.Iterables;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.config.ConfigKey;
    +import org.apache.brooklyn.core.config.ConfigKeys;
    +import org.apache.brooklyn.core.entity.Entities;
    +import org.apache.brooklyn.core.entity.EntityPredicates;
    +import org.apache.brooklyn.core.test.entity.TestEntity;
    +import org.apache.brooklyn.util.text.StringPredicates;
    +
    +@Test
    +public class IdentityYamlTest extends AbstractYamlTest {
    +    private static final Logger log = LoggerFactory.getLogger(IdentityYamlTest.class);
    +
    +    private static final ConfigKey<String> TEST_ENTITY_ONE_ID = ConfigKeys.newStringConfigKey("testentityone.id");
    +    private static final ConfigKey<String> TEST_ENTITY_TWO_ID = ConfigKeys.newStringConfigKey("testentitytwo.id");
    +
    +    protected Iterable<? extends Entity> setupAndCheckTestEntityInBasicYamlWith()
throws Exception {
    +        Entity app = createAndStartApplication(loadYaml("test-entity-identity.yaml"));
    --- End diff --
    
    I have a personal dislike for this style of test, where the tiny amount of yaml is kept
separately from the code that uses it. My rule of thumb is that it's only worth having it
in a separate file if the yaml reaches some level of length/complexity (e.g. a dozen lines).
    
    I'd write this as the java below. Note that it strips out all the extra assertions that
aren't needed, or that are already covered in dozens of other tests.
    
        public void testBrooklynIdentityFunction() throws Exception {
        Entity app = createAndStartApplication(
                "services:",
                "- type: "+TestEntity.class.getName(),
                "  id: testentityone",
                "  name: Test Entity One",
                "  brooklyn.config:",
                "    testentityone.id: $brooklyn:identity()",
                "    testentitytwo.id: $brooklyn:entity(\"testentitytwo\").identity()",
                "- type: "+TestEntity.class.getName(),
                "  id: testentitytwo",
                "  name: test Entity Two");
    
        Entity entity1 = Iterables.find(testEntities, EntityPredicates.displayNameEqualTo("test
Entity One"));
        Entity entity2 = Iterables.find(testEntities, EntityPredicates.displayNameEqualTo("test
Entity Two"));
    
        assertEquals(entity1.config().get(TEST_ENTITY_ONE_ID), entity1.getId());
        assertEquals(entity1.config().get(TEST_ENTITY_TWO_ID), entity2.getId());
        }


---
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.
---

Mime
View raw message