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.bgp.mock;
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.threadpool.impl.EventBusModuleFactory;
24 import org.opendaylight.controller.config.yang.threadpool.impl.EventBusModuleMXBean;
26 public class BgpMockModuleTest extends AbstractConfigTest {
28 private final String instanceName = "bgp-mock";
30 private BgpMockModuleFactory factory;
32 private EventBusModuleFactory eventBusFactory;
35 public void setUp() throws Exception {
36 this.factory = new BgpMockModuleFactory();
37 this.eventBusFactory = new EventBusModuleFactory();
38 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.factory, this.eventBusFactory));
42 public void testValidationExceptionBothAttributesSet() throws InstanceAlreadyExistsException {
44 ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
45 createInstance(transaction, this.factory.getImplementationName(), instanceName, new byte[] { 1 }, "hexMsg",
46 this.eventBusFactory.getImplementationName());
47 transaction.validateConfig();
49 } catch (ValidationException e) {
50 assertTrue(e.getMessage().contains("Both 'HexDump' and 'BinDump' contain value"));
55 public void testCreateBean() throws Exception {
56 ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
57 createInstance(transaction, this.factory.getImplementationName(), instanceName, null, "hexString",
58 this.eventBusFactory.getImplementationName());
59 transaction.validateConfig();
60 CommitStatus status = transaction.commit();
61 assertBeanCount(1, factory.getImplementationName());
62 assertStatus(status, 2, 0, 0);
65 public static ObjectName createInstance(final ConfigTransactionJMXClient transaction, final String moduleName,
66 final String instanceName, final byte[] binDump, final String hexDump, final String eventBusImplName)
67 throws InstanceAlreadyExistsException {
68 ObjectName nameCreated = transaction.createModule(moduleName, instanceName);
69 BgpMockModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated, BgpMockModuleMXBean.class);
70 mxBean.setBinDump(binDump);
71 mxBean.setHexDump(hexDump);
72 mxBean.setEventBus(createEventBus(transaction, eventBusImplName, "event-bus1"));
76 public static ObjectName createEventBus(final ConfigTransactionJMXClient transaction, final String moduleName, final String instanceName)
77 throws InstanceAlreadyExistsException {
78 ObjectName nameCreated = transaction.createModule(moduleName, instanceName);
79 transaction.newMBeanProxy(nameCreated, EventBusModuleMXBean.class);