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
|
// 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.config.model.builder.xml.test.DomBuilderTest;
import com.yahoo.vespa.model.container.ContainerCluster;
import com.yahoo.vespa.model.container.component.Handler;
import org.junit.Test;
import org.w3c.dom.Element;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertThat;
/**
* @author Einar M R Rosenvinge
*/
public class ContainerDocumentApiBuilderTest extends ContainerModelBuilderTestBase {
private Map<String, Handler<?>> getHandlers(String clusterName) {
ContainerCluster cluster = (ContainerCluster) root.getChildren().get(clusterName);
Map<String, Handler<?>> handlerMap = new HashMap<>();
Collection<Handler<?>> handlers = cluster.getHandlers();
for (Handler<?> handler : handlers) {
assertThat(handlerMap.containsKey(handler.getComponentId().toString()), is(false)); //die on overwrites
handlerMap.put(handler.getComponentId().toString(), handler);
}
return handlerMap;
}
@Test
public void custom_bindings_are_allowed() {
Element elem = DomBuilderTest.parse(
"<container id='cluster1' version='1.0'>",
" <document-api>",
" <binding>http://*/document-api/</binding>",
" <binding>missing-trailing-slash</binding>",
" </document-api>",
nodesXml,
"</container>");
createModel(root, elem);
verifyCustomBindings("com.yahoo.vespa.http.server.FeedHandler", ContainerCluster.RESERVED_URI_PREFIX + "/feedapi");
}
private void verifyCustomBindings(String id, String bindingSuffix) {
Handler<?> handler = getHandlers("cluster1").get(id);
assertThat(handler.getServerBindings(), hasItem("http://*/document-api/" + bindingSuffix));
assertThat(handler.getServerBindings(), hasItem("http://*/document-api/" + bindingSuffix + "/"));
assertThat(handler.getServerBindings(), hasItem("missing-trailing-slash/" + bindingSuffix));
assertThat(handler.getServerBindings(), hasItem("missing-trailing-slash/" + bindingSuffix + "/"));
assertThat(handler.getServerBindings().size(), is(4));
}
@Test
public void requireThatHandlersAreSetup() {
Element elem = DomBuilderTest.parse(
"<container id='cluster1' version='1.0'>",
" <document-api />",
nodesXml,
"</container>");
createModel(root, elem);
Map<String, Handler<?>> handlerMap = getHandlers("cluster1");
assertThat(handlerMap.get("com.yahoo.container.handler.VipStatusHandler"), not(nullValue()));
assertThat(handlerMap.get("com.yahoo.container.handler.observability.ApplicationStatusHandler"), not(nullValue()));
assertThat(handlerMap.get("com.yahoo.container.jdisc.state.StateHandler"), not(nullValue()));
assertThat(handlerMap.get("com.yahoo.vespa.http.server.FeedHandler"), not(nullValue()));
assertThat(handlerMap.get("com.yahoo.vespa.http.server.FeedHandler").getServerBindings().contains("http://*/" + ContainerCluster.RESERVED_URI_PREFIX + "/feedapi"), is(true));
assertThat(handlerMap.get("com.yahoo.vespa.http.server.FeedHandler").getServerBindings().contains("http://*/" + ContainerCluster.RESERVED_URI_PREFIX + "/feedapi/"), is(true));
assertThat(handlerMap.get("com.yahoo.vespa.http.server.FeedHandler").getServerBindings().size(), equalTo(2));
}
}
|