Merge "Refactor DOMDataBrokerImpl"
[controller.git] / opendaylight / config / netty-event-executor-config / src / test / java / org / opendaylight / controller / config / yang / netty / eventexecutor / GlobalEventExecutorModuleTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.config.yang.netty.eventexecutor;
10
11 import static org.junit.Assert.assertTrue;
12 import static org.junit.Assert.fail;
13
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.ConflictingVersionException;
19 import org.opendaylight.controller.config.api.ValidationException;
20 import org.opendaylight.controller.config.api.jmx.CommitStatus;
21 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
22 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
23 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
24
25 public class GlobalEventExecutorModuleTest extends AbstractConfigTest {
26
27     private GlobalEventExecutorModuleFactory factory;
28     private final String instanceName = GlobalEventExecutorModuleFactory.SINGLETON_NAME;
29
30     @Before
31     public void setUp() {
32         factory = new GlobalEventExecutorModuleFactory();
33         super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,factory));
34     }
35
36     @Test
37     public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,
38             ConflictingVersionException {
39         ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
40
41         createInstance(transaction, instanceName);
42
43         transaction.validateConfig();
44         CommitStatus status = transaction.commit();
45
46         assertBeanCount(1, factory.getImplementationName());
47         assertStatus(status, 1, 0, 0);
48     }
49
50     @Test
51     public void testConflictingName() throws Exception {
52         ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
53         try {
54             createInstance(transaction, instanceName + "x");
55             fail();
56         }catch(IllegalArgumentException e){
57             assertTrue(e.getMessage() + " failure", e.getMessage().contains("only allowed name is singleton"));
58         }
59     }
60
61     @Test
62     public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,
63             ValidationException {
64
65         ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
66         createInstance(transaction, instanceName);
67
68         transaction.commit();
69
70         transaction = configRegistryClient.createTransaction();
71         assertBeanCount(1, factory.getImplementationName());
72         CommitStatus status = transaction.commit();
73
74         assertBeanCount(1, factory.getImplementationName());
75         assertStatus(status, 0, 0, 1);
76     }
77
78     private ObjectName createInstance(ConfigTransactionJMXClient transaction, String instanceName)
79             throws InstanceAlreadyExistsException {
80         ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);
81         transaction.newMXBeanProxy(nameCreated, GlobalEventExecutorModuleMXBean.class);
82         return nameCreated;
83     }
84
85 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.