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
9 package org.opendaylight.controller.config.yang.pcep.sr.cfg;
11 import static org.junit.Assert.assertTrue;
12 import static org.junit.Assert.fail;
14 import javax.management.InstanceAlreadyExistsException;
15 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.Stateful07PCEPSessionProposalFactoryModuleMXBean;
25 public class SrPCEPSessionProposalFactoryModuleTest extends AbstractConfigTest {
27 private static final String INSTANCE_NAME = "sr02-session-proposal";
28 private static final String FACTORY_NAME = SrPCEPSessionProposalFactoryModuleFactory.NAME;
31 public void setUp() throws Exception {
32 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, new SrPCEPSessionProposalFactoryModuleFactory()));
36 public void testValidationExceptionDeadTimerValueNotSet() throws Exception {
38 createInstance(null, (short) 100, true, true, true, true);
40 } catch (final ValidationException e) {
41 assertTrue(e.getMessage().contains("DeadTimerValue value is not set"));
46 public void testValidationExceptionKeepAliveTimerNotSet() throws Exception {
48 createInstance((short) 200, null, true, true, true, true);
50 } catch (final ValidationException e) {
51 assertTrue(e.getMessage().contains("KeepAliveTimerValue value is not set"));
56 public void testValidationExceptionStatefulNotSet() throws Exception {
58 createInstance((short) 200, (short) 100, null, false, false, true);
60 } catch (final ValidationException e) {
61 assertTrue(e.getMessage().contains("Stateful value is not set"));
66 public void testValidationExceptionActiveNotSet() throws Exception {
68 createInstance((short) 200, (short) 100, true, null, true, true);
70 } catch (final ValidationException e) {
71 assertTrue(e.getMessage().contains("Active value is not set"));
76 public void testValidationExceptionInstantiatedNotSet() throws Exception {
78 createInstance((short) 200, (short) 100, true, true, null, true);
80 } catch (final ValidationException e) {
81 assertTrue(e.getMessage().contains("Initiated value is not set"));
86 public void testValidationExceptionKeepAliveTimerMinValue() throws Exception {
88 createInstance((short) 200, (short) -10, true, true, true, true);
90 } catch (final ValidationException e) {
91 assertTrue(e.getMessage().contains("minimum value is 1."));
96 public void testStatefulAfterCommitted() throws Exception {
97 createInstance((short) 200, (short) 100, false, true, true, true);
98 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
99 final Stateful07PCEPSessionProposalFactoryModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(
100 FACTORY_NAME, INSTANCE_NAME), Stateful07PCEPSessionProposalFactoryModuleMXBean.class);
101 assertTrue(mxBean.getStateful());
105 public void testValidationExceptionSrCapableValueNotSet() throws Exception {
107 createInstance((short) 200, (short) 100, true, true, true, null);
109 } catch (final ValidationException e) {
110 assertTrue(e.getMessage().contains("SrCapable value is not set"));
115 public void testCreateBean() throws Exception {
116 final CommitStatus status = createInstance();
117 assertBeanCount(1, FACTORY_NAME);
118 assertStatus(status, 1, 0, 0);
122 public void testReusingOldInstance() throws Exception {
124 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
125 assertBeanCount(1, FACTORY_NAME);
126 final CommitStatus status = transaction.commit();
127 assertBeanCount(1, FACTORY_NAME);
128 assertStatus(status, 0, 0, 1);
132 public void testReconfigure() throws Exception {
134 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
135 assertBeanCount(1, FACTORY_NAME);
136 transaction.newMXBeanProxy(transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME),
137 Stateful07PCEPSessionProposalFactoryModuleMXBean.class);
138 final CommitStatus status = transaction.commit();
139 assertBeanCount(1, FACTORY_NAME);
140 assertStatus(status, 0, 0, 1);
143 private CommitStatus createInstance() throws Exception {
144 return createInstance((short) 200, (short) 100, true, true, true, true);
147 private CommitStatus createInstance(final Short deadTimer, final Short keepAlive,
148 final Boolean stateful, final Boolean active, final Boolean instant, final Boolean srCapable) throws Exception {
149 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
150 createInstance(transaction, deadTimer, keepAlive, stateful, active, instant, srCapable);
151 return transaction.commit();
154 private ObjectName createInstance(final ConfigTransactionJMXClient transaction, final Short deadTimer, final Short keepAlive,
155 final Boolean stateful, final Boolean active, final Boolean instant, final Boolean srCapable) throws InstanceAlreadyExistsException {
156 final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
157 final SrPCEPSessionProposalFactoryModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated,
158 SrPCEPSessionProposalFactoryModuleMXBean.class);
159 mxBean.setActive(active);
160 mxBean.setDeadTimerValue(deadTimer);
161 mxBean.setInitiated(instant);
162 mxBean.setKeepAliveTimerValue(keepAlive);
163 mxBean.setStateful(stateful);
164 mxBean.setSrCapable(srCapable);