summaryrefslogtreecommitdiffstats
path: root/standalone-container/src/test/java/com/yahoo/container
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /standalone-container/src/test/java/com/yahoo/container
Publish
Diffstat (limited to 'standalone-container/src/test/java/com/yahoo/container')
-rw-r--r--standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java112
1 files changed, 112 insertions, 0 deletions
diff --git a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java
new file mode 100644
index 00000000000..484d4c4d50e
--- /dev/null
+++ b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java
@@ -0,0 +1,112 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.standalone;
+
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import com.yahoo.io.IOUtils;
+import com.yahoo.jdisc.http.ConnectorConfig;
+import com.yahoo.vespa.defaults.Defaults;
+import com.yahoo.vespa.model.container.Container;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.collection.IsEmptyCollection.empty;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
+ * @since 5.22.0
+ */
+public class StandaloneContainerActivatorTest {
+
+ private String getJdiscXml(String contents) throws ParserConfigurationException, IOException, SAXException {
+ return "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
+ "<services>\n" +
+ " <jdisc version=\"1.0\" jetty=\"true\">\n" +
+ contents +
+ " </jdisc>\n" +
+ "</services>";
+ }
+
+ private void writeApplicationPackage(String servicesXml, Path tmpDir) throws IOException {
+ FileWriter fw = new FileWriter(tmpDir.resolve("services.xml").toFile(), false);
+ fw.write(servicesXml);
+ fw.close();
+ }
+
+ @Test
+ public void requireThatPortsCanBeFoundBasic() throws IOException, ParserConfigurationException, SAXException {
+ final Path applicationDir = Files.createTempDirectory("application");
+ try {
+ writeApplicationPackage(getJdiscXml(""), applicationDir);
+ StandaloneContainerActivator activator = new StandaloneContainerActivator();
+ Container container = activator.getContainer(newAppDirBinding(applicationDir));
+ List<Integer> ports = getPorts(activator, container);
+ assertThat(ports, is(asList(Defaults.getDefaults().vespaWebServicePort())));
+ } finally {
+ IOUtils.recursiveDeleteDir(applicationDir.toFile());
+ }
+ }
+
+ private List<Integer> getPorts(StandaloneContainerActivator activator, Container container) {
+ return activator.getConnectorConfigs(container).stream().
+ map(ConnectorConfig::listenPort).
+ collect(toList());
+ }
+
+ @Test
+ public void requireThatPortsCanBeFoundNoHttp() throws IOException, ParserConfigurationException, SAXException {
+ final Path applicationDir = Files.createTempDirectory("application");
+ try {
+ writeApplicationPackage(getJdiscXml("<http/>"), applicationDir);
+ StandaloneContainerActivator activator = new StandaloneContainerActivator();
+ Container container = activator.getContainer(newAppDirBinding(applicationDir));
+ List<Integer> ports = getPorts(activator, container);
+ assertThat(ports, empty());
+ } finally {
+ IOUtils.recursiveDeleteDir(applicationDir.toFile());
+ }
+ }
+
+ @Test
+ public void requireThatPortsCanBeFoundHttpThreeServers() throws IOException, ParserConfigurationException, SAXException {
+ final Path applicationDir = Files.createTempDirectory("application");
+ try {
+ final String contents =
+ "<http>\n" +
+ " <server id=\"a\" port=\"123\"/>\n" +
+ " <server id=\"b\" port=\"456\"/>\n" +
+ " <server id=\"c\" port=\"789\"/>\n" +
+ "</http>\n";
+ writeApplicationPackage(getJdiscXml(contents), applicationDir);
+ StandaloneContainerActivator activator = new StandaloneContainerActivator();
+ Container container = activator.getContainer(newAppDirBinding(applicationDir));
+ List<Integer> ports = getPorts(activator, container);
+ assertThat(ports, is(asList(123, 456, 789)));
+ } finally {
+ IOUtils.recursiveDeleteDir(applicationDir.toFile());
+ }
+ }
+
+ private Module newAppDirBinding(final Path applicationDir) {
+ return new Module() {
+ @Override
+ public void configure(Binder binder) {
+ binder.bind(Path.class)
+ .annotatedWith(StandaloneContainerApplication.applicationPathName())
+ .toInstance(applicationDir);
+ }
+ };
+ }
+
+}