InstanceIdentifierContext does not take generics
[netconf.git] / restconf / restconf-nb-bierman02 / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / URITest.java
index 5e1d59d7c70f481195caaacf0374a214bd5f8892..8178674c49b3887addc89810e43085ec61ccecf3 100644 (file)
@@ -8,39 +8,37 @@
 package org.opendaylight.controller.sal.restconf.impl.test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import java.io.FileNotFoundException;
+import java.util.Optional;
 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.rest.common.TestRestconfUtils;
 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
 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.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 
 public class URITest {
 
-    private static SchemaContext schemaContext;
-    private static SchemaContext mountSchemaContext;
+    private static EffectiveModelContext schemaContext;
+    private static EffectiveModelContext 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 {
         schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
@@ -48,8 +46,8 @@ public class URITest {
     }
 
     @Test
-    public void testToInstanceIdentifierList() throws FileNotFoundException {
-        InstanceIdentifierContext<?> instanceIdentifier = controllerContext
+    public void testToInstanceIdentifierList() {
+        InstanceIdentifierContext instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:userWithoutClass/foo");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "userWithoutClass");
 
@@ -66,7 +64,7 @@ public class URITest {
 
     @Test
     public void testToInstanceIdentifierWithDoubleSlash() {
-        InstanceIdentifierContext<?> instanceIdentifier = controllerContext
+        InstanceIdentifierContext instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:food//nonalcoholic");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "nonalcoholic");
 
@@ -81,19 +79,19 @@ public class URITest {
 
     @Test
     public void testToInstanceIdentifierListWithNullKey() {
-        this.exception.expect(RestconfDocumentedException.class);
-        controllerContext.toInstanceIdentifier("simple-nodes:user/null/boo");
+        assertThrows(RestconfDocumentedException.class,
+            () -> controllerContext.toInstanceIdentifier("simple-nodes:user/null/boo"));
     }
 
     @Test
     public void testToInstanceIdentifierListWithMissingKey() {
-        this.exception.expect(RestconfDocumentedException.class);
-        controllerContext.toInstanceIdentifier("simple-nodes:user/foo");
+        assertThrows(RestconfDocumentedException.class,
+            () -> controllerContext.toInstanceIdentifier("simple-nodes:user/foo"));
     }
 
     @Test
-    public void testToInstanceIdentifierContainer() throws FileNotFoundException {
-        final InstanceIdentifierContext<?> instanceIdentifier =
+    public void testToInstanceIdentifierContainer() {
+        final InstanceIdentifierContext instanceIdentifier =
                 controllerContext.toInstanceIdentifier("simple-nodes:users");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "users");
         assertTrue(instanceIdentifier.getSchemaNode() instanceof ContainerSchemaNode);
@@ -101,42 +99,40 @@ public class URITest {
     }
 
     @Test
-    @Ignore //jenkins has problem with JerseyTest
-    // - we expecting problems with singletons ControllerContext as schemaContext holder
-    public void testToInstanceIdentifierChoice() throws FileNotFoundException {
-        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext
+    public void testToInstanceIdentifierChoice() {
+        final InstanceIdentifierContext instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:food/nonalcoholic");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "nonalcoholic");
     }
 
     @Test
     public void testToInstanceIdentifierChoiceException() {
-        this.exception.expect(RestconfDocumentedException.class);
-        controllerContext.toInstanceIdentifier("simple-nodes:food/snack");
+        assertThrows(RestconfDocumentedException.class,
+            () -> controllerContext.toInstanceIdentifier("simple-nodes:food/snack"));
     }
 
     @Test
     public void testToInstanceIdentifierCaseException() {
-        this.exception.expect(RestconfDocumentedException.class);
-        controllerContext.toInstanceIdentifier("simple-nodes:food/sports-arena");
+        assertThrows(RestconfDocumentedException.class,
+            () -> controllerContext.toInstanceIdentifier("simple-nodes:food/sports-arena"));
     }
 
     @Test
     public void testToInstanceIdentifierChoiceCaseException() {
-        this.exception.expect(RestconfDocumentedException.class);
-        controllerContext.toInstanceIdentifier("simple-nodes:food/snack/sports-arena");
+        assertThrows(RestconfDocumentedException.class,
+            () -> controllerContext.toInstanceIdentifier("simple-nodes:food/snack/sports-arena"));
     }
 
     @Test
     public void testToInstanceIdentifierWithoutNode() {
-        this.exception.expect(RestconfDocumentedException.class);
-        controllerContext.toInstanceIdentifier("simple-nodes");
+        assertThrows(RestconfDocumentedException.class,
+            () -> controllerContext.toInstanceIdentifier("simple-nodes"));
     }
 
     @Test
-    public void testMountPointWithExternModul() throws FileNotFoundException, ReactorException {
-        initMountService(true);
-        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext
+    public void testMountPointWithExternModul() {
+        initSchemaService();
+        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, "
@@ -147,26 +143,21 @@ public class URITest {
     }
 
     @Test
-    public void testMountPointWithoutExternModul() throws FileNotFoundException, ReactorException {
-        initMountService(true);
-        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext
+    public void testMountPointWithoutExternModul() {
+        initSchemaService();
+        final InstanceIdentifierContext instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/");
         assertTrue(Iterables.isEmpty(instanceIdentifier.getInstanceIdentifier().getPathArguments()));
     }
 
     @Test
-    public void testMountPointWithoutMountPointSchema() throws FileNotFoundException, ReactorException {
-        initMountService(false);
-        this.exception.expect(RestconfDocumentedException.class);
-
-        controllerContext.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class");
+    public void testMountPointWithoutMountPointSchema() {
+        assertThrows(RestconfDocumentedException.class,
+            () -> controllerContext.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class"));
     }
 
-    public void initMountService(final boolean withSchema) throws FileNotFoundException, ReactorException {
-        if (withSchema) {
-            when(mountInstance.getSchemaContext()).thenReturn(mountSchemaContext);
-        } else {
-            when(mountInstance.getSchemaContext()).thenReturn(null);
-        }
+    private void initSchemaService() {
+        doReturn(Optional.of(FixedDOMSchemaService.of(mountSchemaContext))).when(mountInstance)
+            .getService(DOMSchemaService.class);
     }
 }