summaryrefslogtreecommitdiffstats
path: root/standalone-container/src/test/scala/com/yahoo/container/standalone/StandaloneContainerTest.scala
blob: 87bef2efd95e543bdfa28bb13522c79460de103a (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.standalone


import com.yahoo.container.standalone.StandaloneContainerTest._
import com.yahoo.vespa.model.AbstractService
import org.junit.Assert._
import org.junit.Test

import scala.util.Try


/**
 * @author tonytv
 * @author gjoranv
 */

class StandaloneContainerTest {
  @Test
  def container_is_allowed_root_element() {
    StandaloneContainer.withContainerModel(plainXml) { root =>  }
  }

  @Test
  def services_is_allowed_root_element() {
    val servicesXml =
      <services>
        <container version="1.0" />
      </services>

    StandaloneContainer.withContainerModel(servicesXml) { root =>  }
  }

  @Test
  def multiple_container_elements_cannot_be_deployed() {
    val twoContainersXml =
      <services>
        <container id="container-1" version="1.0" />
        <container id="container-2" version="1.0" />
      </services>

    assertTrue(
      Try {
        StandaloneContainer.withContainerModel(twoContainersXml) { root =>  }
      }.isFailure)
  }

  @Test
  def application_preprocessor_is_run() {
    val servicesXml =
      <services xmlns:preprocess="properties">
        <preprocess:properties>
          <container_id>container-1</container_id>
        </preprocess:properties>
        <container id="${container_id}" version="1.0" />
      </services>
    StandaloneContainer.withContainerModel(servicesXml) {
      root =>
        assertTrue(root.getConfigProducer("container-1/standalone").isPresent)
    }
  }

  @Test
  def no_default_ports_are_enabled_when_using_http() {
    val xml =
      <jdisc version="1.0">
        <http>
          <server port="4000" id="server1" />
        </http>
      </jdisc>

    StandaloneContainer.withContainerModel(xml) { root =>
      val container = root.getConfigProducer("jdisc/standalone").get().asInstanceOf[AbstractService]
      println("portCnt: " + container.getPortCount)
      println("numPorts: " + container.getNumPortsAllocated)
      assertEquals(1, container.getNumPortsAllocated)
    }
  }

}

object StandaloneContainerTest {

  val plainXml = <container version="1.0" />
}