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
54
55
56
57
58
59
60
61
|
// 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.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.Test;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* @author gjoranv
* @author ollivir
*/
public class BundleInstantiationSpecificationBuilderTest {
@Test
public void bundle_is_not_replaced_for_user_defined_class() throws IOException, SAXException {
final String userDefinedClass = "my own class that will also be set as bundle";
verifyExpectedBundle(userDefinedClass, null, userDefinedClass);
}
@Test
public void bundle_is_replaced_for_internal_class() throws IOException, SAXException {
String internalClass = GroupingValidator.class.getName();
verifyExpectedBundle(internalClass, null, PlatformBundles.searchAndDocprocBundle);
}
@Test
public void bundle_is_not_replaced_for_internal_class_with_explicitly_set_bundle()
throws IOException, SAXException {
String internalClass = GroupingValidator.class.getName();
String explicitBundle = "my-own-implementation";
verifyExpectedBundle(internalClass, explicitBundle, explicitBundle);
}
private static void verifyExpectedBundle(String className, String explicitBundle, String expectedBundle)
throws IOException, SAXException {
String xml = "<component id=\"_\" class=\"" + className + "\"";
if (explicitBundle != null) {
xml += " bundle=\"" + explicitBundle + "\"";
}
xml += " />";
InputStream xmlStream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
Element component = XmlHelper.getDocumentBuilder().parse(xmlStream).getDocumentElement();
BundleInstantiationSpecification spec = BundleInstantiationSpecificationBuilder.build(component);
assertThat(spec.bundle, is(ComponentSpecification.fromString(expectedBundle)));
}
}
|