2 * Copyright (c) 2014 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.protocol.pcep.ietf;
10 import static org.junit.Assert.assertTrue;
11 import static org.junit.Assert.fail;
13 import javax.management.InstanceAlreadyExistsException;
14 import javax.management.ObjectName;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.controller.config.api.ValidationException;
19 import org.opendaylight.controller.config.api.jmx.CommitStatus;
20 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
21 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
22 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
23 import org.opendaylight.controller.config.yang.pcep.stateful07.cfg.Stateful07PCEPSessionProposalFactoryModuleFactory;
24 import org.opendaylight.controller.config.yang.pcep.stateful07.cfg.Stateful07PCEPSessionProposalFactoryModuleMXBean;
26 public class Stateful07SessionProposalFactoryModuleTest extends AbstractConfigTest {
28 private static final String INSTANCE_NAME = "pcep-stateful07-proposal";
29 private static final String FACTORY_NAME = Stateful07PCEPSessionProposalFactoryModuleFactory.NAME;
32 public void setUp() throws Exception {
33 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, new Stateful07PCEPSessionProposalFactoryModuleFactory()));
37 public void testValidationExceptionDeadTimerValueNotSet() throws Exception {
39 createInstance(null, (short) 100, true, true, true);
41 } catch (final ValidationException e) {
42 assertTrue(e.getMessage().contains("DeadTimerValue value is not set"));
47 public void testValidationExceptionKeepAliveTimerNotSet() throws Exception {
49 createInstance((short) 200, null, true, true, true);
51 } catch (final ValidationException e) {
52 assertTrue(e.getMessage().contains("KeepAliveTimerValue value is not set"));
57 public void testValidationExceptionStatefulNotSet() throws Exception {
59 createInstance((short) 200, (short) 100, null, false, false);
61 } catch (final ValidationException e) {
62 assertTrue(e.getMessage().contains("Stateful value is not set"));
67 public void testValidationExceptionActiveNotSet() throws Exception {
69 createInstance((short) 200, (short) 100, true, null, true);
71 } catch (final ValidationException e) {
72 assertTrue(e.getMessage().contains("Active value is not set"));
77 public void testValidationExceptionInstantiatedNotSet() throws Exception {
79 createInstance((short) 200, (short) 100, true, true, null);
81 } catch (final ValidationException e) {
82 assertTrue(e.getMessage().contains("Initiated value is not set"));
87 public void testValidationExceptionKeepAliveTimerMinValue() throws Exception {
89 createInstance((short) 200, (short) -10, true, true, true);
91 } catch (final ValidationException e) {
92 assertTrue(e.getMessage().contains("minimum value is 1."));
97 public void testStatefulAfterCommitted() throws Exception {
98 createInstance((short) 200, (short) 100, false, true, true);
99 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
100 final Stateful07PCEPSessionProposalFactoryModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(
101 FACTORY_NAME, INSTANCE_NAME), Stateful07PCEPSessionProposalFactoryModuleMXBean.class);
102 assertTrue(mxBean.getStateful());
106 public void testCreateBean() throws Exception {
107 final CommitStatus status = createInstance();
108 assertBeanCount(1, FACTORY_NAME);
109 assertStatus(status, 1, 0, 0);
113 public void testReusingOldInstance() throws Exception {
115 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
116 assertBeanCount(1, FACTORY_NAME);
117 final CommitStatus status = transaction.commit();
118 assertBeanCount(1, FACTORY_NAME);
119 assertStatus(status, 0, 0, 1);
123 public void testReconfigure() throws Exception {
125 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
126 assertBeanCount(1, FACTORY_NAME);
127 transaction.newMXBeanProxy(transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME),
128 Stateful07PCEPSessionProposalFactoryModuleMXBean.class);
129 final CommitStatus status = transaction.commit();
130 assertBeanCount(1, FACTORY_NAME);
131 assertStatus(status, 0, 0, 1);
134 private CommitStatus createInstance(final Short deadTimer, final Short keepAlive, final Boolean stateful, final Boolean active,
135 final Boolean instant) throws Exception {
136 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
137 createInstance(transaction, deadTimer, keepAlive, stateful, active, instant);
138 return transaction.commit();
141 private CommitStatus createInstance() throws Exception {
142 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
143 createStateful07SessionProposalInstance(transaction);
144 return transaction.commit();
147 public static ObjectName createStateful07SessionProposalInstance(final ConfigTransactionJMXClient transaction) throws Exception {
148 return createInstance(transaction, (short) 200, (short) 100, true, true, true);
151 private static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final Short deadTimer, final Short keepAlive,
152 final Boolean stateful, final Boolean active, final Boolean instant) throws InstanceAlreadyExistsException {
153 final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
154 final Stateful07PCEPSessionProposalFactoryModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated,
155 Stateful07PCEPSessionProposalFactoryModuleMXBean.class);
156 mxBean.setActive(active);
157 mxBean.setDeadTimerValue(deadTimer);
158 mxBean.setInitiated(instant);
159 mxBean.setKeepAliveTimerValue(keepAlive);
160 mxBean.setStateful(stateful);