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;
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;
24 public class PCEPSessionProposalFactoryImplModuleTest extends AbstractConfigTest {
26 private static final String INSTANCE_NAME = "pcep-session-proposal-factory-impl";
27 private static final String FACTORY_NAME = PCEPSessionProposalFactoryImplModuleFactory.NAME;
30 public void setUp() throws Exception {
31 final PCEPSessionProposalFactoryImplModuleFactory factory = new PCEPSessionProposalFactoryImplModuleFactory();
32 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, factory));
36 public void testValidationExceptionDeadTimerValueNotSet() throws Exception {
38 createSessionInstance(null, (short) 100);
40 } catch (final ValidationException e) {
41 assertTrue(e.getMessage().contains("DeadTimerValue value is not set"));
46 public void testValidationExceptionKeepAliveTimerNotSet() throws Exception {
48 createSessionInstance((short) 200, null);
50 } catch (final ValidationException e) {
51 assertTrue(e.getMessage().contains("KeepAliveTimerValue value is not set"));
56 public void testValidationExceptionKeepAliveTimerMinValue() throws Exception {
58 createSessionInstance((short) 200, (short) -10);
60 } catch (final ValidationException e) {
61 assertTrue(e.getMessage().contains("minimum value is 1."));
66 public void testCreateBean() throws Exception {
67 final CommitStatus status = createInstance();
68 assertBeanCount(1, FACTORY_NAME);
69 assertStatus(status, 1, 0, 0);
73 public void testReusingOldInstance() throws Exception {
75 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
76 assertBeanCount(1, FACTORY_NAME);
77 final CommitStatus status = transaction.commit();
78 assertBeanCount(1, FACTORY_NAME);
79 assertStatus(status, 0, 0, 1);
83 public void testReconfigure() throws Exception {
85 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
86 assertBeanCount(1, FACTORY_NAME);
87 PCEPSessionProposalFactoryImplModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(FACTORY_NAME,
88 INSTANCE_NAME), PCEPSessionProposalFactoryImplModuleMXBean.class);
89 mxBean.setKeepAliveTimerValue((short) 180);
90 final CommitStatus status = transaction.commit();
91 assertBeanCount(1, FACTORY_NAME);
92 assertStatus(status, 0, 1, 0);
95 private CommitStatus createInstance() throws Exception {
96 return createSessionInstance((short) 200, (short) 100);
99 private CommitStatus createSessionInstance(final Short deadTimer, final Short keepAlive) throws Exception {
100 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
101 createSessionInstance(transaction, deadTimer, keepAlive);
102 return transaction.commit();
105 public static ObjectName createSessionInstance(final ConfigTransactionJMXClient transaction, final Short deadTimer,
106 final Short keepAlive) throws InstanceAlreadyExistsException {
107 final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
108 final PCEPSessionProposalFactoryImplModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated,
109 PCEPSessionProposalFactoryImplModuleMXBean.class);
110 mxBean.setDeadTimerValue(deadTimer);
111 mxBean.setKeepAliveTimerValue(keepAlive);