diff options
Diffstat (limited to 'config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java')
-rw-r--r-- | config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java index cfe4b72f37d..9dee99f8f17 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java @@ -13,8 +13,9 @@ import com.yahoo.vespa.model.container.ApplicationContainerCluster; import com.yahoo.vespa.model.container.ContainerCluster; import com.yahoo.vespa.model.container.ContainerModel; import com.yahoo.vespa.model.container.component.Component; +import com.yahoo.vespa.model.container.component.Handler; import com.yahoo.vespa.model.container.search.ContainerSearch; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.w3c.dom.Element; import java.util.ArrayList; @@ -22,6 +23,8 @@ import java.util.Collections; import java.util.List; import java.util.logging.Level; +import static org.junit.jupiter.api.Assertions.assertNotNull; + /** * Utility functions for testing the ContainerModelBuilder. Note that XML validation will * not be done when using this class @@ -51,23 +54,31 @@ public abstract class ContainerModelBuilderTestBase { protected MockRoot root; + @BeforeEach + public void prepareTest() { + root = new MockRoot("root"); + } + protected void createBasicContainerModel() { Element clusterElem = DomBuilderTest.parse("<container id='default' version='1.0' />"); createModel(root, clusterElem); } - public static void createModel(MockRoot root, DeployState deployState, VespaModel vespaModel, Element... containerElems) { + public static List<ContainerModel> createModel(MockRoot root, DeployState deployState, VespaModel vespaModel, Element... containerElems) { + List<ContainerModel> containerModels = new ArrayList<>(); for (Element containerElem : containerElems) { ContainerModel model = new ContainerModelBuilder(false, ContainerModelBuilder.Networking.enable) .build(deployState, vespaModel, null, root, containerElem); ContainerCluster<?> cluster = model.getCluster(); generateDefaultSearchChains(cluster); + containerModels.add(model); } root.freezeModelTopology(); + return containerModels; } - public static void createModel(MockRoot root, Element... containerElems) { - createModel(root, DeployState.createTestState(), null, containerElems); + public static List<ContainerModel> createModel(MockRoot root, Element... containerElems) { + return createModel(root, DeployState.createTestState(), null, containerElems); } public static void createModel(MockRoot root, DeployLogger testLogger, Element... containerElems) { @@ -80,16 +91,11 @@ public abstract class ContainerModelBuilderTestBase { search.initializeSearchChains(Collections.emptyMap()); } - @Before - public void prepareTest() { - root = new MockRoot("root"); - } - protected ComponentsConfig componentsConfig() { return root.getConfig(ComponentsConfig.class, "default"); } - protected ComponentsConfig.Components getComponent(ComponentsConfig componentsConfig, String id) { + protected ComponentsConfig.Components getComponentInConfig(ComponentsConfig componentsConfig, String id) { for (ComponentsConfig.Components component : componentsConfig.components()) { if (component.id().equals(id)) return component; @@ -101,9 +107,21 @@ public abstract class ContainerModelBuilderTestBase { return (ApplicationContainerCluster) root.getChildren().get(clusterId); } - public Component<?, ?> getContainerComponent(String clusterId, String componentId) { + public Component<?, ?> getComponent(String clusterId, String componentId) { return getContainerCluster(clusterId).getComponentsMap().get( ComponentId.fromString(componentId)); } + public Handler getHandler(String clusterId, String componentId) { + Component<?,?> component = getComponent(clusterId, componentId); + if (! (component instanceof Handler)) + throw new RuntimeException("Component is not a handler: " + componentId); + return (Handler) component; + } + + void assertComponentConfigured(ApplicationContainerCluster cluster, String componentId) { + Component<?, ?> component = cluster.getComponentsMap().get(ComponentId.fromString(componentId)); + assertNotNull(component); + } + } |