Use ControllerContext non-statically 35/70935/1
authorTom Pantelis <tompantelis@gmail.com>
Fri, 13 Apr 2018 23:19:10 +0000 (19:19 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Fri, 13 Apr 2018 23:36:38 +0000 (19:36 -0400)
This is a preliminary patch for removing the web.xml and converting
to the new programmtic web API which will allow us to remove the
static instances that bridge between the web-instantiated
and blueprint-instanriated components. First up is the
ControllerContext - this patch keeps the static instance temporarily
for the RestconfApplication but converts the rest of the code to
inject the ControllerContext instance and reference it non-statically.

This patch touches a lot of files but most are UTs.

Change-Id: I08e2ee24e518c01bb1d5fdb5796abd9354dccfa2
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
74 files changed:
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/AbstractIdentifierAwareJaxRsProvider.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonNormalizedNodeBodyReader.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/JsonToPatchBodyReader.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfApplication.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfDocumentedExceptionMapper.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlNormalizedNodeBodyReader.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/XmlToPatchBodyReader.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestCodec.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfProviderImpl.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/ListenerAdapter.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/Notificator.java
restconf/restconf-nb-bierman02/src/main/resources/org/opendaylight/blueprint/restconf-config.xml
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/md/sal/rest/common/TestRestconfUtils.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/InstanceIdentifierTypeLeafTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/AbstractBodyReaderTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyReader.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyReaderMountPoint.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonBodyWriter.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPatchBodyReader.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestJsonPatchBodyReaderMountPoint.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReader.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyReaderMountPoint.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlBodyWriter.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReader.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReaderMountPoint.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/input/to/cnsn/test/RestPutListDataTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/nn/test/JsonIdentityrefToNnTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/nn/test/JsonLeafrefToNnTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/nn/test/JsonToNnTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnJsonChoiceCaseTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonLeafrefType.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonWithAugmentTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/xml/test/NnInstanceIdentifierToXmlTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/xml/test/NnToXmlTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/xml/test/NnToXmlWithChoiceTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/xml/test/NnToXmlWithDataFromSeveralModulesTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/BrokerFacadeTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/Bug3595Test.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/Bug8072Test.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CodecsExceptionsCatchingTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CutDataToCorrectDepthTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ExpressionParserTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/JSONRestconfServiceImplTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/MediaTypesTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestCodecExceptionsTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetAugmentedElementWhenEqualNamesTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutConfigTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplNotificationSubscribingTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URIParametersParsing.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/test/RestStreamTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/netconf/sal/restconf/impl/InstanceIdentifierCodecImplTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/netconf/sal/streams/listeners/ListenerAdapterTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerTest.java
restconf/restconf-nb-bierman02/src/test/resources/json-to-nn/empty-data.json
restconf/restconf-nb-bierman02/src/test/resources/json-to-nn/invalid-uri-character-in-value.json
restconf/restconf-nb-bierman02/src/test/resources/json-to-nn/multiple-items-in-list.json
restconf/restconf-nb-bierman02/src/test/resources/json-to-nn/multiple-leaflist-items.json
restconf/restconf-nb-bierman02/src/test/resources/json-to-nn/simple-container.json
restconf/restconf-nb-bierman02/src/test/resources/json-to-nn/simple-list.json
restconf/restconf-nb-bierman02/src/test/resources/json-to-nn/wrong-top-level1.json
restconf/restconf-nb-bierman02/src/test/resources/json-to-nn/wrong-top-level2.json

index 095e73c952b76add9a2d3b69f9fa9269dc81177d..761b3bdd2eab7c539ca7ee001f2d1a7b771ab568 100644 (file)
@@ -31,12 +31,18 @@ public class AbstractIdentifierAwareJaxRsProvider {
     @Context
     private Request request;
 
+    private final ControllerContext controllerContext;
+
+    protected AbstractIdentifierAwareJaxRsProvider(ControllerContext controllerContext) {
+        this.controllerContext = controllerContext;
+    }
+
     protected final String getIdentifier() {
         return this.uriInfo.getPathParameters(false).getFirst(RestconfConstants.IDENTIFIER);
     }
 
     protected InstanceIdentifierContext<?> getInstanceIdentifierContext() {
-        return ControllerContext.getInstance().toInstanceIdentifier(getIdentifier());
+        return controllerContext.toInstanceIdentifier(getIdentifier());
     }
 
     protected UriInfo getUriInfo() {
@@ -47,6 +53,10 @@ public class AbstractIdentifierAwareJaxRsProvider {
         return POST.equals(this.request.getMethod());
     }
 
+    protected ControllerContext getControllerContext() {
+        return controllerContext;
+    }
+
     Request getRequest() {
         return this.request;
     }
index f684af7dec8cdb3d5bbf6b80ce7797e8a2aba71c..f90997354b2ab0305313ac8975e6207bd95c3b6a 100644 (file)
@@ -61,6 +61,10 @@ public class JsonNormalizedNodeBodyReader
 
     private static final Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class);
 
+    public JsonNormalizedNodeBodyReader(ControllerContext controllerContext) {
+        super(controllerContext);
+    }
+
     @Override
     public boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
             final MediaType mediaType) {
@@ -83,10 +87,10 @@ public class JsonNormalizedNodeBodyReader
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     public static NormalizedNodeContext readFrom(final String uriPath, final InputStream entityStream,
-                                                 final boolean isPost) throws RestconfDocumentedException {
+            final boolean isPost, final ControllerContext controllerContext) throws RestconfDocumentedException {
 
         try {
-            return readFrom(ControllerContext.getInstance().toInstanceIdentifier(uriPath), entityStream, isPost);
+            return readFrom(controllerContext.toInstanceIdentifier(uriPath), entityStream, isPost);
         } catch (final Exception e) {
             propagateExceptionAs(e);
             return null; // no-op
index 9ed1d045bcb13525879dcde7b9509cf267ecbc9e..53cc16f8d35053e7d06f95147c9c2741233291e4 100644 (file)
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Optional;
+import java.util.concurrent.atomic.AtomicReference;
 import javax.annotation.Nonnull;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.WebApplicationException;
@@ -66,7 +67,10 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider
         implements MessageBodyReader<PatchContext> {
 
     private static final Logger LOG = LoggerFactory.getLogger(JsonToPatchBodyReader.class);
-    private String patchId;
+
+    public JsonToPatchBodyReader(ControllerContext controllerContext) {
+        super(controllerContext);
+    }
 
     @Override
     public boolean isReadable(final Class<?> type, final Type genericType,
@@ -91,7 +95,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider
     public PatchContext readFrom(final String uriPath, final InputStream entityStream) throws
             RestconfDocumentedException {
         try {
-            return readFrom(ControllerContext.getInstance().toInstanceIdentifier(uriPath), entityStream);
+            return readFrom(getControllerContext().toInstanceIdentifier(uriPath), entityStream);
         } catch (final Exception e) {
             propagateExceptionAs(e);
             return null; // no-op
@@ -107,10 +111,11 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider
 
         final JsonReader jsonReader = new JsonReader(new InputStreamReader(nonEmptyInputStreamOptional.get(),
                 StandardCharsets.UTF_8));
-        final List<PatchEntity> resultList = read(jsonReader, path);
+        AtomicReference<String> patchId = new AtomicReference<>();
+        final List<PatchEntity> resultList = read(jsonReader, path, patchId);
         jsonReader.close();
 
-        return new PatchContext(path, resultList, this.patchId);
+        return new PatchContext(path, resultList, patchId.get());
     }
 
     private static RuntimeException propagateExceptionAs(final Exception exception) throws RestconfDocumentedException {
@@ -127,7 +132,8 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider
                 ErrorTag.MALFORMED_MESSAGE, exception);
     }
 
-    private List<PatchEntity> read(final JsonReader in, final InstanceIdentifierContext<?> path) throws IOException {
+    private List<PatchEntity> read(final JsonReader in, final InstanceIdentifierContext<?> path,
+            final AtomicReference<String> patchId) throws IOException {
         final List<PatchEntity> resultCollection = new ArrayList<>();
         final StringModuleInstanceIdentifierCodec codec = new StringModuleInstanceIdentifierCodec(
                 path.getSchemaContext());
@@ -154,7 +160,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider
                 case END_DOCUMENT:
                     break;
                 case NAME:
-                    parseByName(in.nextName(), edit, in, path, codec, resultCollection);
+                    parseByName(in.nextName(), edit, in, path, codec, resultCollection, patchId);
                     break;
                 case END_OBJECT:
                     in.endObject();
@@ -185,7 +191,8 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider
     private void parseByName(@Nonnull final String name, @Nonnull final PatchEdit edit,
                              @Nonnull final JsonReader in, @Nonnull final InstanceIdentifierContext<?> path,
                              @Nonnull final StringModuleInstanceIdentifierCodec codec,
-                             @Nonnull final List<PatchEntity> resultCollection) throws IOException {
+                             @Nonnull final List<PatchEntity> resultCollection,
+                             @Nonnull final AtomicReference<String> patchId) throws IOException {
         switch (name) {
             case "edit" :
                 if (in.peek() == JsonToken.BEGIN_ARRAY) {
@@ -206,7 +213,7 @@ public class JsonToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider
 
                 break;
             case "patch-id" :
-                this.patchId = in.nextString();
+                patchId.set(in.nextString());
                 break;
             default:
                 break;
index 97227bded52e1082b7a4e3c73053b4ef8f6e3264..882ac2e9163dd2f9f77fdf00aecba9b62b79f90c 100644 (file)
@@ -24,11 +24,6 @@ public class RestconfApplication extends Application {
     @Override
     public Set<Class<?>> getClasses() {
         return ImmutableSet.<Class<?>>builder()
-                .add(RestconfDocumentedExceptionMapper.class)
-                .add(XmlNormalizedNodeBodyReader.class)
-                .add(JsonNormalizedNodeBodyReader.class)
-                .add(JsonToPatchBodyReader.class)
-                .add(XmlToPatchBodyReader.class)
                 .add(PatchJsonBodyWriter.class)
                 .add(PatchXmlBodyWriter.class)
                 .add(NormalizedNodeJsonBodyWriter.class)
@@ -51,6 +46,11 @@ public class RestconfApplication extends Application {
         singletons.add(brokerFacade);
         singletons.add(schemaRetrieval);
         singletons.add(new RestconfCompositeWrapper(StatisticsRestconfServiceWrapper.getInstance(), schemaRetrieval));
+        singletons.add(new RestconfDocumentedExceptionMapper(controllerContext));
+        singletons.add(new XmlNormalizedNodeBodyReader(controllerContext));
+        singletons.add(new JsonNormalizedNodeBodyReader(controllerContext));
+        singletons.add(new XmlToPatchBodyReader(controllerContext));
+        singletons.add(new JsonToPatchBodyReader(controllerContext));
 //        singletons.add(StructuredDataToXmlProvider.INSTANCE);
 //        singletons.add(StructuredDataToJsonProvider.INSTANCE);
 //        singletons.add(JsonToCompositeNodeProvider.INSTANCE);
index 430f36641229e4e6bf70abfba2627a6e6dcbd858..c271bf33d2d28c856df14065f5574525ae40042d 100644 (file)
@@ -88,6 +88,12 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
     @Context
     private HttpHeaders headers;
 
+    private final ControllerContext controllerContext;
+
+    public RestconfDocumentedExceptionMapper(ControllerContext controllerContext) {
+        this.controllerContext = Preconditions.checkNotNull(controllerContext);
+    }
+
     @Override
     public Response toResponse(final RestconfDocumentedException exception) {
 
@@ -121,8 +127,8 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
 
         final int status = errors.iterator().next().getErrorTag().getStatusCode();
 
-        final ControllerContext context = ControllerContext.getInstance();
-        final DataNodeContainer errorsSchemaNode = (DataNodeContainer) context.getRestconfModuleErrorsSchemaNode();
+        final DataNodeContainer errorsSchemaNode =
+                (DataNodeContainer) controllerContext.getRestconfModuleErrorsSchemaNode();
 
         if (errorsSchemaNode == null) {
             return Response.status(status).type(MediaType.TEXT_PLAIN_TYPE).entity(exception.getMessage()).build();
@@ -148,7 +154,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
         errContBuild.withChild(listErorsBuilder.build());
 
         final NormalizedNodeContext errContext =  new NormalizedNodeContext(new InstanceIdentifierContext<>(null,
-                (DataSchemaNode) errorsSchemaNode, null, context.getGlobalSchema()), errContBuild.build());
+                (DataSchemaNode) errorsSchemaNode, null, controllerContext.getGlobalSchema()), errContBuild.build());
 
         Object responseBody;
         if (mediaType.getSubtype().endsWith("json")) {
index 12d933f4b1faa01cb4e425fec907c8b32a283d82..510a6cf3440a32096246e461990f56f1d74f75f0 100644 (file)
@@ -31,6 +31,7 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMSource;
 import org.opendaylight.netconf.sal.rest.api.Draft02;
 import org.opendaylight.netconf.sal.rest.api.RestconfService;
+import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
@@ -71,6 +72,10 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
 
     private static final Logger LOG = LoggerFactory.getLogger(XmlNormalizedNodeBodyReader.class);
 
+    public XmlNormalizedNodeBodyReader(ControllerContext controllerContext) {
+        super(controllerContext);
+    }
+
     @Override
     public boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
             final MediaType mediaType) {
index 965bdf5fb0145e7b2ad1cd2f5616c63351654f82..071f8bda595a32125eea3606c8e04db1376f7af3 100644 (file)
@@ -33,6 +33,7 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMSource;
 import org.opendaylight.netconf.sal.rest.api.Draft02;
 import org.opendaylight.netconf.sal.rest.api.RestconfService;
+import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
@@ -79,6 +80,10 @@ public class XmlToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider i
 
     private static final Logger LOG = LoggerFactory.getLogger(XmlToPatchBodyReader.class);
 
+    public XmlToPatchBodyReader(ControllerContext controllerContext) {
+        super(controllerContext);
+    }
+
     @Override
     public boolean isReadable(final Class<?> type, final Type genericType,
                               final Annotation[] annotations, final MediaType mediaType) {
index 2aa300f00eeec7c4781f0a1ca6cda166f3b9658f..3ab324393de837abf9c40bfef7b530f557a03557 100644 (file)
@@ -96,6 +96,7 @@ public class BrokerFacade {
 
     private DOMDataBroker domDataBroker;
     private DOMNotificationService domNotification;
+    private ControllerContext controllerContext;
 
     BrokerFacade() {
 
@@ -109,6 +110,10 @@ public class BrokerFacade {
         this.domNotification = service;
     }
 
+    public void setControllerContext(ControllerContext controllerContext) {
+        this.controllerContext = controllerContext;
+    }
+
     public static BrokerFacade getInstance() {
         return BrokerFacade.INSTANCE;
     }
@@ -569,7 +574,7 @@ public class BrokerFacade {
                 throw new RestconfDocumentedException("Bad value used with with-defaults parameter : " + withDefa);
         }
 
-        final SchemaContext ctx = ControllerContext.getInstance().getGlobalSchema();
+        final SchemaContext ctx = controllerContext.getGlobalSchema();
         final DataSchemaContextTree baseSchemaCtxTree = DataSchemaContextTree.from(ctx);
         final DataSchemaNode baseSchemaNode = baseSchemaCtxTree.getChild(path).getDataSchemaNode();
         if (result instanceof ContainerNode) {
@@ -791,13 +796,12 @@ public class BrokerFacade {
         }
     }
 
-    private static void insertWithPointLeafListPost(final DOMDataReadWriteTransaction rwTransaction,
+    private void insertWithPointLeafListPost(final DOMDataReadWriteTransaction rwTransaction,
             final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
             final SchemaContext schemaContext, final String point, final OrderedLeafSetNode<?> readLeafList,
             final boolean before) {
         rwTransaction.delete(datastore, path.getParent().getParent());
-        final InstanceIdentifierContext<?> instanceIdentifier =
-                ControllerContext.getInstance().toInstanceIdentifier(point);
+        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext.toInstanceIdentifier(point);
         int lastItemPosition = 0;
         for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
             if (nodeChild.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
@@ -824,13 +828,12 @@ public class BrokerFacade {
         }
     }
 
-    private static void insertWithPointListPost(final DOMDataReadWriteTransaction rwTransaction,
+    private void insertWithPointListPost(final DOMDataReadWriteTransaction rwTransaction,
             final LogicalDatastoreType datastore,
             final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext,
             final String point, final MapNode readList, final boolean before) {
         rwTransaction.delete(datastore, path.getParent().getParent());
-        final InstanceIdentifierContext<?> instanceIdentifier =
-                ControllerContext.getInstance().toInstanceIdentifier(point);
+        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext.toInstanceIdentifier(point);
         int lastItemPosition = 0;
         for (final MapEntryNode mapEntryNode : readList.getValue()) {
             if (mapEntryNode.getIdentifier()
@@ -1102,13 +1105,12 @@ public class BrokerFacade {
         }
     }
 
-    private static void insertWithPointLeafListPut(final DOMDataWriteTransaction tx,
+    private void insertWithPointLeafListPut(final DOMDataWriteTransaction tx,
             final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
             final SchemaContext schemaContext, final String point, final OrderedLeafSetNode<?> readLeafList,
             final boolean before) {
         tx.delete(datastore, path.getParent());
-        final InstanceIdentifierContext<?> instanceIdentifier =
-                ControllerContext.getInstance().toInstanceIdentifier(point);
+        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext.toInstanceIdentifier(point);
         int index1 = 0;
         for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
             if (nodeChild.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
@@ -1133,12 +1135,11 @@ public class BrokerFacade {
         }
     }
 
-    private static void insertWithPointListPut(final DOMDataWriteTransaction tx, final LogicalDatastoreType datastore,
+    private void insertWithPointListPut(final DOMDataWriteTransaction tx, final LogicalDatastoreType datastore,
             final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext,
             final String point, final OrderedMapNode readList, final boolean before) {
         tx.delete(datastore, path.getParent());
-        final InstanceIdentifierContext<?> instanceIdentifier =
-                ControllerContext.getInstance().toInstanceIdentifier(point);
+        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext.toInstanceIdentifier(point);
         int index1 = 0;
         for (final MapEntryNode mapEntryNode : readList.getValue()) {
             if (mapEntryNode.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
index 988384c24e5c781628de53af49d3ea73f234b640..866eb0ccf488380570202bff478238efc8651a9e 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.io.Closeable;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URLDecoder;
@@ -36,6 +37,8 @@ import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizat
 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.sal.rest.api.Draft02;
 import org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule;
@@ -45,6 +48,7 @@ import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.common.util.RestUtil;
 import org.opendaylight.yangtools.concepts.Codec;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -74,7 +78,7 @@ import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ControllerContext implements SchemaContextListener {
+public final class ControllerContext implements SchemaContextListener, Closeable {
     // FIXME: this should be in md-sal somewhere
     public static final String MOUNT = "yang-ext:mount";
 
@@ -95,44 +99,66 @@ public class ControllerContext implements SchemaContextListener {
 
     private final AtomicReference<Map<QName, RpcDefinition>> qnameToRpc = new AtomicReference<>(Collections.emptyMap());
 
-    // FIXME; these three should be final
+    private DOMMountPointService mountService;
+    private DOMYangTextSourceProvider yangTextSourceProvider;
+    private ListenerRegistration<SchemaContextListener> listenerRegistration;
     private volatile SchemaContext globalSchema;
-    private volatile DOMMountPointService mountService;
-    private volatile DOMYangTextSourceProvider yangTextSourceProvider;
-    private DataNormalizer dataNormalizer;
+    private volatile DataNormalizer dataNormalizer;
 
+    private ControllerContext(SchemaService schemaService, DOMMountPointService mountService,
+            DOMYangTextSourceProvider yangTextSourceProvider) {
+        this.mountService = mountService;
+        this.yangTextSourceProvider = yangTextSourceProvider;
 
-    public void setGlobalSchema(final SchemaContext globalSchema) {
-        this.globalSchema = globalSchema;
-        this.dataNormalizer = new DataNormalizer(globalSchema);
+        setGlobalSchema(schemaService.getGlobalContext());
+        listenerRegistration = schemaService.registerSchemaContextListener(this);
     }
 
-    public void setMountService(final DOMMountPointService mountService) {
-        this.mountService = mountService;
+    // Temporary until the static instance is removed.
+    @Deprecated
+    private ControllerContext() {
     }
 
-    public DOMYangTextSourceProvider getYangTextSourceProvider() {
-        return yangTextSourceProvider;
-    }
+    public static ControllerContext newInstance(SchemaService schemaService, DOMMountPointService mountService,
+            DOMSchemaService domSchemaService) {
+        final DOMYangTextSourceProvider yangTextSourceProvider =
+            (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions().get(DOMYangTextSourceProvider.class);
 
-    public void setYangTextSourceProvider(DOMYangTextSourceProvider yangTextSourceProvider) {
-        this.yangTextSourceProvider = yangTextSourceProvider;
-    }
+        INSTANCE.mountService = mountService;
+        INSTANCE.yangTextSourceProvider = yangTextSourceProvider;
 
-    ControllerContext() {
+        INSTANCE.onGlobalContextUpdated(schemaService.getGlobalContext());
+        INSTANCE.listenerRegistration = schemaService.registerSchemaContextListener(INSTANCE);
 
+        return INSTANCE;
+        //return new ControllerContext(schemaService, mountService, domSchemaServiceExtension);
     }
 
+    @Deprecated
     public static ControllerContext getInstance() {
         return INSTANCE;
     }
 
+    private void setGlobalSchema(final SchemaContext globalSchema) {
+        this.globalSchema = globalSchema;
+        this.dataNormalizer = new DataNormalizer(globalSchema);
+    }
+
+    public DOMYangTextSourceProvider getYangTextSourceProvider() {
+        return yangTextSourceProvider;
+    }
+
     private void checkPreconditions() {
         if (this.globalSchema == null) {
             throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE);
         }
     }
 
+    @Override
+    public void close() {
+        listenerRegistration.close();
+    }
+
     public void setSchemas(final SchemaContext schemas) {
         onGlobalContextUpdated(schemas);
     }
@@ -522,9 +548,9 @@ public class ControllerContext implements SchemaContextListener {
         return ret;
     }
 
-    private static String toUriString(final Object object, final LeafSchemaNode leafNode, final DOMMountPoint mount)
+    private String toUriString(final Object object, final LeafSchemaNode leafNode, final DOMMountPoint mount)
             throws UnsupportedEncodingException {
-        final Codec<Object, Object> codec = RestCodec.from(leafNode.getType(), mount);
+        final Codec<Object, Object> codec = RestCodec.from(leafNode.getType(), mount, this);
         // FIXME: UrlEncoder looks up a well-known charset, we need something that will use it directly
         return object == null ? "" : URLEncoder.encode(codec.serialize(object).toString(), URI_ENCODING_CHARSET.name());
     }
@@ -626,11 +652,10 @@ public class ControllerContext implements SchemaContextListener {
             if (targetNode == null && parentNode instanceof Module) {
                 final RpcDefinition rpc;
                 if (mountPoint == null) {
-                    rpc = ControllerContext.getInstance().getRpcDefinition(head, module.getRevision());
+                    rpc = getRpcDefinition(head, module.getRevision());
                 } else {
                     final String rpcName = toNodeName(head);
-                    ControllerContext.getInstance();
-                    rpc = ControllerContext.getRpcDefinition(module, rpcName);
+                    rpc = getRpcDefinition(module, rpcName);
                 }
                 if (rpc != null) {
                     return new InstanceIdentifierContext<>(builder.build(), rpc, mountPoint,
@@ -782,7 +807,7 @@ public class ControllerContext implements SchemaContextListener {
         if (baseType instanceof LeafrefTypeDefinition) {
             typedef = SchemaContextUtil.getBaseTypeForLeafRef((LeafrefTypeDefinition) baseType, schemaContext, node);
         }
-        final Codec<Object, Object> codec = RestCodec.from(typedef, mountPoint);
+        final Codec<Object, Object> codec = RestCodec.from(typedef, mountPoint, this);
         Object decoded = codec.deserialize(urlDecoded);
         String additionalInfo = "";
         if (decoded == null) {
@@ -1000,5 +1025,4 @@ public class ControllerContext implements SchemaContextListener {
     public DataNormalizationOperation<?> getRootOperation() {
         return this.dataNormalizer.getRootOperation();
     }
-
 }
index c409e78126053896011d0236f9cd4a3b8354c193..47c4f487c903aab0ca7fcbc41df5c05b0e9ec98d 100644 (file)
@@ -50,6 +50,12 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
 
     private static final Annotation[] EMPTY_ANNOTATIONS = new Annotation[0];
 
+    private final ControllerContext controllerContext;
+
+    public JSONRestconfServiceImpl(ControllerContext controllerContext) {
+        this.controllerContext = controllerContext;
+    }
+
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public void put(final String uriPath, final String payload) throws OperationFailedException {
@@ -58,7 +64,8 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
         LOG.debug("put: uriPath: {}, payload: {}", uriPath, payload);
 
         final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
-        final NormalizedNodeContext context = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, false);
+        final NormalizedNodeContext context = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, false,
+                controllerContext);
 
         LOG.debug("Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier());
         LOG.debug("Parsed NormalizedNode: {}", context.getData());
@@ -79,7 +86,8 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
         LOG.debug("post: uriPath: {}, payload: {}", uriPath, payload);
 
         final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
-        final NormalizedNodeContext context = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, true);
+        final NormalizedNodeContext context = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, true,
+                controllerContext);
 
         LOG.debug("Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier());
         LOG.debug("Parsed NormalizedNode: {}", context.getData());
@@ -150,7 +158,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
             if (actualInput != null) {
                 final InputStream entityStream = new ByteArrayInputStream(actualInput.getBytes(StandardCharsets.UTF_8));
                 final NormalizedNodeContext inputContext =
-                        JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, true);
+                        JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, true, controllerContext);
 
                 LOG.debug("Parsed YangInstanceIdentifier: {}", inputContext.getInstanceIdentifierContext()
                         .getInstanceIdentifier());
@@ -183,7 +191,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab
 
         final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
 
-        JsonToPatchBodyReader jsonToPatchBodyReader = new JsonToPatchBodyReader();
+        JsonToPatchBodyReader jsonToPatchBodyReader = new JsonToPatchBodyReader(controllerContext);
         final PatchContext context = jsonToPatchBodyReader.readFrom(uriPath, entityStream);
 
         LOG.debug("Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier());
index 4b84cb0dea2ca5533a652f4a51b9a789cef798de..513060e7bee6b756be50dc009c0c708f5181ffaf 100644 (file)
@@ -51,8 +51,8 @@ public final class RestCodec {
     }
 
     public static Codec<Object, Object> from(final TypeDefinition<?> typeDefinition,
-            final DOMMountPoint mountPoint) {
-        return new ObjectCodec(typeDefinition, mountPoint);
+            final DOMMountPoint mountPoint, final ControllerContext controllerContext) {
+        return new ObjectCodec(typeDefinition, mountPoint, controllerContext);
     }
 
     @SuppressWarnings("rawtypes")
@@ -61,20 +61,24 @@ public final class RestCodec {
         private static final Logger LOG = LoggerFactory.getLogger(ObjectCodec.class);
 
         public static final Codec LEAFREF_DEFAULT_CODEC = new LeafrefCodecImpl();
+
+        private final ControllerContext controllerContext;
         private final Codec instanceIdentifier;
         private final Codec identityrefCodec;
 
         private final TypeDefinition<?> type;
 
-        private ObjectCodec(final TypeDefinition<?> typeDefinition, final DOMMountPoint mountPoint) {
+        private ObjectCodec(final TypeDefinition<?> typeDefinition, final DOMMountPoint mountPoint,
+                final ControllerContext controllerContext) {
+            this.controllerContext = controllerContext;
             this.type = RestUtil.resolveBaseTypeFrom(typeDefinition);
             if (this.type instanceof IdentityrefTypeDefinition) {
-                this.identityrefCodec = new IdentityrefCodecImpl(mountPoint);
+                this.identityrefCodec = new IdentityrefCodecImpl(mountPoint, controllerContext);
             } else {
                 this.identityrefCodec = null;
             }
             if (this.type instanceof InstanceIdentifierTypeDefinition) {
-                this.instanceIdentifier = new InstanceIdentifierCodecImpl(mountPoint);
+                this.instanceIdentifier = new InstanceIdentifierCodecImpl(mountPoint, controllerContext);
             } else {
                 this.instanceIdentifier = null;
             }
@@ -100,7 +104,7 @@ public final class RestCodec {
                         return this.instanceIdentifier.deserialize(input);
                     } else {
                         final StringModuleInstanceIdentifierCodec codec = new StringModuleInstanceIdentifierCodec(
-                                ControllerContext.getInstance().getGlobalSchema());
+                                controllerContext.getGlobalSchema());
                         return codec.deserialize((String) input);
                     }
                 } else {
@@ -163,9 +167,11 @@ public final class RestCodec {
         private static final Logger LOG = LoggerFactory.getLogger(IdentityrefCodecImpl.class);
 
         private final DOMMountPoint mountPoint;
+        private final ControllerContext controllerContext;
 
-        public IdentityrefCodecImpl(final DOMMountPoint mountPoint) {
+        public IdentityrefCodecImpl(final DOMMountPoint mountPoint, ControllerContext controllerContext) {
             this.mountPoint = mountPoint;
+            this.controllerContext = controllerContext;
         }
 
         @Override
@@ -176,7 +182,8 @@ public final class RestCodec {
         @Override
         public QName deserialize(final IdentityValuesDTO data) {
             final IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0);
-            final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), this.mountPoint);
+            final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), this.mountPoint,
+                    controllerContext);
             if (module == null) {
                 LOG.info("Module was not found for namespace {}", valueWithNamespace.getNamespace());
                 LOG.info("Idenetityref will be translated as NULL for data - {}", String.valueOf(valueWithNamespace));
@@ -204,10 +211,14 @@ public final class RestCodec {
 
     public static class InstanceIdentifierCodecImpl implements InstanceIdentifierCodec<IdentityValuesDTO> {
         private static final Logger LOG = LoggerFactory.getLogger(InstanceIdentifierCodecImpl.class);
+
         private final DOMMountPoint mountPoint;
+        private final ControllerContext controllerContext;
 
-        public InstanceIdentifierCodecImpl(final DOMMountPoint mountPoint) {
+        public InstanceIdentifierCodecImpl(final DOMMountPoint mountPoint,
+                final ControllerContext controllerContext) {
             this.mountPoint = mountPoint;
+            this.controllerContext = controllerContext;
         }
 
         @Override
@@ -236,7 +247,8 @@ public final class RestCodec {
         public YangInstanceIdentifier deserialize(final IdentityValuesDTO data) {
             final List<PathArgument> result = new ArrayList<>();
             final IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0);
-            final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), this.mountPoint);
+            final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), this.mountPoint,
+                    controllerContext);
             if (module == null) {
                 LOG.info("Module by namespace '{}' of first node in instance-identifier was not found.",
                         valueWithNamespace.getNamespace());
@@ -249,7 +261,8 @@ public final class RestCodec {
             final List<IdentityValue> identities = data.getValuesWithNamespaces();
             for (int i = 0; i < identities.size(); i++) {
                 final IdentityValue identityValue = identities.get(i);
-                URI validNamespace = resolveValidNamespace(identityValue.getNamespace(), this.mountPoint);
+                URI validNamespace = resolveValidNamespace(identityValue.getNamespace(), this.mountPoint,
+                        controllerContext);
                 final DataSchemaNode node = ControllerContext.findInstanceDataChildByNameAndNamespace(
                         parentContainer, identityValue.getValue(), validNamespace);
                 if (node == null) {
@@ -276,7 +289,8 @@ public final class RestCodec {
                         final DataNodeContainer listNode = (DataNodeContainer) node;
                         final Map<QName, Object> predicatesMap = new HashMap<>();
                         for (final Predicate predicate : identityValue.getPredicates()) {
-                            validNamespace = resolveValidNamespace(predicate.getName().getNamespace(), this.mountPoint);
+                            validNamespace = resolveValidNamespace(predicate.getName().getNamespace(), this.mountPoint,
+                                    controllerContext);
                             final DataSchemaNode listKey = ControllerContext
                                     .findInstanceDataChildByNameAndNamespace(listNode, predicate.getName().getValue(),
                                             validNamespace);
@@ -325,14 +339,15 @@ public final class RestCodec {
         }
     }
 
-    private static Module getModuleByNamespace(final String namespace, final DOMMountPoint mountPoint) {
-        final URI validNamespace = resolveValidNamespace(namespace, mountPoint);
+    private static Module getModuleByNamespace(final String namespace, final DOMMountPoint mountPoint,
+            final ControllerContext controllerContext) {
+        final URI validNamespace = resolveValidNamespace(namespace, mountPoint, controllerContext);
 
         Module module = null;
         if (mountPoint != null) {
-            module = ControllerContext.getInstance().findModuleByNamespace(mountPoint, validNamespace);
+            module = controllerContext.findModuleByNamespace(mountPoint, validNamespace);
         } else {
-            module = ControllerContext.getInstance().findModuleByNamespace(validNamespace);
+            module = controllerContext.findModuleByNamespace(validNamespace);
         }
         if (module == null) {
             LOG.info("Module for namespace " + validNamespace + " wasn't found.");
@@ -341,12 +356,13 @@ public final class RestCodec {
         return module;
     }
 
-    private static URI resolveValidNamespace(final String namespace, final DOMMountPoint mountPoint) {
+    private static URI resolveValidNamespace(final String namespace, final DOMMountPoint mountPoint,
+            final ControllerContext controllerContext) {
         URI validNamespace;
         if (mountPoint != null) {
-            validNamespace = ControllerContext.getInstance().findNamespaceByModuleName(mountPoint, namespace);
+            validNamespace = controllerContext.findNamespaceByModuleName(mountPoint, namespace);
         } else {
-            validNamespace = ControllerContext.getInstance().findNamespaceByModuleName(namespace);
+            validNamespace = controllerContext.findNamespaceByModuleName(namespace);
         }
         if (validNamespace == null) {
             validNamespace = URI.create(namespace);
index 95d5995e2124db5e945c419501ffaea1e026ad62..aac9645c5a277a7a12d805ccd7037322c6af2b03 100644 (file)
@@ -653,7 +653,7 @@ public final class RestconfImpl implements RestconfService {
                         .withChild(ImmutableNodes.leafNode(streamNameQname, streamName)).build();
 
         if (!Notificator.existListenerFor(streamName)) {
-            Notificator.createListener(pathIdentifier, streamName, outputType);
+            Notificator.createListener(pathIdentifier, streamName, outputType, controllerContext);
         }
 
         final DOMRpcResult defaultDOMRpcResult = new DefaultDOMRpcResult(output);
@@ -1158,9 +1158,9 @@ public final class RestconfImpl implements RestconfService {
      * @return {@link InstanceIdentifierContext} of location leaf for
      *         notification
      */
-    private static InstanceIdentifierContext<?> prepareIIDSubsStreamOutput() {
+    private InstanceIdentifierContext<?> prepareIIDSubsStreamOutput() {
         final QName qnameBase = QName.create("subscribe:to:notification", "2016-10-28", "notifi");
-        final SchemaContext schemaCtx = ControllerContext.getInstance().getGlobalSchema();
+        final SchemaContext schemaCtx = controllerContext.getGlobalSchema();
         final DataSchemaNode location = ((ContainerSchemaNode) schemaCtx
                 .findModule(qnameBase.getModule()).orElse(null)
                 .getDataChildByName(qnameBase)).getDataChildByName(QName.create(qnameBase, "location"));
@@ -1493,7 +1493,7 @@ public final class RestconfImpl implements RestconfService {
      *            contains list of qnames of notifications
      * @return - checked future object
      */
-    private static CheckedFuture<DOMRpcResult, DOMRpcException> invokeSalRemoteRpcNotifiStrRPC(
+    private CheckedFuture<DOMRpcResult, DOMRpcException> invokeSalRemoteRpcNotifiStrRPC(
             final NormalizedNodeContext payload) {
         final ContainerNode data = (ContainerNode) payload.getData();
         LeafSetNode leafSet = null;
@@ -1514,8 +1514,7 @@ public final class RestconfImpl implements RestconfService {
         final Iterator<LeafSetEntryNode> iterator = entryNodes.iterator();
         while (iterator.hasNext()) {
             final QName valueQName = QName.create((String) iterator.next().getValue());
-            final Module module =
-                    ControllerContext.getInstance().findModuleByNamespace(valueQName.getModule().getNamespace());
+            final Module module = controllerContext.findModuleByNamespace(valueQName.getModule().getNamespace());
             Preconditions.checkNotNull(module,
                     "Module for namespace " + valueQName.getModule().getNamespace() + " does not exist");
             NotificationDefinition notifiDef = null;
@@ -1546,7 +1545,7 @@ public final class RestconfImpl implements RestconfService {
                         .withChild(ImmutableNodes.leafNode(streamNameQname, streamName)).build();
 
         if (!Notificator.existNotificationListenerFor(streamName)) {
-            Notificator.createNotificationListener(paths, streamName, outputType);
+            Notificator.createNotificationListener(paths, streamName, outputType, controllerContext);
         }
 
         final DOMRpcResult defaultDOMRpcResult = new DefaultDOMRpcResult(output);
index 4afc5f8a6810716343653963f666648d5ded60e2..06e38484754d5ce7454787f8f8d8426a2cbb2e80 100644 (file)
@@ -11,12 +11,8 @@ import com.google.common.base.Preconditions;
 import java.math.BigInteger;
 import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.controller.sal.core.api.model.SchemaService;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.netconf.sal.rest.api.RestConnector;
 import org.opendaylight.netconf.sal.restconf.impl.jmx.Config;
 import org.opendaylight.netconf.sal.restconf.impl.jmx.Delete;
@@ -29,50 +25,35 @@ import org.opendaylight.netconf.sal.restconf.impl.jmx.Rpcs;
 import org.opendaylight.netconf.sal.streams.websockets.WebSocketServer;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 
 public class RestconfProviderImpl extends AbstractMXBean
         implements AutoCloseable, RestConnector, RestConnectorRuntimeMXBean {
     private final DOMDataBroker domDataBroker;
-    private final SchemaService schemaService;
     private final DOMRpcService rpcService;
     private final DOMNotificationService notificationService;
-    private final DOMMountPointService mountPointService;
     private final IpAddress websocketAddress;
     private final PortNumber websocketPort;
     private final StatisticsRestconfServiceWrapper stats = StatisticsRestconfServiceWrapper.getInstance();
-    private final DOMSchemaService domSchemaService;
-    private ListenerRegistration<SchemaContextListener> listenerRegistration;
+    private final ControllerContext controllerContext;
     private Thread webSocketServerThread;
 
-    public RestconfProviderImpl(DOMDataBroker domDataBroker, SchemaService schemaService, DOMRpcService rpcService,
-            DOMNotificationService notificationService, DOMMountPointService mountPointService,
-            DOMSchemaService domSchemaService, IpAddress websocketAddress, PortNumber websocketPort) {
+    public RestconfProviderImpl(DOMDataBroker domDataBroker, DOMRpcService rpcService,
+            DOMNotificationService notificationService, ControllerContext controllerContext,
+            IpAddress websocketAddress, PortNumber websocketPort) {
         super("Draft02ProviderStatistics", "restconf-connector", null);
         this.domDataBroker = Preconditions.checkNotNull(domDataBroker);
-        this.schemaService = Preconditions.checkNotNull(schemaService);
         this.rpcService = Preconditions.checkNotNull(rpcService);
         this.notificationService = Preconditions.checkNotNull(notificationService);
-        this.mountPointService = Preconditions.checkNotNull(mountPointService);
         this.websocketAddress = Preconditions.checkNotNull(websocketAddress);
         this.websocketPort = Preconditions.checkNotNull(websocketPort);
-        this.domSchemaService = Preconditions.checkNotNull(domSchemaService);
+        this.controllerContext = Preconditions.checkNotNull(controllerContext);
     }
 
     public void start() {
-        this.listenerRegistration = schemaService.registerSchemaContextListener(ControllerContext.getInstance());
-
         BrokerFacade.getInstance().setDomDataBroker(domDataBroker);
         BrokerFacade.getInstance().setRpcService(rpcService);
         BrokerFacade.getInstance().setDomNotificationService(notificationService);
-
-        ControllerContext.getInstance().setSchemas(schemaService.getGlobalContext());
-        ControllerContext.getInstance().setMountService(mountPointService);
-        final DOMYangTextSourceProvider domSchemaServiceExtension =
-                (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions()
-                        .get(DOMYangTextSourceProvider.class);
-        ControllerContext.getInstance().setYangTextSourceProvider(domSchemaServiceExtension);
+        BrokerFacade.getInstance().setControllerContext(controllerContext);
 
         this.webSocketServerThread = new Thread(WebSocketServer.createInstance(
                 new String(websocketAddress.getValue()), websocketPort.getValue()));
@@ -86,10 +67,6 @@ public class RestconfProviderImpl extends AbstractMXBean
     public void close() {
         BrokerFacade.getInstance().setDomDataBroker(null);
 
-        if (this.listenerRegistration != null) {
-            this.listenerRegistration.close();
-        }
-
         WebSocketServer.destroyInstance();
         if (this.webSocketServerThread != null) {
             this.webSocketServerThread.interrupt();
index f67bd749da03c6ee55768eba41f47708f9cb1c30..d58ca9a6a7ba11ddb02d9c8fb1a0ade595fd29aa 100644 (file)
@@ -48,6 +48,7 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
 
     private static final Logger LOG = LoggerFactory.getLogger(ListenerAdapter.class);
 
+    private final ControllerContext controllerContext;
     private final YangInstanceIdentifier path;
     private final String streamName;
     private final NotificationOutputType outputType;
@@ -66,12 +67,13 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
      *            Type of output on notification (JSON, XML)
      */
     ListenerAdapter(final YangInstanceIdentifier path, final String streamName,
-            final NotificationOutputType outputType) {
+            final NotificationOutputType outputType, final ControllerContext controllerContext) {
         register(this);
         this.outputType = Preconditions.checkNotNull(outputType);
         this.path = Preconditions.checkNotNull(path);
         Preconditions.checkArgument(streamName != null && !streamName.isEmpty());
         this.streamName = streamName;
+        this.controllerContext = controllerContext;
     }
 
     @Override
@@ -132,7 +134,7 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
      * @return Data in printable form.
      */
     private String prepareXml() {
-        final SchemaContext schemaContext = ControllerContext.getInstance().getGlobalSchema();
+        final SchemaContext schemaContext = controllerContext.getGlobalSchema();
         final DataSchemaContextTree dataContextTree = DataSchemaContextTree.from(schemaContext);
         final Document doc = createDocument();
         final Element notificationElement = basePartDoc(doc);
@@ -202,7 +204,7 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
         YangInstanceIdentifier yiid = YangInstanceIdentifier.builder(parentYiid)
                                                             .append(normalizedNode.getIdentifier()).build();
 
-        boolean isNodeMixin = ControllerContext.getInstance().isNodeMixin(yiid);
+        boolean isNodeMixin = controllerContext.isNodeMixin(yiid);
         boolean isSkippedNonLeaf = getLeafNodesOnly() && !(normalizedNode instanceof LeafNode);
         if (!isNodeMixin && !isSkippedNonLeaf) {
             Node node = null;
@@ -238,17 +240,17 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
      *
      * @param doc
      *            {@link Document}
-     * @param path
+     * @param dataPath
      *            Path to data in data store.
      * @param operation
      *            {@link Operation}
      * @return {@link Node} node represented by changed event element.
      */
-    private static Node createDataChangeEventElement(final Document doc, final YangInstanceIdentifier path,
+    private Node createDataChangeEventElement(final Document doc, final YangInstanceIdentifier dataPath,
             final Operation operation) {
         final Element dataChangeEventElement = doc.createElement("data-change-event");
         final Element pathElement = doc.createElement("path");
-        addPathAsValueToElement(path, pathElement);
+        addPathAsValueToElement(dataPath, pathElement);
         dataChangeEventElement.appendChild(pathElement);
 
         final Element operationElement = doc.createElement("operation");
@@ -294,14 +296,14 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
     /**
      * Adds path as value to element.
      *
-     * @param path
+     * @param dataPath
      *            Path to data in data store.
      * @param element
      *            {@link Element}
      */
     @SuppressWarnings("rawtypes")
-    private static void addPathAsValueToElement(final YangInstanceIdentifier path, final Element element) {
-        final YangInstanceIdentifier normalizedPath = ControllerContext.getInstance().toXpathRepresentation(path);
+    private void addPathAsValueToElement(final YangInstanceIdentifier dataPath, final Element element) {
+        final YangInstanceIdentifier normalizedPath = controllerContext.toXpathRepresentation(dataPath);
         final StringBuilder textContent = new StringBuilder();
 
         for (final PathArgument pathArgument : normalizedPath.getPathArguments()) {
@@ -342,9 +344,9 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
      * @param qualifiedName
      *            QName
      */
-    private static void writeIdentifierWithNamespacePrefix(final Element element, final StringBuilder textContent,
+    private void writeIdentifierWithNamespacePrefix(final Element element, final StringBuilder textContent,
             final QName qualifiedName) {
-        final Module module = ControllerContext.getInstance().getGlobalSchema().findModule(qualifiedName.getModule())
+        final Module module = controllerContext.getGlobalSchema().findModule(qualifiedName.getModule())
                 .get();
 
         textContent.append(module.getName());
index 9775e344f6018361eb4b7d07bbafe5117136edeb..e9471635e43ada0660d2955188c7ac95b6d30dc6 100644 (file)
@@ -48,6 +48,7 @@ public class NotificationListenerAdapter extends AbstractCommonSubscriber implem
 
     private static final Logger LOG = LoggerFactory.getLogger(NotificationListenerAdapter.class);
 
+    private final ControllerContext controllerContext;
     private final String streamName;
     private final SchemaPath path;
     private final String outputType;
@@ -65,12 +66,14 @@ public class NotificationListenerAdapter extends AbstractCommonSubscriber implem
      * @param outputType
      *             type of output on notification (JSON, XML)
      */
-    NotificationListenerAdapter(final SchemaPath path, final String streamName, final String outputType) {
+    NotificationListenerAdapter(final SchemaPath path, final String streamName, final String outputType,
+            final ControllerContext controllerContext) {
         register(this);
         this.outputType = Preconditions.checkNotNull(outputType);
         this.path = Preconditions.checkNotNull(path);
         Preconditions.checkArgument(streamName != null && !streamName.isEmpty());
         this.streamName = streamName;
+        this.controllerContext = controllerContext;
     }
 
     /**
@@ -86,7 +89,7 @@ public class NotificationListenerAdapter extends AbstractCommonSubscriber implem
     @Override
     @SuppressWarnings("checkstyle:hiddenField")
     public void onNotification(final DOMNotification notification) {
-        this.schemaContext = ControllerContext.getInstance().getGlobalSchema();
+        this.schemaContext = controllerContext.getGlobalSchema();
         this.notification = notification;
 
         final String xml = prepareXml();
index c08a2463c32fb3a5f1f2df03c554faa1f5ff71ca..241b66d06f2f4a538a207dea57fc7cac11342e3c 100644 (file)
@@ -14,6 +14,7 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
+import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
@@ -79,8 +80,8 @@ public final class Notificator {
      *         {@link YangInstanceIdentifier} path and stream name.
      */
     public static ListenerAdapter createListener(final YangInstanceIdentifier path, final String streamName,
-            final NotificationOutputType outputType) {
-        final ListenerAdapter listener = new ListenerAdapter(path, streamName, outputType);
+            final NotificationOutputType outputType, final ControllerContext controllerContext) {
+        final ListenerAdapter listener = new ListenerAdapter(path, streamName, outputType, controllerContext);
         try {
             LOCK.lock();
             dataChangeListener.put(streamName, listener);
@@ -180,10 +181,11 @@ public final class Notificator {
      * @return List of {@link NotificationListenerAdapter} by paths
      */
     public static List<NotificationListenerAdapter> createNotificationListener(final List<SchemaPath> paths,
-            final String streamName, final String outputType) {
+            final String streamName, final String outputType, final ControllerContext controllerContext) {
         final List<NotificationListenerAdapter> listListeners = new ArrayList<>();
         for (final SchemaPath path : paths) {
-            final NotificationListenerAdapter listener = new NotificationListenerAdapter(path, streamName, outputType);
+            final NotificationListenerAdapter listener =
+                    new NotificationListenerAdapter(path, streamName, outputType, controllerContext);
             listListeners.add(listener);
         }
         try {
index 51d72f74ead1b3bc65aec37e09bc6252c2cd5a34..0e523d0d4f55676fda6a2bb74982555dd99950be 100644 (file)
     <argument value="${websocket-address}"/>
   </bean>
 
+  <bean id="controllerContext" class="org.opendaylight.netconf.sal.restconf.impl.ControllerContext"
+      factory-method="newInstance" destroy-method="close">
+    <argument ref="schemaService"/>
+    <argument ref="domMountPointService"/>
+    <argument ref="domSchemaService"/>
+  </bean>
+
   <bean id="restconfProviderDraft02" class="org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl"
           init-method="start" destroy-method="close">
     <argument ref="domDataBroker"/>
-    <argument ref="schemaService"/>
     <argument ref="domRpcService"/>
     <argument ref="domNotificationService"/>
-    <argument ref="domMountPointService"/>
-    <argument ref="domSchemaService"/>
+    <argument ref="controllerContext"/>
     <argument ref="webSocketAddress"/>
     <argument ref="webSocketPort"/>
   </bean>
@@ -68,7 +73,9 @@
   <!-- JSONRestconfService -->
   <bean id="jsonRestconfServiceDraft02"
       class="org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceImpl"
-      destroy-method="close"/>
+      destroy-method="close">
+    <argument ref="controllerContext"/>
+  </bean>
 
   <service ref="jsonRestconfServiceDraft02" odl:type="default"
       interface="org.opendaylight.netconf.sal.restconf.api.JSONRestconfService" />
index 39b881ac657bd9cc9a0cf8aa978522f4592cc810..9c4795e2879627264bbc07e604c6dec504b6ee19 100644 (file)
@@ -8,6 +8,11 @@
 
 package org.opendaylight.controller.md.sal.rest.common;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -20,11 +25,16 @@ import java.util.List;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMSource;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.sal.core.api.model.SchemaService;
 import org.opendaylight.controller.sal.rest.impl.test.providers.TestJsonBodyWriter;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream;
@@ -51,6 +61,27 @@ public final class TestRestconfUtils {
         throw new UnsupportedOperationException("Test utility class");
     }
 
+    public static ControllerContext newControllerContext(SchemaContext schemaContext) {
+        return newControllerContext(schemaContext, null);
+    }
+
+    public static ControllerContext newControllerContext(SchemaContext schemaContext, DOMMountPoint mountInstance) {
+        if (mountInstance != null) {
+            doReturn(schemaContext).when(mountInstance).getSchemaContext();
+        }
+
+        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
+        doReturn(Optional.fromNullable(mountInstance)).when(mockMountService)
+            .getMountPoint(any(YangInstanceIdentifier.class));
+
+        SchemaService mockSchemaService = mock(SchemaService.class);
+        doReturn(schemaContext).when(mockSchemaService).getGlobalContext();
+
+        DOMSchemaService mockDomSchemaService = mock(DOMSchemaService.class);
+
+        return ControllerContext.newInstance(mockSchemaService, mockMountService, mockDomSchemaService);
+    }
+
     @SuppressWarnings("checkstyle:IllegalCatch")
     public static SchemaContext loadSchemaContext(final String yangPath, final SchemaContext schemaContext) {
         try {
@@ -73,8 +104,8 @@ public final class TestRestconfUtils {
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     public static NormalizedNodeContext loadNormalizedContextFromXmlFile(final String pathToInputFile,
-            final String uri) {
-        final InstanceIdentifierContext<?> iiContext = ControllerContext.getInstance().toInstanceIdentifier(uri);
+            final String uri, final ControllerContext controllerContext) {
+        final InstanceIdentifierContext<?> iiContext = controllerContext.toInstanceIdentifier(uri);
         final InputStream inputStream = TestJsonBodyWriter.class.getResourceAsStream(pathToInputFile);
         try {
             final Document doc = UntrustedXML.newDocumentBuilder().parse(inputStream);
index 4e0801c2c80558620f4ae32d8ce38a3a6f62ccfe..98eb5a0890094f815dab703d25ca62b21732a032 100644 (file)
@@ -25,9 +25,9 @@ public class InstanceIdentifierTypeLeafTest {
     public void stringToInstanceIdentifierTest() throws Exception {
         final SchemaContext schemaContext =
                 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/instanceidentifier"));
-        ControllerContext.getInstance().setGlobalSchema(schemaContext);
+        ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
         final InstanceIdentifierContext<?> instanceIdentifier =
-                ControllerContext.getInstance().toInstanceIdentifier(
+                controllerContext.toInstanceIdentifier(
                         "/iid-value-module:cont-iid/iid-list/%2Fiid-value-module%3Acont-iid%2Fiid-value-module%3A"
                                 + "values-iid%5Biid-value-module:value-iid='value'%5D");
         final YangInstanceIdentifier yiD = instanceIdentifier.getInstanceIdentifier();
index 0912ce245a4db4af442bf41eb8fa21e5dc742102..adc3ad3dbb7330f1b59c8912f3379b96e172fc2a 100644 (file)
@@ -20,6 +20,7 @@ import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.UriInfo;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.api.RestconfConstants;
 import org.opendaylight.netconf.sal.rest.impl.AbstractIdentifierAwareJaxRsProvider;
@@ -29,20 +30,29 @@ import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public abstract class AbstractBodyReaderTest {
-
-    protected static final ControllerContext CONTROLLER_CONTEXT = ControllerContext.getInstance();
-    protected final MediaType mediaType;
     private static Field uriField;
     private static Field requestField;
 
-    public AbstractBodyReaderTest() throws NoSuchFieldException {
-        uriField = AbstractIdentifierAwareJaxRsProvider.class
-                .getDeclaredField("uriInfo");
-        uriField.setAccessible(true);
-        requestField = AbstractIdentifierAwareJaxRsProvider.class
-                .getDeclaredField("request");
-        requestField.setAccessible(true);
+    static {
+        try {
+            uriField = AbstractIdentifierAwareJaxRsProvider.class
+                    .getDeclaredField("uriInfo");
+            uriField.setAccessible(true);
+            requestField = AbstractIdentifierAwareJaxRsProvider.class
+                    .getDeclaredField("request");
+            requestField.setAccessible(true);
+        } catch (NoSuchFieldException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected final ControllerContext controllerContext;
+    protected final MediaType mediaType;
+
+    protected AbstractBodyReaderTest(SchemaContext schemaContext, DOMMountPoint mountInstance) {
         this.mediaType = getMediaType();
+
+        controllerContext = TestRestconfUtils.newControllerContext(schemaContext, mountInstance);
     }
 
     protected abstract MediaType getMediaType();
index 7d5b015c1690f8ae323c27ce81101868561630ae..cffbea138b0f570d628180d1012b3cff78bfd414 100644 (file)
@@ -46,8 +46,9 @@ public class TestJsonBodyReader extends AbstractBodyReaderTest {
     private static final QNameModule INSTANCE_IDENTIFIER_MODULE_QNAME = QNameModule.create(
         URI.create("instance:identifier:module"), Revision.of("2014-01-17"));
 
-    public TestJsonBodyReader() throws NoSuchFieldException, SecurityException {
-        this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
+    public TestJsonBodyReader() {
+        super(schemaContext, null);
+        this.jsonBodyReader = new JsonNormalizedNodeBodyReader(controllerContext);
     }
 
     @Override
@@ -61,7 +62,6 @@ public class TestJsonBodyReader extends AbstractBodyReaderTest {
         final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
         testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
         schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     @Test
index 328e6182c135240c2e908e6fcc234a7eeee32f7d..675425704d1f843414a41d7da0849e31f2987f0f 100644 (file)
@@ -10,11 +10,8 @@ package org.opendaylight.controller.sal.rest.impl.test.providers;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import java.io.File;
 import java.io.InputStream;
 import java.net.URI;
@@ -23,10 +20,8 @@ import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
-import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -49,9 +44,9 @@ public class TestJsonBodyReaderMountPoint extends AbstractBodyReaderTest {
     private static final QNameModule INSTANCE_IDENTIFIER_MODULE_QNAME = QNameModule.create(
         URI.create("instance:identifier:module"), Revision.of("2014-01-17"));
 
-    public TestJsonBodyReaderMountPoint() throws NoSuchFieldException,
-            SecurityException {
-        this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
+    public TestJsonBodyReaderMountPoint() throws NoSuchFieldException, SecurityException {
+        super(schemaContext, mock(DOMMountPoint.class));
+        this.jsonBodyReader = new JsonNormalizedNodeBodyReader(controllerContext);
     }
 
     @Override
@@ -64,15 +59,6 @@ public class TestJsonBodyReaderMountPoint extends AbstractBodyReaderTest {
         final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
         testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
         schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
-
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
-        when(mountInstance.getSchemaContext()).thenReturn(schemaContext);
-        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
-        when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class)))
-                .thenReturn(Optional.of(mountInstance));
-
-        ControllerContext.getInstance().setMountService(mockMountService);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     @Test
index 8f7b008ec66fd75787cad7d169daf9ef83a923cd..24c58a03ad5e0c8191c0207ead99e6a4918503ab 100644 (file)
@@ -31,9 +31,10 @@ public class TestJsonBodyWriter extends AbstractBodyReaderTest {
     private final NormalizedNodeJsonBodyWriter jsonBodyWriter;
     private static SchemaContext schemaContext;
 
-    public TestJsonBodyWriter() throws NoSuchFieldException, SecurityException {
+    public TestJsonBodyWriter() {
+        super(schemaContext, null);
         this.jsonBodyWriter = new NormalizedNodeJsonBodyWriter();
-        this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
+        this.jsonBodyReader = new JsonNormalizedNodeBodyReader(controllerContext);
     }
 
     @Override
@@ -46,7 +47,6 @@ public class TestJsonBodyWriter extends AbstractBodyReaderTest {
         final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
         testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
         schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     @Test
index aec82f69dc13531a13df48ebe27ec2ea67784721..b29136702d3869538ffc65ad3688d7e69a0a7665 100644 (file)
@@ -26,8 +26,9 @@ public class TestJsonPatchBodyReader extends AbstractBodyReaderTest {
     private final JsonToPatchBodyReader jsonToPatchBodyReader;
     private static SchemaContext schemaContext;
 
-    public TestJsonPatchBodyReader() throws NoSuchFieldException, SecurityException {
-        jsonToPatchBodyReader = new JsonToPatchBodyReader();
+    public TestJsonPatchBodyReader() {
+        super(schemaContext, null);
+        jsonToPatchBodyReader = new JsonToPatchBodyReader(controllerContext);
     }
 
     @Override
@@ -38,7 +39,6 @@ public class TestJsonPatchBodyReader extends AbstractBodyReaderTest {
     @BeforeClass
     public static void initialization() {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     @Test
index 8567d67b5acbb940a478bc05421f0cb63abf036e..eca76aa33a4cdcc49f3a428b2519e5c5c1d0368f 100644 (file)
@@ -11,21 +11,16 @@ package org.opendaylight.controller.sal.rest.impl.test.providers;
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import java.io.InputStream;
 import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.netconf.sal.rest.impl.JsonToPatchBodyReader;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class TestJsonPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
@@ -34,8 +29,9 @@ public class TestJsonPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     private static SchemaContext schemaContext;
     private static final String MOUNT_POINT = "instance-identifier-module:cont/yang-ext:mount";
 
-    public TestJsonPatchBodyReaderMountPoint() throws NoSuchFieldException, SecurityException {
-        jsonToPatchBodyReader = new JsonToPatchBodyReader();
+    public TestJsonPatchBodyReaderMountPoint() {
+        super(schemaContext, mock(DOMMountPoint.class));
+        jsonToPatchBodyReader = new JsonToPatchBodyReader(controllerContext);
     }
 
     @Override
@@ -46,15 +42,6 @@ public class TestJsonPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     @BeforeClass
     public static void initialization() {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
-
-        final DOMMountPoint mockMountPoint = mock(DOMMountPoint.class);
-        when(mockMountPoint.getSchemaContext()).thenReturn(schemaContext);
-        final DOMMountPointService mockMountPointService = mock(DOMMountPointService.class);
-        when(mockMountPointService.getMountPoint(any(YangInstanceIdentifier.class)))
-                .thenReturn(Optional.of(mockMountPoint));
-
-        CONTROLLER_CONTEXT.setMountService(mockMountPointService);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     @Test
index a34308160e2a6470d9ca02518da12e01dfeac9af..cd3762e1d5ed926c1528d85ced912b590ca93bf1 100644 (file)
@@ -49,8 +49,9 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest {
     private static final QNameModule INSTANCE_IDENTIFIER_MODULE_QNAME = QNameModule.create(
         URI.create("instance:identifier:module"), Revision.of("2014-01-17"));
 
-    public TestXmlBodyReader() throws Exception {
-        this.xmlBodyReader = new XmlNormalizedNodeBodyReader();
+    public TestXmlBodyReader() {
+        super(schemaContext, null);
+        this.xmlBodyReader = new XmlNormalizedNodeBodyReader(controllerContext);
     }
 
     @Override
@@ -64,7 +65,6 @@ public class TestXmlBodyReader extends AbstractBodyReaderTest {
         testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
         testFiles.addAll(TestRestconfUtils.loadFiles("/foo-xml-test/yang"));
         schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     @Test
index 214ee79cc0cb808086ee619117434fb673be9fb9..955a310b24cb0b3fcaab19b14b183a8cb55b96e0 100644 (file)
@@ -11,11 +11,8 @@ package org.opendaylight.controller.sal.rest.impl.test.providers;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import java.io.File;
 import java.io.InputStream;
 import java.net.URI;
@@ -25,10 +22,8 @@ import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
-import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
@@ -52,8 +47,9 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest {
     private static final QNameModule INSTANCE_IDENTIFIER_MODULE_QNAME = QNameModule.create(
         URI.create("instance:identifier:module"), Revision.of("2014-01-17"));
 
-    public TestXmlBodyReaderMountPoint() throws Exception {
-        this.xmlBodyReader = new XmlNormalizedNodeBodyReader();
+    public TestXmlBodyReaderMountPoint() {
+        super(schemaContext, mock(DOMMountPoint.class));
+        this.xmlBodyReader = new XmlNormalizedNodeBodyReader(controllerContext);
     }
 
     @Override
@@ -66,15 +62,6 @@ public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest {
         final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
         testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
         schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
-
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
-        when(mountInstance.getSchemaContext()).thenReturn(schemaContext);
-        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
-        when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class)))
-                .thenReturn(Optional.of(mountInstance));
-
-        ControllerContext.getInstance().setMountService(mockMountService);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     @Test
index ca594a36901b3b74d11d91cb2f13c5a154c610ce..ef1bffee3871d2ba0e30209c80c82407de23caa6 100644 (file)
@@ -28,7 +28,8 @@ public class TestXmlBodyWriter extends AbstractBodyReaderTest {
     private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
     private static SchemaContext schemaContext;
 
-    public TestXmlBodyWriter() throws NoSuchFieldException, SecurityException {
+    public TestXmlBodyWriter() {
+        super(schemaContext, null);
         this.xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
     }
 
@@ -42,7 +43,6 @@ public class TestXmlBodyWriter extends AbstractBodyReaderTest {
         final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
         testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
         schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     @Test
@@ -50,7 +50,7 @@ public class TestXmlBodyWriter extends AbstractBodyReaderTest {
         final String uri = "invoke-rpc-module:rpc-test";
         final String pathToInputFile = "/invoke-rpc/xml/rpc-output.xml";
         final NormalizedNodeContext nnContext = TestRestconfUtils
-                .loadNormalizedContextFromXmlFile(pathToInputFile, uri);
+                .loadNormalizedContextFromXmlFile(pathToInputFile, uri, controllerContext);
         final OutputStream output = new ByteArrayOutputStream();
         this.xmlBodyWriter.writeTo(nnContext, null, null, null, this.mediaType, null,
                 output);
index 1bdbab9519a476c4967b77e5304fccdf53520d20..9850f57452ccb40b27b5d7929fea38e27aa7ef47 100644 (file)
@@ -25,8 +25,9 @@ public class TestXmlPatchBodyReader extends AbstractBodyReaderTest {
     private final XmlToPatchBodyReader xmlToPatchBodyReader;
     private static SchemaContext schemaContext;
 
-    public TestXmlPatchBodyReader() throws NoSuchFieldException, SecurityException {
-        xmlToPatchBodyReader = new XmlToPatchBodyReader();
+    public TestXmlPatchBodyReader() {
+        super(schemaContext, null);
+        xmlToPatchBodyReader = new XmlToPatchBodyReader(controllerContext);
     }
 
     @Override
@@ -37,7 +38,6 @@ public class TestXmlPatchBodyReader extends AbstractBodyReaderTest {
     @BeforeClass
     public static void initialization() throws NoSuchFieldException, SecurityException {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     @Test
index b9fd057ea28f136da530c7af77ff3b4352a262b3..04cbc95fb8217d2338ca07f8e0f068ca0a7f7f80 100644 (file)
@@ -10,21 +10,16 @@ package org.opendaylight.controller.sal.rest.impl.test.providers;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import java.io.InputStream;
 import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.netconf.sal.rest.impl.XmlToPatchBodyReader;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
@@ -33,8 +28,9 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     private static SchemaContext schemaContext;
     private static final String MOUNT_POINT = "instance-identifier-module:cont/yang-ext:mount";
 
-    public TestXmlPatchBodyReaderMountPoint() throws NoSuchFieldException, SecurityException {
-        xmlToPatchBodyReader = new XmlToPatchBodyReader();
+    public TestXmlPatchBodyReaderMountPoint() {
+        super(schemaContext, mock(DOMMountPoint.class));
+        xmlToPatchBodyReader = new XmlToPatchBodyReader(controllerContext);
     }
 
     @Override
@@ -45,15 +41,6 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     @BeforeClass
     public static void initialization() throws NoSuchFieldException, SecurityException {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
-
-        final DOMMountPoint mockMountPoint = mock(DOMMountPoint.class);
-        when(mockMountPoint.getSchemaContext()).thenReturn(schemaContext);
-        final DOMMountPointService mockMountPointService = mock(DOMMountPointService.class);
-        when(mockMountPointService.getMountPoint(any(YangInstanceIdentifier.class)))
-                .thenReturn(Optional.of(mockMountPoint));
-
-        CONTROLLER_CONTEXT.setMountService(mockMountPointService);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     @Test
index c18c13a2328a2ef4d5a4f0ee0290aff6062db1bf..7d1d524d40009f8778b700c2016f628dad2a4e36 100644 (file)
@@ -17,14 +17,15 @@ import static org.mockito.Mockito.when;
 import com.google.common.collect.Iterables;
 import com.google.common.util.concurrent.CheckedFuture;
 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;
@@ -53,24 +54,22 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 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 {
-        final ControllerContext controllerContext = ControllerContext.getInstance();
-        schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module");
-        controllerContext.setSchemas(schemaContextTestModule);
+        final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContextTestModule);
         brokerFacade = mock(BrokerFacade.class);
         restconfImpl = RestconfImpl.getInstance();
         restconfImpl.setBroker(brokerFacade);
index 0345beab950ab9f0c08ccb26744c61376f4195e3..e3bb5c31f785eee62734e3a6bf9ed9f330d9b2de 100644 (file)
@@ -25,16 +25,14 @@ public class JsonIdentityrefToNnTest extends AbstractBodyReaderTest {
     private final JsonNormalizedNodeBodyReader jsonBodyReader;
     private static SchemaContext schemaContext;
 
-    public JsonIdentityrefToNnTest() throws NoSuchFieldException,
-            SecurityException {
-        this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
+    public JsonIdentityrefToNnTest() {
+        super(schemaContext, null);
+        this.jsonBodyReader = new JsonNormalizedNodeBodyReader(controllerContext);
     }
 
     @BeforeClass
     public static void initialize() {
-        schemaContext = schemaContextLoader("/json-to-nn/identityref",
-                schemaContext);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        schemaContext = schemaContextLoader("/json-to-nn/identityref", schemaContext);
     }
 
     @Test
index f0bfa63d348670a532f5afdbba7da4873b022b8d..d25e36101202cc09eace5a187e87ad2a30d80708 100644 (file)
@@ -25,15 +25,14 @@ public class JsonLeafrefToNnTest extends AbstractBodyReaderTest {
     private final JsonNormalizedNodeBodyReader jsonBodyReader;
     private static SchemaContext schemaContext;
 
-    public JsonLeafrefToNnTest() throws NoSuchFieldException, SecurityException {
-        this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
+    public JsonLeafrefToNnTest() {
+        super(schemaContext, null);
+        this.jsonBodyReader = new JsonNormalizedNodeBodyReader(controllerContext);
     }
 
     @BeforeClass
     public static void initialize() {
-        schemaContext = schemaContextLoader("/json-to-nn/leafref",
-                schemaContext);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        schemaContext = schemaContextLoader("/json-to-nn/leafref", schemaContext);
     }
 
     @Test
index 7f1de7f3f1f88436d7fbca7dce4fb001cc6e5a27..b6289b400976515319ecc04679cb542beec39da6 100644 (file)
@@ -13,17 +13,23 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Collection;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
+import org.junit.BeforeClass;
 import org.junit.Test;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,35 +37,38 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(AbstractBodyReaderTest.class);
 
-    private JsonNormalizedNodeBodyReader jsonBodyReader;
-    private SchemaContext schemaContext;
+    private final JsonNormalizedNodeBodyReader jsonBodyReader;
+    private static SchemaContext schemaContext;
 
-    public JsonToNnTest() throws NoSuchFieldException, SecurityException {
+    public JsonToNnTest() {
+        super(schemaContext, null);
+        this.jsonBodyReader = new JsonNormalizedNodeBodyReader(controllerContext);
     }
 
-    public static void initialize(final String path, SchemaContext schemaContext) {
-        schemaContext = schemaContextLoader(path, schemaContext);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+    @BeforeClass
+    public static void initialize() throws FileNotFoundException {
+        final Collection<File> testFiles = TestRestconfUtils.loadFiles("/json-to-nn/simple-list-yang/1");
+        testFiles.addAll(TestRestconfUtils.loadFiles("/json-to-nn/simple-list-yang/3"));
+        testFiles.addAll(TestRestconfUtils.loadFiles("/json-to-nn/simple-list-yang/4"));
+        testFiles.addAll(TestRestconfUtils.loadFiles("/json-to-nn/simple-container-yang"));
+        testFiles.addAll(TestRestconfUtils.loadFiles("/common/augment/yang"));
+        schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
     }
 
     @Test
     public void simpleListTest() throws Exception {
         simpleTest("/json-to-nn/simple-list.json",
-                "/json-to-nn/simple-list-yang/1", "lst", "simple-list-yang1");
+                "lst", "simple-list-yang1");
     }
 
     @Test
     public void simpleContainerTest() throws Exception {
         simpleTest("/json-to-nn/simple-container.json",
-                "/json-to-nn/simple-container-yang", "cont",
-                "simple-container-yang");
+                "cont", "simple-container-yang");
     }
 
     @Test
     public void multipleItemsInLeafListTest() throws Exception {
-
-        initialize("/json-to-nn/simple-list-yang/1", this.schemaContext);
-
         final NormalizedNodeContext normalizedNodeContext = prepareNNC(
                 "/json-to-nn/multiple-leaflist-items.json",
                 "simple-list-yang1:lst");
@@ -74,8 +83,6 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
 
     @Test
     public void multipleItemsInListTest() throws Exception {
-        initialize("/json-to-nn/simple-list-yang/3", this.schemaContext);
-
         final NormalizedNodeContext normalizedNodeContext = prepareNNC(
                 "/json-to-nn/multiple-items-in-list.json",
                 "multiple-items-yang:lst");
@@ -89,8 +96,6 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
 
     @Test
     public void nullArrayToSimpleNodeWithNullValueTest() throws Exception {
-        initialize("/json-to-nn/simple-list-yang/4", this.schemaContext);
-
         final NormalizedNodeContext normalizedNodeContext = prepareNNC(
                 "/json-to-nn/array-with-null.json", "array-with-null-yang:cont");
         assertNotNull(normalizedNodeContext);
@@ -106,9 +111,6 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
 
     @Test
     public void incorrectTopLevelElementsTest() throws Exception {
-
-        this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
-        initialize("/json-to-nn/simple-list-yang/1", this.schemaContext);
         mockBodyReader("simple-list-yang1:lst", this.jsonBodyReader, false);
 
         InputStream inputStream = this.getClass().getResourceAsStream(
@@ -126,7 +128,7 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
         }
         assertNotNull(exception);
         assertEquals(
-                "Error parsing input: Schema node with name cont was not found under "
+                "Error parsing input: Schema node with name wrong was not found under "
                         + "(urn:ietf:params:xml:ns:netconf:base:1.0)data.",
                 exception.getErrors().get(0).getErrorMessage());
 
@@ -166,9 +168,6 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
 
     @Test
     public void emptyDataReadTest() throws Exception {
-
-        initialize("/json-to-nn/simple-list-yang/4", this.schemaContext);
-
         final NormalizedNodeContext normalizedNodeContext = prepareNNC(
                 "/json-to-nn/empty-data.json", "array-with-null-yang:cont");
         assertNotNull(normalizedNodeContext);
@@ -183,7 +182,6 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
 
         assertTrue(dataTree.contains("lflst2 45"));
 
-        this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
         RestconfDocumentedException exception = null;
         mockBodyReader("array-with-null-yang:cont", this.jsonBodyReader, false);
         final InputStream inputStream = this.getClass().getResourceAsStream(
@@ -202,7 +200,6 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
 
     @Test
     public void testJsonBlankInput() throws Exception {
-        initialize("/json-to-nn/simple-list-yang/4", this.schemaContext);
         final NormalizedNodeContext normalizedNodeContext = prepareNNC("",
                 "array-with-null-yang:cont");
         assertNull(normalizedNodeContext);
@@ -210,9 +207,6 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
 
     @Test
     public void notSupplyNamespaceIfAlreadySupplied()throws Exception {
-
-        initialize("/json-to-nn/simple-list-yang/1", this.schemaContext);
-
         final String uri = "simple-list-yang1" + ":" + "lst";
 
         final NormalizedNodeContext normalizedNodeContext = prepareNNC(
@@ -238,9 +232,6 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
 
     @Test
     public void dataAugmentedTest() throws Exception {
-
-        initialize("/common/augment/yang", this.schemaContext);
-
         NormalizedNodeContext normalizedNodeContext = prepareNNC(
                 "/common/augment/json/dataa.json", "main:cont");
 
@@ -265,11 +256,8 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
         assertTrue(dataTree.contains("lf11 lf11 value from b"));
     }
 
-    private void simpleTest(final String jsonPath, final String yangPath,
-            final String topLevelElementName, final String moduleName) throws Exception {
-
-        initialize(yangPath, this.schemaContext);
-
+    private void simpleTest(final String jsonPath, final String topLevelElementName,
+            final String moduleName) throws Exception {
         final String uri = moduleName + ":" + topLevelElementName;
 
         final NormalizedNodeContext normalizedNodeContext = prepareNNC(jsonPath, uri);
@@ -279,7 +267,6 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
     }
 
     private NormalizedNodeContext prepareNNC(final String jsonPath, final String uri) throws Exception {
-        this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
         try {
             mockBodyReader(uri, this.jsonBodyReader, false);
         } catch (NoSuchFieldException | SecurityException
@@ -329,8 +316,6 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
 
     @Test
     public void unsupportedDataFormatTest() throws Exception {
-        this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
-        initialize("/json-to-nn/simple-list-yang/1", this.schemaContext);
         mockBodyReader("simple-list-yang1:lst", this.jsonBodyReader, false);
 
         final InputStream inputStream = this.getClass().getResourceAsStream(
@@ -352,9 +337,6 @@ public class JsonToNnTest extends AbstractBodyReaderTest {
 
     @Test
     public void invalidUriCharacterInValue() throws Exception {
-
-        this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
-        initialize("/json-to-nn/simple-list-yang/4", this.schemaContext);
         mockBodyReader("array-with-null-yang:cont", this.jsonBodyReader, false);
 
         final InputStream inputStream = this.getClass().getResourceAsStream(
index c83261e0285d1e8ba91f85e2cbed39fd7ffcd55a..43e950c9e9980748154a0c4a3f34fb2238e1d5e2 100644 (file)
@@ -26,15 +26,14 @@ public class NnJsonChoiceCaseTest extends AbstractBodyReaderTest {
     private static SchemaContext schemaContext;
     private final NormalizedNodeJsonBodyWriter jsonBodyWriter;
 
-    public NnJsonChoiceCaseTest() throws NoSuchFieldException,
-            SecurityException {
+    public NnJsonChoiceCaseTest()  {
+        super(schemaContext, null);
         jsonBodyWriter = new NormalizedNodeJsonBodyWriter();
     }
 
     @BeforeClass
     public static void initialization() {
         schemaContext = schemaContextLoader("/nn-to-json/choice", schemaContext);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     /**
@@ -167,7 +166,7 @@ public class NnJsonChoiceCaseTest extends AbstractBodyReaderTest {
     private String getJson(final String xmlPath) throws Exception {
         final String uri = "choice-case-test:cont";
         final NormalizedNodeContext testNN = TestRestconfUtils
-                .loadNormalizedContextFromXmlFile(xmlPath, uri);
+                .loadNormalizedContextFromXmlFile(xmlPath, uri, controllerContext);
 
         final OutputStream output = new ByteArrayOutputStream();
         jsonBodyWriter.writeTo(testNN, null, null, null, mediaType, null,
index c5d77133285d4dc90fb4c3a51c37a6f7f2aeb291..cb1bf574c848cffc4399853cb975bfd73c3d2b54 100644 (file)
@@ -28,15 +28,14 @@ public class NnToJsonLeafrefType extends AbstractBodyReaderTest {
     private static SchemaContext schemaContext;
     private final NormalizedNodeJsonBodyWriter jsonBodyWriter;
 
-    public NnToJsonLeafrefType() throws NoSuchFieldException, SecurityException {
+    public NnToJsonLeafrefType() {
+        super(schemaContext, null);
         jsonBodyWriter = new NormalizedNodeJsonBodyWriter();
     }
 
     @BeforeClass
     public static void initialization() {
-        schemaContext = schemaContextLoader("/nn-to-json/leafref",
-                schemaContext);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        schemaContext = schemaContextLoader("/nn-to-json/leafref", schemaContext);
     }
 
     @Test
@@ -91,7 +90,7 @@ public class NnToJsonLeafrefType extends AbstractBodyReaderTest {
         final String pathToInputFile = xmlDataPath;
 
         final NormalizedNodeContext testNN = TestRestconfUtils
-                .loadNormalizedContextFromXmlFile(pathToInputFile, uri);
+                .loadNormalizedContextFromXmlFile(pathToInputFile, uri, controllerContext);
 
         final OutputStream output = new ByteArrayOutputStream();
         jsonBodyWriter.writeTo(testNN, null, null, null, mediaType, null,
index 0aadde5a78e5ebce0143ada85b5a12e77b95e881..0623a07be5357ab2f23b22527b1c6e70969570ce 100644 (file)
@@ -29,16 +29,14 @@ public class NnToJsonWithAugmentTest extends AbstractBodyReaderTest {
     private static SchemaContext schemaContext;
     private final NormalizedNodeJsonBodyWriter xmlBodyWriter;
 
-    public NnToJsonWithAugmentTest() throws NoSuchFieldException,
-            SecurityException {
+    public NnToJsonWithAugmentTest() {
+        super(schemaContext, null);
         xmlBodyWriter = new NormalizedNodeJsonBodyWriter();
     }
 
     @BeforeClass
     public static void initialize() {
-        schemaContext = schemaContextLoader("/nn-to-json/augmentation",
-                schemaContext);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        schemaContext = schemaContextLoader("/nn-to-json/augmentation", schemaContext);
     }
 
     @Test
@@ -48,7 +46,7 @@ public class NnToJsonWithAugmentTest extends AbstractBodyReaderTest {
         final String pathToInputFile = "/nn-to-json/augmentation/xml/data.xml";
 
         final NormalizedNodeContext testNN = TestRestconfUtils
-                .loadNormalizedContextFromXmlFile(pathToInputFile, uri);
+                .loadNormalizedContextFromXmlFile(pathToInputFile, uri, controllerContext);
 
         final OutputStream output = new ByteArrayOutputStream();
         xmlBodyWriter
index f1e5786b47af19ec16654666acbea5ef5decd873..b6c6ec3207c518ee00d669054600ecb341350e5e 100644 (file)
@@ -48,16 +48,14 @@ public class NnInstanceIdentifierToXmlTest extends AbstractBodyReaderTest {
     private static SchemaContext schemaContext;
     NormalizedNodeXmlBodyWriter xmlBodyWriter;
 
-    public NnInstanceIdentifierToXmlTest() throws NoSuchFieldException,
-            SecurityException {
+    public NnInstanceIdentifierToXmlTest() {
+        super(schemaContext, null);
         xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
     }
 
     @BeforeClass
     public static void initialization() throws URISyntaxException {
-        schemaContext = schemaContextLoader("/instanceidentifier/yang",
-                schemaContext);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
     }
 
     @Test
index da5f91e25c7848d6b3dc5f365eeb4b5e018611a6..e5d4c8cc7c37948c65b07ac49d97f3e8575c9aaa 100644 (file)
@@ -52,14 +52,14 @@ public class NnToXmlTest extends AbstractBodyReaderTest {
     private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
     private static SchemaContext schemaContext;
 
-    public NnToXmlTest() throws NoSuchFieldException, SecurityException {
+    public NnToXmlTest() {
+        super(schemaContext, null);
         this.xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
     }
 
     @BeforeClass
     public static void initialization() {
         schemaContext = schemaContextLoader("/nn-to-xml/yang", schemaContext);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     @Test
index 01830d816c4e48842ec9d20bbea1b8eba94ca36d..6fbb4683e5b037f38f04e49d96d8294cc4088113 100644 (file)
@@ -40,15 +40,14 @@ public class NnToXmlWithChoiceTest extends AbstractBodyReaderTest {
     private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
     private static SchemaContext schemaContext;
 
-    public NnToXmlWithChoiceTest() throws NoSuchFieldException,
-            SecurityException {
+    public NnToXmlWithChoiceTest() {
+        super(schemaContext, null);
         xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
     }
 
     @BeforeClass
     public static void initialization() {
         schemaContext = schemaContextLoader("/nn-to-xml/choice", schemaContext);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
     }
 
     @Test
index 08539d0a5b63f3761791f26a950277eb3acee87e..1f4b0456d8c2a3785264a6045c6e3973dbed78cd 100644 (file)
@@ -42,16 +42,14 @@ public class NnToXmlWithDataFromSeveralModulesTest extends
     private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
     private static SchemaContext schemaContext;
 
-    public NnToXmlWithDataFromSeveralModulesTest() throws NoSuchFieldException,
-            SecurityException {
+    public NnToXmlWithDataFromSeveralModulesTest() {
+        super(schemaContext, null);
         xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
     }
 
     @BeforeClass
     public static void initialize() {
-        schemaContext = schemaContextLoader(
-                "/nn-to-xml/data-of-several-modules/yang", schemaContext);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        schemaContext = schemaContextLoader("/nn-to-xml/data-of-several-modules/yang", schemaContext);
     }
 
     @Test
index 70e1c340a63819b3aebd5b960825d9ca944700d0..287598868ff5582e3355060d6defd43b7db6058f 100644 (file)
@@ -28,7 +28,6 @@ import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
-
 import java.util.HashMap;
 import java.util.concurrent.Future;
 import org.junit.Before;
@@ -53,6 +52,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+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;
@@ -107,22 +107,26 @@ public class BrokerFacadeTest {
     private final QName qname = TestUtils.buildQName("interfaces","test:module", "2014-01-09");
     private final SchemaPath type = SchemaPath.create(true, this.qname);
     private final YangInstanceIdentifier instanceID = YangInstanceIdentifier.builder().node(this.qname).build();
+    private ControllerContext controllerContext;
 
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
+
+        controllerContext = TestRestconfUtils.newControllerContext(
+                TestUtils.loadSchemaContext("/full-versions/test-module", "/modules"));
+
         this.brokerFacade.setDomDataBroker(this.domDataBroker);
         this.brokerFacade.setDomNotificationService(this.domNotification);
         this.brokerFacade.setRpcService(this.mockRpcService);
+        this.brokerFacade.setControllerContext(controllerContext);
+
         when(this.domDataBroker.newReadOnlyTransaction()).thenReturn(this.readTransaction);
         when(this.domDataBroker.newWriteOnlyTransaction()).thenReturn(this.writeTransaction);
         when(this.domDataBroker.newReadWriteTransaction()).thenReturn(this.rwTransaction);
         HashMap extensions = new HashMap();
         extensions.put(DOMDataTreeChangeService.class, Mockito.mock(DOMDataTreeChangeService.class));
         when(this.domDataBroker.getSupportedExtensions()).thenReturn(extensions);
-
-        ControllerContext.getInstance()
-                .setSchemas(TestUtils.loadSchemaContext("/full-versions/test-module", "/modules"));
     }
 
     private static CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> wrapDummyNode(
@@ -331,7 +335,7 @@ public class BrokerFacadeTest {
     @Test
     public void testRegisterToListenDataChanges() {
         final ListenerAdapter listener = Notificator.createListener(this.instanceID, "stream",
-                NotificationOutputType.XML);
+                NotificationOutputType.XML, controllerContext);
 
         @SuppressWarnings("unchecked")
         final ListenerRegistration<ListenerAdapter> mockRegistration = mock(ListenerRegistration.class);
@@ -362,7 +366,7 @@ public class BrokerFacadeTest {
         final String identifier = "create-notification-stream/toaster:toastDone";
         final SchemaPath path = SchemaPath.create(true,
                 QName.create("http://netconfcentral.org/ns/toaster", "2009-11-20", "toastDone"));
-        Notificator.createNotificationListener(Lists.newArrayList(path), identifier, "XML");
+        Notificator.createNotificationListener(Lists.newArrayList(path), identifier, "XML", controllerContext);
         final NotificationListenerAdapter listener = Notificator.getNotificationListenerFor(identifier).get(0);
 
         // mock registration
index db96f0cb2b1fc4b612d2f082f652985f2d8fd6e0..96d7b5e3851488f79beedea5715295f863acbdcb 100644 (file)
@@ -14,6 +14,7 @@ import static org.junit.Assert.assertNotNull;
 import java.io.FileNotFoundException;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -27,19 +28,17 @@ public class Bug3595Test {
     private static final QName CONT_QNAME = QName.create("leafref:module", "2014-04-17", "cont");
     private static final QName LST_WITH_LFREF_KEY_QNAME = QName.create(CONT_QNAME, "lst-with-lfref-key");
     private static final QName LFREF_KEY_QNAME = QName.create(CONT_QNAME, "lfref-key");
+    private static SchemaContext schemaContext;
 
-
-    private static ControllerContext controllerContext = ControllerContext.getInstance();
+    private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
 
     @BeforeClass
     public static void initialize() throws FileNotFoundException {
-        final SchemaContext schemaContext = TestUtils.loadSchemaContext("/leafref/yang");
+        schemaContext = TestUtils.loadSchemaContext("/leafref/yang");
         Module module = TestUtils.findModule(schemaContext.getModules(), "leafref-module");
         assertNotNull(module);
         module = TestUtils.findModule(schemaContext.getModules(), "referenced-module");
         assertNotNull(module);
-
-        controllerContext.setGlobalSchema(schemaContext);
     }
 
     @Test
index ad2ce0dc7b65d2ff10a8295d3a7d0cc695fdbf40..a6dbef2c3a93b7bd4024cccb5e3cb00e5d4d501e 100644 (file)
@@ -9,11 +9,9 @@ package org.opendaylight.controller.sal.restconf.impl.test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import java.io.FileNotFoundException;
 import java.util.HashMap;
 import java.util.Map;
@@ -21,7 +19,7 @@ import java.util.Set;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+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.RestconfImpl;
@@ -40,21 +38,33 @@ public class Bug8072Test {
     private static final QName TYPE_QNAME = QName.create("test:module", "2014-01-09", "type");
     private static final QName MODULE_TYPE_QNAME = QName.create("test:module", "2014-01-09", "module-type");
 
-    private static final ControllerContext CONTROLLER_CONTEXT = ControllerContext.getInstance();
+    private static SchemaContext schemaContext;
+
+    private final ControllerContext controllerContext;
+
+    public Bug8072Test() throws FileNotFoundException {
+        final SchemaContext mountPointContext = TestUtils.loadSchemaContext("/full-versions/test-module");
+        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
+        controllerContext = TestRestconfUtils.newControllerContext(schemaContext, mountInstance);
+        doReturn(mountPointContext).when(mountInstance).getSchemaContext();
+
+        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
+        final RestconfImpl restconfImpl = RestconfImpl.getInstance();
+        restconfImpl.setBroker(brokerFacade);
+        restconfImpl.setControllerContext(controllerContext);
+    }
 
     @BeforeClass
     public static void init() throws FileNotFoundException, ReactorException {
-        final SchemaContext globalContext = TestUtils.loadSchemaContext("/full-versions/yangs");
-        assertEquals(0, globalContext.findModules(EXTERNAL_MODULE_NAME).size());
-        final Set<Module> allModules = globalContext.getModules();
+        schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
+        assertEquals(0, schemaContext.findModules(EXTERNAL_MODULE_NAME).size());
+        final Set<Module> allModules = schemaContext.getModules();
         assertNotNull(allModules);
-        CONTROLLER_CONTEXT.setSchemas(globalContext);
     }
 
     @Test
     public void testIdentityRefFromExternalModule() throws FileNotFoundException, ReactorException {
-        initMountService();
-        final InstanceIdentifierContext<?> ctx = CONTROLLER_CONTEXT.toInstanceIdentifier(
+        final InstanceIdentifierContext<?> ctx = controllerContext.toInstanceIdentifier(
                 "simple-nodes:users/yang-ext:mount/test-module:modules/module/test-module:module-type/name");
 
         final Map<QName, Object> keyValues = new HashMap<>();
@@ -65,17 +75,4 @@ public class Bug8072Test {
 
         assertEquals(expectedYII, ctx.getInstanceIdentifier());
     }
-
-    private void initMountService() throws FileNotFoundException, ReactorException {
-        final DOMMountPointService mountService = mock(DOMMountPointService.class);
-        CONTROLLER_CONTEXT.setMountService(mountService);
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
-        final RestconfImpl restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(CONTROLLER_CONTEXT);
-        final SchemaContext mountPointContext = TestUtils.loadSchemaContext("/full-versions/test-module");
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
-        when(mountInstance.getSchemaContext()).thenReturn(mountPointContext);
-        when(mountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
-    }
 }
index 67f10412271292a3cc008c6a99494a29d53a3783..a671a6c85a42481b3aab3af52d234a981244a9dc 100644 (file)
@@ -17,9 +17,10 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import org.glassfish.jersey.server.ResourceConfig;
 import org.glassfish.jersey.test.JerseyTest;
-import org.junit.BeforeClass;
+import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
@@ -32,15 +33,14 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
 public class CodecsExceptionsCatchingTest extends JerseyTest {
 
-    private static RestconfImpl restConf;
-    private static ControllerContext controllerContext = ControllerContext.getInstance();
+    private RestconfImpl restConf;
+    private ControllerContext controllerContext;
 
-    @BeforeClass
-    public static void init() throws FileNotFoundException, ReactorException {
+    @Before
+    public void init() throws FileNotFoundException, ReactorException {
         restConf = RestconfImpl.getInstance();
-        controllerContext = ControllerContext.getInstance();
         final SchemaContext schemaContext = TestUtils.loadSchemaContext("/decoding-exception/yang");
-        controllerContext.setGlobalSchema(schemaContext);
+        controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
         restConf.setControllerContext(controllerContext);
     }
 
@@ -53,7 +53,8 @@ public class CodecsExceptionsCatchingTest extends JerseyTest {
         // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
         ResourceConfig resourceConfig = new ResourceConfig();
         resourceConfig = resourceConfig.registerInstances(restConf, new NormalizedNodeJsonBodyWriter(),
-            new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(), new JsonNormalizedNodeBodyReader());
+            new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(controllerContext),
+            new JsonNormalizedNodeBodyReader(controllerContext));
         resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
         return resourceConfig;
     }
@@ -66,4 +67,4 @@ public class CodecsExceptionsCatchingTest extends JerseyTest {
         final String exceptionMessage = response.readEntity(String.class);
         assertTrue(exceptionMessage.contains("invalid-value"));
     }
-}
\ No newline at end of file
+}
index 649ec8fc87d99b00726603afbd65c7a1111da752..1224c3d389e298fe4f35edd833fa856030fef56c 100644 (file)
@@ -30,6 +30,7 @@ import javax.ws.rs.core.UriInfo;
 import org.glassfish.jersey.server.ResourceConfig;
 import org.glassfish.jersey.test.JerseyTest;
 import org.junit.BeforeClass;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
@@ -73,6 +74,9 @@ public class CutDataToCorrectDepthTest extends JerseyTest {
     private NormalizedNode<?, ?> globalPayload;
     private static SchemaContext schemaContextModules;
 
+    private final ControllerContext controllerContext =
+            TestRestconfUtils.newControllerContext(schemaContextModules, null);
+
     @Path("/")
     public class RestImpl {
 
@@ -82,8 +86,7 @@ public class CutDataToCorrectDepthTest extends JerseyTest {
         public NormalizedNodeContext getData(@Encoded @PathParam("identifier") final String identifier,
                                              @Context final UriInfo uriInfo) {
 
-            final InstanceIdentifierContext<?> iiWithData = ControllerContext.getInstance().toInstanceIdentifier(
-                    identifier);
+            final InstanceIdentifierContext<?> iiWithData = controllerContext.toInstanceIdentifier(identifier);
 
             NormalizedNode<?, ?> data = null;
             if (identifier.equals("nested-module:depth1-cont/depth2-cont1")) {
@@ -167,7 +170,6 @@ public class CutDataToCorrectDepthTest extends JerseyTest {
     }
 
     public void getDataWithUriDepthParameter(final String mediaType) throws WebApplicationException, IOException {
-        ControllerContext.getInstance().setGlobalSchema(schemaContextModules);
         Response response;
 
         // Test config with depth 1
index 434304da2193c08464e2fd71830fa841e28afa2b..220537909cf16b25c896ee3ce0e85bacf9cda01a 100644 (file)
@@ -134,7 +134,8 @@ public class ExpressionParserTest {
         final YangInstanceIdentifier path = Mockito.mock(YangInstanceIdentifier.class);
         final PathArgument pathValue = NodeIdentifier.create(QName.create("module", "2016-12-14", "localName"));
         Mockito.when(path.getLastPathArgument()).thenReturn(pathValue);
-        final ListenerAdapter listener = Notificator.createListener(path, "streamName", NotificationOutputType.JSON);
+        final ListenerAdapter listener = Notificator.createListener(path, "streamName", NotificationOutputType.JSON,
+                null);
         listener.setQueryParams(Instant.now(), Optional.empty(), Optional.ofNullable(filter), false);
 
         // FIXME: do not use reflection here
index bebb7f4e5f233fc9f0906c8772c16ab7c52433e9..8f97a1e7565be80991e2b829dbbe09f7d27b368d 100644 (file)
@@ -16,7 +16,6 @@ import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
 
 import com.google.common.base.Optional;
@@ -32,7 +31,6 @@ import java.util.Set;
 import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
-import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -40,6 +38,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
+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.RestconfImpl;
@@ -71,32 +70,31 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
 public class InvokeRpcMethodTest {
 
-    private RestconfImpl restconfImpl = null;
-    private static ControllerContext controllerContext = null;
     private static UriInfo uriInfo;
+    private static SchemaContext schemaContext;
 
+    private final RestconfImpl restconfImpl = RestconfImpl.getInstance();
+    private final ControllerContext controllerContext;
+
+    public InvokeRpcMethodTest() {
+        controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
+        restconfImpl.setControllerContext(controllerContext);
+    }
 
     @BeforeClass
     public static void init() throws FileNotFoundException, ReactorException {
-        final SchemaContext schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs", "/invoke-rpc");
+        schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs", "/invoke-rpc");
         final Set<Module> allModules = schemaContext.getModules();
         assertNotNull(allModules);
         final Module module = TestUtils.resolveModule("invoke-rpc-module", allModules);
         assertNotNull(module);
-        controllerContext = spy(ControllerContext.getInstance());
-        controllerContext.setSchemas(schemaContext);
+
         uriInfo = mock(UriInfo.class);
         final MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
         map.put("prettyPrint", Collections.singletonList("true"));
         when(uriInfo.getQueryParameters(any(Boolean.class))).thenReturn(map);
     }
 
-    @Before
-    public void initMethod() {
-        this.restconfImpl = RestconfImpl.getInstance();
-        this.restconfImpl.setControllerContext(controllerContext);
-    }
-
     /**
      * Test method invokeRpc in RestconfImpl class tests if composite node as input parameter of method invokeRpc
      * (second argument) is wrapped to parent composite node which has QName equals to QName of rpc (resolved from
@@ -105,28 +103,26 @@ public class InvokeRpcMethodTest {
     @Test
     @Ignore
     public void invokeRpcMethodTest() {
-        final ControllerContext contContext = controllerContext;
         try {
-            contContext.findModuleNameByNamespace(new URI("invoke:rpc:module"));
+            controllerContext.findModuleNameByNamespace(new URI("invoke:rpc:module"));
         } catch (final URISyntaxException e) {
             assertTrue("Uri wasn't created sucessfuly", false);
         }
 
         final BrokerFacade mockedBrokerFacade = mock(BrokerFacade.class);
 
-        final RestconfImpl restconf = RestconfImpl.getInstance();
-        restconf.setBroker(mockedBrokerFacade);
-        restconf.setControllerContext(contContext);
+        restconfImpl.setBroker(mockedBrokerFacade);
 
         final NormalizedNodeContext payload = prepareDomPayload();
 
-        final NormalizedNodeContext rpcResponse = restconf.invokeRpc("invoke-rpc-module:rpc-test", payload, uriInfo);
+        final NormalizedNodeContext rpcResponse =
+                restconfImpl.invokeRpc("invoke-rpc-module:rpc-test", payload, uriInfo);
         assertTrue(rpcResponse != null);
         assertTrue(rpcResponse.getData() == null);
 
     }
 
-    private static NormalizedNodeContext prepareDomPayload() {
+    private NormalizedNodeContext prepareDomPayload() {
         final SchemaContext schema = controllerContext.getGlobalSchema();
         final Module rpcModule = schema.findModules("invoke-rpc-module").iterator().next();
         assertNotNull(rpcModule);
@@ -289,7 +285,6 @@ public class InvokeRpcMethodTest {
         final SchemaPath path = SchemaPath.create(true,
                 QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)make-toast"));
 
-        final SchemaContext schemaContext = controllerContext.getGlobalSchema();
         final Module rpcModule = schemaContext.findModules("toaster").iterator().next();
         assertNotNull(rpcModule);
         final QName rpcQName = QName.create(rpcModule.getQNameModule(), "make-toast");
index 5037c4bbf09f96cfbb88a7d4c5988d2cfd4951fc..390a87f719fa2f2b0dcd02216b6f75e83f28b2ef 100644 (file)
@@ -19,7 +19,6 @@ import static org.mockito.Matchers.notNull;
 import static org.mockito.Matchers.same;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -41,11 +40,11 @@ import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
+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.JSONRestconfServiceImpl;
@@ -106,21 +105,27 @@ public class JSONRestconfServiceImplTest {
     static final QName TEST_OUTPUT_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "testOutput");
     static final QName TEXT_OUT_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "textOut");
 
-    private static BrokerFacade brokerFacade;
+    private static SchemaContext schemaContext;
 
-    private final JSONRestconfServiceImpl service = new JSONRestconfServiceImpl();
+    private final BrokerFacade brokerFacade = mock(BrokerFacade.class);
+    private final DOMMountPoint mockMountPoint = mock(DOMMountPoint.class);
+    private JSONRestconfServiceImpl service;
 
     @BeforeClass
     public static void init() throws IOException, ReactorException {
-        ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext("/full-versions/yangs"));
-        brokerFacade = mock(BrokerFacade.class);
-        RestconfImpl.getInstance().setBroker(brokerFacade);
-        RestconfImpl.getInstance().setControllerContext(ControllerContext.getInstance());
+        schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
     }
 
     @Before
-    public void setup() {
-        reset(brokerFacade);
+    public void setup() throws FileNotFoundException {
+        final SchemaContext mountPointSchemaContext = TestUtils.loadSchemaContext("/full-versions/test-module");
+        final ControllerContext controllerContext =
+                TestRestconfUtils.newControllerContext(schemaContext, mockMountPoint);
+        doReturn(mountPointSchemaContext).when(mockMountPoint).getSchemaContext();
+
+        service = new JSONRestconfServiceImpl(controllerContext);
+        RestconfImpl.getInstance().setBroker(brokerFacade);
+        RestconfImpl.getInstance().setControllerContext(controllerContext);
     }
 
     private static String loadData(final String path) throws IOException {
@@ -164,7 +169,6 @@ public class JSONRestconfServiceImplTest {
     @SuppressWarnings("rawtypes")
     @Test
     public void testPutBehindMountPoint() throws Exception {
-        final DOMMountPoint mockMountPoint = setupTestMountPoint();
         final PutResult result = mock(PutResult.class);
         when(brokerFacade.commitMountPointDataPut(notNull(DOMMountPoint.class),
                 notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), Mockito.anyString(),
@@ -253,7 +257,6 @@ public class JSONRestconfServiceImplTest {
     @SuppressWarnings("rawtypes")
     @Test
     public void testPostBehindMountPoint() throws Exception {
-        final DOMMountPoint mockMountPoint = setupTestMountPoint();
         doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
                 notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class),
                 Mockito.anyString(), Mockito.anyString());
@@ -323,7 +326,6 @@ public class JSONRestconfServiceImplTest {
     @SuppressWarnings("rawtypes")
     @Test
     public void testPatchBehindMountPoint() throws Exception {
-        final DOMMountPoint mockMountPoint = setupTestMountPoint();
         final PatchStatusContext result = mock(PatchStatusContext.class);
         when(brokerFacade.patchConfigurationDataWithinTransaction(notNull(PatchContext.class)))
             .thenReturn(result);
@@ -527,19 +529,6 @@ public class JSONRestconfServiceImplTest {
                 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
     }
 
-    DOMMountPoint setupTestMountPoint() throws FileNotFoundException, ReactorException {
-        final SchemaContext schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module");
-        final DOMMountPoint mockMountPoint = mock(DOMMountPoint.class);
-        doReturn(schemaContextTestModule).when(mockMountPoint).getSchemaContext();
-
-        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
-        doReturn(Optional.of(mockMountPoint))
-                .when(mockMountService).getMountPoint(notNull(YangInstanceIdentifier.class));
-
-        ControllerContext.getInstance().setMountService(mockMountService);
-        return mockMountPoint;
-    }
-
     void verifyLeafNode(final DataContainerNode<?> parent, final QName leafType, final Object leafValue) {
         final java.util.Optional<DataContainerChild<?, ?>> leafChild = parent.getChild(new NodeIdentifier(leafType));
         assertEquals(leafType.toString() + " present", true, leafChild.isPresent());
index 7b3f3f716c1d0675183729cc9d8574cf26e4ecfd..51b7ce05214ed65c64d5016f19fd043cad432703 100644 (file)
@@ -31,22 +31,19 @@ import org.junit.Test;
 import org.mockito.Mockito;
 import org.opendaylight.netconf.sal.rest.api.Draft02;
 import org.opendaylight.netconf.sal.rest.api.RestconfService;
-import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
-import org.opendaylight.netconf.sal.rest.impl.RestconfDocumentedExceptionMapper;
-import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 
 public class MediaTypesTest extends JerseyTest {
 
-    private static RestconfService restconfService;
     private static String jsonData;
     private static String xmlData;
 
+    private RestconfService restconfService;
+
     @BeforeClass
     public static void init() throws IOException {
-        restconfService = mock(RestconfService.class);
         final String jsonPath = RestconfImplTest.class.getResource("/parts/ietf-interfaces_interfaces.json").getPath();
         jsonData = TestUtils.loadTextFile(jsonPath);
         final InputStream xmlStream =
@@ -60,11 +57,11 @@ public class MediaTypesTest extends JerseyTest {
         // enable(TestProperties.LOG_TRAFFIC);
         // enable(TestProperties.DUMP_ENTITY);
         // enable(TestProperties.RECORD_LOG_LEVEL);
-        // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
+        // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());'
+        restconfService = mock(RestconfService.class);
         ResourceConfig resourceConfig = new ResourceConfig();
         resourceConfig = resourceConfig.registerInstances(restconfService,  new NormalizedNodeJsonBodyWriter(),
-            new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(), new JsonNormalizedNodeBodyReader());
-        resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
+            new NormalizedNodeXmlBodyWriter());
         return resourceConfig;
     }
 
@@ -249,12 +246,12 @@ public class MediaTypesTest extends JerseyTest {
     private int post(final String uri, final String acceptMediaType, final String contentTypeMediaType,
                      final String data) {
         if (acceptMediaType == null) {
-            if ((contentTypeMediaType == null) || (data == null)) {
+            if (contentTypeMediaType == null || data == null) {
                 return target(uri).request().post(null).getStatus();
             }
             return target(uri).request().post(Entity.entity(data, contentTypeMediaType)).getStatus();
         }
-        if ((contentTypeMediaType == null) || (data == null)) {
+        if (contentTypeMediaType == null || data == null) {
             return target(uri).request(acceptMediaType).post(null).getStatus();
         }
         return target(uri).request(acceptMediaType).post(Entity.entity(data, contentTypeMediaType)).getStatus();
index b14ec16560ebfa8695f7683e53d47f3eddddb82d..c91a61badb54c3539c7e9c24f9d70b21b9fa67f2 100644 (file)
@@ -25,7 +25,7 @@ public class RestCodecExceptionsTest {
 
     @Test
     public void serializeExceptionTest() {
-        final Codec<Object, Object> codec = RestCodec.from(BaseTypes.bitsTypeBuilder(PATH).build(), null);
+        final Codec<Object, Object> codec = RestCodec.from(BaseTypes.bitsTypeBuilder(PATH).build(), null, null);
         final String serializedValue = (String) codec.serialize("incorrect value"); // set
                                                                               // expected
         assertEquals("incorrect value", serializedValue);
@@ -35,7 +35,7 @@ public class RestCodecExceptionsTest {
     public void deserializeExceptionTest() {
         final IdentityrefTypeDefinition mockedIidentityrefType = mock(IdentityrefTypeDefinition.class);
 
-        final Codec<Object, Object> codec = RestCodec.from(mockedIidentityrefType, null);
+        final Codec<Object, Object> codec = RestCodec.from(mockedIidentityrefType, null, null);
         assertNull(codec.deserialize("incorrect value"));
     }
 
index aabc469499a08d18d6f0847bab8193d0e643242d..72da87bacfde684a4bdb8c2fa5f981d7fae9efe3 100644 (file)
@@ -27,6 +27,7 @@ import org.glassfish.jersey.test.JerseyTest;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
@@ -42,23 +43,17 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
 public class RestDeleteOperationTest extends JerseyTest {
+    private static SchemaContext schemaContext;
 
-    private static ControllerContext controllerContext;
-    private static BrokerFacade brokerFacade;
-    private static RestconfImpl restconfImpl;
+    private ControllerContext controllerContext;
+    private BrokerFacade brokerFacade;
+    private RestconfImpl restconfImpl;
 
     @BeforeClass
     public static void init() throws FileNotFoundException, ReactorException {
-        final SchemaContext schemaContext = TestUtils.loadSchemaContext("/test-config-data/yang1");
+        schemaContext = TestUtils.loadSchemaContext("/test-config-data/yang1");
         final Set<Module> allModules = schemaContext.getModules();
         assertNotNull(allModules);
-
-        controllerContext = ControllerContext.getInstance();
-        controllerContext.setSchemas(schemaContext);
-        brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
     }
 
     @Override
@@ -68,10 +63,18 @@ public class RestDeleteOperationTest extends JerseyTest {
         // enable(TestProperties.DUMP_ENTITY);
         // enable(TestProperties.RECORD_LOG_LEVEL);
         // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
+        controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
+        controllerContext.setSchemas(schemaContext);
+        brokerFacade = mock(BrokerFacade.class);
+        restconfImpl = RestconfImpl.getInstance();
+        restconfImpl.setBroker(brokerFacade);
+        restconfImpl.setControllerContext(controllerContext);
+
         ResourceConfig resourceConfig = new ResourceConfig();
         resourceConfig = resourceConfig.registerInstances(restconfImpl, new NormalizedNodeJsonBodyWriter(),
-            new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(), new JsonNormalizedNodeBodyReader());
-        resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
+            new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(controllerContext),
+            new JsonNormalizedNodeBodyReader(controllerContext),
+            new RestconfDocumentedExceptionMapper(controllerContext));
         return resourceConfig;
     }
 
index bf1841c97736a6ec9bccc935dc95b94e9b94f8d2..e9488c18115fbf30ffa067cc3e5307e553b452e3 100644 (file)
@@ -16,23 +16,24 @@ import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
 public class RestGetAugmentedElementWhenEqualNamesTest {
 
-    private static ControllerContext controllerContext = ControllerContext.getInstance();
+    private static SchemaContext schemaContext;
+
+    private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
 
     @Rule
     public ExpectedException exception = ExpectedException.none();
 
     @BeforeClass
-    public static void init() throws FileNotFoundException, ReactorException {
-        final SchemaContext schemaContextTestModule = TestUtils.loadSchemaContext("/common/augment/yang");
-        controllerContext.setSchemas(schemaContextTestModule);
+    public static void init() throws FileNotFoundException {
+        schemaContext = TestUtils.loadSchemaContext("/common/augment/yang");
     }
 
     @Test
index 051ca9e7da976616a10418fda25dd7327a15a565..ebe05da1b141c7e5c5bf10fe5bf325d143f159bf 100644 (file)
@@ -19,7 +19,6 @@ import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 import java.net.URI;
@@ -43,11 +42,10 @@ import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
-import org.opendaylight.netconf.sal.rest.impl.RestconfApplication;
 import org.opendaylight.netconf.sal.rest.impl.RestconfDocumentedExceptionMapper;
 import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
@@ -86,15 +84,18 @@ public class RestGetOperationTest extends JerseyTest {
         }
     }
 
-    private static BrokerFacade brokerFacade;
-    private static RestconfImpl restconfImpl;
     private static SchemaContext schemaContextYangsIetf;
     private static SchemaContext schemaContextTestModule;
+    private static SchemaContext schemaContextModules;
+    private static SchemaContext schemaContextBehindMountPoint;
+
     @SuppressWarnings("rawtypes")
     private static NormalizedNode answerFromGet;
 
-    private static SchemaContext schemaContextModules;
-    private static SchemaContext schemaContextBehindMountPoint;
+    private BrokerFacade brokerFacade;
+    private RestconfImpl restconfImpl;
+    private ControllerContext controllerContext;
+    private DOMMountPoint mountInstance;
 
     private static final String RESTCONF_NS = "urn:ietf:params:xml:ns:yang:ietf-restconf";
 
@@ -102,13 +103,10 @@ public class RestGetOperationTest extends JerseyTest {
     public static void init() throws Exception {
         schemaContextYangsIetf = TestUtils.loadSchemaContext("/full-versions/yangs");
         schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module");
-        brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        answerFromGet = TestUtils.prepareNormalizedNodeWithIetfInterfacesInterfacesData();
-
         schemaContextModules = TestUtils.loadSchemaContext("/modules");
         schemaContextBehindMountPoint = TestUtils.loadSchemaContext("/modules/modules-behind-mount-point");
+
+        answerFromGet = TestUtils.prepareNormalizedNodeWithIetfInterfacesInterfacesData();
     }
 
     @Override
@@ -118,18 +116,24 @@ public class RestGetOperationTest extends JerseyTest {
         // enable(TestProperties.DUMP_ENTITY);
         // enable(TestProperties.RECORD_LOG_LEVEL);
         // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
+
+        mountInstance = mock(DOMMountPoint.class);
+        controllerContext = TestRestconfUtils.newControllerContext(schemaContextYangsIetf, mountInstance);
+        brokerFacade = mock(BrokerFacade.class);
+        restconfImpl = RestconfImpl.getInstance();
+        restconfImpl.setBroker(brokerFacade);
+        restconfImpl.setControllerContext(controllerContext);
+
         ResourceConfig resourceConfig = new ResourceConfig();
         resourceConfig = resourceConfig.registerInstances(restconfImpl, new NormalizedNodeJsonBodyWriter(),
-            new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(), new JsonNormalizedNodeBodyReader());
-        resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
-        resourceConfig.registerClasses(new RestconfApplication().getClasses());
+            new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(controllerContext),
+            new JsonNormalizedNodeBodyReader(controllerContext),
+            new RestconfDocumentedExceptionMapper(controllerContext));
         return resourceConfig;
     }
 
-    private static void setControllerContext(final SchemaContext schemaContext) {
-        final ControllerContext controllerContext = ControllerContext.getInstance();
+    private void setControllerContext(final SchemaContext schemaContext) {
         controllerContext.setSchemas(schemaContext);
-        restconfImpl.setControllerContext(controllerContext);
     }
 
     /**
@@ -169,12 +173,7 @@ public class RestGetOperationTest extends JerseyTest {
         when(brokerFacade.readConfigurationData(any(DOMMountPoint.class), any(YangInstanceIdentifier.class),
                 Mockito.anyString())).thenReturn(
                 prepareCnDataForMountPointTest(false));
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
         when(mountInstance.getSchemaContext()).thenReturn(schemaContextTestModule);
-        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
-        when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
-
-        ControllerContext.getInstance().setMountService(mockMountService);
 
         String uri = "/config/ietf-interfaces:interfaces/interface/0/yang-ext:mount/test-module:cont/cont1";
         assertEquals(200, get(uri, MediaType.APPLICATION_XML));
@@ -196,12 +195,8 @@ public class RestGetOperationTest extends JerseyTest {
         final YangInstanceIdentifier awaitedInstanceIdentifier = prepareInstanceIdentifierForList();
         when(brokerFacade.readConfigurationData(any(DOMMountPoint.class), eq(awaitedInstanceIdentifier),
                 Mockito.anyString())).thenReturn(prepareCnDataForSlashesBehindMountPointTest());
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
-        when(mountInstance.getSchemaContext()).thenReturn(schemaContextTestModule);
-        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
-        when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
 
-        ControllerContext.getInstance().setMountService(mockMountService);
+        when(mountInstance.getSchemaContext()).thenReturn(schemaContextTestModule);
 
         final String uri = "/config/ietf-interfaces:interfaces/interface/0/yang-ext:mount/"
                 + "test-module:cont/lst1/GigabitEthernet0%2F0%2F0%2F0";
@@ -231,12 +226,8 @@ public class RestGetOperationTest extends JerseyTest {
         when(brokerFacade.readConfigurationData(any(DOMMountPoint.class), any(YangInstanceIdentifier.class),
                 Mockito.anyString())).thenReturn(
                 prepareCnDataForMountPointTest(true));
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
-        when(mountInstance.getSchemaContext()).thenReturn(schemaContextTestModule);
-        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
-        when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
 
-        ControllerContext.getInstance().setMountService(mockMountService);
+        when(mountInstance.getSchemaContext()).thenReturn(schemaContextTestModule);
 
         final String uri = "/config/ietf-interfaces:interfaces/interface/0/yang-ext:mount/test-module:cont";
         assertEquals(200, get(uri, MediaType.APPLICATION_XML));
@@ -269,9 +260,7 @@ public class RestGetOperationTest extends JerseyTest {
     // /modules
     @Test
     public void getModulesTest() throws Exception {
-        final ControllerContext controllerContext = ControllerContext.getInstance();
-        controllerContext.setGlobalSchema(schemaContextModules);
-        restconfImpl.setControllerContext(controllerContext);
+        setControllerContext(schemaContextModules);
 
         final String uri = "/modules";
 
@@ -379,43 +368,13 @@ public class RestGetOperationTest extends JerseyTest {
         }
     }
 
-    private static Matcher validateOperationsResponseXml(final String searchIn, final String rpcName,
-                                                         final String namespace) {
-        final StringBuilder regex = new StringBuilder();
-
-        regex.append("^");
-
-        regex.append(".*<operations");
-        regex.append(".*xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\"");
-        regex.append(".*>");
-
-        regex.append(".*<");
-        regex.append(".*" + rpcName);
-        regex.append(".*" + namespace);
-        regex.append(".*/");
-        regex.append(".*>");
-
-        regex.append(".*</operations.*");
-        regex.append(".*>");
-
-        regex.append(".*");
-        regex.append("$");
-        final Pattern ptrn = Pattern.compile(regex.toString(), Pattern.DOTALL);
-        return ptrn.matcher(searchIn);
-    }
-
     // /operations/pathToMountPoint/yang-ext:mount
     @Ignore
     @Test
     public void getOperationsBehindMountPointTest() throws Exception {
         setControllerContext(schemaContextModules);
 
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
         when(mountInstance.getSchemaContext()).thenReturn(schemaContextBehindMountPoint);
-        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
-        when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
-
-        ControllerContext.getInstance().setMountService(mockMountService);
 
         final String uri = "/operations/ietf-interfaces:interfaces/interface/0/yang-ext:mount/";
 
@@ -449,12 +408,7 @@ public class RestGetOperationTest extends JerseyTest {
     public void getModulesBehindMountPoint() throws Exception {
         setControllerContext(schemaContextModules);
 
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
         when(mountInstance.getSchemaContext()).thenReturn(schemaContextBehindMountPoint);
-        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
-        when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
-
-        ControllerContext.getInstance().setMountService(mockMountService);
 
         final String uri = "/modules/ietf-interfaces:interfaces/interface/0/yang-ext:mount/";
 
@@ -482,12 +436,7 @@ public class RestGetOperationTest extends JerseyTest {
     public void getModuleBehindMountPoint() throws Exception {
         setControllerContext(schemaContextModules);
 
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
         when(mountInstance.getSchemaContext()).thenReturn(schemaContextBehindMountPoint);
-        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
-        when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
-
-        ControllerContext.getInstance().setMountService(mockMountService);
 
         final String uri = "/modules/module/ietf-interfaces:interfaces/interface/0/yang-ext:mount/"
                 + "module1-behind-mount-point/2014-02-03";
@@ -657,12 +606,12 @@ public class RestGetOperationTest extends JerseyTest {
     }
 
     @SuppressWarnings("unchecked")
-    private static void mockReadOperationalDataMethod() {
+    private void mockReadOperationalDataMethod() {
         when(brokerFacade.readOperationalData(any(YangInstanceIdentifier.class))).thenReturn(answerFromGet);
     }
 
     @SuppressWarnings("unchecked")
-    private static void mockReadConfigurationDataMethod() {
+    private void mockReadConfigurationDataMethod() {
         when(brokerFacade.readConfigurationData(any(YangInstanceIdentifier.class), Mockito.anyString()))
                 .thenReturn(answerFromGet);
     }
@@ -735,7 +684,7 @@ public class RestGetOperationTest extends JerseyTest {
     }
 
     @SuppressWarnings({"rawtypes", "unchecked"})
-    private static void getDataWithInvalidDepthParameterTest(final UriInfo uriInfo) {
+    private void getDataWithInvalidDepthParameterTest(final UriInfo uriInfo) {
         try {
             final QName qNameDepth1Cont = QName.create("urn:nested:module", "2014-06-3", "depth1-cont");
             final YangInstanceIdentifier ii = YangInstanceIdentifier.builder().node(qNameDepth1Cont).build();
index 910bd7e1be859fabcd9847bed65f7698f453a9d7..0f5ef01fc9a85fd2f24774bfeacf9ed23024885c 100644 (file)
@@ -15,16 +15,13 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.XML;
 
-import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URISyntaxException;
 import java.text.ParseException;
-import java.util.Set;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MediaType;
@@ -37,7 +34,7 @@ import org.mockito.ArgumentCaptor;
 import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.api.Draft02;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
@@ -49,39 +46,29 @@ import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
 public class RestPostOperationTest extends JerseyTest {
 
-    private static String xmlDataAbsolutePath;
-    private static String xmlDataInterfaceAbsolutePath;
-    private static String xmlDataRpcInput;
     private static String xmlBlockData;
-    private static String xmlTestInterface;
     private static String xmlData3;
     private static String xmlData4;
 
-    private static BrokerFacade brokerFacade;
-    private static RestconfImpl restconfImpl;
     private static SchemaContext schemaContextYangsIetf;
     private static SchemaContext schemaContextTestModule;
     private static SchemaContext schemaContext;
 
-    private static DOMMountPointService mountService;
+    private BrokerFacade brokerFacade;
+    private RestconfImpl restconfImpl;
+    private ControllerContext controllerContext;
+    private DOMMountPoint mountInstance;
 
     @BeforeClass
     public static void init() throws URISyntaxException, IOException, ReactorException {
         schemaContextYangsIetf = TestUtils.loadSchemaContext("/full-versions/yangs");
         schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module");
-        brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-
         schemaContext = TestUtils.loadSchemaContext("/test-config-data/yang1");
-        final Set<Module> modules = schemaContext.getModules();
-
         loadData();
     }
 
@@ -92,17 +79,24 @@ public class RestPostOperationTest extends JerseyTest {
         // enable(TestProperties.DUMP_ENTITY);
         // enable(TestProperties.RECORD_LOG_LEVEL);
         // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
+
+        mountInstance = mock(DOMMountPoint.class);
+        controllerContext = TestRestconfUtils.newControllerContext(schemaContext, mountInstance);
+        brokerFacade = mock(BrokerFacade.class);
+        restconfImpl = RestconfImpl.getInstance();
+        restconfImpl.setBroker(brokerFacade);
+        restconfImpl.setControllerContext(controllerContext);
+
         ResourceConfig resourceConfig = new ResourceConfig();
-        resourceConfig = resourceConfig.registerInstances(restconfImpl, new XmlNormalizedNodeBodyReader(),
-            new NormalizedNodeXmlBodyWriter(), new JsonNormalizedNodeBodyReader(), new NormalizedNodeJsonBodyWriter());
-        resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
+        resourceConfig = resourceConfig.registerInstances(restconfImpl,
+                new XmlNormalizedNodeBodyReader(controllerContext), new NormalizedNodeXmlBodyWriter(),
+                new JsonNormalizedNodeBodyReader(controllerContext), new NormalizedNodeJsonBodyWriter(),
+                new RestconfDocumentedExceptionMapper(controllerContext));
         return resourceConfig;
     }
 
-    private static void setSchemaControllerContext(final SchemaContext schema) {
-        final ControllerContext context = ControllerContext.getInstance();
-        context.setSchemas(schema);
-        restconfImpl.setControllerContext(context);
+    private void setSchemaControllerContext(final SchemaContext schema) {
+        controllerContext.setSchemas(schema);
     }
 
     @SuppressWarnings("unchecked")
@@ -110,16 +104,10 @@ public class RestPostOperationTest extends JerseyTest {
     @Ignore /// xmlData* need netconf-yang
     public void postDataViaUrlMountPoint() throws UnsupportedEncodingException {
         setSchemaControllerContext(schemaContextYangsIetf);
-        when(
-                brokerFacade.commitConfigurationDataPost(any(DOMMountPoint.class), any(YangInstanceIdentifier.class),
-                        any(NormalizedNode.class), null, null)).thenReturn(mock(CheckedFuture.class));
+        when(brokerFacade.commitConfigurationDataPost(any(DOMMountPoint.class), any(YangInstanceIdentifier.class),
+                any(NormalizedNode.class), null, null)).thenReturn(mock(CheckedFuture.class));
 
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
         when(mountInstance.getSchemaContext()).thenReturn(schemaContextTestModule);
-        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
-        when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
-
-        ControllerContext.getInstance().setMountService(mockMountService);
 
         String uri = "/config/ietf-interfaces:interfaces/interface/0/";
         assertEquals(204, post(uri, Draft02.MediaTypes.DATA + XML, xmlData4));
@@ -134,7 +122,6 @@ public class RestPostOperationTest extends JerseyTest {
     @Ignore //jenkins has problem with JerseyTest
     // - we expecting problems with singletons ControllerContext as schemaContext holder
     public void createConfigurationDataTest() throws UnsupportedEncodingException, ParseException {
-        initMocking();
         when(brokerFacade.commitConfigurationDataPost((SchemaContext) null, any(YangInstanceIdentifier.class),
                 any(NormalizedNode.class), null, null))
                 .thenReturn(mock(CheckedFuture.class));
@@ -166,8 +153,6 @@ public class RestPostOperationTest extends JerseyTest {
 
     @Test
     public void createConfigurationDataNullTest() throws UnsupportedEncodingException {
-        initMocking();
-
         when(brokerFacade.commitConfigurationDataPost(any(SchemaContext.class), any(YangInstanceIdentifier.class),
                 any(NormalizedNode.class), Mockito.anyString(), Mockito.anyString()))
                 .thenReturn(Futures.<Void, TransactionCommitFailedException>immediateCheckedFuture(null));
@@ -180,38 +165,14 @@ public class RestPostOperationTest extends JerseyTest {
         assertEquals(204, post(URI_2, Draft02.MediaTypes.DATA + XML, xmlBlockData));
     }
 
-    private static void initMocking() {
-        final ControllerContext controllerContext = ControllerContext.getInstance();
-        controllerContext.setSchemas(schemaContext);
-        mountService = mock(DOMMountPointService.class);
-        controllerContext.setMountService(mountService);
-        brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
-    }
-
     private int post(final String uri, final String mediaType, final String data) {
         return target(uri).request(mediaType).post(Entity.entity(data, mediaType)).getStatus();
     }
 
     private static void loadData() throws IOException, URISyntaxException {
-        InputStream xmlStream = RestconfImplTest.class
-                .getResourceAsStream("/parts/ietf-interfaces_interfaces_absolute_path.xml");
-        xmlDataAbsolutePath = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream));
-        xmlStream = RestconfImplTest.class
-                .getResourceAsStream("/parts/ietf-interfaces_interfaces_interface_absolute_path.xml");
-        xmlDataInterfaceAbsolutePath = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream));
-        final String xmlPathRpcInput =
-                RestconfImplTest.class.getResource("/full-versions/test-data2/data-rpc-input.xml").getPath();
-        xmlDataRpcInput = TestUtils.loadTextFile(xmlPathRpcInput);
         final String xmlPathBlockData =
                 RestconfImplTest.class.getResource("/test-config-data/xml/block-data.xml").getPath();
         xmlBlockData = TestUtils.loadTextFile(xmlPathBlockData);
-        final String xmlPathTestInterface =
-                RestconfImplTest.class.getResource("/test-config-data/xml/test-interface.xml").getPath();
-        xmlTestInterface = TestUtils.loadTextFile(xmlPathTestInterface);
-//        cnSnDataOutput = prepareCnSnRpcOutput();
         final String data3Input = RestconfImplTest.class.getResource("/full-versions/test-data2/data3.xml").getPath();
         xmlData3 = TestUtils.loadTextFile(data3Input);
         final String data4Input = RestconfImplTest.class.getResource("/full-versions/test-data2/data7.xml").getPath();
index 958111767456a32290ee92d1a7b1f9217991d65e..043f78b807ef931459cf82642c4a18db82d599e2 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;
@@ -39,19 +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.controllerCx = TestRestconfUtils.newControllerContext(schemaContext);
         this.restconfService.setControllerContext(this.controllerCx);
     }
 
@@ -131,7 +136,7 @@ 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);
index 3400474c304e9f0a7ec7426fab1d8b3965938a1d..981c9d29f5b030f5d546bfa7455fc0ebaa835b96 100644 (file)
@@ -14,7 +14,6 @@ import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import java.io.FileNotFoundException;
@@ -35,7 +34,7 @@ import org.junit.Test;
 import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
@@ -59,21 +58,17 @@ public class RestPutOperationTest extends JerseyTest {
     private static String xmlData2;
     private static String xmlData3;
 
-    private static BrokerFacade brokerFacade;
-    private static RestconfImpl restconfImpl;
     private static SchemaContext schemaContextYangsIetf;
     private static SchemaContext schemaContextTestModule;
 
+    private BrokerFacade brokerFacade;
+    private RestconfImpl restconfImpl;
+    private DOMMountPoint mountInstance;
+
     @BeforeClass
     public static void init() throws IOException, ReactorException {
         schemaContextYangsIetf = TestUtils.loadSchemaContext("/full-versions/yangs");
         schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module");
-        final ControllerContext controllerContext = ControllerContext.getInstance();
-        controllerContext.setSchemas(schemaContextYangsIetf);
-        brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
         loadData();
     }
 
@@ -96,10 +91,20 @@ public class RestPutOperationTest extends JerseyTest {
         // enable(TestProperties.DUMP_ENTITY);
         // enable(TestProperties.RECORD_LOG_LEVEL);
         // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
+
+        mountInstance = mock(DOMMountPoint.class);
+        final ControllerContext controllerContext =
+                TestRestconfUtils.newControllerContext(schemaContextYangsIetf, mountInstance);
+        brokerFacade = mock(BrokerFacade.class);
+        restconfImpl = RestconfImpl.getInstance();
+        restconfImpl.setBroker(brokerFacade);
+        restconfImpl.setControllerContext(controllerContext);
+
         ResourceConfig resourceConfig = new ResourceConfig();
-        resourceConfig = resourceConfig.registerInstances(restconfImpl,new XmlNormalizedNodeBodyReader(),
-            new NormalizedNodeXmlBodyWriter(), new JsonNormalizedNodeBodyReader(), new NormalizedNodeJsonBodyWriter());
-        resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
+        resourceConfig = resourceConfig.registerInstances(restconfImpl,
+                new XmlNormalizedNodeBodyReader(controllerContext), new NormalizedNodeXmlBodyWriter(),
+                new JsonNormalizedNodeBodyReader(controllerContext), new NormalizedNodeJsonBodyWriter(),
+                new RestconfDocumentedExceptionMapper(controllerContext));
         return resourceConfig;
     }
 
@@ -138,12 +143,7 @@ public class RestPutOperationTest extends JerseyTest {
         when(result.getFutureOfPutData()).thenReturn(dummyFuture);
         when(result.getStatus()).thenReturn(Status.OK);
 
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
         when(mountInstance.getSchemaContext()).thenReturn(schemaContextTestModule);
-        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
-        when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
-
-        ControllerContext.getInstance().setMountService(mockMountService);
 
         String uri = "/config/ietf-interfaces:interfaces/interface/0/yang-ext:mount/test-module:cont";
         assertEquals(200, put(uri, MediaType.APPLICATION_XML, xmlData2));
@@ -161,12 +161,7 @@ public class RestPutOperationTest extends JerseyTest {
         when(result.getFutureOfPutData()).thenReturn(dummyFuture);
         when(result.getStatus()).thenReturn(Status.OK);
 
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
         when(mountInstance.getSchemaContext()).thenReturn(schemaContextTestModule);
-        final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
-        when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
-
-        ControllerContext.getInstance().setMountService(mockMountService);
 
         final String uri = "/config/ietf-interfaces:interfaces/yang-ext:mount";
         assertEquals(200, put(uri, MediaType.APPLICATION_XML, xmlData3));
@@ -205,7 +200,7 @@ public class RestPutOperationTest extends JerseyTest {
         return target(uri).request(mediaType).put(Entity.entity(data, mediaType)).getStatus();
     }
 
-    private static void mockCommitConfigurationDataPutMethod(final boolean noErrors) {
+    private void mockCommitConfigurationDataPutMethod(final boolean noErrors) {
         final PutResult putResMock = mock(PutResult.class);
         if (noErrors) {
             doReturn(putResMock).when(brokerFacade).commitConfigurationDataPut(
index 07effb57720092230e4ce7711c8c1b2ff7927b24..d00d382221623626ebaad06f9e7b522107541d4b 100644 (file)
@@ -53,6 +53,7 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.api.Draft02;
 import org.opendaylight.netconf.sal.rest.api.RestconfService;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
@@ -67,6 +68,7 @@ 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.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -122,9 +124,11 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
     static XPathExpression ERROR_APP_TAG;
     static XPathExpression ERROR_INFO;
 
+    private static SchemaContext schemaContext;
+
     @BeforeClass
     public static void init() throws Exception {
-        ControllerContext.getInstance().setGlobalSchema(TestUtils.loadSchemaContext("/modules"));
+        schemaContext = TestUtils.loadSchemaContext("/modules");
 
         final NamespaceContext nsContext = new NamespaceContext() {
             @Override
@@ -162,9 +166,11 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
     @Override
     protected Application configure() {
         ResourceConfig resourceConfig = new ResourceConfig();
-        resourceConfig = resourceConfig.registerInstances(mockRestConf, new XmlNormalizedNodeBodyReader(),
-            new JsonNormalizedNodeBodyReader(), new NormalizedNodeJsonBodyWriter(), new NormalizedNodeXmlBodyWriter());
-        resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
+        ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
+        resourceConfig = resourceConfig.registerInstances(mockRestConf,
+                new XmlNormalizedNodeBodyReader(controllerContext), new JsonNormalizedNodeBodyReader(controllerContext),
+                new NormalizedNodeJsonBodyWriter(), new NormalizedNodeXmlBodyWriter(),
+                new RestconfDocumentedExceptionMapper(controllerContext));
         return resourceConfig;
     }
 
index 945eb6b211c607855676d55db30db8e92df27d30..6e644b9ca145d4815351d94b669ef5ac1e7534cf 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.sal.restconf.impl.test;
 
+import java.io.FileNotFoundException;
 import java.time.Instant;
 import java.util.AbstractMap.SimpleImmutableEntry;
 import java.util.ArrayList;
@@ -19,6 +20,7 @@ import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
@@ -37,12 +39,15 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class RestconfImplNotificationSubscribingTest {
 
     private final String identifier = "data-change-event-subscription/datastore=OPERATIONAL/scope=ONE";
 
+    private static SchemaContext schemaContext;
+
     @Mock
     private BrokerFacade broker;
 
@@ -52,19 +57,27 @@ public class RestconfImplNotificationSubscribingTest {
     @Mock
     private UriInfo uriInfo;
 
+    private ControllerContext controllerContext;
+
+    @BeforeClass
+    public static void init() throws FileNotFoundException {
+        schemaContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/notifications"));
+    }
+
     @Before
     public void setup() throws Exception {
         MockitoAnnotations.initMocks(this);
 
         this.broker.setDomDataBroker(this.domDataBroker);
         RestconfImpl.getInstance().setBroker(this.broker);
-        ControllerContext.getInstance()
-                .setGlobalSchema(YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/notifications")));
+
+        controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
+        RestconfImpl.getInstance().setControllerContext(controllerContext);
 
         final YangInstanceIdentifier path = Mockito.mock(YangInstanceIdentifier.class);
         final PathArgument pathValue = NodeIdentifier.create(QName.create("module", "2016-12-14", "localName"));
         Mockito.when(path.getLastPathArgument()).thenReturn(pathValue);
-        Notificator.createListener(path, this.identifier, NotificationOutputType.XML);
+        Notificator.createListener(path, this.identifier, NotificationOutputType.XML, controllerContext);
     }
 
     @Test
@@ -198,7 +211,8 @@ public class RestconfImplNotificationSubscribingTest {
         final YangInstanceIdentifier path = Mockito.mock(YangInstanceIdentifier.class);
         final PathArgument pathValue = NodeIdentifier.create(QName.create("module", "2016-12-14", "localName"));
         Mockito.when(path.getLastPathArgument()).thenReturn(pathValue);
-        final ListenerAdapter listener = Notificator.createListener(path, this.identifier, NotificationOutputType.XML);
+        final ListenerAdapter listener = Notificator.createListener(path, this.identifier, NotificationOutputType.XML,
+                controllerContext);
 
         final List<Entry<String, List<String>>> list = new ArrayList<>();
         final List<String> time = new ArrayList<>();
@@ -208,7 +222,7 @@ public class RestconfImplNotificationSubscribingTest {
 
         subscribe(list);
 
-        ArrayList<DataTreeCandidate> candidates = new ArrayList<DataTreeCandidate>(0);
+        ArrayList<DataTreeCandidate> candidates = new ArrayList<>(0);
         Instant startOrig = listener.getStart();
         Assert.assertNotNull(startOrig);
         listener.onDataTreeChanged(candidates);
index 433684041f49d37173444d16b30c95d68e5f2231..26dc6587420325bfced3f3af1551e6cb8803118c 100644 (file)
@@ -42,6 +42,7 @@ import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
+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.RestconfImpl;
@@ -73,18 +74,16 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
  */
 public class RestconfImplTest {
 
-    private RestconfImpl restconfImpl = null;
-    private static ControllerContext controllerContext = null;
+    private static SchemaContext schemaContext;
+
+    private RestconfImpl restconfImpl;
+    private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
 
     @BeforeClass
     public static void init() throws FileNotFoundException, ReactorException {
-        final SchemaContext schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
-
+        schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
         final Set<Module> allModules = schemaContext.getModules();
         assertNotNull(allModules);
-
-        controllerContext = ControllerContext.getInstance();
-        controllerContext.setSchemas(schemaContext);
     }
 
     @Before
@@ -214,7 +213,7 @@ public class RestconfImplTest {
         // register test notification stream
         final SchemaPath path = SchemaPath.create(
                 true, QName.create("http://netconfcentral.org/ns/toaster", "2009-11-20", "toastDone"));
-        Notificator.createNotificationListener(Lists.newArrayList(path), identifier, "XML");
+        Notificator.createNotificationListener(Lists.newArrayList(path), identifier, "XML", controllerContext);
 
         final UriInfo uriInfo = mock(UriInfo.class);
         final UriBuilder uriBuilder = mock(UriBuilder.class);
index 10d7f75d17102ba1c21e2b52fa219eb0291527eb..f7fbd80bdca415ae8b73891817e478576756dcde 100644 (file)
@@ -24,6 +24,7 @@ import org.junit.Test;
 import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+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.RestconfImpl;
@@ -65,8 +66,8 @@ public class URIParametersParsing {
     public void init() throws FileNotFoundException, ReactorException {
         this.restconf = RestconfImpl.getInstance();
         this.mockedBrokerFacade = mock(BrokerFacade.class);
-        this.controllerContext = ControllerContext.getInstance();
-        this.controllerContext.setSchemas(TestUtils.loadSchemaContext("/datastore-and-scope-specification"));
+        this.controllerContext = TestRestconfUtils.newControllerContext(
+                TestUtils.loadSchemaContext("/datastore-and-scope-specification"));
         this.restconf.setControllerContext(this.controllerContext);
         this.restconf.setBroker(this.mockedBrokerFacade);
     }
@@ -90,7 +91,7 @@ public class URIParametersParsing {
         final String datastoreValue = datastore == null ? "CONFIGURATION" : datastore;
         final String scopeValue = scope == null ? "BASE" : scope + "";
         Notificator.createListener(iiBuilder.build(), "dummyStreamName/datastore=" + datastoreValue + "/scope="
-                + scopeValue, NotificationOutputType.XML);
+                + scopeValue, NotificationOutputType.XML, controllerContext);
 
         final UriInfo mockedUriInfo = mock(UriInfo.class);
         @SuppressWarnings("unchecked")
index e3999f63d79c231f6d2e3c993165124ef232390e..164a241565bf5c78144c863c4d219e3b0bfb658f 100644 (file)
@@ -8,64 +8,60 @@
 package org.opendaylight.controller.sal.restconf.impl.test;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import java.io.FileNotFoundException;
-import java.util.Set;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+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.RestconfImpl;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
 public class URITest {
 
-    private static final ControllerContext CONTROLLER_CONTEXT = ControllerContext.getInstance();
+    private static SchemaContext schemaContext;
+    private static SchemaContext mountSchemaContext;
+
+    private final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
+    private final ControllerContext controllerContext =
+            TestRestconfUtils.newControllerContext(schemaContext, mountInstance);
 
     @Rule
     public ExpectedException exception = ExpectedException.none();
 
     @BeforeClass
     public static void init() throws FileNotFoundException, ReactorException {
-        final SchemaContext schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
-        final Set<Module> allModules = schemaContext.getModules();
-        assertNotNull(allModules);
-
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+        schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
+        mountSchemaContext = TestUtils.loadSchemaContext("/test-config-data/yang2");
     }
 
     @Test
     public void testToInstanceIdentifierList() throws FileNotFoundException {
-        InstanceIdentifierContext<?> instanceIdentifier = CONTROLLER_CONTEXT
+        InstanceIdentifierContext<?> instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:userWithoutClass/foo");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "userWithoutClass");
 
-        instanceIdentifier = CONTROLLER_CONTEXT.toInstanceIdentifier("simple-nodes:userWithoutClass/foo");
+        instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:userWithoutClass/foo");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "userWithoutClass");
 
-        instanceIdentifier = CONTROLLER_CONTEXT.toInstanceIdentifier("simple-nodes:user/foo/boo");
+        instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:user/foo/boo");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "user");
 
-        instanceIdentifier = CONTROLLER_CONTEXT.toInstanceIdentifier("simple-nodes:user//boo");
+        instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:user//boo");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "user");
 
     }
@@ -73,19 +69,19 @@ public class URITest {
     @Test
     public void testToInstanceIdentifierListWithNullKey() {
         this.exception.expect(RestconfDocumentedException.class);
-        CONTROLLER_CONTEXT.toInstanceIdentifier("simple-nodes:user/null/boo");
+        controllerContext.toInstanceIdentifier("simple-nodes:user/null/boo");
     }
 
     @Test
     public void testToInstanceIdentifierListWithMissingKey() {
         this.exception.expect(RestconfDocumentedException.class);
-        CONTROLLER_CONTEXT.toInstanceIdentifier("simple-nodes:user/foo");
+        controllerContext.toInstanceIdentifier("simple-nodes:user/foo");
     }
 
     @Test
     public void testToInstanceIdentifierContainer() throws FileNotFoundException {
         final InstanceIdentifierContext<?> instanceIdentifier =
-                CONTROLLER_CONTEXT.toInstanceIdentifier("simple-nodes:users");
+                controllerContext.toInstanceIdentifier("simple-nodes:users");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "users");
         assertTrue(instanceIdentifier.getSchemaNode() instanceof ContainerSchemaNode);
         assertEquals(2, ((ContainerSchemaNode) instanceIdentifier.getSchemaNode()).getChildNodes().size());
@@ -95,7 +91,7 @@ public class URITest {
     @Ignore //jenkins has problem with JerseyTest
     // - we expecting problems with singletons ControllerContext as schemaContext holder
     public void testToInstanceIdentifierChoice() throws FileNotFoundException {
-        final InstanceIdentifierContext<?> instanceIdentifier = CONTROLLER_CONTEXT
+        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:food/nonalcoholic");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "nonalcoholic");
     }
@@ -103,31 +99,31 @@ public class URITest {
     @Test
     public void testToInstanceIdentifierChoiceException() {
         this.exception.expect(RestconfDocumentedException.class);
-        CONTROLLER_CONTEXT.toInstanceIdentifier("simple-nodes:food/snack");
+        controllerContext.toInstanceIdentifier("simple-nodes:food/snack");
     }
 
     @Test
     public void testToInstanceIdentifierCaseException() {
         this.exception.expect(RestconfDocumentedException.class);
-        CONTROLLER_CONTEXT.toInstanceIdentifier("simple-nodes:food/sports-arena");
+        controllerContext.toInstanceIdentifier("simple-nodes:food/sports-arena");
     }
 
     @Test
     public void testToInstanceIdentifierChoiceCaseException() {
         this.exception.expect(RestconfDocumentedException.class);
-        CONTROLLER_CONTEXT.toInstanceIdentifier("simple-nodes:food/snack/sports-arena");
+        controllerContext.toInstanceIdentifier("simple-nodes:food/snack/sports-arena");
     }
 
     @Test
     public void testToInstanceIdentifierWithoutNode() {
         this.exception.expect(RestconfDocumentedException.class);
-        CONTROLLER_CONTEXT.toInstanceIdentifier("simple-nodes");
+        controllerContext.toInstanceIdentifier("simple-nodes");
     }
 
     @Test
     public void testMountPointWithExternModul() throws FileNotFoundException, ReactorException {
         initMountService(true);
-        final InstanceIdentifierContext<?> instanceIdentifier = CONTROLLER_CONTEXT
+        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
         assertEquals(
                 "[(urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)class, "
@@ -140,43 +136,29 @@ public class URITest {
     @Test
     public void testMountPointWithoutExternModul() throws FileNotFoundException, ReactorException {
         initMountService(true);
-        final InstanceIdentifierContext<?> instanceIdentifier = CONTROLLER_CONTEXT
+        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/");
         assertTrue(Iterables.isEmpty(instanceIdentifier.getInstanceIdentifier().getPathArguments()));
     }
 
-    @Test
-    public void testMountPointWithoutMountService() throws FileNotFoundException {
-        this.exception.expect(RestconfDocumentedException.class);
-
-        CONTROLLER_CONTEXT.setMountService(null);
-        CONTROLLER_CONTEXT.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
-    }
-
     @Test
     public void testMountPointWithoutMountPointSchema() throws FileNotFoundException, ReactorException {
         initMountService(false);
         this.exception.expect(RestconfDocumentedException.class);
 
-        CONTROLLER_CONTEXT.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class");
+        controllerContext.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class");
     }
 
     public void initMountService(final boolean withSchema) throws FileNotFoundException, ReactorException {
-        final DOMMountPointService mountService = mock(DOMMountPointService.class);
-        CONTROLLER_CONTEXT.setMountService(mountService);
         final BrokerFacade brokerFacade = mock(BrokerFacade.class);
         final RestconfImpl restconfImpl = RestconfImpl.getInstance();
         restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(CONTROLLER_CONTEXT);
-        final SchemaContext schemaContext2 = TestUtils.loadSchemaContext("/test-config-data/yang2");
-        final Set<Module> modules2 = schemaContext2.getModules();
+        restconfImpl.setControllerContext(controllerContext);
 
-        final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
         if (withSchema) {
-            when(mountInstance.getSchemaContext()).thenReturn(schemaContext2);
+            when(mountInstance.getSchemaContext()).thenReturn(mountSchemaContext);
         } else {
             when(mountInstance.getSchemaContext()).thenReturn(null);
         }
-        when(mountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
     }
 }
index 11f76c8ea43ff3ad120657458fb3a5b42e535389..6400c3225892b57e194ca70f91c0963856ad8994 100644 (file)
@@ -24,6 +24,7 @@ import org.glassfish.jersey.test.JerseyTest;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
@@ -41,19 +42,14 @@ import org.w3c.dom.Node;
 
 public class RestStreamTest extends JerseyTest {
 
-    private static BrokerFacade brokerFacade;
-    private static RestconfImpl restconfImpl;
     private static SchemaContext schemaContextYangsIetf;
 
+    private BrokerFacade brokerFacade;
+    private RestconfImpl restconfImpl;
+
     @BeforeClass
     public static void init() throws FileNotFoundException, ReactorException {
         schemaContextYangsIetf = TestUtils.loadSchemaContext("/full-versions/yangs");
-        final ControllerContext controllerContext = ControllerContext.getInstance();
-        controllerContext.setSchemas(schemaContextYangsIetf);
-        brokerFacade = mock(BrokerFacade.class);
-        restconfImpl = RestconfImpl.getInstance();
-        restconfImpl.setBroker(brokerFacade);
-        restconfImpl.setControllerContext(controllerContext);
     }
 
     @Override
@@ -63,10 +59,18 @@ public class RestStreamTest extends JerseyTest {
         // enable(TestProperties.DUMP_ENTITY);
         // enable(TestProperties.RECORD_LOG_LEVEL);
         // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
+
+        final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContextYangsIetf);
+        brokerFacade = mock(BrokerFacade.class);
+        restconfImpl = RestconfImpl.getInstance();
+        restconfImpl.setBroker(brokerFacade);
+        restconfImpl.setControllerContext(controllerContext);
+
         ResourceConfig resourceConfig = new ResourceConfig();
         resourceConfig = resourceConfig.registerInstances(restconfImpl, new NormalizedNodeJsonBodyWriter(),
-            new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(), new JsonNormalizedNodeBodyReader());
-        resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
+            new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(controllerContext),
+            new JsonNormalizedNodeBodyReader(controllerContext),
+            new RestconfDocumentedExceptionMapper(controllerContext));
         return resourceConfig;
     }
 
index fca1543b0557d26d64ac65c8a956adb68febd528..44940b4a5ad1650bc57ae10917064d0c497ff9e0 100644 (file)
@@ -11,7 +11,9 @@ package org.opendaylight.netconf.sal.restconf.impl;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 
+import java.io.FileNotFoundException;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.restconf.impl.RestCodec.InstanceIdentifierCodecImpl;
@@ -23,19 +25,24 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class InstanceIdentifierCodecImplTest {
+    private static SchemaContext schemaContext;
 
     private Codec<IdentityValuesDTO, YangInstanceIdentifier> instanceIdentifierDTO;
     private YangInstanceIdentifier instanceIdentifierBadNamespace;
     private YangInstanceIdentifier instanceIdentifierOKList;
     private YangInstanceIdentifier instanceIdentifierOKLeafList;
-    private SchemaContext schemaContext;
+
+    @BeforeClass
+    public static void init() throws FileNotFoundException {
+        schemaContext = YangParserTestUtils.parseYangFiles(
+                TestRestconfUtils.loadFiles("/restconf/parser/deserializer"));
+    }
 
     @Before
     public void setUp() throws Exception {
-        this.schemaContext =
-                YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/restconf/parser/deserializer"));
-        this.instanceIdentifierDTO = new InstanceIdentifierCodecImpl(null);
-        ControllerContext.getInstance().setGlobalSchema(this.schemaContext);
+        ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
+
+        this.instanceIdentifierDTO = new InstanceIdentifierCodecImpl(null, controllerContext);
 
         final QName baseQName = QName.create("deserializer:test", "2016-06-06", "deserializer-test");
         final QName contA = QName.create(baseQName, "contA");
@@ -90,4 +97,4 @@ public class InstanceIdentifierCodecImplTest {
                 this.instanceIdentifierDTO.deserialize(valuesDTO);
         assertNull(deserializedIdentifier);
     }
-}
\ No newline at end of file
+}
index df9cf7fca00907f44d63ae11c4236b41a98ea3c8..52ede84d419fabb374cb53e57890f401b6ad2805 100644 (file)
@@ -19,6 +19,7 @@ import java.nio.file.Paths;
 import java.util.Optional;
 import org.json.JSONObject;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -27,6 +28,7 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.PatchCont;
 import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.patch.cont.MyList1;
@@ -54,16 +56,23 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
     private static YangInstanceIdentifier PATCH_CONT_YIID =
             YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(PatchCont.QNAME));
 
+    private static SchemaContext schemaContext;
+
     private DataBroker dataBroker;
     private DOMDataBroker domDataBroker;
+    private ControllerContext controllerContext;
+
+    @BeforeClass
+    public static void init() {
+        schemaContext = YangParserTestUtils.parseYangResource(
+                "/instanceidentifier/yang/instance-identifier-patch-module.yang");
+    }
 
     @Before
     public void setUp() throws Exception {
         dataBroker = getDataBroker();
         domDataBroker = getDomBroker();
-        SchemaContext sc = YangParserTestUtils.parseYangResource(
-                "/instanceidentifier/yang/instance-identifier-patch-module.yang");
-        ControllerContext.getInstance().setGlobalSchema(sc);
+        controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
     }
 
     class ListenerAdapterTester extends ListenerAdapter {
@@ -73,7 +82,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
         ListenerAdapterTester(final YangInstanceIdentifier path, final String streamName,
                               final NotificationOutputTypeGrouping.NotificationOutputType outputType,
                               final boolean leafNodesOnly) {
-            super(path, streamName, outputType);
+            super(path, streamName, outputType, controllerContext);
             setQueryParams(EPOCH, Optional.empty(), Optional.empty(), leafNodesOnly);
         }
 
index 1edfecb32790d22ac45c8dd1b2cacae1af67c6cb..2f03868cadba57018b5a2c04f6dc3c33cd4d4101 100644 (file)
@@ -14,6 +14,7 @@ import static org.mockito.Mockito.when;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
+import java.io.FileNotFoundException;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -22,9 +23,11 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
+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.ControllerContext;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
@@ -48,13 +51,19 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 public class NotificationListenerTest {
     private static final QNameModule MODULE = QNameModule.create(URI.create("notifi:mod"), Revision.of("2016-11-23"));
 
-    private SchemaContext schmeaCtx;
+    private static SchemaContext schemaContext;
+
+    private ControllerContext controllerContext;
+
+    @BeforeClass
+    public static void staticInit() throws FileNotFoundException {
+        schemaContext = TestUtils.loadSchemaContext("/notifications");
+    }
 
     @Before
     public void init() throws Exception {
         MockitoAnnotations.initMocks(this);
-        ControllerContext.getInstance().setGlobalSchema(TestUtils.loadSchemaContext("/notifications"));
-        this.schmeaCtx = ControllerContext.getInstance().getGlobalSchema();
+        controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
     }
 
     @Test
@@ -222,10 +231,11 @@ public class NotificationListenerTest {
         final List<SchemaPath> paths = new ArrayList<>();
         paths.add(schemaPathNotifi);
         final List<NotificationListenerAdapter> listNotifi =
-                Notificator.createNotificationListener(paths, "stream-name", NotificationOutputType.JSON.toString());
+                Notificator.createNotificationListener(paths, "stream-name", NotificationOutputType.JSON.toString(),
+                        controllerContext);
         final NotificationListenerAdapter notifi = listNotifi.get(0);
         notifi.setNotification(notificationData);
-        notifi.setSchemaContext(this.schmeaCtx);
+        notifi.setSchemaContext(schemaContext);
         final String result = notifi.prepareJson();
         return Preconditions.checkNotNull(result);
     }
index a6ad7f6272e38d0895dfd3b4a322e8f130f416d7..aa7142d4e56651cc7b77570b1d6983cff346b2c3 100644 (file)
@@ -1,6 +1,6 @@
 {
-       "cont": {       
-               "lflst1":[],
-               "lflst2":[45]           
-       }
-}
\ No newline at end of file
+    "array-with-null-yang:cont": {
+        "lflst1":[],
+        "lflst2":[45]
+    }
+}
index 828154683649d81a1e6830198d56b0ea1a12331e..545f99b085b008645f65aa06954cd8fe958fb70d 100644 (file)
@@ -1,6 +1,6 @@
 {
-    "cont":{
-       "lf1":"module<Name:value lf1",
-       "lf2":"module>Name:value lf2"
-       }
-}
\ No newline at end of file
+    "array-with-null-yang:cont":{
+        "lf1":"module<Name:value lf1",
+        "lf2":"module>Name:value lf2"
+    }
+}
index 7702b8860ffb34bd2e09234232d3229b55f76ea1..2131744ad2fe7a5678e6687d8826a0a26acfdec5 100644 (file)
@@ -1,26 +1,26 @@
 {
-       "multiple-items:lst":[
-               {
-                       "lst1": [
-                               {
-                                       "lf11":"lf11_1"
-                               },
-                               {
-                                       "lflst11":[
-                                               45
-                                       ]
-                               },
-                               {
-                                       "cont11":{
-                                       }
-                               },
-                               {
-                                       "lst11":[
-                                       {
-                                               }
-                                       ]
-                               }
-                       ]
-               }
-       ]
-}
\ No newline at end of file
+    "multiple-items-yang:lst":[
+        {
+            "lst1": [
+                {
+                    "lf11":"lf11_1"
+                },
+                {
+                    "lflst11":[
+                        45
+                    ]
+                },
+                {
+                    "cont11":{
+                    }
+                },
+                {
+                    "lst11":[
+                    {
+                        }
+                    ]
+                }
+            ]
+        }
+    ]
+}
index d8f0ce665431f5384dab155b78b42eff59aaed75..c1f5d1e52dae51fce23edc5d7c0f6325c1d75157 100644 (file)
@@ -1,5 +1,5 @@
 {
-       "multiple-leaflist:lst": {
-               "lflst1":[45,55,66]
-       }
-}
\ No newline at end of file
+    "simple-list-yang1:lst": {
+        "lflst1":[45,55,66]
+    }
+}
index 1be414991e70ce0fa274b6f30782da5580c386ae..28d244dc3af97f140f425f7a67f0d07acccad26a 100644 (file)
@@ -1,15 +1,15 @@
 {
-       "cont":{
-               "cont1":{
-               },
-               "lst1": [
-                       {
-                       }
-               ],
-               "lflst1":[
-                       "lflst1_1",
-                       "lflst1_2"
-               ],
-               "lf1":"lf1"
-       }
-}
\ No newline at end of file
+    "simple-container-yang:cont":{
+        "cont1":{
+        },
+        "lst1": [
+            {
+            }
+        ],
+        "lflst1":[
+            "lflst1_1",
+            "lflst1_2"
+        ],
+        "lf1":"lf1"
+    }
+}
index d18ecc007e1223d4d6045ba301b61e50b9bea305..76a0190e86901bc3956fc699a1e3f2899b1d2333 100644 (file)
@@ -1,17 +1,17 @@
 {
-       "simple-list:lst":[
-               {
-                       "cont1":{
-                       },
-                       "lst1": [
-                               {
-                               }
-                       ],
-                       "lflst1":[
-                               "lflst1_1",
-                               "lflst1_2"
-                       ],
-                       "lf1":"lf1"
-               }
-       ]
-}
\ No newline at end of file
+    "simple-list-yang1:lst":[
+        {
+            "cont1":{
+            },
+            "lst1": [
+                {
+                }
+            ],
+            "lflst1":[
+                "lflst1_1",
+                "lflst1_2"
+            ],
+            "lf1":"lf1"
+        }
+    ]
+}
index 594a802c0e796e6e96a49bd21ff3656e00b1a672..88baef328fcab09eae2b6d00f909ef29c4c8675a 100644 (file)
@@ -1,9 +1,8 @@
 {
-
-       "cont":[
-               {
-               },
-               {
-               }
-       ]
-}
\ No newline at end of file
+    "wrong":[
+        {
+        },
+        {
+        }
+    ]
+}
index af75a47e8bf031a44f17d504a5a44f65a215964c..c56727388223aca31dd429c1ca260de90c568707 100644 (file)
@@ -1,9 +1,9 @@
 {
 
-       "lst": {
-       },
-       "lst1":[
-               {
-               }
-       ]
-}
\ No newline at end of file
+    "simple-list-yang1:lst": {
+    },
+    "lst1":[
+        {
+        }
+    ]
+}