import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
-import static org.mockito.Mockito.when;
-import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl;
import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
+import org.opendaylight.restconf.api.ApiPath;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.nb.rfc8040.legacy.ErrorTags;
import org.opendaylight.yangtools.yang.common.ErrorTag;
YangParserTestUtils.parseYangResourceDirectory("/parser-identifier");
// mount point and mount point service
+ private final DOMMountPointService mountPointService = new DOMMountPointServiceImpl();
private DOMMountPoint mountPoint;
- private DOMMountPointService mountPointService;
// mock mount point and mount point service
@Mock
@Before
public void setup() throws Exception {
- mountPointService = new DOMMountPointServiceImpl();
-
// create and register mount point
final var mountPointId = YangInstanceIdentifier.builder()
.node(QName.create("mount:point", "2016-06-02", "mount-container"))
.addService(DOMSchemaService.class, FixedDOMSchemaService.of(MODEL_CONTEXT_ON_MOUNT_POINT))
.register()
.getInstance();
-
- // register mount point with null schema context
- when(mockMountPointService.getMountPoint(YangInstanceIdentifier.of()))
- .thenReturn(Optional.of(mockMountPoint));
}
/**
assertEquals(MODEL_CONTEXT_ON_MOUNT_POINT, context.getSchemaContext());
}
- /**
- * Test of creating <code>InstanceIdentifierContext</code> when identifier is <code>null</code>.
- * <code>{@link YangInstanceIdentifier#empty()}</code> should be returned.
- */
- @Test
- public void toInstanceIdentifierNullIdentifierTest() {
- final var context = ParserIdentifier.toInstanceIdentifier(null, MODEL_CONTEXT, null);
- assertEquals(YangInstanceIdentifier.of(), context.getInstanceIdentifier());
- }
-
/**
* Negative test of creating <code>InstanceIdentifierContext</code> when <code>SchemaContext</code> is
* <code>null</code>. Test fails expecting <code>NullPointerException</code>.
@Test
public void toInstanceIdentifierMissingMountPointNegativeTest() {
final var ex = assertThrows(RestconfDocumentedException.class,
- () -> ParserIdentifier.toInstanceIdentifier("/yang-ext:mount", MODEL_CONTEXT, mountPointService));
+ () -> ParserIdentifier.toInstanceIdentifier("yang-ext:mount", MODEL_CONTEXT, mountPointService));
final var errors = ex.getErrors();
assertEquals(1, errors.size());
final var error = errors.get(0);
- assertEquals("Mount point does not exist.", error.getErrorMessage());
+ assertEquals("Mount point '' does not exist", error.getErrorMessage());
assertEquals(ErrorType.PROTOCOL, error.getErrorType());
assertEquals(ErrorTags.RESOURCE_DENIED_TRANSPORT, error.getErrorTag());
}
@Test
public void toSchemaExportContextFromIdentifierNullSchemaContextBehindMountPointNegativeTest() {
- assertThrows(IllegalStateException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
- MODEL_CONTEXT, "/yang-ext:mount/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
- mockMountPointService, sourceProvider));
+ final var ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.toSchemaExportContextFromIdentifier(MODEL_CONTEXT,
+ "/yang-ext:mount/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, mockMountPointService,
+ sourceProvider));
+ final var errors = ex.getErrors();
+ assertEquals(1, errors.size());
+ final var error = errors.get(0);
+ // FIXME: this should be something different
+ assertEquals("Identifier may not be empty", error.getErrorMessage());
+ assertEquals(ErrorType.PROTOCOL, error.getErrorType());
+ assertEquals(ErrorTag.INVALID_VALUE, error.getErrorTag());
}
/**
- * Test invoke RPC.
- *
- * <p>
- * Verify if RPC schema node was found.
+ * Test invoke RPC. Verify if RPC schema node was found.
*/
@Test
- public void invokeRpcTest() {
+ public void invokeRpcTest() throws Exception {
final var result = ParserIdentifier.toInstanceIdentifier(INVOKE_RPC, MODEL_CONTEXT, null);
// RPC schema node
assertEquals("rpc-test", rpcQName.getLocalName());
// other fields
- assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, MODEL_CONTEXT), result.getInstanceIdentifier());
+ assertEquals(IdentifierCodec.deserialize(ApiPath.parse(INVOKE_RPC), MODEL_CONTEXT),
+ result.getInstanceIdentifier());
assertEquals(null, result.getMountPoint());
assertEquals(MODEL_CONTEXT, result.getSchemaContext());
}
/**
- * Test invoke RPC on mount point.
- *
- * <p>
- * Verify if RPC schema node was found.
+ * Test invoke RPC on mount point. Verify if RPC schema node was found.
*/
@Test
- public void invokeRpcOnMountPointTest() {
+ public void invokeRpcOnMountPointTest() throws Exception {
final var result = ParserIdentifier.toInstanceIdentifier(MOUNT_POINT_IDENT + "/" + INVOKE_RPC, MODEL_CONTEXT,
mountPointService);
// RPC schema node
- final QName rpcQName = result.getSchemaNode().getQName();
+ final var rpcQName = result.getSchemaNode().getQName();
assertEquals("invoke:rpc:module", rpcQName.getModule().getNamespace().toString());
assertEquals("rpc-test", rpcQName.getLocalName());
// other fields
- assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, MODEL_CONTEXT), result.getInstanceIdentifier());
+ assertEquals(IdentifierCodec.deserialize(ApiPath.parse(INVOKE_RPC), MODEL_CONTEXT),
+ result.getInstanceIdentifier());
assertEquals(mountPoint, result.getMountPoint());
assertEquals(MODEL_CONTEXT_ON_MOUNT_POINT, result.getSchemaContext());
}
/**
- * Test Action.
- * Verify if Action schema node was found.
+ * Test Action. Verify if Action schema node was found.
*/
@Test
- public void invokeActionTest() {
+ public void invokeActionTest() throws Exception {
final var result = ParserIdentifier.toInstanceIdentifier(INVOKE_ACTION, MODEL_CONTEXT, null);
// Action schema node
- final QName actionQName = result.getSchemaNode().getQName();
+ final var 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, MODEL_CONTEXT), result.getInstanceIdentifier());
+ assertEquals(IdentifierCodec.deserialize(ApiPath.parse(INVOKE_ACTION), MODEL_CONTEXT),
+ result.getInstanceIdentifier());
assertNull(result.getMountPoint());
assertSame(MODEL_CONTEXT, result.getSchemaContext());
}
/**
- * Test invoke Action on mount point.
- * Verify if Action schema node was found.
+ * Test invoke Action on mount point. Verify if Action schema node was found.
*/
@Test
- public void invokeActionOnMountPointTest() {
+ public void invokeActionOnMountPointTest() throws Exception {
final var result = ParserIdentifier.toInstanceIdentifier(MOUNT_POINT_IDENT + "/" + INVOKE_ACTION,
MODEL_CONTEXT, mountPointService);
assertEquals("reset", actionQName.getLocalName());
// other fields
- assertEquals(IdentifierCodec.deserialize(INVOKE_ACTION, MODEL_CONTEXT), result.getInstanceIdentifier());
+ assertEquals(IdentifierCodec.deserialize(ApiPath.parse(INVOKE_ACTION), MODEL_CONTEXT),
+ result.getInstanceIdentifier());
assertEquals(mountPoint, result.getMountPoint());
assertEquals(MODEL_CONTEXT_ON_MOUNT_POINT, result.getSchemaContext());
}