*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class LeafrefStaticAnalysisTest {
+class LeafrefStaticAnalysisTest {
private static final QName FOO = QName.create("leafrefs", "foo");
private static EffectiveModelContext context;
private static ContainerSchemaNode bar;
private static Module module;
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
context = YangParserTestUtils.parseYangResource("/leafrefs.yang");
module = context.getModules().iterator().next();
- foo = (ListSchemaNode) module.findDataChildByName(FOO).get();
- bar = (ContainerSchemaNode) foo.findDataChildByName(QName.create(FOO, "bar")).get();
+ foo = assertInstanceOf(ListSchemaNode.class, module.getDataChildByName(FOO));
+ bar = assertInstanceOf(ContainerSchemaNode.class, foo.getDataChildByName(QName.create(FOO, "bar")));
grp = module.getGroupings().iterator().next();
}
@Test
- public void testGrpOuterId() {
- final LeafSchemaNode leaf = (LeafSchemaNode) grp.findDataChildByName(QName.create(FOO, "outer-id")).get();
+ void testGrpOuterId() {
+ final var leaf = assertInstanceOf(LeafSchemaNode.class, grp.getDataChildByName(QName.create(FOO, "outer-id")));
// Cannot be found as the reference goes outside of the grouping
- final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
+ final var stack = SchemaInferenceStack.of(context);
stack.enterGrouping(grp.getQName());
stack.enterSchemaTree(QName.create(FOO, "outer-id"));
assertThrowsInvalidPath(stack, leaf);
}
@Test
- public void testFooOuterId() {
- final LeafSchemaNode leaf = (LeafSchemaNode) bar.findDataChildByName(QName.create(FOO, "outer-id")).get();
- final SchemaInferenceStack stack = SchemaInferenceStack.ofDataTreePath(context, foo.getQName(), bar.getQName());
+ void testFooOuterId() {
+ final var leaf = assertInstanceOf(LeafSchemaNode.class, bar.getDataChildByName(QName.create(FOO, "outer-id")));
+ final var leafType = assertInstanceOf(LeafrefTypeDefinition.class, leaf.getType());
+ final var stack = SchemaInferenceStack.ofDataTreePath(context, foo.getQName(), bar.getQName());
stack.enterSchemaTree(QName.create(FOO, "outer-id"));
- final SchemaNode found = (SchemaNode) stack.resolvePathExpression(((LeafrefTypeDefinition) leaf.getType())
- .getPathStatement());
-
- assertThat(found, isA(LeafSchemaNode.class));
+ final var found = assertInstanceOf(LeafSchemaNode.class,
+ stack.resolvePathExpression(leafType.getPathStatement()));
assertEquals(QName.create(FOO, "id"), found.getQName());
}
@Test
- public void testGrpOuterIndirectProp() {
- final LeafSchemaNode leaf = (LeafSchemaNode) grp.findDataChildByName(
- QName.create(FOO, "outer-indirect-prop")).get();
- final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
+ void testGrpOuterIndirectProp() {
+ final var leaf = assertInstanceOf(LeafSchemaNode.class,
+ grp.getDataChildByName(QName.create(FOO, "outer-indirect-prop")));
+ final var stack = SchemaInferenceStack.of(context);
stack.enterGrouping(grp.getQName());
stack.enterSchemaTree(QName.create(FOO, "outer-indirect-prop"));
// Cannot resolve deref outer-id
}
@Test
- public void testFooOuterIndirectProp() {
- final LeafSchemaNode leaf = (LeafSchemaNode) bar.findDataChildByName(
- QName.create(FOO, "outer-indirect-prop")).get();
- final SchemaInferenceStack stack = SchemaInferenceStack.ofDataTreePath(context, foo.getQName(), bar.getQName());
+ void testFooOuterIndirectProp() {
+ final var leaf = assertInstanceOf(LeafSchemaNode.class,
+ bar.getDataChildByName(QName.create(FOO, "outer-indirect-prop")));
+ final var leafType = assertInstanceOf(LeafrefTypeDefinition.class, leaf.getType());
+ final var stack = SchemaInferenceStack.ofDataTreePath(context, foo.getQName(), bar.getQName());
stack.enterSchemaTree(QName.create(FOO, "outer-indirect-prop"));
- final SchemaNode found = (SchemaNode) stack.resolvePathExpression(((LeafrefTypeDefinition) leaf.getType())
- .getPathStatement());
-
- assertThat(found, isA(LeafSchemaNode.class));
+ final var found = assertInstanceOf(LeafSchemaNode.class,
+ stack.resolvePathExpression(leafType.getPathStatement()));
assertEquals(QName.create(FOO, "prop"), found.getQName());
}
@Test
- public void testGrpIndirect() {
- final LeafSchemaNode leaf = (LeafSchemaNode) grp.findDataChildByName(QName.create(FOO, "indirect")).get();
- final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
+ void testGrpIndirect() {
+ final var leaf = assertInstanceOf(LeafSchemaNode.class, grp.getDataChildByName(QName.create(FOO, "indirect")));
+ final var leafType = assertInstanceOf(LeafrefTypeDefinition.class, leaf.getType());
+ final var stack = SchemaInferenceStack.of(context);
stack.enterGrouping(grp.getQName());
stack.enterSchemaTree(QName.create(FOO, "indirect"));
- final SchemaNode found = (SchemaNode) stack.resolvePathExpression(((LeafrefTypeDefinition) leaf.getType())
- .getPathStatement());
-
- assertThat(found, isA(LeafSchemaNode.class));
+ final var found = assertInstanceOf(LeafSchemaNode.class,
+ stack.resolvePathExpression(leafType.getPathStatement()));
assertEquals(QName.create(FOO, "prop"), found.getQName());
}
@Test
- public void testFooIndirect() {
- final LeafSchemaNode leaf = (LeafSchemaNode) bar.findDataChildByName(QName.create(FOO, "indirect")).get();
- final SchemaInferenceStack stack = SchemaInferenceStack.ofDataTreePath(context, foo.getQName(), bar.getQName());
+ void testFooIndirect() {
+ final var leaf = assertInstanceOf(LeafSchemaNode.class, bar.getDataChildByName(QName.create(FOO, "indirect")));
+ final var leafType = assertInstanceOf(LeafrefTypeDefinition.class, leaf.getType());
+ final var stack = SchemaInferenceStack.ofDataTreePath(context, foo.getQName(), bar.getQName());
stack.enterSchemaTree(QName.create(FOO, "indirect"));
- final SchemaNode found = (SchemaNode) stack.resolvePathExpression(((LeafrefTypeDefinition) leaf.getType())
- .getPathStatement());
-
- assertThat(found, isA(LeafSchemaNode.class));
+ final var found = assertInstanceOf(LeafSchemaNode.class,
+ stack.resolvePathExpression(leafType.getPathStatement()));
assertEquals(QName.create(FOO, "prop"), found.getQName());
}
@Test
- public void testGrpDerefNonExistent() {
- final LeafSchemaNode leaf = (LeafSchemaNode) grp.findDataChildByName(
- QName.create(FOO, "deref-non-existent")).get();
- final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
+ void testGrpDerefNonExistent() {
+ final var leaf = assertInstanceOf(LeafSchemaNode.class,
+ grp.getDataChildByName(QName.create(FOO, "deref-non-existent")));
+ final var stack = SchemaInferenceStack.of(context);
stack.enterGrouping(grp.getQName());
stack.enterSchemaTree(QName.create(FOO, "deref-non-existent"));
assertThrowsMissingXyzzy(stack, leaf, "grouping (leafrefs)grp");
}
@Test
- public void testFooDerefNonExistent() {
- final LeafSchemaNode leaf = (LeafSchemaNode) bar.findDataChildByName(
- QName.create(FOO, "deref-non-existent")).get();
- final SchemaInferenceStack stack = SchemaInferenceStack.ofDataTreePath(context, foo.getQName(), bar.getQName());
+ void testFooDerefNonExistent() {
+ final var leaf = assertInstanceOf(LeafSchemaNode.class,
+ bar.getDataChildByName(QName.create(FOO, "deref-non-existent")));
+ final var stack = SchemaInferenceStack.ofDataTreePath(context, foo.getQName(), bar.getQName());
stack.enterSchemaTree(QName.create(FOO, "deref-non-existent"));
assertThrowsMissingXyzzy(stack, leaf, "schema parent (leafrefs)bar");
}
@Test
- public void testGrpNonExistentDeref() {
- final LeafSchemaNode leaf = (LeafSchemaNode) grp.findDataChildByName(
- QName.create(FOO, "non-existent-deref")).get();
- final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
+ void testGrpNonExistentDeref() {
+ final var leaf = assertInstanceOf(LeafSchemaNode.class,
+ grp.getDataChildByName(QName.create(FOO, "non-existent-deref")));
+ final var stack = SchemaInferenceStack.of(context);
stack.enterGrouping(grp.getQName());
stack.enterSchemaTree(QName.create(FOO, "non-existent-deref"));
assertThrowsMissingXyzzy(stack, leaf, "schema parent (leafrefs)foo");
}
@Test
- public void testFooNonExistentDeref() {
- final LeafSchemaNode leaf = (LeafSchemaNode) bar.findDataChildByName(
- QName.create(FOO, "non-existent-deref")).get();
- final SchemaInferenceStack stack = SchemaInferenceStack.ofDataTreePath(context, foo.getQName(), bar.getQName());
+ void testFooNonExistentDeref() {
+ final var leaf = assertInstanceOf(LeafSchemaNode.class,
+ bar.getDataChildByName(QName.create(FOO, "non-existent-deref")));
+ final var stack = SchemaInferenceStack.ofDataTreePath(context, foo.getQName(), bar.getQName());
stack.enterSchemaTree(QName.create(FOO, "non-existent-deref"));
assertThrowsMissingXyzzy(stack, leaf, "schema parent (leafrefs)foo");
}
@Test
- public void testNonExistentRelativeXpath() {
- final LeafSchemaNode leaf = (LeafSchemaNode) bar.findDataChildByName(
- QName.create(FOO, "indirect-with-current")).get();
- final SchemaInferenceStack stack = SchemaInferenceStack.ofDataTreePath(context,
+ void testNonExistentRelativeXpath() {
+ final var leaf = assertInstanceOf(LeafSchemaNode.class,
+ bar.getDataChildByName(QName.create(FOO, "indirect-with-current")));
+ final var stack = SchemaInferenceStack.ofDataTreePath(context,
foo.getQName(), bar.getQName(), QName.create(FOO, "indirect-with-current"));
assertThrowsMissingChild(stack, leaf, "(leafrefs)n", "module (leafrefs)leafrefs");
}
private static void assertThrowsInvalidPath(final SchemaInferenceStack stack, final LeafSchemaNode leaf) {
- final IllegalArgumentException ex = assertThrowsIAE(stack, leaf);
+ final var ex = assertThrowsIAE(stack, leaf);
assertThat(ex.getMessage(), startsWith("Illegal parent access in "));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(IllegalStateException.class));
+ final var cause = assertInstanceOf(IllegalStateException.class, ex.getCause());
assertEquals("Unexpected current EmptyGroupingEffectiveStatement{argument=(leafrefs)grp}", cause.getMessage());
}
private static IllegalArgumentException assertThrowsIAE(final SchemaInferenceStack stack,
final LeafSchemaNode leaf) {
- return assertThrows(IllegalArgumentException.class,
- () -> stack.resolvePathExpression(((LeafrefTypeDefinition) leaf.getType()).getPathStatement()));
+ return assertThrows(IllegalArgumentException.class, () -> stack.resolvePathExpression(
+ assertInstanceOf(LeafrefTypeDefinition.class, leaf.getType()).getPathStatement()));
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import com.google.common.collect.ImmutableSet;
-import java.net.URI;
import java.util.Arrays;
-import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.spi.AbstractSchemaContext;
import org.opendaylight.yangtools.yang.model.util.FilteringSchemaContextProxy.ModuleId;
-public class SchemaContextProxyTest {
+class SchemaContextProxyTest {
- private static final URI NAMESPACE = URI.create("urn:opendaylight:params:xml:ns:yang:controller:config");
+ private static final String NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:config";
private static final Revision REVISION = Revision.of("2015-01-01");
private static final Revision REVISION2 = Revision.of("2015-01-15");
private static final String MODULE5_NAME = "module5";
private static SchemaContext mockSchema(final Module... modules) {
- final List<Module> sortedModules = Arrays.asList(modules);
- sortedModules.sort(AbstractSchemaContext.NAME_REVISION_COMPARATOR);
+ Arrays.sort(modules, AbstractSchemaContext.NAME_REVISION_COMPARATOR);
SchemaContext mock = mock(SchemaContext.class);
- doReturn(ImmutableSet.copyOf(sortedModules)).when(mock).getModules();
+ doReturn(ImmutableSet.copyOf(modules)).when(mock).getModules();
return mock;
}
* M2 <- M3
*/
@Test
- public void testBasic() {
+ void testBasic() {
Module moduleConfig = mockModule(CONFIG_NAME);
Module module2 = mockModule(MODULE2_NAME);
Module module3 = mockModule(MODULE3_NAME);
* M2 <- M3
*/
@Test
- public void testNull() {
+ void testNull() {
Module moduleConfig = mockModule(CONFIG_NAME);
Module module2 = mockModule(MODULE2_NAME);
Module module3 = mockModule(MODULE3_NAME);
* M2 <- M3
*/
@Test
- public void testConfigDifferentRevisions() {
+ void testConfigDifferentRevisions() {
Module moduleConfigNullRevision = mockModule(CONFIG_NAME, null);
Module moduleConfig = mockModule(CONFIG_NAME, REVISION);
Module moduleConfig2 = mockModule(CONFIG_NAME, REVISION2);
* M2<-(NullRev)M3
*/
@Test
- public void testBasicNullRevision() throws Exception {
+ void testBasicNullRevision() throws Exception {
final Module moduleConfig = mockModule(CONFIG_NAME, Revision.of("2013-04-05"));
final Module module2 = mockModule(MODULE2_NAME, Revision.of("2014-06-17"));
final Module module20 = mockModule(MODULE2_NAME, null);
* M2 M3
*/
@Test
- public void testBasicMoreRootModules() {
+ void testBasicMoreRootModules() {
final Module moduleConfig = mockModule(CONFIG_NAME);
final Module moduleRoot = mockModule(ROOT_NAME);
final Module module2 = mockModule(MODULE2_NAME);
* M2 <- M3
*/
@Test
- public void testChainNotDepend() {
+ void testChainNotDepend() {
Module moduleConfig = mockModule(CONFIG_NAME);
Module module2 = mockModule(MODULE2_NAME);
Module module3 = mockModule(MODULE3_NAME);
* M2 -> M3 -> M4 -> M5
*/
@Test
- public void testChainDependMulti() {
+ void testChainDependMulti() {
Module moduleConfig = mockModule(CONFIG_NAME);
Module module2 = mockModule(MODULE2_NAME);
Module module3 = mockModule(MODULE3_NAME);
* M2 -> M3 <- M4
*/
@Test
- public void testChainNotDependMulti() {
+ void testChainNotDependMulti() {
Module moduleConfig = mockModule(CONFIG_NAME);
Module module2 = mockModule(MODULE2_NAME);
Module module3 = mockModule(MODULE3_NAME);
* M2 M3 M4 M5
*/
@Test
- public void testChainNotMulti() {
+ void testChainNotMulti() {
final Module moduleConfig = mockModule(CONFIG_NAME);
final Module module2 = mockModule(MODULE2_NAME);
final Module module3 = mockModule(MODULE3_NAME);
* M2 <- M3 M4=M3(Different revision)
*/
@Test
- public void testBasicRevisionChange() throws Exception {
+ void testBasicRevisionChange() throws Exception {
Module moduleConfig = mockModule(CONFIG_NAME);
Module module2 = mockModule(MODULE2_NAME);
Module module3 = mockModule(MODULE3_NAME);
* M2 -(no revision)-> M3(R2) ... M3(R1)
*/
@Test
- public void testImportNoRevision() {
+ void testImportNoRevision() {
Module moduleConfig = mockModule(CONFIG_NAME, REVISION);
Module module2 = mockModule(MODULE2_NAME, REVISION);
- Module module3 = mockModule(MODULE3_NAME, null);
+ Module module3 = mockModule(MODULE3_NAME, null);
Module module30 = mockModule(MODULE3_NAME, REVISION);
Module module31 = mockModule(MODULE3_NAME, REVISION2);
mockModuleImport(module2, moduleConfig, module3);
* M41(S) => M4
*/
@Test
- public void testBasicSubmodule() {
+ void testBasicSubmodule() {
Module moduleConfig = mockModule(CONFIG_NAME);
Module module2 = mockModule(MODULE2_NAME);
Module module3 = mockModule(MODULE3_NAME);
* M2 -> M3 -> M4 -> M5
*/
@Test
- public void testChainAdditionalModules() {
+ void testChainAdditionalModules() {
Module module2 = mockModule(MODULE2_NAME);
Module module3 = mockModule(MODULE3_NAME);
Module module4 = mockModule(MODULE4_NAME);
SchemaContext schemaContext = mockSchema(module2, module3, module4, module5);
FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Set.of(module2),
- null);
+ null);
assertProxyContext(filteringSchemaContextProxy, module2, module3, module4, module5);
}
* M3 -> M4
*/
@Test
- public void testChainAdditionalModulesConfig() {
+ void testChainAdditionalModulesConfig() {
Module moduleConfig = mockModule(CONFIG_NAME);
Module module2 = mockModule(MODULE2_NAME);
SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3, module4, module5);
FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Set.of(module3),
- moduleConfig);
+ moduleConfig);
assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3, module4);
}
@Test
- public void testGetDataDefinitions() {
+ void testGetDataDefinitions() {
final Module moduleConfig = mockModule(CONFIG_NAME);
final SchemaContext schemaContext = mockSchema(moduleConfig);
final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Set.of(),
- moduleConfig);
+ moduleConfig);
final ContainerSchemaNode mockedContainer = mock(ContainerSchemaNode.class);
doReturn(Set.of(mockedContainer)).when(moduleConfig).getChildNodes();
- final Collection<? extends DataSchemaNode> dataDefinitions = filteringSchemaContextProxy.getDataDefinitions();
+ final var dataDefinitions = filteringSchemaContextProxy.getDataDefinitions();
assertTrue(dataDefinitions.contains(mockedContainer));
}
@Test
- public void testGetNotifications() {
+ void testGetNotifications() {
final Module moduleConfig = mockModule(CONFIG_NAME);
final SchemaContext schemaContext = mockSchema(moduleConfig);
final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Set.of(),
- moduleConfig);
+ moduleConfig);
final NotificationDefinition mockedNotification = mock(NotificationDefinition.class);
doReturn(Set.of(mockedNotification)).when(moduleConfig).getNotifications();
- final Collection<? extends NotificationDefinition> schemaContextProxyNotifications =
- filteringSchemaContextProxy.getNotifications();
+ final var schemaContextProxyNotifications = filteringSchemaContextProxy.getNotifications();
assertTrue(schemaContextProxyNotifications.contains(mockedNotification));
}
@Test
- public void testGetOperations() {
+ void testGetOperations() {
final Module moduleConfig = mockModule(CONFIG_NAME);
final SchemaContext schemaContext = mockSchema(moduleConfig);
final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Set.of(),
- moduleConfig);
+ moduleConfig);
final RpcDefinition mockedRpc = mock(RpcDefinition.class);
doReturn(Set.of(mockedRpc)).when(moduleConfig).getRpcs();
- final Collection<? extends RpcDefinition> operations = filteringSchemaContextProxy.getOperations();
+ final var operations = filteringSchemaContextProxy.getOperations();
assertTrue(operations.contains(mockedRpc));
}
@Test
- public void testGetExtensions() {
+ void testGetExtensions() {
final Module moduleConfig = mockModule(CONFIG_NAME);
final SchemaContext schemaContext = mockSchema(moduleConfig);
final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Set.of(),
- moduleConfig);
+ moduleConfig);
final ExtensionDefinition mockedExtension = mock(ExtensionDefinition.class);
doReturn(List.of(mockedExtension)).when(moduleConfig).getExtensionSchemaNodes();
- final Collection<? extends ExtensionDefinition> schemaContextProxyExtensions =
- filteringSchemaContextProxy.getExtensions();
+ final var schemaContextProxyExtensions = filteringSchemaContextProxy.getExtensions();
assertTrue(schemaContextProxyExtensions.contains(mockedExtension));
}
@Test
- public void testGetUnknownSchemaNodes() {
+ void testGetUnknownSchemaNodes() {
final Module moduleConfig = mockModule(CONFIG_NAME);
final SchemaContext schemaContext = mockSchema(moduleConfig);
final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Set.of(),
- moduleConfig);
+ moduleConfig);
final UnknownSchemaNode mockedUnknownSchemaNode = mock(UnknownSchemaNode.class);
doReturn(List.of(mockedUnknownSchemaNode)).when(moduleConfig).getUnknownSchemaNodes();
- final Collection<? extends UnknownSchemaNode> schemaContextProxyUnknownSchemaNodes =
- filteringSchemaContextProxy.getUnknownSchemaNodes();
+ final var schemaContextProxyUnknownSchemaNodes = filteringSchemaContextProxy.getUnknownSchemaNodes();
assertTrue(schemaContextProxyUnknownSchemaNodes.contains(mockedUnknownSchemaNode));
}
@Test
- public void testGetTypeDefinitions() {
+ void testGetTypeDefinitions() {
final Module moduleConfig = mockModule(CONFIG_NAME);
final SchemaContext schemaContext = mockSchema(moduleConfig);
final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Set.of(),
- moduleConfig);
+ moduleConfig);
final TypeDefinition<?> mockedTypeDefinition = mock(TypeDefinition.class);
doReturn(Set.of(mockedTypeDefinition)).when(moduleConfig).getTypeDefinitions();
- final Collection<? extends TypeDefinition<?>> schemaContextProxyTypeDefinitions = filteringSchemaContextProxy
- .getTypeDefinitions();
+ final var schemaContextProxyTypeDefinitions = filteringSchemaContextProxy.getTypeDefinitions();
assertTrue(schemaContextProxyTypeDefinitions.contains(mockedTypeDefinition));
}
@Test
- public void testGetChildNodes() {
+ void testGetChildNodes() {
final Module moduleConfig = mockModule(CONFIG_NAME);
final SchemaContext schemaContext = mockSchema(moduleConfig);
final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Set.of(),
- moduleConfig);
+ moduleConfig);
final ContainerSchemaNode mockedContainer = mock(ContainerSchemaNode.class);
doReturn(Set.of(mockedContainer)).when(moduleConfig).getChildNodes();
- final Collection<? extends DataSchemaNode> schemaContextProxyChildNodes =
- filteringSchemaContextProxy.getChildNodes();
+ final var schemaContextProxyChildNodes = filteringSchemaContextProxy.getChildNodes();
assertTrue(schemaContextProxyChildNodes.contains(mockedContainer));
}
@Test
- public void testGetGroupings() {
+ void testGetGroupings() {
final Module moduleConfig = mockModule(CONFIG_NAME);
final SchemaContext schemaContext = mockSchema(moduleConfig);
final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Set.of(),
- moduleConfig);
+ moduleConfig);
final GroupingDefinition mockedGrouping = mock(GroupingDefinition.class);
doReturn(Set.of(mockedGrouping)).when(moduleConfig).getGroupings();
- final Collection<? extends GroupingDefinition> schemaContextProxyGroupings =
- filteringSchemaContextProxy.getGroupings();
+ final var schemaContextProxyGroupings = filteringSchemaContextProxy.getGroupings();
assertTrue(schemaContextProxyGroupings.contains(mockedGrouping));
}
@Test
- public void testGetDataChildByName() {
+ void testGetDataChildByName() {
final Module moduleConfig = mockModule(CONFIG_NAME);
final SchemaContext schemaContext = mockSchema(moduleConfig);
final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Set.of(),
- moduleConfig);
+ moduleConfig);
final QName qname = QName.create("config-namespace", "2016-08-11", "cont");
final ContainerSchemaNode mockedContainer = mock(ContainerSchemaNode.class);
//asserting collections
if (expected != null) {
for (final Module module : expected) {
- assertEquals(module, filteringSchemaContextProxy.findModule(module.getName(), module.getRevision())
- .get());
+ assertEquals(Optional.of(module),
+ filteringSchemaContextProxy.findModule(module.getName(), module.getRevision()));
- Collection<? extends Module> mod = filteringSchemaContextProxy.findModules(module.getNamespace());
+ final var mod = filteringSchemaContextProxy.findModules(module.getNamespace());
assertTrue(mod.contains(module));
- assertEquals(module, filteringSchemaContextProxy.findModule(module.getNamespace(),
- module.getRevision().orElse(null)).get());
+ assertEquals(Optional.of(module),
+ filteringSchemaContextProxy.findModule(module.getNamespace(), module.getRevision().orElse(null)));
}
}
}
private static FilteringSchemaContextProxy createProxySchemaCtx(final SchemaContext schemaContext,
final Set<Module> additionalModules, final Module... modules) {
- Set<Module> modulesSet = modules != null ? ImmutableSet.copyOf(modules) : Set.of();
+ final var modulesSet = modules != null ? ImmutableSet.copyOf(modules) : Set.<Module>of();
return new FilteringSchemaContextProxy(schemaContext, createModuleIds(modulesSet),
createModuleIds(additionalModules));
}
private static Set<ModuleId> createModuleIds(final Set<Module> modules) {
- Set<ModuleId> moduleIds = new HashSet<>();
+ final var moduleIds = new HashSet<ModuleId>();
if (modules != null) {
- for (Module module : modules) {
+ for (var module : modules) {
moduleIds.add(new ModuleId(module.getName(), module.getRevision()));
}
}
}
private static void mockModuleImport(final ModuleLike importer, final Module... imports) {
- Set<ModuleImport> mockedImports = new HashSet<>();
- for (final Module module : imports) {
+ final var mockedImports = new HashSet<ModuleImport>();
+ for (final var module : imports) {
mockedImports.add(new ModuleImport() {
@Override
public Unqualified getModuleName() {
//mock module with revision
private static Module mockModule(final String name, final Revision rev) {
-
- final Module mod = mockModule(name);
+ final var mod = mockModule(name);
doReturn(QNameModule.create(mod.getNamespace(), rev)).when(mod).getQNameModule();
doReturn(Optional.ofNullable(rev)).when(mod).getRevision();
//mock module with default revision
private static Module mockModule(final String name) {
- Module mockedModule = mock(Module.class);
+ final var mockedModule = mock(Module.class);
mockModuleLike(mockedModule, name);
return mockedModule;
}
private static Submodule mockSubmodule(final String name) {
- Submodule mockedModule = mock(Submodule.class);
+ final var mockedModule = mock(Submodule.class);
mockModuleLike(mockedModule, name);
return mockedModule;
}
private static void mockModuleLike(final ModuleLike mockedModule, final String name) {
doReturn(name).when(mockedModule).getName();
doReturn(Optional.of(REVISION)).when(mockedModule).getRevision();
- final XMLNamespace newNamespace = XMLNamespace.of(NAMESPACE.toString() + ":" + name);
+ final XMLNamespace newNamespace = XMLNamespace.of(NAMESPACE + ":" + name);
doReturn(newNamespace).when(mockedModule).getNamespace();
doReturn(QNameModule.create(newNamespace, REVISION)).when(mockedModule).getQNameModule();
doReturn(Set.of()).when(mockedModule).getSubmodules();
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath;
import org.opendaylight.yangtools.yang.xpath.api.YangXPathAxis;
-public class SchemaInferenceStackTest {
+class SchemaInferenceStackTest {
private static EffectiveModelContext context;
private static Module myModule;
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
context = YangParserTestUtils.parseYangResourceDirectory("/schema-context-util");
- myModule = context.findModule(XMLNamespace.of("uri:my-module"), Revision.of("2014-10-07")).get();
+ myModule = context.findModule(XMLNamespace.of("uri:my-module"), Revision.of("2014-10-07")).orElseThrow();
}
@Test
- public void findDataSchemaNodeTest() {
+ void findDataSchemaNodeTest() {
final Module importedModule = context.findModule(XMLNamespace.of("uri:imported-module"),
- Revision.of("2014-10-07")).get();
+ Revision.of("2014-10-07")).orElseThrow();
final QName myImportedContainer = QName.create(importedModule.getQNameModule(), "my-imported-container");
final QName myImportedLeaf = QName.create(importedModule.getQNameModule(), "my-imported-leaf");
final SchemaNode testNode = ((ContainerSchemaNode) importedModule.getDataChildByName(myImportedContainer))
- .getDataChildByName(myImportedLeaf);
+ .getDataChildByName(myImportedLeaf);
final PathExpression expr = mock(PathExpression.class);
doReturn(true).when(expr).isAbsolute();
doReturn(new LocationPathSteps(YangLocationPath.absolute(
- YangXPathAxis.CHILD.asStep(myImportedContainer), YangXPathAxis.CHILD.asStep(myImportedLeaf))))
+ YangXPathAxis.CHILD.asStep(myImportedContainer), YangXPathAxis.CHILD.asStep(myImportedLeaf))))
.when(expr).getSteps();
assertEquals(testNode, SchemaInferenceStack.of(context).resolvePathExpression(expr));
}
@Test
- public void findDataSchemaNodeTest2() {
+ void findDataSchemaNodeTest2() {
final QName myLeafInGrouping2 = QName.create(myModule.getQNameModule(), "my-leaf-in-gouping2");
final PathExpression expr = mock(PathExpression.class);
doReturn(true).when(expr).isAbsolute();
doReturn(new LocationPathSteps(YangLocationPath.relative(YangXPathAxis.CHILD.asStep(myLeafInGrouping2))))
- .when(expr).getSteps();
+ .when(expr).getSteps();
final GroupingDefinition grouping = getGroupingByName(myModule, "my-grouping");
final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
}
@Test
- public void enterGroupingNegativeTest() {
+ void enterGroupingNegativeTest() {
final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
assertNotExistentGrouping(stack, "module (uri:my-module?revision=2014-10-07)my-module");
stack.enterDataTree(QName.create(myModule.getQNameModule(), "my-container"));
}
@Test
- public void enterNestedTypedefTest() {
+ void enterNestedTypedefTest() {
final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
stack.enterDataTree(QName.create(myModule.getQNameModule(), "my-container"));
assertNotNull(stack.enterTypedef(QName.create(myModule.getQNameModule(), "my-typedef-in-container")));
}
@Test
- public void enterTypedefNegativeTest() {
+ void enterTypedefNegativeTest() {
final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
assertNotExistentTypedef(stack, "module (uri:my-module?revision=2014-10-07)my-module");
stack.enterDataTree(QName.create(myModule.getQNameModule(), "my-container"));
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.junit.Assert.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.spi.SimpleSchemaContext;
-public class SimpleSchemaContextTest {
+class SimpleSchemaContextTest {
@Test
- public void testGetModulesOrdering() {
- final Module foo0 = mockModule("foo", Optional.empty());
- final Module foo1 = mockModule("foo", Revision.ofNullable("2018-01-01"));
- final Module foo2 = mockModule("foo", Revision.ofNullable("2018-01-16"));
+ void testGetModulesOrdering() {
+ final var foo0 = mockModule("foo", Optional.empty());
+ final var foo1 = mockModule("foo", Revision.ofNullable("2018-01-01"));
+ final var foo2 = mockModule("foo", Revision.ofNullable("2018-01-16"));
- final List<Module> expected = ImmutableList.of(foo2, foo1, foo0);
+ final var expected = List.of(foo2, foo1, foo0);
assertGetModules(expected, foo0, foo1, foo2);
assertGetModules(expected, foo0, foo2, foo1);
assertGetModules(expected, foo1, foo0, foo2);
}
private static void assertGetModules(final List<Module> expected, final Module... modules) {
- final Set<Module> actual = SimpleSchemaContext.forModules(ImmutableList.copyOf(modules)).getModules();
+ final var actual = SimpleSchemaContext.forModules(List.of(modules)).getModules();
assertArrayEquals(expected.toArray(), actual.toArray());
}
private static void assertFindModules(final List<Module> expected, final String name, final Module... modules) {
- final Collection<? extends Module> actual = SimpleSchemaContext.forModules(ImmutableList.copyOf(modules))
- .findModules(name);
+ final var actual = SimpleSchemaContext.forModules(List.of(modules)).findModules(name);
assertArrayEquals(expected.toArray(), actual.toArray());
}
private static void assertFindModules(final List<Module> expected, final XMLNamespace uri,
final Module... modules) {
- final Collection<? extends Module> actual = SimpleSchemaContext.forModules(ImmutableSet.copyOf(modules))
- .findModules(uri);
+ final var actual = SimpleSchemaContext.forModules(List.of(modules)).findModules(uri);
assertArrayEquals(expected.toArray(), actual.toArray());
}
private static Module mockModule(final String name, final Optional<Revision> revision) {
- final QNameModule mod = QNameModule.create(XMLNamespace.of(name), revision);
- final Module ret = mock(Module.class);
+ final var mod = QNameModule.create(XMLNamespace.of(name), revision);
+ final var ret = mock(Module.class);
doReturn(name).when(ret).getName();
doReturn(mod.getNamespace()).when(ret).getNamespace();
doReturn(mod.getRevision()).when(ret).getRevision();
doReturn(mod).when(ret).getQNameModule();
doReturn(mod.toString()).when(ret).toString();
- doReturn(ImmutableSet.of()).when(ret).getImports();
- doReturn(ImmutableSet.of()).when(ret).getSubmodules();
- doReturn(ImmutableList.of()).when(ret).getUnknownSchemaNodes();
+ doReturn(Set.of()).when(ret).getImports();
+ doReturn(Set.of()).when(ret).getSubmodules();
+ doReturn(List.of()).when(ret).getUnknownSchemaNodes();
return ret;
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertSame;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1050Test {
+class YT1050Test {
private static final QName SECONDARY = QName.create("yt1050", "secondary");
private static final QName TYPE = QName.create(SECONDARY, "type");
private static final QName GRP_USES = QName.create(SECONDARY, "grp-uses");
private LeafSchemaNode primaryType;
private Module module;
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
context = YangParserTestUtils.parseYangResource("/yt1050.yang");
module = context.getModules().iterator().next();
- final ListSchemaNode grpUses = (ListSchemaNode) module.findDataChildByName(GRP_USES).get();
- primaryType = (LeafSchemaNode) grpUses.findDataChildByName(TYPE).get();
+ final var grpUses = assertInstanceOf(ListSchemaNode.class, module.getDataChildByName(GRP_USES));
+ primaryType = assertInstanceOf(LeafSchemaNode.class, grpUses.getDataChildByName(TYPE));
- final GroupingDefinition grp = module.getGroupings().iterator().next();
- secondaryType = (LeafSchemaNode) ((ListSchemaNode) grp.findDataChildByName(SECONDARY).get())
- .findDataChildByName(TYPE).get();
+ final var grp = module.getGroupings().iterator().next();
+ secondaryType = assertInstanceOf(LeafSchemaNode.class,
+ assertInstanceOf(ListSchemaNode.class, grp.getDataChildByName(SECONDARY)).getDataChildByName(TYPE));
}
@Test
- public void testFindDataSchemaNodeForRelativeXPathWithDeref() {
- final TypeDefinition<?> typeNodeType = secondaryType.getType();
- assertThat(typeNodeType, isA(LeafrefTypeDefinition.class));
-
- final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
+ void testFindDataSchemaNodeForRelativeXPathWithDeref() {
+ final var typeNodeType = assertInstanceOf(LeafrefTypeDefinition.class, secondaryType.getType());
+ final var stack = SchemaInferenceStack.of(context);
stack.enterGrouping(QName.create(module.getQNameModule(), "grp"));
stack.enterSchemaTree(QName.create(module.getQNameModule(), "secondary"));
stack.enterSchemaTree(secondaryType.getQName());
- final EffectiveStatement<?, ?> found = stack.resolvePathExpression(((LeafrefTypeDefinition) typeNodeType)
- .getPathStatement());
- assertSame(primaryType, found);
+ assertSame(primaryType, stack.resolvePathExpression(typeNodeType.getPathStatement()));
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import com.google.common.collect.ImmutableList;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.PathExpression;
import org.opendaylight.yangtools.yang.model.api.PathExpression.LocationPathSteps;
-import org.opendaylight.yangtools.yang.model.api.PathExpression.Steps;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath;
import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.ResolvedQNameStep;
-import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.Step;
-public class YT1060Test {
+class YT1060Test {
private static final QName CONT = QName.create("parent", "cont");
private static final QName LEAF1 = QName.create(CONT, "leaf1");
private EffectiveModelContext context;
private PathExpression path;
- @Before
- public void before() {
+ @BeforeEach
+ void before() {
context = YangParserTestUtils.parseYangResourceDirectory("/yt1060");
- final Module module = context.findModule(CONT.getModule()).get();
- final ContainerSchemaNode cont = (ContainerSchemaNode) module.findDataChildByName(CONT).get();
- final LeafSchemaNode leaf1 = (LeafSchemaNode) cont.findDataChildByName(LEAF1).get();
- path = ((LeafrefTypeDefinition) leaf1.getType()).getPathStatement();
+ final var module = context.findModule(CONT.getModule()).orElseThrow();
+ final var cont = assertInstanceOf(ContainerSchemaNode.class, module.getDataChildByName(CONT));
+ final var leaf1 = assertInstanceOf(LeafSchemaNode.class, cont.getDataChildByName(LEAF1));
+ path = assertInstanceOf(LeafrefTypeDefinition.class, leaf1.getType()).getPathStatement();
// Quick checks before we get to the point
- final Steps pathSteps = path.getSteps();
- assertThat(pathSteps, isA(LocationPathSteps.class));
- final YangLocationPath locationPath = ((LocationPathSteps) pathSteps).getLocationPath();
+ final var pathSteps = assertInstanceOf(LocationPathSteps.class, path.getSteps());
+ final var locationPath = pathSteps.getLocationPath();
assertTrue(locationPath.isAbsolute());
- final ImmutableList<Step> steps = locationPath.getSteps();
+ final var steps = locationPath.getSteps();
assertEquals(2, steps.size());
- steps.forEach(step -> assertThat(step, isA(ResolvedQNameStep.class)));
+ steps.forEach(step -> assertInstanceOf(ResolvedQNameStep.class, step));
}
@Test
- public void testFindDataSchemaNodeAbsolutePathImportedModule() {
- final EffectiveStatement<?, ?> foundStmt = SchemaInferenceStack.ofDataTreePath(context, CONT, LEAF1)
- .resolvePathExpression(path);
- assertThat(foundStmt, isA(LeafSchemaNode.class));
- assertEquals(QName.create(XMLNamespace.of("imported"), "leaf1"), ((LeafSchemaNode) foundStmt).getQName());
+ void testFindDataSchemaNodeAbsolutePathImportedModule() {
+ final var foundStmt = assertInstanceOf(LeafSchemaNode.class,
+ SchemaInferenceStack.ofDataTreePath(context, CONT, LEAF1).resolvePathExpression(path));
+ assertEquals(QName.create(XMLNamespace.of("imported"), "leaf1"), foundStmt.getQName());
// since this is absolute path with prefixes stack should be able to resolve it from any state
- final EffectiveStatement<?, ?> foundStmtSecond = SchemaInferenceStack.of(context).resolvePathExpression(path);
- assertSame(foundStmt, foundStmtSecond);
+ assertSame(foundStmt, SchemaInferenceStack.of(context).resolvePathExpression(path));
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.PathExpression;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1100Test {
+class YT1100Test {
@Test
- public void testChoiceCaseRelativeLeafref() {
- final EffectiveModelContext context = YangParserTestUtils.parseYangResource("/yt1100.yang");
- final Module module = context.findModule("yt1100").orElseThrow();
- final QNameModule qnm = module.getQNameModule();
- final QName foo = QName.create(qnm, "foo");
- final QName schedulerNode = QName.create(qnm, "scheduler-node");
- final QName childSchedulerNodes = QName.create(qnm, "child-scheduler-nodes");
- final QName name = QName.create(qnm, "name");
- final DataSchemaNode leaf = module.findDataTreeChild(foo, schedulerNode, childSchedulerNodes, name)
- .orElseThrow();
- assertThat(leaf, instanceOf(LeafSchemaNode.class));
+ void testChoiceCaseRelativeLeafref() {
+ final var context = YangParserTestUtils.parseYangResource("/yt1100.yang");
+ final var module = context.findModule("yt1100").orElseThrow();
+ final var qnm = module.getQNameModule();
+ final var foo = QName.create(qnm, "foo");
+ final var schedulerNode = QName.create(qnm, "scheduler-node");
+ final var childSchedulerNodes = QName.create(qnm, "child-scheduler-nodes");
+ final var name = QName.create(qnm, "name");
+ final var leaf = assertInstanceOf(LeafSchemaNode.class,
+ module.findDataTreeChild(foo, schedulerNode, childSchedulerNodes, name).orElseThrow());
+ final var leafref = assertInstanceOf(LeafrefTypeDefinition.class, leaf.getType()).getPathStatement();
- final TypeDefinition<?> type = ((LeafSchemaNode) leaf).getType();
- assertThat(type, instanceOf(LeafrefTypeDefinition.class));
- final PathExpression leafref = ((LeafrefTypeDefinition) type).getPathStatement();
-
- final EffectiveStatement<?, ?> resolvedLeafRef = SchemaInferenceStack.ofDataTreePath(
- context, foo, schedulerNode,childSchedulerNodes, name).resolvePathExpression(leafref);
- assertThat(resolvedLeafRef, instanceOf(LeafSchemaNode.class));
- final LeafSchemaNode targetLeaf = (LeafSchemaNode) resolvedLeafRef;
- assertEquals(QName.create(qnm, "name"), targetLeaf.getQName());
- assertThat(targetLeaf.getType(), instanceOf(StringTypeDefinition.class));
+ final var resolvedLeafRef = assertInstanceOf(LeafSchemaNode.class,
+ SchemaInferenceStack.ofDataTreePath(context, foo, schedulerNode, childSchedulerNodes, name)
+ .resolvePathExpression(leafref));
+ assertEquals(QName.create(qnm, "name"), resolvedLeafRef.getQName());
+ assertInstanceOf(StringTypeDefinition.class, resolvedLeafRef.getType());
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.NoSuchElementException;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1127Test {
+class YT1127Test {
private static EffectiveModelContext context;
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
context = YangParserTestUtils.parseYangResource("/yt1127.yang");
}
- @AfterClass
- public static void afterClass() {
+ @AfterAll
+ static void afterClass() {
context = null;
}
@Test
- public void testGroupingLeafRef() {
- final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
+ void testGroupingLeafRef() {
+ final var stack = SchemaInferenceStack.of(context);
stack.enterGrouping(QName.create("foo", "grp"));
- final SchemaTreeEffectiveStatement<?> leaf1 = stack.enterSchemaTree(QName.create("foo", "leaf1"));
- assertThat(leaf1, instanceOf(LeafSchemaNode.class));
- final TypeDefinition<?> type = ((LeafSchemaNode) leaf1).getType();
- assertThat(type, instanceOf(LeafrefTypeDefinition.class));
+ final var leaf1 = assertInstanceOf(LeafSchemaNode.class, stack.enterSchemaTree(QName.create("foo", "leaf1")));
+ final var type = assertInstanceOf(LeafrefTypeDefinition.class, leaf1.getType());
- final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
- () -> stack.resolveLeafref((LeafrefTypeDefinition) type));
+ final var ex = assertThrows(IllegalArgumentException.class, () -> stack.resolveLeafref(type));
assertThat(ex.getMessage(), startsWith("Illegal parent access in YangLocationPath"));
- final Throwable cause = ex.getCause();
- assertThat(cause, instanceOf(IllegalStateException.class));
+ final var cause = assertInstanceOf(IllegalStateException.class, ex.getCause());
assertEquals("Unexpected current EmptyGroupingEffectiveStatement{argument=(foo)grp}", cause.getMessage());
}
@Test
- public void testContainerLeafRef() {
- final SchemaInferenceStack stack = SchemaInferenceStack.ofDataTreePath(context,
+ void testContainerLeafRef() {
+ final var stack = SchemaInferenceStack.ofDataTreePath(context,
QName.create("foo", "cont"), QName.create("foo", "leaf2"));
- final EffectiveStatement<?, ?> leaf2 = stack.currentStatement();
- assertThat(leaf2, instanceOf(LeafSchemaNode.class));
- final TypeDefinition<?> type = ((LeafSchemaNode) leaf2).getType();
- assertThat(type, instanceOf(LeafrefTypeDefinition.class));
+ final var leaf2 = assertInstanceOf(LeafSchemaNode.class, stack.currentStatement());
+ final var type = assertInstanceOf(LeafrefTypeDefinition.class, leaf2.getType());
- final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
- () -> stack.resolveLeafref((LeafrefTypeDefinition) type));
+ final var ex = assertThrows(IllegalArgumentException.class, () -> stack.resolveLeafref(type));
assertThat(ex.getMessage(), startsWith("Illegal parent access in YangLocationPath"));
- assertThat(ex.getCause(), instanceOf(NoSuchElementException.class));
+ assertInstanceOf(NoSuchElementException.class, ex.getCause());
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1231Test {
+class YT1231Test {
private static final QName FOO = QName.create("foo", "foo");
private static final QName BAR = QName.create("foo", "bar");
private static final QName BAZ = QName.create("foo", "baz");
private final SchemaInferenceStack stack = SchemaInferenceStack.of(CONTEXT);
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
CONTEXT = YangParserTestUtils.parseYangResource("/yt1231.yang");
}
@Test
- public void testEnterDataTree() {
+ void testEnterDataTree() {
// Trivial
- assertThat(stack.enterDataTree(FOO), instanceOf(ContainerEffectiveStatement.class));
+ assertInstanceOf(ContainerEffectiveStatement.class, stack.enterDataTree(FOO));
assertSame(CONTEXT.getModuleStatement(FOO.getModule()), stack.currentModule());
assertEquals(Absolute.of(FOO), stack.toSchemaNodeIdentifier());
- assertThat(stack.enterDataTree(FOO), instanceOf(ContainerEffectiveStatement.class));
+ assertInstanceOf(ContainerEffectiveStatement.class, stack.enterDataTree(FOO));
assertEquals(Absolute.of(FOO, FOO), stack.toSchemaNodeIdentifier());
stack.exit();
// Has to cross four layers of choice/case
- assertThat(stack.enterDataTree(XYZZY), instanceOf(ContainerEffectiveStatement.class));
+ assertInstanceOf(ContainerEffectiveStatement.class, stack.enterDataTree(XYZZY));
assertEquals(Absolute.of(FOO, BAR, BAR, BAZ, BAZ, XYZZY), stack.toSchemaNodeIdentifier());
stack.exit();
- assertThat(stack.enterSchemaTree(BAR), instanceOf(ChoiceEffectiveStatement.class));
- assertThat(stack.enterSchemaTree(BAR), instanceOf(CaseEffectiveStatement.class));
+ assertInstanceOf(ChoiceEffectiveStatement.class, stack.enterSchemaTree(BAR));
+ assertInstanceOf(CaseEffectiveStatement.class, stack.enterSchemaTree(BAR));
assertEquals(Absolute.of(FOO, BAR, BAR), stack.toSchemaNodeIdentifier());
}
@Test
- public void testEnterChoice() {
+ void testEnterChoice() {
// Simple
- assertThat(stack.enterDataTree(FOO), instanceOf(ContainerEffectiveStatement.class));
+ assertInstanceOf(ContainerEffectiveStatement.class, stack.enterDataTree(FOO));
assertEquals(Absolute.of(FOO), stack.toSchemaNodeIdentifier());
- assertThat(stack.enterChoice(BAR), instanceOf(ChoiceEffectiveStatement.class));
+ assertInstanceOf(ChoiceEffectiveStatement.class, stack.enterChoice(BAR));
assertEquals(Absolute.of(FOO, BAR), stack.toSchemaNodeIdentifier());
// Has to cross choice -> case -> choice
- assertThat(stack.enterChoice(BAZ), instanceOf(ChoiceEffectiveStatement.class));
+ assertInstanceOf(ChoiceEffectiveStatement.class, stack.enterChoice(BAZ));
assertEquals(Absolute.of(FOO, BAR, BAR, BAZ), stack.toSchemaNodeIdentifier());
// Now the same with just case -> choice
stack.exit();
- assertThat(stack.enterSchemaTree(BAR), instanceOf(CaseEffectiveStatement.class));
- assertThat(stack.enterChoice(BAZ), instanceOf(ChoiceEffectiveStatement.class));
+ assertInstanceOf(CaseEffectiveStatement.class, stack.enterSchemaTree(BAR));
+ assertInstanceOf(ChoiceEffectiveStatement.class, stack.enterChoice(BAZ));
assertEquals(Absolute.of(FOO, BAR, BAR, BAZ), stack.toSchemaNodeIdentifier());
}
@Test
- public void testEnterChoiceToRootContainer() {
+ void testEnterChoiceToRootContainer() {
assertEquals("Choice (foo)foo not present", assertEnterChoiceThrows(FOO));
}
@Test
- public void testEnterChoiceToNestedContainer() {
- assertThat(stack.enterDataTree(FOO), instanceOf(ContainerEffectiveStatement.class));
+ void testEnterChoiceToNestedContainer() {
+ assertInstanceOf(ContainerEffectiveStatement.class, stack.enterDataTree(FOO));
assertEquals(Absolute.of(FOO), stack.toSchemaNodeIdentifier());
assertEquals("Choice (foo)foo not present in schema parent (foo)foo", assertEnterChoiceThrows(FOO));
}
@Test
- public void testEnterChoiceNonExistent() {
- assertThat(stack.enterDataTree(FOO), instanceOf(ContainerEffectiveStatement.class));
+ void testEnterChoiceNonExistent() {
+ assertInstanceOf(ContainerEffectiveStatement.class, stack.enterDataTree(FOO));
assertEquals(Absolute.of(FOO), stack.toSchemaNodeIdentifier());
- assertThat(stack.enterSchemaTree(BAR), instanceOf(ChoiceEffectiveStatement.class));
+ assertInstanceOf(ChoiceEffectiveStatement.class, stack.enterSchemaTree(BAR));
assertEquals("Choice (foo)foo not present in schema parent (foo)bar", assertEnterChoiceThrows(FOO));
assertEquals("Choice (foo)bar not present in schema parent (foo)bar", assertEnterChoiceThrows(BAR));
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.NoSuchElementException;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1233Test {
+class YT1233Test {
private static EffectiveModelContext context;
private final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
context = YangParserTestUtils.parseYangResource("/yt1233.yang");
}
@Test
- public void testExitToDataTree() {
- final DataTreeEffectiveStatement<?> foo = stack.enterDataTree(QName.create("foo", "foo"));
+ void testExitToDataTree() {
+ final var foo = stack.enterDataTree(QName.create("foo", "foo"));
assertSame(foo, stack.exitToDataTree());
assertTrue(stack.isEmpty());
assertSame(foo, stack.enterDataTree(foo.argument()));
}
@Test
- public void testExitToGrouping() {
- final GroupingEffectiveStatement baz = stack.enterGrouping(QName.create("foo", "baz"));
+ void testExitToGrouping() {
+ final var baz = stack.enterGrouping(QName.create("foo", "baz"));
assertTrue(stack.inGrouping());
- final DataTreeEffectiveStatement<?> xyzzy = stack.enterDataTree(QName.create("foo", "xyzzy"));
+ final var xyzzy = stack.enterDataTree(QName.create("foo", "xyzzy"));
assertSame(xyzzy, stack.exitToDataTree());
assertSame(baz, stack.currentStatement());
assertSame(xyzzy, stack.enterDataTree(xyzzy.argument()));
}
@Test
- public void testEmptyExitToDataTree() {
+ void testEmptyExitToDataTree() {
assertThrows(NoSuchElementException.class, stack::exitToDataTree);
}
@Test
- public void testSchemaExitToDataTree() {
+ void testSchemaExitToDataTree() {
stack.enterSchemaTree(QName.create("foo", "bar"));
- final IllegalStateException ex = assertThrows(IllegalStateException.class, stack::exitToDataTree);
+ final var ex = assertThrows(IllegalStateException.class, stack::exitToDataTree);
assertThat(ex.getMessage(), startsWith("Unexpected current "));
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PathEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1282Test {
+class YT1282Test {
private static EffectiveModelContext context;
private final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
context = YangParserTestUtils.parseYangResource("/yt1282.yang");
}
@Test
- public void testResolveTypedef() {
+ void testResolveTypedef() {
final TypeEffectiveStatement<?> type = stack.enterTypedef(QName.create("foo", "foo"))
- .findFirstEffectiveSubstatement(TypeEffectiveStatement.class).orElseThrow();
+ .findFirstEffectiveSubstatement(TypeEffectiveStatement.class).orElseThrow();
assertFalse(stack.inInstantiatedContext());
assertFalse(stack.inGrouping());
- final EffectiveStatement<?, ?> bar = stack.resolvePathExpression(
- type.findFirstEffectiveSubstatementArgument(PathEffectiveStatement.class).orElseThrow());
- assertThat(bar, instanceOf(LeafEffectiveStatement.class));
+ final var bar = assertInstanceOf(LeafEffectiveStatement.class,
+ stack.resolvePathExpression(
+ type.findFirstEffectiveSubstatementArgument(PathEffectiveStatement.class).orElseThrow()));
assertEquals(QName.create("foo", "bar"), bar.argument());
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1283Test {
+class YT1283Test {
private static final QName FOO = QName.create("foo", "foo");
private static final QName BAR = QName.create("foo", "bar");
private final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
context = YangParserTestUtils.parseYangResource("/yt1283.yang");
}
@Test
- public void testResolveUnderCaseViaDataTree() {
- assertThat(stack.enterDataTree(FOO), instanceOf(ContainerEffectiveStatement.class));
+ void testResolveUnderCaseViaDataTree() {
+ assertInstanceOf(ContainerEffectiveStatement.class, stack.enterDataTree(FOO));
assertResolve(stack.enterDataTree(FOO));
}
@Test
- public void testResolveUnderCaseViaSchemaTree() {
- assertThat(stack.enterSchemaTree(FOO), instanceOf(ContainerEffectiveStatement.class));
- assertThat(stack.enterSchemaTree(FOO), instanceOf(ChoiceEffectiveStatement.class));
- assertThat(stack.enterSchemaTree(FOO), instanceOf(CaseEffectiveStatement.class));
+ void testResolveUnderCaseViaSchemaTree() {
+ assertInstanceOf(ContainerEffectiveStatement.class, stack.enterSchemaTree(FOO));
+ assertInstanceOf(ChoiceEffectiveStatement.class, stack.enterSchemaTree(FOO));
+ assertInstanceOf(CaseEffectiveStatement.class, stack.enterSchemaTree(FOO));
assertResolve(stack.enterSchemaTree(FOO));
}
private void assertResolve(final EffectiveStatement<?, ?> foo) {
- assertThat(foo, instanceOf(LeafEffectiveStatement.class));
+ assertInstanceOf(LeafEffectiveStatement.class, foo);
final TypeEffectiveStatement<?> type = foo.findFirstEffectiveSubstatement(TypeEffectiveStatement.class)
.orElseThrow();
- final EffectiveStatement<?, ?> bar = stack.resolvePathExpression(
- type.findFirstEffectiveSubstatementArgument(PathEffectiveStatement.class).orElseThrow());
- assertThat(bar, instanceOf(LeafEffectiveStatement.class));
+ final var bar = assertInstanceOf(LeafEffectiveStatement.class,
+ stack.resolvePathExpression(
+ type.findFirstEffectiveSubstatementArgument(PathEffectiveStatement.class).orElseThrow()));
assertEquals(BAR, bar.argument());
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import com.google.common.collect.Iterables;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1291Test {
+class YT1291Test {
private static final QName FOO = QName.create("foo", "foo");
private static final QName INPUT = QName.create("foo", "input");
private static final QName OUTPUT = QName.create("foo", "output");
private static EffectiveModelContext context;
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
context = YangParserTestUtils.parseYangResource("/yt1291.yang");
}
@Test
- public void testRpcIndexing() {
- final SchemaTreeEffectiveStatement<?> foo = Iterables.getOnlyElement(context.getModuleStatements().values())
- .findSchemaTreeNode(FOO).orElseThrow();
- assertThat(foo, instanceOf(RpcEffectiveStatement.class));
- final RpcEffectiveStatement rpc = (RpcEffectiveStatement) foo;
-
- assertThat(rpc.findDataTreeNode(INPUT).orElseThrow(), instanceOf(InputEffectiveStatement.class));
- assertThat(rpc.findDataTreeNode(OUTPUT).orElseThrow(), instanceOf(OutputEffectiveStatement.class));
+ void testRpcIndexing() {
+ final var rpc = assertInstanceOf(RpcEffectiveStatement.class,
+ Iterables.getOnlyElement(context.getModuleStatements().values()).findSchemaTreeNode(FOO).orElseThrow());
+ assertInstanceOf(InputEffectiveStatement.class, rpc.findDataTreeNode(INPUT).orElseThrow());
+ assertInstanceOf(OutputEffectiveStatement.class, rpc.findDataTreeNode(OUTPUT).orElseThrow());
}
@Test
- public void testEnterDataTree() {
- final SchemaInferenceStack stack = SchemaInferenceStack.of(context, Absolute.of(FOO));
- assertThat(stack.enterDataTree(INPUT), instanceOf(InputEffectiveStatement.class));
+ void testEnterDataTree() {
+ final var stack = SchemaInferenceStack.of(context, Absolute.of(FOO));
+ assertInstanceOf(InputEffectiveStatement.class, stack.enterDataTree(INPUT));
stack.exit();
- assertThat(stack.enterDataTree(OUTPUT), instanceOf(OutputEffectiveStatement.class));
+ assertInstanceOf(OutputEffectiveStatement.class, stack.enterDataTree(OUTPUT));
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import com.google.common.collect.Iterables;
import java.util.Optional;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1292Test {
+class YT1292Test {
private static final QName FOO = QName.create("foo", "foo");
private static final QName BAR = QName.create("foo", "bar");
private static final QName BAZ = QName.create("foo", "baz");
private ContainerEffectiveStatement baz;
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
module = Iterables.getOnlyElement(YangParserTestUtils.parseYangResource("/yt1292.yang").getModuleStatements()
- .values());
+ .values());
}
- @Before
- public void before() {
- final DataTreeEffectiveStatement<?> tmp = module.findDataTreeNode(BAZ).orElseThrow();
- assertThat(tmp, instanceOf(ContainerEffectiveStatement.class));
- baz = (ContainerEffectiveStatement) tmp;
+ @BeforeEach
+ void before() {
+ baz = assertInstanceOf(ContainerEffectiveStatement.class, module.findDataTreeNode(BAZ).orElseThrow());
}
@Test
- public void testRpc() {
+ void testRpc() {
assertEquals(Optional.empty(), module.findDataTreeNode(FOO));
- final SchemaTreeEffectiveStatement<?> foo = module.findSchemaTreeNode(FOO).orElseThrow();
- assertThat(foo, instanceOf(RpcEffectiveStatement.class));
+ assertInstanceOf(RpcEffectiveStatement.class, module.findSchemaTreeNode(FOO).orElseThrow());
}
@Test
- public void testNotification() {
+ void testNotification() {
assertEquals(Optional.empty(), module.findDataTreeNode(BAR));
- SchemaTreeEffectiveStatement<?> bar = module.findSchemaTreeNode(BAR).orElseThrow();
- assertThat(bar, instanceOf(NotificationEffectiveStatement.class));
+ assertInstanceOf(NotificationEffectiveStatement.class, module.findSchemaTreeNode(BAR).orElseThrow());
assertEquals(Optional.empty(), baz.findDataTreeNode(BAR));
- bar = baz.findSchemaTreeNode(BAR).orElseThrow();
- assertThat(bar, instanceOf(NotificationEffectiveStatement.class));
+ assertInstanceOf(NotificationEffectiveStatement.class, baz.findSchemaTreeNode(BAR).orElseThrow());
}
@Test
- public void testAction() {
+ void testAction() {
assertEquals(Optional.empty(), baz.findDataTreeNode(FOO));
- final SchemaTreeEffectiveStatement<?> foo = baz.findSchemaTreeNode(FOO).orElseThrow();
- assertThat(foo, instanceOf(ActionEffectiveStatement.class));
+ assertInstanceOf(ActionEffectiveStatement.class, baz.findSchemaTreeNode(FOO).orElseThrow());
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1297Test {
+class YT1297Test {
private static final QNameModule RESTCONF =
QNameModule.create(XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-restconf"), Revision.of("2017-01-26"));
private static final QNameModule BAD_MODULE =
private final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
context = YangParserTestUtils.parseYangResource("/ietf-restconf.yang");
}
@Test
- public void testEnterYangData() {
+ void testEnterYangData() {
assertNotNull(stack.enterYangData(new YangDataName(RESTCONF, "yang-api")));
assertNotNull(stack.enterDataTree(QName.create(RESTCONF, "restconf")));
}
@Test
- public void testEnterYangDataNegative() {
+ void testEnterYangDataNegative() {
Exception ex = assertThrows(IllegalArgumentException.class,
() -> stack.enterYangData(new YangDataName(RESTCONF, "bad-name")));
assertEquals("yang-data bad-name not present in " + RESTCONF, ex.getMessage());
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertSame;
import com.google.common.collect.Iterables;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1404Test {
+class YT1404Test {
private static final QName FOO = QName.create("foo", "foo");
private static final QName BAR = QName.create("foo", "bar");
private static final QName BAZ = QName.create("foo", "baz");
@Test
- public void testDeviatedEffectiveAugmentationSchema() {
+ void testDeviatedEffectiveAugmentationSchema() {
final var module = YangParserTestUtils.parseYangResourceDirectory("/yt1404").findModule("foo").orElseThrow();
final var augment = Iterables.getOnlyElement(module.getAugmentations());
assertEquals(2, augment.getChildNodes().size());
- assertThat(augment.dataChildByName(BAR), instanceOf(LeafSchemaNode.class));
- assertThat(augment.dataChildByName(BAZ), instanceOf(LeafSchemaNode.class));
+ assertInstanceOf(LeafSchemaNode.class, augment.dataChildByName(BAR));
+ assertInstanceOf(LeafSchemaNode.class, augment.dataChildByName(BAZ));
- final var foo = module.getDataChildByName(FOO);
- assertThat(foo, instanceOf(ContainerSchemaNode.class));
- final var fooCont = (ContainerSchemaNode) foo;
- assertEquals(1, fooCont.getChildNodes().size());
- final var fooBar = fooCont.dataChildByName(BAR);
- assertThat(fooBar, instanceOf(LeafSchemaNode.class));
+ final var foo = assertInstanceOf(ContainerSchemaNode.class, module.getDataChildByName(FOO));
+ assertEquals(1, foo.getChildNodes().size());
+ final var fooBar = assertInstanceOf(LeafSchemaNode.class, foo.dataChildByName(BAR));
- final var fooAugment = Iterables.getOnlyElement(fooCont.getAvailableAugmentations());
+ final var fooAugment = Iterables.getOnlyElement(foo.getAvailableAugmentations());
assertSame(augment, fooAugment);
- final var effectiveAug = new EffectiveAugmentationSchema(augment, fooCont);
+ final var effectiveAug = new EffectiveAugmentationSchema(augment, foo);
assertEquals(1, effectiveAug.getChildNodes().size());
assertSame(fooBar, effectiveAug.getDataChildByName(BAR));
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableList;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.opendaylight.yangtools.yang.model.spi.DefaultSchemaTreeInference;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT1414Test {
+class YT1414Test {
private static final QName MY_CONTAINER = QName.create("uri:my-module", "2014-10-07", "my-container");
private static final QName MY_LIST = QName.create(MY_CONTAINER, "my-list");
private static final Absolute MY_LIST_ID = Absolute.of(MY_CONTAINER, MY_LIST);
private static final Absolute BAR_FOO_ID = Absolute.of(BAR, FOO);
@Test
- public void testToFromSchemaTreeInference() {
+ void testToFromSchemaTreeInference() {
final var stack = SchemaInferenceStack.of(
- YangParserTestUtils.parseYangResourceDirectory("/schema-context-util"));
+ YangParserTestUtils.parseYangResourceDirectory("/schema-context-util"));
stack.enterSchemaTree(MY_LIST_ID);
- final var inference = stack.toSchemaTreeInference();
- assertThat(inference, instanceOf(DefaultSchemaTreeInference.class));
+ final var inference = assertInstanceOf(DefaultSchemaTreeInference.class, stack.toSchemaTreeInference());
assertEquals(MY_LIST_ID, inference.toSchemaNodeIdentifier());
assertEquals(MY_LIST_ID, stack.toSchemaNodeIdentifier());
assertEquals(MY_LIST_ID, SchemaInferenceStack.ofInference(inference).toSchemaNodeIdentifier());
}
@Test
- public void testOfUntrustedSchemaTreeInference() {
+ void testOfUntrustedSchemaTreeInference() {
final var context = YangParserTestUtils.parseYangResource("/yt1414.yang");
final var foo = context.findSchemaTreeNode(Absolute.of(FOO)).orElseThrow();
final var bar = context.findSchemaTreeNode(Absolute.of(BAR)).orElseThrow();
final var correct = DefaultSchemaTreeInference.of(context, BAR_FOO_ID);
assertEquals(List.of(bar, barFoo), correct.statementPath());
assertEquals(correct.statementPath(),
- SchemaInferenceStack.ofUntrusted(correct).toSchemaTreeInference().statementPath());
+ SchemaInferenceStack.ofUntrusted(correct).toSchemaTreeInference().statementPath());
// Now let's try some abuse: we use 'foo' instead of 'barFoo', created unsafely ...
final var incorrect = DefaultSchemaTreeInference.unsafeOf(context, ImmutableList.of(bar, foo));
// ... the default non-verify method is happy to oblige ...
assertEquals(incorrect.statementPath(),
- SchemaInferenceStack.ofInference(incorrect).toSchemaTreeInference().statementPath());
+ SchemaInferenceStack.ofInference(incorrect).toSchemaTreeInference().statementPath());
// ... but ofUntrusted() will reject it
assertEquals("Provided " + incorrect + " is not consistent with resolved path " + correct,
- assertThrows(IllegalArgumentException.class, () -> SchemaInferenceStack.ofUntrusted(incorrect))
- .getMessage());
+ assertThrows(IllegalArgumentException.class, () -> SchemaInferenceStack.ofUntrusted(incorrect))
+ .getMessage());
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.PathExpression;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT588Test {
+class YT588Test {
private static final String NS = "foo";
private static final String REV = "2016-03-01";
@Test
- public void test() {
- EffectiveModelContext context = YangParserTestUtils.parseYangResource("/yt588.yang");
-
- QName root = QName.create(NS, REV, "root");
- QName leafRef2 = QName.create(NS, REV, "leaf-ref-2");
- QName conGrp = QName.create(NS, REV, "con-grp");
- QName leafRef = QName.create(NS, REV, "leaf-ref");
-
- SchemaNode findDataSchemaNode = context.findDataTreeChild(root, conGrp, leafRef).get();
- SchemaNode findDataSchemaNode2 = context.findDataTreeChild(root, leafRef2).get();
- assertThat(findDataSchemaNode, isA(LeafSchemaNode.class));
- assertThat(findDataSchemaNode2, isA(LeafSchemaNode.class));
-
- LeafSchemaNode leafRefNode = (LeafSchemaNode) findDataSchemaNode;
- LeafSchemaNode leafRefNode2 = (LeafSchemaNode) findDataSchemaNode2;
-
- assertThat(leafRefNode.getType(), isA(LeafrefTypeDefinition.class));
- assertThat(leafRefNode2.getType(), isA(LeafrefTypeDefinition.class));
-
- EffectiveStatement<?, ?> found = SchemaInferenceStack.ofDataTreePath(context, root, conGrp, leafRef)
- .resolvePathExpression(((LeafrefTypeDefinition) leafRefNode.getType()).getPathStatement());
- assertThat(((TypedDataSchemaNode)found).getType(), isA(BinaryTypeDefinition.class));
+ void test() {
+ final var context = YangParserTestUtils.parseYangResource("/yt588.yang");
+ final var root = QName.create(NS, REV, "root");
+ final var leafRef2 = QName.create(NS, REV, "leaf-ref-2");
+ final var conGrp = QName.create(NS, REV, "con-grp");
+ final var leafRef = QName.create(NS, REV, "leaf-ref");
+
+ assertResolvedTypeDefinition(BinaryTypeDefinition.class,
+ SchemaInferenceStack.ofDataTreePath(context, root, conGrp, leafRef),
+ assertInstanceOf(LeafrefTypeDefinition.class,
+ assertInstanceOf(LeafSchemaNode.class, context.findDataTreeChild(root, conGrp, leafRef).orElseThrow())
+ .getType()).getPathStatement());
+
+ assertResolvedTypeDefinition(Int16TypeDefinition.class,
+ SchemaInferenceStack.ofDataTreePath(context, root, leafRef2),
+ assertInstanceOf(LeafrefTypeDefinition.class,
+ assertInstanceOf(LeafSchemaNode.class, context.findDataTreeChild(root, leafRef2).orElseThrow())
+ .getType()).getPathStatement());
+ }
- found = SchemaInferenceStack.ofDataTreePath(context, root, leafRef2)
- .resolvePathExpression(((LeafrefTypeDefinition) leafRefNode2.getType()).getPathStatement());
- assertThat(((TypedDataSchemaNode)found).getType(), isA(Int16TypeDefinition.class));
+ private static void assertResolvedTypeDefinition(final Class<? extends TypeDefinition<?>> expectedType,
+ final SchemaInferenceStack stack, final PathExpression expression) {
+ final var typed = assertInstanceOf(TypedDataSchemaNode.class, stack.resolvePathExpression(expression));
+ assertInstanceOf(expectedType, typed.getType());
}
}
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import com.google.common.collect.ImmutableSet;
import java.util.Set;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.spi.SimpleSchemaContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class YT691Test {
+class YT691Test {
@Test
- public void testGetAllModuleIdentifiers() {
- final SourceIdentifier foo = new SourceIdentifier("foo", "2016-01-01");
- final SourceIdentifier sub1Foo = new SourceIdentifier("sub1-foo", "2016-01-01");
- final SourceIdentifier sub2Foo = new SourceIdentifier("sub2-foo", "2016-01-01");
- final SourceIdentifier bar = new SourceIdentifier("bar", "2016-01-01");
- final SourceIdentifier sub1Bar = new SourceIdentifier("sub1-bar", "2016-01-01");
- final SourceIdentifier baz = new SourceIdentifier("baz", "2016-01-01");
- final Set<SourceIdentifier> testSet = ImmutableSet.of(foo, sub1Foo, sub2Foo, bar, sub1Bar, baz);
- final EffectiveModelContext context = YangParserTestUtils.parseYangResourceDirectory("/yt691");
- final Set<SourceIdentifier> allModuleIdentifiers = SchemaContextUtil.getConstituentModuleIdentifiers(context);
+ void testGetAllModuleIdentifiers() {
+ final var foo = new SourceIdentifier("foo", "2016-01-01");
+ final var sub1Foo = new SourceIdentifier("sub1-foo", "2016-01-01");
+ final var sub2Foo = new SourceIdentifier("sub2-foo", "2016-01-01");
+ final var bar = new SourceIdentifier("bar", "2016-01-01");
+ final var sub1Bar = new SourceIdentifier("sub1-bar", "2016-01-01");
+ final var baz = new SourceIdentifier("baz", "2016-01-01");
+ final var context = YangParserTestUtils.parseYangResourceDirectory("/yt691");
+ final var allModuleIdentifiers = SchemaContextUtil.getConstituentModuleIdentifiers(context);
assertEquals(6, allModuleIdentifiers.size());
- final Set<SourceIdentifier> allModuleIdentifiersResolved = SchemaContextUtil.getConstituentModuleIdentifiers(
- SimpleSchemaContext.forModules(context.getModules()));
+ final var allModuleIdentifiersResolved = SchemaContextUtil.getConstituentModuleIdentifiers(
+ SimpleSchemaContext.forModules(context.getModules()));
assertEquals(6, allModuleIdentifiersResolved.size());
assertEquals(allModuleIdentifiersResolved, allModuleIdentifiers);
- assertEquals(allModuleIdentifiers, testSet);
+ assertEquals(Set.of(foo, sub1Foo, sub2Foo, bar, sub1Bar, baz), allModuleIdentifiers);
assertTrue(allModuleIdentifiers.contains(foo));
}
}
\ No newline at end of file