Merge "Simplify method isMutualExclusive in Subnet. Remove redundant 'if' statements."
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / util / ObjectNameUtilTest.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 package org.opendaylight.controller.config.manager.impl.util;
9
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;
17
18 import javax.management.ObjectName;
19 import java.util.Set;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertFalse;
23
24 public class ObjectNameUtilTest extends AbstractLockedPlatformMBeanServerTest {
25     private Set<ObjectName> unregisterONs;
26
27     @Before
28     public void initUnregisterList() {
29         unregisterONs = Sets.newHashSet();
30     }
31
32     @After
33     public void unregisterONs() {
34         Exception lastException = null;
35         for (ObjectName on : unregisterONs) {
36             try {
37                 platformMBeanServer.unregisterMBean(on);
38             } catch (Exception e) {
39                 lastException = e;
40             }
41         }
42         if (lastException != null) {
43             throw Throwables.propagate(lastException);
44         }
45     }
46
47     @Test
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));
57
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));
63
64     }
65 }