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.manager.impl.util;
10 import com.google.common.base.Throwables;
11 import com.google.common.collect.Sets;
12 import org.junit.After;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
16 import org.opendaylight.controller.config.manager.impl.AbstractLockedPlatformMBeanServerTest;
18 import javax.management.ObjectName;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertFalse;
24 public class ObjectNameUtilTest extends AbstractLockedPlatformMBeanServerTest {
25 private Set<ObjectName> unregisterONs;
28 public void initUnregisterList() {
29 unregisterONs = Sets.newHashSet();
33 public void unregisterONs() {
34 Exception lastException = null;
35 for (ObjectName on : unregisterONs) {
37 platformMBeanServer.unregisterMBean(on);
38 } catch (Exception e) {
42 if (lastException != null) {
43 throw Throwables.propagate(lastException);
48 public void testQuotation() throws Exception {
49 String serviceQName = "(namespace?revision=r)qname";
50 String refName = "refName";
51 String transaction = "transaction";
52 ObjectName serviceReferenceON = ObjectNameUtil.createTransactionServiceON(transaction, serviceQName, refName);
53 assertFalse(serviceReferenceON.isPattern());
54 assertEquals(serviceQName, ObjectNameUtil.getServiceQName(serviceReferenceON));
55 assertEquals(refName, ObjectNameUtil.getReferenceName(serviceReferenceON));
56 assertEquals(transaction, ObjectNameUtil.getTransactionName(serviceReferenceON));
58 serviceReferenceON = ObjectNameUtil.createReadOnlyServiceON(serviceQName, refName);
59 assertFalse(serviceReferenceON.isPattern());
60 assertEquals(serviceQName, ObjectNameUtil.getServiceQName(serviceReferenceON));
61 assertEquals(refName, ObjectNameUtil.getReferenceName(serviceReferenceON));
62 assertEquals(null, ObjectNameUtil.getTransactionName(serviceReferenceON));