aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilderTest.java
blob: c321eb5e3bc22807529052d77e2d9f1e366c66de (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
46
47
48
49
50
51
52
53
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.xml;

import com.yahoo.component.ComponentSpecification;
import com.yahoo.config.model.builder.xml.XmlHelper;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.search.grouping.GroupingValidator;
import com.yahoo.vespa.model.container.PlatformBundles;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Element;

import java.io.StringReader;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author gjoranv
 * @author ollivir
 */

public class BundleInstantiationSpecificationBuilderTest {

    @Test
    void bundle_is_not_replaced_for_user_defined_class() {
        final String userDefinedClass = "my own class that will also be set as bundle";
        verifyExpectedBundle(userDefinedClass, null, userDefinedClass);
    }

    @Test
    void bundle_is_replaced_for_internal_class() {
        String internalClass = GroupingValidator.class.getName();
        verifyExpectedBundle(internalClass, null, PlatformBundles.SEARCH_AND_DOCPROC_BUNDLE);
    }

    @Test
    void bundle_is_not_replaced_for_internal_class_with_explicitly_set_bundle() {
        String internalClass = GroupingValidator.class.getName();
        String explicitBundle = "my-own-implementation";
        verifyExpectedBundle(internalClass, explicitBundle, explicitBundle);
    }

    private static void verifyExpectedBundle(String className, String explicitBundle, String expectedBundle) {
        String xml = "<component id=\"_\" class=\"" + className + "\"";
        if (explicitBundle != null) {
            xml += " bundle=\"" + explicitBundle + "\"";
        }
        xml += " />";
        Element component = XmlHelper.getDocument(new StringReader(xml)).getDocumentElement();

        BundleInstantiationSpecification spec = BundleInstantiationSpecificationBuilder.build(component);
        assertEquals(ComponentSpecification.fromString(expectedBundle), spec.bundle);
    }
}