2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.config.yang.pcep.impl;
10 import static org.junit.Assert.assertTrue;
11 import static org.junit.Assert.fail;
13 import javax.management.InstanceAlreadyExistsException;
14 import javax.management.ObjectName;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.controller.config.api.ValidationException;
18 import org.opendaylight.controller.config.api.jmx.CommitStatus;
19 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
20 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
21 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
22 import org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgroupModuleFactory;
23 import org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgroupModuleMXBean;
24 import org.opendaylight.controller.config.yang.pcep.spi.SimplePCEPExtensionProviderContextModuleFactory;
25 import org.opendaylight.controller.config.yang.pcep.spi.SimplePCEPExtensionProviderContextModuleMXBean;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.impl.rev130627.PathType;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.impl.rev130627.StoreType;
29 public class PCEPDispatcherImplModuleTest extends AbstractConfigTest {
31 private static final String INSTANCE_NAME = "pcep-dispatcher-impl";
32 private static final String FACTORY_NAME = PCEPDispatcherImplModuleFactory.NAME;
34 private static final String THREADGROUP_FACTORY_NAME = NettyThreadgroupModuleFactory.NAME;
35 private static final String BOSS_TG_INSTANCE_NAME = "boss-group";
36 private static final String WORKER_TG_INSTANCE_NAME = "worker-group";
38 private static final String EXTENSION_INSTANCE_NAME = "pcep-extension-privider";
39 private static final String EXTENSION_FACTORYNAME = SimplePCEPExtensionProviderContextModuleFactory.NAME;
41 private static final String STORE_PASSWORD = "opendaylight";
42 private static final String KEYSTORE = "ctl.jks";
43 private static final String TRUSTSTORE = "truststore.jks";
46 public void setUp() throws Exception {
47 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.mockedContext, new PCEPDispatcherImplModuleFactory(), new PCEPSessionProposalFactoryImplModuleFactory(), new NettyThreadgroupModuleFactory(), new SimplePCEPExtensionProviderContextModuleFactory()));
51 public void testValidationExceptionMaxUnknownMessagesNotSet() throws Exception {
53 createDispatcherInstance(null);
55 } catch (final ValidationException e) {
56 assertTrue(e.getMessage().contains("MaxUnknownMessages value is not set"));
61 public void testValidationExceptionMaxUnknownMessagesMinValue() throws Exception {
63 createDispatcherInstance(0);
65 } catch (final ValidationException e) {
66 assertTrue(e.getMessage().contains("must be greater than 0"));
71 public void testValidationExceptionCertificatePassword() throws Exception {
73 createDispatcherInstance(1, createTls(null, KEYSTORE, STORE_PASSWORD, PathType.PATH, StoreType.JKS, TRUSTSTORE, STORE_PASSWORD,
74 PathType.PATH, StoreType.JKS));
76 } catch (final ValidationException e) {
77 assertTrue(e.getMessage().contains("certificate password"));
82 public void testValidationExceptionKeystoreLocation() throws Exception {
84 createDispatcherInstance(1, createTls(STORE_PASSWORD, null, STORE_PASSWORD, PathType.PATH, StoreType.JKS, TRUSTSTORE, STORE_PASSWORD,
85 PathType.PATH, StoreType.JKS));
87 } catch (final ValidationException e) {
88 assertTrue(e.getMessage().contains("keystore location"));
93 public void testValidationExceptionKeystorePassword() throws Exception {
95 createDispatcherInstance(1, createTls(STORE_PASSWORD, KEYSTORE, null, PathType.PATH, StoreType.JKS, TRUSTSTORE, STORE_PASSWORD,
96 PathType.PATH, StoreType.JKS));
98 } catch (final ValidationException e) {
99 assertTrue(e.getMessage().contains("keystore password"));
104 public void testValidationExceptionKeystorePathType() throws Exception {
106 createDispatcherInstance(1, createTls(STORE_PASSWORD, KEYSTORE, STORE_PASSWORD, null, StoreType.JKS, TRUSTSTORE, STORE_PASSWORD,
107 PathType.PATH, StoreType.JKS));
109 } catch (final ValidationException e) {
110 assertTrue(e.getMessage().contains("keystore path type"));
115 public void testValidationExceptionKeystoreType() throws Exception {
117 createDispatcherInstance(1, createTls(STORE_PASSWORD, KEYSTORE, STORE_PASSWORD, PathType.PATH, null, TRUSTSTORE, STORE_PASSWORD,
118 PathType.PATH, StoreType.JKS));
120 } catch (final ValidationException e) {
121 assertTrue(e.getMessage().contains("keystore type"));
126 public void testValidationExceptionTruststoreLocation() throws Exception {
128 createDispatcherInstance(1, createTls(STORE_PASSWORD, KEYSTORE, STORE_PASSWORD, PathType.PATH, StoreType.JKS, null, STORE_PASSWORD,
129 PathType.PATH, StoreType.JKS));
131 } catch (final ValidationException e) {
132 assertTrue(e.getMessage().contains("truststore location"));
137 public void testValidationExceptionTruststorePassword() throws Exception {
139 createDispatcherInstance(1, createTls(STORE_PASSWORD, KEYSTORE, STORE_PASSWORD, PathType.PATH, StoreType.JKS, TRUSTSTORE, null,
140 PathType.PATH, StoreType.JKS));
142 } catch (final ValidationException e) {
143 assertTrue(e.getMessage().contains("truststore password"));
148 public void testValidationExceptionTruststorePathType() throws Exception {
150 createDispatcherInstance(1, createTls(STORE_PASSWORD, KEYSTORE, STORE_PASSWORD, PathType.PATH, StoreType.JKS, TRUSTSTORE, STORE_PASSWORD,
151 null, StoreType.JKS));
153 } catch (final ValidationException e) {
154 assertTrue(e.getMessage().contains("truststore path type"));
159 public void testValidationExceptionTruststoreType() throws Exception {
161 createDispatcherInstance(1, createTls(STORE_PASSWORD, KEYSTORE, STORE_PASSWORD, PathType.PATH, StoreType.JKS, TRUSTSTORE, STORE_PASSWORD,
162 PathType.PATH, null));
164 } catch (final ValidationException e) {
165 assertTrue(e.getMessage().contains("truststore type"));
170 public void testCreateBean() throws Exception {
171 final CommitStatus status = createDispatcherInstance(5);
172 assertBeanCount(1, FACTORY_NAME);
173 assertStatus(status, 5, 0, 0);
177 public void testReusingOldInstance() throws Exception {
178 createDispatcherInstance(5);
179 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
180 assertBeanCount(1, FACTORY_NAME);
181 final CommitStatus status = transaction.commit();
182 assertBeanCount(1, FACTORY_NAME);
183 assertStatus(status, 0, 0, 5);
187 public void testReconfigure() throws Exception {
188 createDispatcherInstance(5);
189 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
190 assertBeanCount(1, FACTORY_NAME);
191 final PCEPDispatcherImplModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME),
192 PCEPDispatcherImplModuleMXBean.class);
193 mxBean.setMaxUnknownMessages(10);
194 final CommitStatus status = transaction.commit();
195 assertBeanCount(1, FACTORY_NAME);
196 assertStatus(status, 0, 1, 4);
200 public void testCreateBeanWithTls() throws Exception {
201 final CommitStatus status = createDispatcherInstance(5, createTls(STORE_PASSWORD, KEYSTORE, STORE_PASSWORD, PathType.PATH, StoreType.JKS,
202 TRUSTSTORE, STORE_PASSWORD, PathType.PATH, StoreType.JKS));
203 assertBeanCount(1, FACTORY_NAME);
204 assertStatus(status, 5, 0, 0);
207 private CommitStatus createDispatcherInstance(final Integer maxUnknownMessages) throws Exception {
208 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
209 createDispatcherInstance(transaction, maxUnknownMessages);
210 return transaction.commit();
213 private CommitStatus createDispatcherInstance(final Integer maxUnknownMessages, final Tls tls) throws Exception {
214 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
215 createDispatcherInstance(transaction, maxUnknownMessages, tls);
216 return transaction.commit();
219 public static ObjectName createDispatcherInstance(final ConfigTransactionJMXClient transaction, final Integer maxUnknownMessages)
221 final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
222 final PCEPDispatcherImplModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, PCEPDispatcherImplModuleMXBean.class);
223 mxBean.setPcepSessionProposalFactory(PCEPSessionProposalFactoryImplModuleTest.createSessionInstance(transaction));
224 mxBean.setMaxUnknownMessages(maxUnknownMessages);
225 mxBean.setBossGroup(createThreadGroupInstance(transaction, 10, BOSS_TG_INSTANCE_NAME));
226 mxBean.setWorkerGroup(createThreadGroupInstance(transaction, 10, WORKER_TG_INSTANCE_NAME));
227 mxBean.setPcepExtensions(createExtensionsInstance(transaction));
231 private static ObjectName createDispatcherInstance(final ConfigTransactionJMXClient transaction, final Integer maxUnknownMessages,
232 final Tls tls) throws Exception {
233 final ObjectName objName = createDispatcherInstance(transaction, maxUnknownMessages);
234 final PCEPDispatcherImplModuleMXBean mxBean = transaction.newMXBeanProxy(objName, PCEPDispatcherImplModuleMXBean.class);
239 private static ObjectName createExtensionsInstance(final ConfigTransactionJMXClient transaction) throws InstanceAlreadyExistsException {
240 final ObjectName nameCreated = transaction.createModule(EXTENSION_FACTORYNAME, EXTENSION_INSTANCE_NAME);
241 transaction.newMXBeanProxy(nameCreated, SimplePCEPExtensionProviderContextModuleMXBean.class);
246 private static ObjectName createThreadGroupInstance(final ConfigTransactionJMXClient transaction, final Integer threadCount,
247 final String instanceName) throws InstanceAlreadyExistsException {
248 final ObjectName nameCreated = transaction.createModule(THREADGROUP_FACTORY_NAME, instanceName);
249 final NettyThreadgroupModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, NettyThreadgroupModuleMXBean.class);
250 mxBean.setThreadCount(threadCount);
254 private static Tls createTls(final String certificatePassword, final String keystore, final String keystorePassword,
255 final PathType keystorePathType, final StoreType keystoreType, final String truststore,
256 final String truststorePassword, final PathType truststorePathType, final StoreType truststoreType) {
257 final Tls tls = new Tls();
258 tls.setCertificatePassword(certificatePassword);
259 tls.setKeystore(keystore);
260 tls.setKeystorePassword(keystorePassword);
261 tls.setKeystorePathType(keystorePathType);
262 tls.setKeystoreType(keystoreType);
263 tls.setTruststore(truststore);
264 tls.setTruststorePassword(truststorePassword);
265 tls.setTruststorePathType(truststorePathType);
266 tls.setTruststoreType(truststoreType);