*/
package org.opendaylight.controller.config.util;
-import static org.hamcrest.core.Is.is;
+import static org.hamcrest.CoreMatchers.hasItem;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-import static org.junit.matchers.JUnitMatchers.containsString;
+import com.google.common.collect.Sets;
import java.lang.management.ManagementFactory;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
-
import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
-
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.config.api.ConfigRegistry;
-import org.opendaylight.controller.config.api.ValidationException;
-import org.opendaylight.controller.config.util.jolokia.ConfigRegistryJolokiaClient;
public class ConfigRegistryClientsTest {
- private String jolokiaURL;
-
private TestingConfigRegistry testingRegistry;
private ObjectName testingRegistryON;
private final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- private ConfigRegistryClient jmxRegistryClient, jolokiaRegistryClient;
+ private ConfigRegistryClient jmxRegistryClient;
+ private ConfigTransactionClient jmxTransactionClient;
+ private Map<String, ObjectName> map;
@Before
public void setUp() throws Exception {
- jolokiaURL = JolokiaHelper.startTestingJolokia();
testingRegistry = new TestingConfigRegistry();
testingRegistryON = ConfigRegistry.OBJECT_NAME;
mbs.registerMBean(testingRegistry, testingRegistryON);
jmxRegistryClient = new ConfigRegistryJMXClient(
ManagementFactory.getPlatformMBeanServer());
- jolokiaRegistryClient = new ConfigRegistryJolokiaClient(jolokiaURL);
+ map = new HashMap<>();
}
@After
public void cleanUp() throws Exception {
- JolokiaHelper.stopJolokia();
if (testingRegistryON != null) {
mbs.unregisterMBean(testingRegistryON);
}
}
+ @Test
+ public void testCreateTransaction() throws Exception{
+ jmxTransactionClient = jmxRegistryClient.createTransaction();
+ assertNotNull(jmxTransactionClient);
+ }
+
+ @Test
+ public void testGetConfigTransactionClient2() throws Exception{
+ jmxTransactionClient = jmxRegistryClient.getConfigTransactionClient("transactionName");
+ assertNotNull(jmxTransactionClient);
+ }
+
+ @Test
+ public void testGetConfigTransactionClient() throws Exception{
+ jmxTransactionClient = jmxRegistryClient.getConfigTransactionClient(testingRegistryON);
+ assertNotNull(jmxTransactionClient);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testNewMXBeanProxy() throws Exception{
+ if (jmxRegistryClient instanceof ConfigRegistryJMXClient) {
+ ConfigRegistryJMXClient client = (ConfigRegistryJMXClient) jmxRegistryClient;
+ assertNull(client.newMXBeanProxy(testingRegistryON, String.class));
+ } else {
+ throw new AssertionError("brm msg");
+ }
+ }
+
+ @Test
+ public void testBeginConfig() throws Exception{
+ Assert.assertNotNull(jmxRegistryClient.beginConfig());
+ }
+
+ @Test
+ public void testCommitConfig() throws Exception{
+ assertNull(jmxRegistryClient.commitConfig(testingRegistryON));
+ }
+
+ @Test
+ public void testGetOpenConfigs() throws Exception{
+ assertNull(jmxRegistryClient.getOpenConfigs());
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testGetVersion() throws Exception{
+ assertEquals(3, jmxRegistryClient.getVersion());
+ }
+
+ @Test
+ public void testGetAvailableModuleNames() throws Exception{
+ assertNull(jmxRegistryClient.getAvailableModuleNames());
+ }
+
+ @Test
+ public void testIsHealthy() throws Exception{
+ assertEquals(false, jmxRegistryClient.isHealthy());
+ }
+
+ @Test
+ public void testLookupConfigBeans3() throws Exception{
+ Set<ObjectName> son = jmxRegistryClient.lookupConfigBeans();
+ assertEquals(3, son.size());
+ }
+
+ @Test
+ public void testLookupConfigBeans2() throws Exception{
+ Set<ObjectName> son = jmxRegistryClient.lookupConfigBeans(TestingConfigRegistry.moduleName1);
+ assertEquals(2, son.size());
+ }
+
+ @Test
+ public void testLookupConfigBeans() throws Exception{
+ Set<ObjectName> son = jmxRegistryClient.lookupConfigBeans(TestingConfigRegistry.moduleName1, TestingConfigRegistry.instName1);
+ Set<ObjectName> on = Sets.newHashSet(TestingConfigRegistry.conf2);
+ assertEquals(on, son);
+ }
+
+ @Test
+ public void testLookupConfigBean() throws Exception{
+ ObjectName on = jmxRegistryClient.lookupConfigBean(TestingConfigRegistry.moduleName1, null);
+ assertEquals(TestingConfigRegistry.conf3, on);
+ }
+
@Test
public void testLookupRuntimeBeans() throws Exception {
Set<ObjectName> jmxLookup = lookupRuntimeBeans(jmxRegistryClient);
- Set<ObjectName> jolokiaLookup = lookupRuntimeBeans(jolokiaRegistryClient);
- assertEquals(jmxLookup, jolokiaLookup);
+ assertEquals(Sets.newHashSet(TestingConfigRegistry.run2, TestingConfigRegistry.run1, TestingConfigRegistry.run3), jmxLookup);
}
- private Set<ObjectName> lookupRuntimeBeans(ConfigRegistryClient client)
+ private Set<ObjectName> lookupRuntimeBeans(final ConfigRegistryClient client)
throws Exception {
Set<ObjectName> beans = client.lookupRuntimeBeans();
for (ObjectName on : beans) {
jmxRegistryClient, TestingConfigRegistry.moduleName1,
TestingConfigRegistry.instName1);
assertEquals(1, jmxLookup.size());
- Set<ObjectName> jolokiaLookup = clientLookupRuntimeBeansWithModuleAndInstance(
- jolokiaRegistryClient, TestingConfigRegistry.moduleName1,
- TestingConfigRegistry.instName1);
- assertEquals(jmxLookup, jolokiaLookup);
+ assertEquals(Sets.newHashSet(TestingConfigRegistry.run2), jmxLookup);
jmxLookup = clientLookupRuntimeBeansWithModuleAndInstance(
jmxRegistryClient, TestingConfigRegistry.moduleName2,
TestingConfigRegistry.instName2);
assertEquals(1, jmxLookup.size());
- jolokiaLookup = clientLookupRuntimeBeansWithModuleAndInstance(
- jolokiaRegistryClient, TestingConfigRegistry.moduleName2,
- TestingConfigRegistry.instName2);
- assertEquals(jmxLookup, jolokiaLookup);
+ assertEquals(Sets.newHashSet(TestingConfigRegistry.run3), jmxLookup);
jmxLookup = clientLookupRuntimeBeansWithModuleAndInstance(
jmxRegistryClient, TestingConfigRegistry.moduleName1,
TestingConfigRegistry.instName2);
assertEquals(0, jmxLookup.size());
- jolokiaLookup = clientLookupRuntimeBeansWithModuleAndInstance(
- jolokiaRegistryClient, TestingConfigRegistry.moduleName1,
- TestingConfigRegistry.instName2);
- assertEquals(jmxLookup, jolokiaLookup);
+ assertEquals(Sets.newHashSet(), jmxLookup);
}
private Set<ObjectName> clientLookupRuntimeBeansWithModuleAndInstance(
- ConfigRegistryClient client, String moduleName, String instanceName) {
+ final ConfigRegistryClient client, final String moduleName, final String instanceName) {
Set<ObjectName> beans = client.lookupRuntimeBeans(moduleName, instanceName);
if (beans.size() > 0) {
assertEquals("RuntimeBean",
}
@Test
- public void testValidationExceptionDeserialization() {
- try {
- jolokiaRegistryClient.commitConfig(null);
- fail();
- } catch (ValidationException e) {
- String moduleName = "moduleName", instanceName = "instanceName";
- assertThat(e.getFailedValidations().containsKey(moduleName),
- is(true));
- assertThat(e.getFailedValidations().size(), is(1));
- assertThat(e.getFailedValidations().get(moduleName).size(), is(1));
- assertThat(
- e.getFailedValidations().get(moduleName)
- .containsKey(instanceName), is(true));
- assertThat(
- e.getFailedValidations().get(moduleName).get(instanceName)
- .getMessage(), is("message"));
- assertThat(
- e.getFailedValidations().get(moduleName).get(instanceName)
- .getTrace(),
- containsString("org.opendaylight.controller.config.util.TestingConfigRegistry.commitConfig"));
+ public void testCheckConfigBeanExists() throws Exception{
+ jmxRegistryClient.checkConfigBeanExists(testingRegistryON);
+ assertEquals(true, TestingConfigRegistry.checkBool);
+ }
+
+ @Test
+ public void testLookupConfigBeanByServiceInterfaceName() throws Exception{
+ ObjectName on = clientLookupConfigBeanByServiceInterfaceName();
+ assertEquals(TestingConfigRegistry.conf1, on);
+ }
+
+ private ObjectName clientLookupConfigBeanByServiceInterfaceName(){
+ return jmxRegistryClient.lookupConfigBeanByServiceInterfaceName("qnameA", "refA");
+ }
+
+ @Test
+ public void testGetServiceMapping() throws Exception{
+ assertNull(jmxRegistryClient.getServiceMapping());
+ }
+
+ @Test
+ public void testLookupServiceReferencesByServiceInterfaceName() throws Exception{
+ map.put("conf2", TestingConfigRegistry.conf2);
+ assertEquals(map, jmxRegistryClient.lookupServiceReferencesByServiceInterfaceName("qnameB"));
+ }
+
+ @Test
+ public void testLookupServiceInterfaceNames() throws Exception{
+ assertThat(clientLookupServiceInterfaceNames(testingRegistryON), hasItem(TestingConfigRegistry.serviceQName1));
+ assertThat(clientLookupServiceInterfaceNames(testingRegistryON), hasItem(TestingConfigRegistry.serviceQName2));
+ }
+
+ private Set<String> clientLookupServiceInterfaceNames(final ObjectName client) throws InstanceNotFoundException{
+ return jmxRegistryClient.lookupServiceInterfaceNames(client);
+ }
+
+ @Test
+ public void testGetServiceInterfaceName() throws Exception{
+ assertNull(jmxRegistryClient.getServiceInterfaceName(null, null));
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testInvokeMethod() throws Exception{
+ assertNull(jmxRegistryClient.invokeMethod(testingRegistryON, "name", null, null));
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testGetAttributeCurrentValue() throws Exception{
+ assertNull(jmxRegistryClient.getAttributeCurrentValue(testingRegistryON, "attrName"));
+ }
+
+ @Test
+ public void testGetAvailableModuleFactoryQNames() throws Exception{
+ for(String str : jmxRegistryClient.getAvailableModuleFactoryQNames()){
+ if(str != TestingConfigRegistry.moduleName1){
+ assertEquals(TestingConfigRegistry.moduleName2, str);
+ }
+ else{
+ assertEquals(TestingConfigRegistry.moduleName1, str);
+ }
}
}
+ @Test
+ public void testGetServiceReference() throws Exception{
+ Assert.assertNotNull(jmxRegistryClient.getServiceReference(null, null));
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testcheckServiceReferenceExists() throws Exception{
+ jmxRegistryClient.checkServiceReferenceExists(testingRegistryON);
+ }
}