Bug 5526 - Testing - SchemaContextHandler 06/38506/10
authorJakub Toth <jatoth@cisco.com>
Fri, 6 May 2016 10:28:07 +0000 (12:28 +0200)
committerJakub Toth <jatoth@cisco.com>
Fri, 20 May 2016 13:22:56 +0000 (13:22 +0000)
Unit tests for SchemaContextHandlerImpl.

Change-Id: Iff1330700ecc0209aae2d6d1cf6d745b582ca506
Signed-off-by: Jakub Toth <jatoth@cisco.com>
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/rest/impl/schema/context/SchemaContextHandlerTest.java [new file with mode: 0644]

diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/rest/impl/schema/context/SchemaContextHandlerTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/rest/impl/schema/context/SchemaContextHandlerTest.java
new file mode 100644 (file)
index 0000000..d69305f
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.restconf.rest.impl.schema.context;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
+import org.opendaylight.restconf.rest.api.schema.context.SchemaContextHandler;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+
+/**
+ * Tests for handling {@link SchemaContext}
+ */
+public class SchemaContextHandlerTest {
+
+    private static final String PATH_FOR_ACTUAL_SCHEMA_CONTEXT = "/modules";
+    private static final String PATH_FOR_NEW_SCHEMA_CONTEXT = "/modules/modules-behind-mount-point";
+
+    private SchemaContextHandler schemaContextHandler;
+    private SchemaContext schemaContext;
+
+    @Before
+    public void setup() throws Exception {
+        schemaContextHandler = new SchemaContextHandlerImpl();
+
+        schemaContext = TestRestconfUtils.loadSchemaContext(PATH_FOR_ACTUAL_SCHEMA_CONTEXT);
+        schemaContextHandler.onGlobalContextUpdated(schemaContext);
+    }
+
+    /**
+     * Testing init of {@link SchemaContextHandlerImpl}
+     */
+    @Test
+    public void schemaContextHandlerImplInitTest() {
+        assertNotNull("Handler should be created and not null", schemaContextHandler);
+    }
+
+    /**
+     * Test getting actual {@link SchemaContext}.
+     * <p>
+     * Get <code>SchemaContext</code> from <code>SchemaContextHandler</code> and compare it to actual
+     * <code>SchemaContext</code>.
+     */
+    @Test
+    public void getSchemaContextTest() {
+        assertEquals("SchemaContextHandler should has reference to actual SchemaContext",
+                schemaContext, schemaContextHandler.getSchemaContext());
+    }
+
+    /**
+     * Test updating of {@link SchemaContext}.
+     * <p>
+     * Create new <code>SchemaContext</code>, set it to <code>SchemaContextHandler</code> and check if
+     * <code>SchemaContextHandler</code> reference to new <code>SchemaContext</code> instead of old one.
+     */
+    @Test
+    public void onGlobalContextUpdateTest() throws Exception {
+        // create new SchemaContext and update SchemaContextHandler
+        SchemaContext newSchemaContext = TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT);
+        schemaContextHandler.onGlobalContextUpdated(newSchemaContext);
+
+        assertNotEquals("SchemaContextHandler should not has reference to old SchemaContext",
+                schemaContext, schemaContextHandler.getSchemaContext());
+        assertEquals("SchemaContextHandler should has reference to new SchemaContext",
+                newSchemaContext, schemaContextHandler.getSchemaContext());
+    }
+}