-
Notifications
You must be signed in to change notification settings - Fork 912
/
WebServerDTOConfigTest.java
183 lines (157 loc) · 10.9 KB
/
WebServerDTOConfigTest.java
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.tests.integration.web;
import java.util.Properties;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
import org.apache.activemq.artemis.api.core.JsonUtil;
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
import org.apache.activemq.artemis.dto.AppDTO;
import org.apache.activemq.artemis.dto.BindingDTO;
import org.apache.activemq.artemis.dto.WebServerDTO;
import org.apache.activemq.artemis.json.JsonArray;
import org.apache.activemq.artemis.json.JsonObject;
import org.junit.Assert;
import org.junit.Test;
public class WebServerDTOConfigTest {
private static final String INVALID_ATTRIBUTE_NAME = "invalidAttribute";
private static final String BINDING_TEST_NAME = "test-binding";
private static final String BINDING_TEST_URL = "http://localhost:61616";
private static final String APP_TEST_NAME = "test-app";
private static final String APP_TEST_URL = "test-url";
@Test
public void testSetWebProperties() throws Throwable {
WebServerDTO webServer = new WebServerDTO();
Properties properties = new Properties();
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "customizer", "customizerTest");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "rootRedirectLocation", "locationTest");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "webContentEnabled", "true");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + INVALID_ATTRIBUTE_NAME, "true");
Configuration configuration = new ConfigurationImpl();
String systemWebPropertyPrefix = ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix();
configuration.parsePrefixedProperties(webServer, "system-" + systemWebPropertyPrefix, properties, systemWebPropertyPrefix);
Assert.assertEquals("customizerTest", webServer.getCustomizer());
Assert.assertEquals("locationTest", webServer.getRootRedirectLocation());
Assert.assertEquals(true, webServer.getWebContentEnabled());
testStatus(configuration.getStatus(), "system-" + systemWebPropertyPrefix, "");
}
@Test
public void testSetNewWebBindingProperties() throws Throwable {
WebServerDTO webServer = new WebServerDTO();
testSetWebBindingProperties(webServer, BINDING_TEST_NAME);
}
@Test
public void testSetExistingWebBindingProperties() throws Throwable {
WebServerDTO webServer = new WebServerDTO();
BindingDTO exitingBinding = new BindingDTO();
exitingBinding.setName(BINDING_TEST_NAME);
webServer.addBinding(exitingBinding);
testSetWebBindingProperties(webServer, BINDING_TEST_NAME);
}
@Test
public void testSetExistingWebBindingWithoutNameProperties() throws Throwable {
WebServerDTO webServer = new WebServerDTO();
BindingDTO exitingBinding = new BindingDTO();
exitingBinding.setUri(BINDING_TEST_URL);
webServer.addBinding(exitingBinding);
testSetWebBindingProperties(webServer, BINDING_TEST_URL);
}
private void testSetWebBindingProperties(WebServerDTO webServer, String bindingName) throws Throwable {
Properties properties = new Properties();
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".uri", BINDING_TEST_URL);
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".clientAuth", "true");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".passwordCodec", "test-passwordCodec");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".keyStorePath", "test-keyStorePath");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".trustStorePath", "test-trustStorePath");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".includedTLSProtocols", "test-includedTLSProtocols,0");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".excludedTLSProtocols", "test-excludedTLSProtocols,1");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".includedCipherSuites", "test-includedCipherSuites,2");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".excludedCipherSuites", "test-excludedCipherSuites,3");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".keyStorePassword", "test-keyStorePassword");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".trustStorePassword", "test-trustStorePassword");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + "." + INVALID_ATTRIBUTE_NAME, "true");
Configuration configuration = new ConfigurationImpl();
String systemWebPropertyPrefix = ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix();
configuration.parsePrefixedProperties(webServer, "system-" + systemWebPropertyPrefix, properties, systemWebPropertyPrefix);
BindingDTO testBinding = webServer.getAllBindings().stream().filter(binding -> bindingName.equals(binding.getName())).findFirst().get();
Assert.assertEquals(BINDING_TEST_URL, testBinding.getUri());
Assert.assertEquals(true, testBinding.getClientAuth());
Assert.assertEquals("test-passwordCodec", testBinding.getPasswordCodec());
Assert.assertEquals("test-keyStorePath", testBinding.getKeyStorePath());
Assert.assertEquals("test-trustStorePath", testBinding.getTrustStorePath());
Assert.assertEquals("test-includedTLSProtocols,0", String.join(",", testBinding.getIncludedTLSProtocols()));
Assert.assertEquals("test-excludedTLSProtocols,1", String.join(",", testBinding.getExcludedTLSProtocols()));
Assert.assertEquals("test-includedCipherSuites,2", String.join(",", testBinding.getIncludedCipherSuites()));
Assert.assertEquals("test-excludedCipherSuites,3", String.join(",", testBinding.getExcludedCipherSuites()));
Assert.assertEquals("test-keyStorePassword", testBinding.getKeyStorePassword());
Assert.assertEquals("test-trustStorePassword", testBinding.getTrustStorePassword());
testStatus(configuration.getStatus(), "system-" + systemWebPropertyPrefix, "bindings." + bindingName + ".");
}
@Test
public void testSetNewWebBindingAppProperties() throws Throwable {
WebServerDTO webServer = new WebServerDTO();
testSetWebBindingAppProperties(webServer, BINDING_TEST_NAME, APP_TEST_NAME);
}
@Test
public void testSetExistingWebBindingAppProperties() throws Throwable {
WebServerDTO webServer = new WebServerDTO();
BindingDTO exitingBinding = new BindingDTO();
exitingBinding.setName(BINDING_TEST_NAME);
AppDTO existingApp = new AppDTO();
existingApp.setName(APP_TEST_NAME);
exitingBinding.addApp(existingApp);
webServer.addBinding(exitingBinding);
testSetWebBindingAppProperties(webServer, BINDING_TEST_NAME, APP_TEST_NAME);
}
@Test
public void testSetExistingWebBindingAppWithoutNameProperties() throws Throwable {
WebServerDTO webServer = new WebServerDTO();
BindingDTO exitingBinding = new BindingDTO();
exitingBinding.setName(BINDING_TEST_NAME);
AppDTO existingApp = new AppDTO();
existingApp.setUrl(APP_TEST_URL);
exitingBinding.addApp(existingApp);
webServer.addBinding(exitingBinding);
testSetWebBindingAppProperties(webServer, BINDING_TEST_NAME, APP_TEST_URL);
}
private void testSetWebBindingAppProperties(WebServerDTO webServer, String bindingName, String appName) throws Throwable {
Properties properties = new Properties();
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".apps." + appName + ".url", APP_TEST_URL);
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".apps." + appName + ".war", "test-war");
properties.put(ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix() + "bindings." + bindingName + ".apps." + appName + "." + INVALID_ATTRIBUTE_NAME, "true");
Configuration configuration = new ConfigurationImpl();
String systemWebPropertyPrefix = ActiveMQDefaultConfiguration.getDefaultSystemWebPropertyPrefix();
configuration.parsePrefixedProperties(webServer, "system-" + systemWebPropertyPrefix, properties, systemWebPropertyPrefix);
BindingDTO testBinding = webServer.getAllBindings().stream().filter(binding -> bindingName.equals(binding.getName())).findFirst().get();
AppDTO testApp = testBinding.getApps().stream().filter(app -> appName.equals(app.getName())).findFirst().get();
Assert.assertEquals("test-url", testApp.getUrl());
Assert.assertEquals("test-war", testApp.getWar());
testStatus(configuration.getStatus(), "system-" + systemWebPropertyPrefix, "bindings." + bindingName + ".apps." + appName + ".");
}
private void testStatus(String status, String name, String prefix) {
Assert.assertNotNull(status);
JsonObject statusJsonObject = JsonUtil.readJsonObject(status);
Assert.assertNotNull(statusJsonObject);
JsonObject propertiesJsonObject = statusJsonObject.getJsonObject("properties");
Assert.assertNotNull(propertiesJsonObject);
JsonObject systemWebPropertiesJsonObject = propertiesJsonObject.getJsonObject(name);
Assert.assertNotNull(systemWebPropertiesJsonObject);
JsonArray errorsJsonObject = systemWebPropertiesJsonObject.getJsonArray("errors");
Assert.assertNotNull(errorsJsonObject);
Assert.assertEquals(prefix + INVALID_ATTRIBUTE_NAME + "=true", errorsJsonObject.getJsonObject(0).getString("value"));
}
}