Remove yang-test
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / testingservices / parallelapsp / TestingParallelAPSPModule.java
index 1857aaa22f70fbaa5acd7e807b8d9cefc14a1a15..656cf04c28aaa0b8c97e01ea5844aa64244025dd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -14,7 +14,11 @@ import com.google.common.base.Strings;
 import java.io.Closeable;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.NotThreadSafe;
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
 import javax.management.ObjectName;
+import javax.management.ReflectionException;
 import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.JmxAttribute;
 import org.opendaylight.controller.config.api.ModuleIdentifier;
@@ -30,10 +34,8 @@ import org.slf4j.LoggerFactory;
  * Represents service that has dependency to thread pool.
  */
 @NotThreadSafe
-public class TestingParallelAPSPModule implements Module,
-        TestingParallelAPSPConfigMXBean {
-    private static final Logger LOG = LoggerFactory
-            .getLogger(TestingParallelAPSPModule.class);
+public class TestingParallelAPSPModule implements Module, TestingParallelAPSPConfigMXBean {
+    private static final Logger LOG = LoggerFactory.getLogger(TestingParallelAPSPModule.class);
 
     private final DependencyResolver dependencyResolver;
     private final AutoCloseable oldCloseable;
@@ -43,10 +45,8 @@ public class TestingParallelAPSPModule implements Module,
     private TestingParallelAPSPImpl instance;
     private String someParam;
 
-    public TestingParallelAPSPModule(ModuleIdentifier identifier,
-            DependencyResolver dependencyResolver,
-            @Nullable AutoCloseable oldCloseable,
-            @Nullable TestingParallelAPSPImpl oldInstance) {
+    public TestingParallelAPSPModule(final ModuleIdentifier identifier, final DependencyResolver dependencyResolver,
+            @Nullable final AutoCloseable oldCloseable, @Nullable final TestingParallelAPSPImpl oldInstance) {
         this.identifier = identifier;
         this.dependencyResolver = dependencyResolver;
         this.oldCloseable = oldCloseable;
@@ -60,7 +60,7 @@ public class TestingParallelAPSPModule implements Module,
 
     @RequireInterface(TestingThreadPoolServiceInterface.class)
     @Override
-    public void setThreadPool(ObjectName threadPoolName) {
+    public void setThreadPool(final ObjectName threadPoolName) {
         this.threadPoolON = threadPoolName;
     }
 
@@ -70,56 +70,56 @@ public class TestingParallelAPSPModule implements Module,
     }
 
     @Override
-    public void setSomeParam(String someParam) {
+    public void setSomeParam(final String someParam) {
         this.someParam = someParam;
     }
 
     @Override
     public Integer getMaxNumberOfThreads() {
-        if (instance == null)
+        if (instance == null) {
             return null;
+        }
         return instance.getMaxNumberOfThreads();
     }
 
     // this would be generated:
-    private final JmxAttribute threadPoolONJMXAttribute = new JmxAttribute("threadPoolON");
+    private final JmxAttribute threadPoolOnJMXAttribute = new JmxAttribute("threadPoolON");
 
     @Override
     public void validate() {
         checkNotNull(threadPoolON, "Parameter 'threadPool' must be set");
-        dependencyResolver.validateDependency(
-                TestingThreadPoolServiceInterface.class, threadPoolON,
-                threadPoolONJMXAttribute);
+        dependencyResolver.validateDependency(TestingThreadPoolServiceInterface.class, threadPoolON,
+                threadPoolOnJMXAttribute);
 
-        checkState(Strings.isNullOrEmpty(someParam) == false,
-                "Parameter 'SomeParam' is blank");
+        checkState(Strings.isNullOrEmpty(someParam) == false, "Parameter 'SomeParam' is blank");
         // check that calling resolveInstance fails
         try {
-            dependencyResolver.resolveInstance(TestingThreadPoolIfc.class,
-                    threadPoolON, threadPoolONJMXAttribute);
+            dependencyResolver.resolveInstance(TestingThreadPoolIfc.class, threadPoolON, threadPoolOnJMXAttribute);
             throw new RuntimeException("fail");
-        } catch (IllegalStateException e) {
-            checkState("Commit was not triggered".equals(e.getMessage()),
-                    e.getMessage());
+        } catch (final IllegalStateException e) {
+            checkState("Commit was not triggered".equals(e.getMessage()), e.getMessage());
         }
 
         // test retrieving dependent module's attribute
         int threadCount;
         try {
-            threadCount = (Integer)dependencyResolver.getAttribute(threadPoolON, "ThreadCount");
-        } catch (Exception e) {
+            threadCount = (Integer) dependencyResolver.getAttribute(threadPoolON, "ThreadCount");
+        } catch (final ReflectionException | InstanceNotFoundException | AttributeNotFoundException
+                | MBeanException e) {
             throw new IllegalStateException(e);
         }
         checkState(threadCount > 0);
-        TestingThreadPoolConfigMXBean proxy = dependencyResolver.newMXBeanProxy(threadPoolON, TestingThreadPoolConfigMXBean.class);
+        TestingThreadPoolConfigMXBean proxy = dependencyResolver.newMXBeanProxy(threadPoolON,
+                TestingThreadPoolConfigMXBean.class);
         checkState(threadCount == proxy.getThreadCount());
     }
 
     @Override
+    @SuppressWarnings("IllegalCatch")
     public Closeable getInstance() {
         if (instance == null) {
-            TestingThreadPoolIfc threadPoolInstance = dependencyResolver
-                    .resolveInstance(TestingThreadPoolIfc.class, threadPoolON, threadPoolONJMXAttribute);
+            TestingThreadPoolIfc threadPoolInstance = dependencyResolver.resolveInstance(TestingThreadPoolIfc.class,
+                    threadPoolON, threadPoolOnJMXAttribute);
 
             if (oldInstance != null) {
                 // changing thread pool is not supported
@@ -135,12 +135,11 @@ public class TestingParallelAPSPModule implements Module,
                 if (oldCloseable != null) {
                     try {
                         oldCloseable.close();
-                    } catch (Exception e) {
+                    } catch (final Exception e) {
                         throw new RuntimeException(e);
                     }
                 }
-                instance = new TestingParallelAPSPImpl(threadPoolInstance,
-                        someParam);
+                instance = new TestingParallelAPSPImpl(threadPoolInstance, someParam);
             }
         }
         return instance;
@@ -155,6 +154,4 @@ public class TestingParallelAPSPModule implements Module,
     public ModuleIdentifier getIdentifier() {
         return identifier;
     }
-
-
 }