import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
/**
"parser-identifier:cont2/listTest/list-in-grouping=name/leaf-A.B";
// schema context with test modules
- private SchemaContext schemaContext;
+ private EffectiveModelContext schemaContext;
// contains the same modules but it is different object (it can be compared with equals)
- private SchemaContext schemaContextOnMountPoint;
+ private EffectiveModelContext schemaContextOnMountPoint;
private static final String TEST_MODULE_NAME = "test-module";
private static final String TEST_MODULE_REVISION = "2016-06-02";
private static final String TEST_MODULE_NAMESPACE = "test:module";
private static final String INVOKE_RPC = "invoke-rpc-module:rpc-test";
+ private static final String INVOKE_ACTION = "example-actions:interfaces/interface=eth0/reset";
// mount point and mount point service
private DOMMountPoint mountPoint;
.getInstance();
// register mount point with null schema context
- when(this.mockMountPoint.getSchemaContext()).thenReturn(null);
- when(this.mockMountPointService.getMountPoint(YangInstanceIdentifier.EMPTY))
+ when(this.mockMountPoint.getEffectiveModelContext()).thenReturn(null);
+ when(this.mockMountPointService.getMountPoint(YangInstanceIdentifier.empty()))
.thenReturn(Optional.of(this.mockMountPoint));
}
final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
null, this.schemaContext, Optional.empty());
assertEquals("Returned not expected identifier",
- YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
+ YangInstanceIdentifier.empty(), context.getInstanceIdentifier());
}
/**
final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
"", this.schemaContext, Optional.empty());
assertEquals("Returned not expected identifier",
- YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
+ YangInstanceIdentifier.empty(), context.getInstanceIdentifier());
}
/**
- * Negative test with invalid test identifier. Test should fail with <code>IllegalArgumentException</code>.
+ * Negative test with invalid test identifier. Test should fail with <code>RestconfDocumentedException</code>.
*/
@Test
public void toInstanceIdentifierInvalidIdentifierNegativeTest() {
- this.thrown.expect(IllegalArgumentException.class);
+ this.thrown.expect(RestconfDocumentedException.class);
ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, this.schemaContext, Optional.empty());
}
/**
* Negative test when identifier contains {@link RestconfConstants#MOUNT} but identifier part is not valid. Test
- * should fail with <code>IllegalArgumentException</code>.
+ * should fail with <code>RestconfDocumentedException</code>.
*/
@Test
public void toInstanceIdentifierMountPointInvalidIdentifierNegativeTest() {
- this.thrown.expect(IllegalArgumentException.class);
+ this.thrown.expect(RestconfDocumentedException.class);
ParserIdentifier.toInstanceIdentifier(
INVALID_MOUNT_POINT_IDENT, this.schemaContext, Optional.of(this.mountPointService));
}
RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
assertEquals("Not expected error tag",
ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
- assertEquals("Not expected error status code",
- 404, e.getErrors().get(0).getErrorTag().getStatusCode());
}
}
assertEquals(this.mountPoint, result.getMountPoint());
assertEquals(this.schemaContextOnMountPoint, result.getSchemaContext());
}
+
+ /**
+ * Test Action.
+ * Verify if Action schema node was found.
+ */
+ @Test
+ public void invokeActionTest() {
+ final InstanceIdentifierContext<?> result = ParserIdentifier
+ .toInstanceIdentifier(INVOKE_ACTION, this.schemaContext, Optional.empty());
+
+ // Action schema node
+ final QName actionQName = result.getSchemaNode().getQName();
+ assertEquals("https://example.com/ns/example-actions", actionQName.getModule().getNamespace().toString());
+ assertEquals("reset", actionQName.getLocalName());
+
+ // other fields
+ assertEquals(IdentifierCodec.deserialize(INVOKE_ACTION, schemaContext), result.getInstanceIdentifier());
+ assertNull(result.getMountPoint());
+ assertSame(this.schemaContext, result.getSchemaContext());
+ }
+
+ /**
+ * Test invoke Action on mount point.
+ * Verify if Action schema node was found.
+ */
+ @Test
+ public void invokeActionOnMountPointTest() {
+ final InstanceIdentifierContext<?> result = ParserIdentifier
+ .toInstanceIdentifier(MOUNT_POINT_IDENT + "/" + INVOKE_ACTION, this.schemaContext,
+ Optional.of(this.mountPointService));
+
+ // Action schema node
+ final QName actionQName = result.getSchemaNode().getQName();
+ assertEquals("https://example.com/ns/example-actions", actionQName.getModule().getNamespace().toString());
+ assertEquals("reset", actionQName.getLocalName());
+
+ // other fields
+ assertEquals(IdentifierCodec.deserialize(INVOKE_ACTION, schemaContext), result.getInstanceIdentifier());
+ assertEquals(this.mountPoint, result.getMountPoint());
+ assertEquals(this.schemaContextOnMountPoint, result.getSchemaContext());
+ }
}