From fc95227cd9821564be816b637027afb710a85964 Mon Sep 17 00:00:00 2001 From: Jakub Toth Date: Fri, 6 May 2016 12:28:07 +0200 Subject: [PATCH] Bug 5526 - Testing - SchemaContextHandler Unit tests for SchemaContextHandlerImpl. Change-Id: Iff1330700ecc0209aae2d6d1cf6d745b582ca506 Signed-off-by: Jakub Toth --- .../context/SchemaContextHandlerTest.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/rest/impl/schema/context/SchemaContextHandlerTest.java 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 index 0000000000..d69305f7af --- /dev/null +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/rest/impl/schema/context/SchemaContextHandlerTest.java @@ -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}. + *

+ * Get SchemaContext from SchemaContextHandler and compare it to actual + * SchemaContext. + */ + @Test + public void getSchemaContextTest() { + assertEquals("SchemaContextHandler should has reference to actual SchemaContext", + schemaContext, schemaContextHandler.getSchemaContext()); + } + + /** + * Test updating of {@link SchemaContext}. + *

+ * Create new SchemaContext, set it to SchemaContextHandler and check if + * SchemaContextHandler reference to new SchemaContext 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()); + } +} -- 2.36.6