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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// 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.http;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
import com.yahoo.jdisc.http.ServerConfig;
import com.yahoo.vespa.model.container.ContainerModel;
import com.yahoo.vespa.model.container.component.chain.Chain;
import com.yahoo.vespa.model.container.http.xml.HttpBuilder;
import com.yahoo.vespa.model.container.xml.ContainerModelBuilder;
import com.yahoo.vespa.model.container.xml.ContainerModelBuilder.Networking;
import org.junit.Test;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import java.io.IOException;
import static com.yahoo.collections.CollectionUtil.first;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertNotNull;
/**
* @author gjoranv
*/
public class FilterBindingsTest extends DomBuilderTest {
private static final String MY_CHAIN_BINDING = "http://*/my-chain-binding";
private Http buildHttp(Element xml) throws Exception {
Http http = new HttpBuilder().build(root.getDeployState(), root, xml);
root.freezeModelTopology();
http.validate();
return http;
}
private void buildContainerCluster(Element containerElem) throws SAXException, IOException {
ContainerModel model = new ContainerModelBuilder(true, Networking.enable).build(DeployState.createTestState(), null, null, root, containerElem);
root.freezeModelTopology();
}
@Test
public void request_chain_binding_is_added_to_http() throws Exception {
Element xml = parse(
"<http>",
" <filtering>",
" <request-chain id='my-request-chain'>",
" <binding>" + MY_CHAIN_BINDING + "</binding>",
" </request-chain>",
" </filtering>",
"</http>");
Http http = buildHttp(xml);
Http.Binding binding = first(http.bindings);
assertThat(binding.filterId.getName(), is("my-request-chain"));
assertThat(binding.binding, is(MY_CHAIN_BINDING));
Chain<Filter> myChain = http.getFilterChains().allChains().getComponent("my-request-chain");
assertNotNull("Missing chain", myChain);
}
@Test
public void response_chain_binding_is_added_to_http() throws Exception {
Element xml = parse(
"<http>",
" <filtering>",
" <response-chain id='my-response-chain'>",
" <binding>" + MY_CHAIN_BINDING + "</binding>",
" </response-chain>",
" </filtering>",
"</http>");
Http http = buildHttp(xml);
Http.Binding binding = first(http.bindings);
assertThat(binding.filterId.getName(), is("my-response-chain"));
assertThat(binding.binding, is(MY_CHAIN_BINDING));
Chain<Filter> myChain = http.getFilterChains().allChains().getComponent("my-response-chain");
assertNotNull("Missing chain", myChain);
}
@Test
public void bindings_are_added_to_config_for_all_http_servers_with_jetty() throws Exception {
final Element xml = parse(
"<jdisc version='1.0'>",
" <http>",
" <filtering>",
" <request-chain id='my-request-chain'>",
" <binding>" + MY_CHAIN_BINDING + "</binding>",
" </request-chain>",
" </filtering>",
" <server id='server1' port='8000' />",
" <server id='server2' port='9000' />",
" </http>",
"</jdisc>");
buildContainerCluster(xml);
{
final ServerConfig config = root.getConfig(ServerConfig.class, "jdisc/http/jdisc-jetty/server1");
assertThat(config.filter().size(), is(1));
assertThat(config.filter(0).id(), is("my-request-chain"));
assertThat(config.filter(0).binding(), is(MY_CHAIN_BINDING));
}
{
final ServerConfig config = root.getConfig(ServerConfig.class, "jdisc/http/jdisc-jetty/server2");
assertThat(config.filter().size(), is(1));
assertThat(config.filter(0).id(), is("my-request-chain"));
assertThat(config.filter(0).binding(), is(MY_CHAIN_BINDING));
}
}
}
|