Remove static RestconfImpl
[netconf.git] / restconf / restconf-nb-bierman02 / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / RestPutConfigTest.java
index bbc4cd2d5eec4b2ab9258e3c014ac747ad006d1c..94a8284d82e980b8e6af0fd8970ec3a281888df6 100644 (file)
@@ -10,11 +10,13 @@ package org.opendaylight.controller.sal.restconf.impl.test;
 
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
+import java.io.FileNotFoundException;
 import java.util.HashSet;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriInfo;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
@@ -25,10 +27,10 @@ import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.netconf.sal.restconf.impl.PutResult;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
+import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -39,20 +41,22 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 @RunWith(MockitoJUnitRunner.class)
 public class RestPutConfigTest {
 
+    private static SchemaContext schemaContext;
     private RestconfImpl restconfService;
     private ControllerContext controllerCx;
-    private SchemaContext schemaCx;
 
     @Mock
     private BrokerFacade brokerFacade;
 
+    @BeforeClass
+    public static void staticInit() throws FileNotFoundException {
+        schemaContext = TestRestconfUtils.loadSchemaContext("/test-config-data/yang1/", null);
+    }
+
     @Before
     public void init() {
-        this.restconfService = RestconfImpl.getInstance();
-        this.controllerCx = ControllerContext.getInstance();
-        this.schemaCx = TestRestconfUtils.loadSchemaContext("/test-config-data/yang1/", null);
-        this.controllerCx.setSchemas(this.schemaCx);
-        this.restconfService.setControllerContext(this.controllerCx);
+        this.controllerCx = TestRestconfUtils.newControllerContext(schemaContext);
+        this.restconfService = RestconfImpl.newInstance(brokerFacade, controllerCx);
     }
 
     @Test
@@ -131,10 +135,9 @@ public class RestPutConfigTest {
         final PutResult result = Mockito.mock(PutResult.class);
         final CheckedFuture<Void, TransactionCommitFailedException> checkedFuture =
                 Futures.immediateCheckedFuture(null);
-        Mockito.when(this.brokerFacade.commitConfigurationDataPut(this.schemaCx, yii, data, null, null))
+        Mockito.when(this.brokerFacade.commitConfigurationDataPut(this.schemaContext, yii, data, null, null))
                 .thenReturn(result);
         Mockito.when(result.getFutureOfPutData()).thenReturn(checkedFuture);
         Mockito.when(result.getStatus()).thenReturn(Status.OK);
-        this.restconfService.setBroker(this.brokerFacade);
     }
 }