// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.admin.monitoring;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import org.junit.Test;

import java.util.Map;

import static org.junit.Assert.assertEquals;

/**
 * @author gjoranv
 */
public class MetricSetTest {

    @Test
    public void internal_metrics_take_precedence_over_metrics_from_children() {
        String METRIC_NAME = "metric1";
        String COMMON_DIMENSION_KEY = "commonKey";

        Map<String, String> childDimensions = ImmutableMap.<String, String>builder()
                .put(COMMON_DIMENSION_KEY, "childCommonVal")
                .put("childKey", "childVal")
                .build();
        Metric childMetric = new Metric(METRIC_NAME, "child-output-name", "child-description", childDimensions);

        Map<String, String> parentDimensions = ImmutableMap.<String, String>builder()
                .put(COMMON_DIMENSION_KEY, "parentCommonVal")
                .put("parentKey", "parentVal")
                .build();
        Metric parentMetric = new Metric(METRIC_NAME, "parent-output-name", "parent-description", parentDimensions);

        MetricSet child =  new MetricSet("set1", Sets.newHashSet(childMetric));
        MetricSet parent = new MetricSet("set1", Sets.newHashSet(parentMetric), Sets.newHashSet(child));

        Metric combinedMetric = parent.getMetrics().get(METRIC_NAME);
        assertEquals("parent-output-name", combinedMetric.outputName);
        assertEquals("parent-description", combinedMetric.description);
        assertEquals(3, combinedMetric.dimensions.size());
        assertEquals("parentCommonVal", combinedMetric.dimensions.get(COMMON_DIMENSION_KEY));
    }
}

@@ -156,16 +156,64 @@
 oring;%0A%0A
+import com.google.common.collect.ImmutableList;%0A
 import c
@@ -355,95 +355,867 @@
 tic 
-org.junit.Assert.assertEquals;%0A%0A/**%0A * @author gjoranv%0A */%0Apublic class MetricSetTest %7B
+java.util.Collections.emptyList;%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertNotNull;%0A%0A/**%0A * @author gjoranv%0A */%0Apublic class MetricSetTest %7B%0A%0A    @Test%0A    public void metrics_from_children_are_added() %7B%0A        MetricSet child1 = new MetricSet(%22child1%22,%0A                                         ImmutableList.of(new Metric(%22child1_metric%22)));%0A        MetricSet child2 = new MetricSet(%22child2%22,%0A                                         ImmutableList.of(new Metric(%22child2_metric%22)));%0A        MetricSet parent = new MetricSet(%22parent%22, emptyList(), ImmutableList.of(child1, child2));%0A%0A        Map%3CString, Metric%3E parentMetrics = parent.getMetrics();%0A        assertEquals(2, parentMetrics.size());%0A        assertNotNull(parentMetrics.get(%22child1_metric%22));%0A        assertNotNull(parentMetrics.get(%22child2_metric%22));%0A    %7D
 %0A%0A  

Add unit test.