Reduce the use of AttrBuilders
[netconf.git] / restconf / restconf-nb-bierman02 / src / test / java / org / opendaylight / controller / sal / restconf / impl / input / to / cnsn / test / RestPutListDataTest.java
index 2a42d3dfec8b8896d3bf6e92a02b1889ea5697aa..90d917335d8876f2d97710d4cf08f088e6a99e05 100644 (file)
@@ -10,32 +10,33 @@ package org.opendaylight.controller.sal.restconf.impl.input.to.cnsn.test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import com.google.common.collect.Iterables;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
 import java.io.FileNotFoundException;
-import java.net.URI;
 import java.util.List;
 import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriInfo;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
 import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
-import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
-import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.PutResult;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
 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.restconf.common.errors.RestconfError;
+import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -44,43 +45,38 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
 public class RestPutListDataTest {
+    private static SchemaContext schemaContextTestModule;
 
     private static BrokerFacade brokerFacade;
     private static RestconfImpl restconfImpl;
-    private static SchemaContext schemaContextTestModule;
 
     private static final String TEST_MODULE_NS_STRING = "test:module";
-    private static final URI TEST_MODULE_NS;
     private static final String TEST_MODULE_REVISION = "2014-01-09";
 
-    static {
-        TEST_MODULE_NS = URI.create("test:module");
+    @BeforeClass
+    public static void staticSetup() throws FileNotFoundException {
+        schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module");
     }
 
     @Before
-    public void initialize() throws FileNotFoundException, ReactorException {
-        final ControllerContext controllerContext = ControllerContext.getInstance();
-        schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module");
-        controllerContext.setSchemas(schemaContextTestModule);
+    public void initialize() throws FileNotFoundException {
+        final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContextTestModule);
         brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
+        restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
         final PutResult result = mock(PutResult.class);
         when(brokerFacade.commitConfigurationDataPut(any(SchemaContext.class), any(YangInstanceIdentifier.class),
                 any(NormalizedNode.class), Mockito.anyString(), Mockito.anyString()))
                         .thenReturn(result);
-        when(result.getFutureOfPutData()).thenReturn(mock(CheckedFuture.class));
+        when(result.getFutureOfPutData()).thenReturn(mock(FluentFuture.class));
         when(result.getStatus()).thenReturn(Status.OK);
     }
 
@@ -178,7 +174,7 @@ public class RestPutListDataTest {
         final DataSchemaNode testNodeSchemaNode = schemaContextTestModule.getDataChildByName(lstWithCompositeKey);
         assertTrue(testNodeSchemaNode != null);
         assertTrue(testNodeSchemaNode instanceof ListSchemaNode);
-        final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> testNodeContainer =
+        final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> testNodeContainer =
                 Builders.mapEntryBuilder((ListSchemaNode) testNodeSchemaNode);
 
         List<DataSchemaNode> testChildren = ControllerContext.findInstanceDataChildrenByName(
@@ -187,7 +183,7 @@ public class RestPutListDataTest {
         final DataSchemaNode testLeafKey1SchemaNode = Iterables.getFirst(testChildren, null);
         assertTrue(testLeafKey1SchemaNode != null);
         assertTrue(testLeafKey1SchemaNode instanceof LeafSchemaNode);
-        final NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>> leafKey1 =
+        final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafKey1 =
                 Builders.leafBuilder((LeafSchemaNode) testLeafKey1SchemaNode);
         leafKey1.withValue(payloadKey1);
         testNodeContainer.withChild(leafKey1.build());
@@ -199,7 +195,7 @@ public class RestPutListDataTest {
             final DataSchemaNode testLeafKey2SchemaNode = Iterables.getFirst(testChildren, null);
             assertTrue(testLeafKey2SchemaNode != null);
             assertTrue(testLeafKey2SchemaNode instanceof LeafSchemaNode);
-            final NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>> leafKey2 =
+            final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafKey2 =
                     Builders.leafBuilder((LeafSchemaNode) testLeafKey2SchemaNode);
             leafKey2.withValue(payloadKey2);
             testNodeContainer.withChild(leafKey2.build());
@@ -226,5 +222,4 @@ public class RestPutListDataTest {
         }
         return uriBuilder.toString();
     }
-
 }