2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.rest.impl.schema.context;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotEquals;
12 import static org.junit.Assert.assertNotNull;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
16 import org.opendaylight.restconf.handlers.SchemaContextHandler;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 * Tests for handling {@link SchemaContext}
22 public class SchemaContextHandlerTest {
24 private static final String PATH_FOR_ACTUAL_SCHEMA_CONTEXT = "/modules";
25 private static final String PATH_FOR_NEW_SCHEMA_CONTEXT = "/modules/modules-behind-mount-point";
27 private SchemaContextHandler schemaContextHandler;
28 private SchemaContext schemaContext;
31 public void setup() throws Exception {
32 this.schemaContextHandler = new SchemaContextHandler();
34 this.schemaContext = TestRestconfUtils.loadSchemaContext(PATH_FOR_ACTUAL_SCHEMA_CONTEXT);
35 this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext);
39 * Testing init of {@link SchemaContextHandler}
42 public void schemaContextHandlerImplInitTest() {
43 assertNotNull("Handler should be created and not null", this.schemaContextHandler);
47 * Test getting actual {@link SchemaContext}.
49 * Get <code>SchemaContext</code> from <code>SchemaContextHandler</code> and compare it to actual
50 * <code>SchemaContext</code>.
53 public void getSchemaContextTest() {
54 assertEquals("SchemaContextHandler should has reference to actual SchemaContext",
55 this.schemaContext, this.schemaContextHandler.get());
59 * Test updating of {@link SchemaContext}.
61 * Create new <code>SchemaContext</code>, set it to <code>SchemaContextHandler</code> and check if
62 * <code>SchemaContextHandler</code> reference to new <code>SchemaContext</code> instead of old one.
65 public void onGlobalContextUpdateTest() throws Exception {
66 // create new SchemaContext and update SchemaContextHandler
67 final SchemaContext newSchemaContext = TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT);
68 this.schemaContextHandler.onGlobalContextUpdated(newSchemaContext);
70 assertNotEquals("SchemaContextHandler should not has reference to old SchemaContext",
71 this.schemaContext, this.schemaContextHandler.get());
72 assertEquals("SchemaContextHandler should has reference to new SchemaContext",
73 newSchemaContext, this.schemaContextHandler.get());