Remove redundant code constructs
[netconf.git] / restconf / restconf-nb-bierman02 / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / InvokeRpcMethodTest.java
index 8f97a1e7565be80991e2b829dbbe09f7d27b368d..8bbfae93426b712c1864cc2f092e01f2e658ece8 100644 (file)
@@ -73,12 +73,13 @@ public class InvokeRpcMethodTest {
     private static UriInfo uriInfo;
     private static SchemaContext schemaContext;
 
-    private final RestconfImpl restconfImpl = RestconfImpl.getInstance();
+    private final RestconfImpl restconfImpl;
     private final ControllerContext controllerContext;
+    private final BrokerFacade brokerFacade = mock(BrokerFacade.class);
 
     public InvokeRpcMethodTest() {
         controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
-        restconfImpl.setControllerContext(controllerContext);
+        restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
     }
 
     @BeforeClass
@@ -109,10 +110,6 @@ public class InvokeRpcMethodTest {
             assertTrue("Uri wasn't created sucessfuly", false);
         }
 
-        final BrokerFacade mockedBrokerFacade = mock(BrokerFacade.class);
-
-        restconfImpl.setBroker(mockedBrokerFacade);
-
         final NormalizedNodeContext payload = prepareDomPayload();
 
         final NormalizedNodeContext rpcResponse =
@@ -164,21 +161,17 @@ public class InvokeRpcMethodTest {
         final DOMRpcException exception = new DOMRpcImplementationNotAvailableException("testExeption");
         final CheckedFuture<DOMRpcResult, DOMRpcException> future = Futures.immediateFailedCheckedFuture(exception);
 
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
-
         final QName qname = QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast");
         final SchemaPath type = SchemaPath.create(true, qname);
 
         when(brokerFacade.invokeRpc(eq(type), any(NormalizedNode.class))).thenReturn(future);
 
-        this.restconfImpl.setBroker(brokerFacade);
-
         try {
             this.restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo);
             fail("Expected an exception to be thrown.");
         } catch (final RestconfDocumentedException e) {
             verifyRestconfDocumentedException(e, 0, ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED,
-                    Optional.<String>absent(), Optional.<String>absent());
+                    Optional.absent(), Optional.absent());
         }
     }
 
@@ -218,17 +211,14 @@ public class InvokeRpcMethodTest {
         final SchemaPath path = SchemaPath.create(true,
                 QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast"));
 
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
         when(brokerFacade.invokeRpc(eq(path), any(NormalizedNode.class))).thenReturn(future);
 
-        this.restconfImpl.setBroker(brokerFacade);
-
         try {
             this.restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo);
             fail("Expected an exception to be thrown.");
         } catch (final RestconfDocumentedException e) {
             verifyRestconfDocumentedException(e, 0, ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED, Optional.of("foo"),
-                    Optional.<String>absent());
+                    Optional.absent());
             verifyRestconfDocumentedException(e, 1, ErrorType.RPC, ErrorTag.IN_USE, Optional.of("bar"),
                     Optional.of("app-tag"));
         }
@@ -243,11 +233,8 @@ public class InvokeRpcMethodTest {
         final QName qname = QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast");
         final SchemaPath path = SchemaPath.create(true, qname);
 
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
         when(brokerFacade.invokeRpc(eq(path), any(NormalizedNode.class))).thenReturn(future);
 
-        this.restconfImpl.setBroker(brokerFacade);
-
         final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo);
         assertNotNull(output);
         assertEquals(null, output.getData());
@@ -262,7 +249,7 @@ public class InvokeRpcMethodTest {
             fail("Expected an exception");
         } catch (final RestconfDocumentedException e) {
             verifyRestconfDocumentedException(e, 0, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
-                    Optional.<String>absent(), Optional.<String>absent());
+                    Optional.absent(), Optional.absent());
         }
     }
 
@@ -273,7 +260,7 @@ public class InvokeRpcMethodTest {
             fail("Expected an exception");
         } catch (final RestconfDocumentedException e) {
             verifyRestconfDocumentedException(e, 0, ErrorType.RPC, ErrorTag.UNKNOWN_ELEMENT,
-                    Optional.<String>absent(), Optional.<String>absent());
+                    Optional.absent(), Optional.absent());
         }
     }
 
@@ -311,9 +298,7 @@ public class InvokeRpcMethodTest {
                 new NormalizedNodeContext(new InstanceIdentifierContext<>(null, rpcInputSchemaNode,
                 null, schemaContext), containerBuilder.build());
 
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
         when(brokerFacade.invokeRpc(eq(path), any(NormalizedNode.class))).thenReturn(future);
-        this.restconfImpl.setBroker(brokerFacade);
 
         final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:make-toast", payload, uriInfo);
         assertNotNull(output);
@@ -329,7 +314,7 @@ public class InvokeRpcMethodTest {
             fail("Expected an exception.");
         } catch (final RestconfDocumentedException e) {
             verifyRestconfDocumentedException(e, 0, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
-                    Optional.<String>absent(), Optional.<String>absent());
+                    Optional.absent(), Optional.absent());
         }
     }
 
@@ -367,11 +352,8 @@ public class InvokeRpcMethodTest {
         final DOMRpcResult result = new DefaultDOMRpcResult(container);
         final CheckedFuture<DOMRpcResult, DOMRpcException> future = Futures.immediateCheckedFuture(result);
 
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
         when(brokerFacade.invokeRpc(eq(rpcDef.getPath()), any(NormalizedNode.class))).thenReturn(future);
 
-        this.restconfImpl.setBroker(brokerFacade);
-
         final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:testOutput", "", uriInfo);
         assertNotNull(output);
         assertNotNull(output.getData());