Reuse schemaContext in mdsal-netconf-connector tests 76/83976/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 26 Aug 2019 10:26:28 +0000 (12:26 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 26 Aug 2019 19:27:56 +0000 (21:27 +0200)
SchemaContext is well-known invariant, make sure we reuse it.

Change-Id: Id26988be0bd36a21bc4b0f227f5199d217a06300
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractNetconfOperationTest.java
netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfigTest.java
netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java

index 669fa2e0d73b6551f53bf4a4ec7acab7fab0267d..dcafdb2fac868cb933cd58310782e1956bd7a3a3 100644 (file)
@@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.opendaylight.yangtools.yang.test.util.YangParserTestUtils.parseYangResources;
 
 import com.google.common.io.ByteSource;
 import com.google.common.util.concurrent.Futures;
@@ -26,7 +27,9 @@ import javax.xml.transform.stream.StreamResult;
 import org.custommonkey.xmlunit.DetailedDiff;
 import org.custommonkey.xmlunit.Diff;
 import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
@@ -58,9 +61,22 @@ public abstract class AbstractNetconfOperationTest {
     private static final String DATA_ELEMENT = "data";
     protected static final Document RPC_REPLY_OK = getReplyOk();
 
+    private static SchemaContext SCHEMA_CONTEXT;
+
     private CurrentSchemaContext currentSchemaContext;
     private TransactionProvider transactionProvider;
 
+    @BeforeClass
+    public static void beforeClass() {
+        SCHEMA_CONTEXT = parseYangResources(AbstractNetconfOperationTest.class,
+            "/yang/mdsal-netconf-mapping-test.yang");
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        SCHEMA_CONTEXT = null;
+    }
+
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
@@ -68,8 +84,7 @@ public abstract class AbstractNetconfOperationTest {
         XMLUnit.setIgnoreWhitespace(true);
         XMLUnit.setIgnoreAttributeOrder(true);
 
-        final SchemaContext schemaContext = getSchemaContext();
-        final DOMSchemaService schemaService = new SchemaServiceStub(schemaContext);
+        final DOMSchemaService schemaService = new SchemaServiceStub(SCHEMA_CONTEXT);
         final DOMStore operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", schemaService);
         final DOMStore configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", schemaService);
 
@@ -91,8 +106,6 @@ public abstract class AbstractNetconfOperationTest {
         this.transactionProvider = new TransactionProvider(sdb, SESSION_ID_FOR_REPORTING);
     }
 
-    protected abstract SchemaContext getSchemaContext();
-
     protected CurrentSchemaContext getCurrentSchemaContext() {
         return currentSchemaContext;
     }
index 3a34ccd24c36927b87b6dff236fdab68473713ed..0b336adc1860f6332e877e6057fd70c5599b4d08 100644 (file)
@@ -5,12 +5,10 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.mdsal.connector.ops;
 
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.opendaylight.yangtools.yang.test.util.YangParserTestUtils.parseYangResources;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -25,7 +23,6 @@ import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
 
@@ -33,13 +30,6 @@ public class CopyConfigTest extends AbstractNetconfOperationTest {
     @Rule
     public TemporaryFolder tmpDir = new TemporaryFolder();
 
-    @Override
-    protected SchemaContext getSchemaContext() {
-        return parseYangResources(CopyConfigTest.class,
-            "/yang/mdsal-netconf-mapping-test.yang");
-    }
-
-
     @Test
     public void testTargetMissing() throws Exception {
         try {
index 43592f4b72e035bb7f923d1055356be3afcc0773..625acb29994c70a0d2dabdfd1d70a352f9db915e 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.mdsal.connector.ops;
 
 import static org.junit.Assert.assertEquals;
@@ -34,8 +33,6 @@ import org.opendaylight.netconf.mdsal.connector.ops.get.GetConfig;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -70,12 +67,6 @@ public class NetconfMDSalMappingTest extends AbstractNetconfOperationTest {
     private static final YangInstanceIdentifier AUGMENTED_CONTAINER_IN_MODULES =
             YangInstanceIdentifier.builder().node(TOP).node(MODULES).build();
 
-    @Override
-    protected SchemaContext getSchemaContext() {
-        return YangParserTestUtils.parseYangResources(NetconfMDSalMappingTest.class,
-            "/yang/mdsal-netconf-mapping-test.yang");
-    }
-
     @Test
     public void testEmptyDatastore() throws Exception {
         assertEmptyDatastore(get());