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
9 package org.opendaylight.restconf.handlers;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotEquals;
13 import static org.junit.Assert.assertNotNull;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
17 import org.opendaylight.restconf.handlers.SchemaContextHandler;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 * Tests for handling {@link SchemaContext}
23 public class SchemaContextHandlerTest {
25 private static final String PATH_FOR_ACTUAL_SCHEMA_CONTEXT = "/modules";
26 private static final String PATH_FOR_NEW_SCHEMA_CONTEXT = "/modules/modules-behind-mount-point";
28 private SchemaContextHandler schemaContextHandler;
29 private SchemaContext schemaContext;
32 public void setup() throws Exception {
33 this.schemaContextHandler = new SchemaContextHandler();
35 this.schemaContext = TestRestconfUtils.loadSchemaContext(PATH_FOR_ACTUAL_SCHEMA_CONTEXT);
36 this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext);
40 * Testing init of {@link SchemaContextHandler}
43 public void schemaContextHandlerImplInitTest() {
44 assertNotNull("Handler should be created and not null", this.schemaContextHandler);
48 * Test getting actual {@link SchemaContext}.
50 * Get <code>SchemaContext</code> from <code>SchemaContextHandler</code> and compare it to actual
51 * <code>SchemaContext</code>.
54 public void getSchemaContextTest() {
55 assertEquals("SchemaContextHandler should has reference to actual SchemaContext",
56 this.schemaContext, this.schemaContextHandler.get());
60 * Test updating of {@link SchemaContext}.
62 * Create new <code>SchemaContext</code>, set it to <code>SchemaContextHandler</code> and check if
63 * <code>SchemaContextHandler</code> reference to new <code>SchemaContext</code> instead of old one.
66 public void onGlobalContextUpdateTest() throws Exception {
67 // create new SchemaContext and update SchemaContextHandler
68 final SchemaContext newSchemaContext = TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT);
69 this.schemaContextHandler.onGlobalContextUpdated(newSchemaContext);
71 assertNotEquals("SchemaContextHandler should not has reference to old SchemaContext",
72 this.schemaContext, this.schemaContextHandler.get());
73 assertEquals("SchemaContextHandler should has reference to new SchemaContext",
74 newSchemaContext, this.schemaContextHandler.get());