69306a65fcede737bb7bab7534584e99e1341b21
[mdsal.git] / binding / mdsal-binding-runtime-spi / src / test / java / org / opendaylight / mdsal / binding / runtime / spi / ModuleInfoSnapshotBuilderTest.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech s.r.o. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.runtime.spi;
9
10 import static org.junit.Assert.assertEquals;
11
12 import java.util.Map;
13 import java.util.Set;
14 import org.junit.Test;
15 import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
16 import org.opendaylight.yang.gen.v1.mdsal767.norev.$YangModuleInfoImpl;
17 import org.opendaylight.yang.gen.v1.mdsal767.norev.Mdsal767Data;
18 import org.opendaylight.yang.gen.v1.mdsal767.norev.One$F;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.common.QNameModule;
21 import org.opendaylight.yangtools.yang.common.XMLNamespace;
22 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
23 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
25 import org.opendaylight.yangtools.yang.parser.api.YangParserException;
26 import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
27 import org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory;
28
29 public class ModuleInfoSnapshotBuilderTest {
30     private static final YangParserFactory PARSER_FACTORY = new DefaultYangParserFactory();
31
32     @Test
33     public void testModuleRegistration() throws YangParserException {
34         final ModuleInfoSnapshotBuilder snapshotBuilder = new ModuleInfoSnapshotBuilder(PARSER_FACTORY);
35         snapshotBuilder.add($YangModuleInfoImpl.getInstance());
36         snapshotBuilder.addModuleFeatures(Mdsal767Data.class, Set.of(One$F.VALUE));
37
38         final ModuleInfoSnapshot snapshot = snapshotBuilder.build();
39         final EffectiveModelContext modelContext = snapshot.getEffectiveModelContext();
40         final Map<QNameModule, ModuleEffectiveStatement> modules = modelContext.getModuleStatements();
41         final ModuleEffectiveStatement module = modules.get(QNameModule.create(XMLNamespace.of("mdsal767")));
42         assertEquals(1, module.features().size());
43         final FeatureEffectiveStatement feature = module.features().stream().findAny().orElseThrow();
44         assertEquals(QName.create("mdsal767", "one"), feature.argument());
45     }
46 }
47