summaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/builder/xml/dom/DomComponentBuilderTest.java
blob: 08fa820a83088e9da1cb99c39223661b121028bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.builder.xml.dom;

import com.yahoo.component.ComponentId;
import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.vespa.model.container.component.Component;
import org.junit.Test;

import static com.yahoo.collections.CollectionUtil.first;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;

/**
 * @author gjoranv
 */
public class DomComponentBuilderTest extends DomBuilderTest {

    @Test
    public void ensureCorrectModel() {
        Component<?, ?> handler = new DomComponentBuilder().doBuild(root, parse(
                "<handler id='theId' class='theClass' bundle='theBundle' />"));

        BundleInstantiationSpecification instantiationSpecification = handler.model.bundleInstantiationSpec;
        assertThat(instantiationSpecification.id.stringValue(), is("theId"));
        assertThat(instantiationSpecification.classId.stringValue(), is("theClass"));
        assertThat(instantiationSpecification.bundle.stringValue(), is("theBundle"));
    }

    @Test
    @SuppressWarnings("unchecked")
    public void components_can_be_nested() {
        Component<Component<?, ?>, ?> parent = new DomComponentBuilder().doBuild(root, parse(
                "<component id='parent'>",
                "  <component id='child' />",
                "</component>"));

        assertThat(parent.getGlobalComponentId(), is(ComponentId.fromString("parent")));
        Component<?, ?> child = first(parent.getChildren().values());
        assertNotNull(child);

        assertThat(child.getGlobalComponentId(), is(ComponentId.fromString("child@parent")));
    }
}