* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.restconf.nb.rfc8040.utils.parser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableClassToInstanceMap;
-import com.google.common.collect.Maps;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Optional;
+import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.Rule;
+import org.junit.BeforeClass;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl;
-import org.opendaylight.controller.md.sal.dom.broker.spi.mount.SimpleDOMMountPoint;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
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.common.ErrorTags;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
import org.opendaylight.restconf.common.schema.SchemaExportContext;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+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;
/**
* Unit tests for {@link ParserIdentifier}.
*/
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class ParserIdentifierTest {
// mount point identifier
- private static final String MOUNT_POINT_IDENT =
- "mount-point:mount-container/point-number" + "/" + RestconfConstants.MOUNT;
+ private static final String MOUNT_POINT_IDENT = "mount-point:mount-container/point-number/yang-ext:mount";
// invalid mount point identifier
- private static final String INVALID_MOUNT_POINT_IDENT =
- "mount-point:point-number" + "/" + RestconfConstants.MOUNT;
+ private static final String INVALID_MOUNT_POINT_IDENT = "mount-point:point-number/yang-ext:mount";
// test identifier + expected result
private static final String TEST_IDENT =
private static final String INVALID_TEST_IDENT =
"parser-identifier:cont2/listTest/list-in-grouping=name/leaf-A.B";
- // schema context with test modules
- private SchemaContext schemaContext;
- // contains the same modules but it is different object (it can be compared with equals)
- private SchemaContext 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";
+
+ // schema context with test modules
+ private static EffectiveModelContext SCHEMA_CONTEXT;
+ // contains the same modules but it is different object (it can be compared with equals)
+ private static EffectiveModelContext SCHEMA_CONTEXT_ON_MOUNT_POINT;
// mount point and mount point service
private DOMMountPoint mountPoint;
@Mock
private DOMYangTextSourceProvider sourceProvider;
- @Rule
- public final ExpectedException thrown = ExpectedException.none();
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ SCHEMA_CONTEXT = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/parser-identifier"));
+ SCHEMA_CONTEXT_ON_MOUNT_POINT =
+ YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/parser-identifier"));
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ SCHEMA_CONTEXT = null;
+ SCHEMA_CONTEXT_ON_MOUNT_POINT = null;
+ }
@Before
public void setup() throws Exception {
- MockitoAnnotations.initMocks(this);
- this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/parser-identifier"));
- this.schemaContextOnMountPoint =
- YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/parser-identifier"));
+ mountPointService = new DOMMountPointServiceImpl();
// create and register mount point
- this.mountPoint = SimpleDOMMountPoint.create(
- YangInstanceIdentifier.builder()
- .node(QName.create("mount:point", "2016-06-02", "mount-container"))
- .node(QName.create("mount:point", "2016-06-02", "point-number"))
- .build(),
- ImmutableClassToInstanceMap.copyOf(Maps.newHashMap()),
- this.schemaContextOnMountPoint
- );
-
- this.mountPointService = new DOMMountPointServiceImpl();
- ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPoint);
+ final YangInstanceIdentifier mountPointId = YangInstanceIdentifier.builder()
+ .node(QName.create("mount:point", "2016-06-02", "mount-container"))
+ .node(QName.create("mount:point", "2016-06-02", "point-number"))
+ .build();
+
+ mountPoint = mountPointService.createMountPoint(mountPointId)
+ .addService(DOMSchemaService.class, FixedDOMSchemaService.of(SCHEMA_CONTEXT_ON_MOUNT_POINT))
+ .register()
+ .getInstance();
// register mount point with null schema context
- when(this.mockMountPoint.getSchemaContext()).thenReturn(null);
- when(this.mockMountPointService.getMountPoint(YangInstanceIdentifier.EMPTY))
- .thenReturn(Optional.of(this.mockMountPoint));
+ when(mockMountPointService.getMountPoint(YangInstanceIdentifier.empty()))
+ .thenReturn(Optional.of(mockMountPoint));
}
/**
*/
@Test
public void toInstanceIdentifierTest() {
- final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
- TEST_IDENT, this.schemaContext, Optional.absent());
+ final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier(
+ TEST_IDENT, SCHEMA_CONTEXT, Optional.empty());
assertEquals("Returned not expected identifier",
TEST_IDENT_RESULT, context .getInstanceIdentifier().toString());
*/
@Test
public void toInstanceIdentifierOtherModulesTest() {
- final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
- TEST_IDENT_OTHERS, this.schemaContext, Optional.absent());
+ final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier(
+ TEST_IDENT_OTHERS, SCHEMA_CONTEXT, Optional.empty());
assertEquals("Returned not expected identifier",
TEST_IDENT_OTHERS_RESULT, context.getInstanceIdentifier().toString());
*/
@Test
public void toInstanceIdentifierMountPointTest() {
- final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
- MOUNT_POINT_IDENT + "/" + TEST_IDENT, this.schemaContext, Optional.of(this.mountPointService));
+ final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier(
+ MOUNT_POINT_IDENT + "/" + TEST_IDENT, SCHEMA_CONTEXT, Optional.of(mountPointService));
assertEquals("Returned not expected identifier",
TEST_IDENT_RESULT.toString(), context.getInstanceIdentifier().toString());
assertEquals("Mount point not found",
- this.mountPoint, context.getMountPoint());
+ mountPoint, context.getMountPoint());
assertEquals("Schema context from mount point expected",
- this.schemaContextOnMountPoint, context.getSchemaContext());
+ SCHEMA_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.
+ * <code>{@link YangInstanceIdentifier#empty()}</code> should be returned.
*/
@Test
public void toInstanceIdentifierNullIdentifierTest() {
- final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
- null, this.schemaContext, Optional.absent());
+ final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier(
+ null, SCHEMA_CONTEXT, Optional.empty());
assertEquals("Returned not expected identifier",
- YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
+ YangInstanceIdentifier.empty(), context.getInstanceIdentifier());
}
/**
*/
@Test
public void toInstanceIdentifierNullSchemaContextNegativeTest() {
- this.thrown.expect(NullPointerException.class);
- ParserIdentifier.toInstanceIdentifier(TEST_IDENT, null, Optional.absent());
+ assertThrows(NullPointerException.class,
+ () -> ParserIdentifier.toInstanceIdentifier(TEST_IDENT, null, Optional.empty()));
}
/**
*/
@Test
public void toInstanceIdentifierEmptyIdentifierTest() {
- final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
- "", this.schemaContext, Optional.absent());
+ final InstanceIdentifierContext context = ParserIdentifier.toInstanceIdentifier(
+ "", SCHEMA_CONTEXT, 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);
- ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, this.schemaContext, Optional.absent());
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.toInstanceIdentifier(INVALID_TEST_IDENT, SCHEMA_CONTEXT, 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);
- ParserIdentifier.toInstanceIdentifier(
- INVALID_MOUNT_POINT_IDENT, this.schemaContext, Optional.of(this.mountPointService));
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.toInstanceIdentifier(INVALID_MOUNT_POINT_IDENT, SCHEMA_CONTEXT,
+ Optional.of(mountPointService)));
}
/**
*/
@Test
public void toInstanceIdentifierMissingMountPointNegativeTest() {
- try {
- ParserIdentifier.toInstanceIdentifier(
- "" + "/" + RestconfConstants.MOUNT, this.schemaContext, Optional.of(this.mountPointService));
- fail("Test should fail due to missing mount point");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Not expected error type",
- 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());
- }
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.toInstanceIdentifier("/yang-ext:mount", SCHEMA_CONTEXT,
+ Optional.of(mountPointService)));
+ final List<RestconfError> errors = ex.getErrors();
+ assertEquals(1, errors.size());
+ assertEquals("Not expected error type", ErrorType.PROTOCOL, errors.get(0).getErrorType());
+ assertEquals("Not expected error tag", ErrorTags.RESOURCE_DENIED_TRANSPORT, errors.get(0).getErrorTag());
}
/**
*/
@Test
public void toInstanceIdentifierMissingMountPointServiceNegativeTest() {
- try {
- ParserIdentifier.toInstanceIdentifier(RestconfConstants.MOUNT, this.schemaContext, Optional.absent());
- fail("Test should fail due to absent mount point service");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Not expected error type",
- ErrorType.APPLICATION, e.getErrors().get(0).getErrorType());
- assertEquals("Not expected error tag",
- ErrorTag.OPERATION_FAILED, e.getErrors().get(0).getErrorTag());
- assertEquals("Not expected error status code",
- 500, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.toInstanceIdentifier("yang-ext:mount", SCHEMA_CONTEXT, Optional.empty()));
+ assertEquals("Not expected error type", ErrorType.APPLICATION, ex.getErrors().get(0).getErrorType());
+ assertEquals("Not expected error tag", ErrorTag.OPERATION_FAILED, ex.getErrors().get(0).getErrorTag());
}
/**
*/
@Test
public void makeQNameFromIdentifierTest() {
- final QName qName = ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION);
+ final Entry<String, Revision> qName = ParserIdentifier.makeQNameFromIdentifier(
+ TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION);
assertNotNull("QName should be created", qName);
- assertEquals("Returned not expected module name",
- TEST_MODULE_NAME, qName.getLocalName());
- assertEquals("Returned not expected module revision",
- TEST_MODULE_REVISION, qName.getFormattedRevision());
+ assertEquals("Returned not expected module name", TEST_MODULE_NAME, qName.getKey());
+ assertEquals("Returned not expected module revision", Revision.of(TEST_MODULE_REVISION), qName.getValue());
}
/**
*/
@Test
public void makeQNameFromIdentifierInvalidIdentifierNegativeTest() {
- try {
- ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME);
- fail("Test should fail due to invalid identifier format");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Not expected error type",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Not expected error tag",
- RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
- assertEquals("Not expected error status code",
- 400, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME));
+ assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+ assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+ ex.getErrors().get(0).getErrorTag());
}
/**
*/
@Test
public void makeQNameFromIdentifierTooShortIdentifierNegativeTest() {
- try {
- ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME);
- fail("Test should fail due to too short identifier format");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Not expected error type",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Not expected error tag",
- RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
- assertEquals("Not expected error status code",
- 400, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME));
+ assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+ assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+ ex.getErrors().get(0).getErrorTag());
}
/**
*/
@Test
public void makeQNameFromIdentifierMountTest() {
- final QName qName = ParserIdentifier.makeQNameFromIdentifier(
+ final Entry<String, Revision> qName = ParserIdentifier.makeQNameFromIdentifier(
MOUNT_POINT_IDENT
+ "/"
+ TEST_MODULE_NAME
+ TEST_MODULE_REVISION);
assertNotNull("QName should be created", qName);
- assertEquals("Returned not expected module name",
- TEST_MODULE_NAME, qName.getLocalName());
- assertEquals("Returned not expected module revision",
- TEST_MODULE_REVISION, qName.getFormattedRevision());
+ assertEquals("Returned not expected module name", TEST_MODULE_NAME, qName.getKey());
+ assertEquals("Returned not expected module revision", Revision.of(TEST_MODULE_REVISION), qName.getValue());
}
/**
*/
@Test
public void makeQNameFromIdentifierMountPointInvalidIdentifierNegativeTest() {
- try {
- ParserIdentifier.makeQNameFromIdentifier(
- MOUNT_POINT_IDENT
- + "/"
- + TEST_MODULE_REVISION
- + "/"
- + TEST_MODULE_NAME);
-
- fail("Test should fail due to invalid identifier format");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Not expected error type",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Not expected error tag",
- RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
- assertEquals("Not expected error status code",
- 400, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.makeQNameFromIdentifier(
+ MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME));
+ assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+ assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+ ex.getErrors().get(0).getErrorTag());
}
/**
*/
@Test
public void makeQNameFromIdentifierMountPointTooShortIdentifierNegativeTest() {
- try {
- ParserIdentifier.makeQNameFromIdentifier(
- MOUNT_POINT_IDENT
- + "/"
- + TEST_MODULE_NAME);
-
- fail("Test should fail due to too short identifier format");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Not expected error type",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Not expected error tag",
- RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
- assertEquals("Not expected error status code",
- 400, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.makeQNameFromIdentifier(MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME));
+ assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+ assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+ ex.getErrors().get(0).getErrorTag());
}
/**
*/
@Test
public void makeQNameFromIdentifierNullIdentifierNegativeTest() {
- this.thrown.expect(NullPointerException.class);
- ParserIdentifier.makeQNameFromIdentifier(null);
+ assertThrows(NullPointerException.class, () -> ParserIdentifier.makeQNameFromIdentifier(null));
}
/**
*/
@Test
public void makeQNameFromIdentifierEmptyIdentifierNegativeTest() {
- try {
- ParserIdentifier.makeQNameFromIdentifier("");
- fail("Test should fail due to empty identifier");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Not expected error type",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Not expected error tag",
- RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
- assertEquals("Not expected error status code",
- 400, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.makeQNameFromIdentifier(""));
+ assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+ assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+ ex.getErrors().get(0).getErrorTag());
}
/**
*/
@Test
public void makeQNameFromIdentifierDoubleSlashNegativeTest() {
- try {
- ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "//" + TEST_MODULE_REVISION);
- fail("Test should fail due to identifier containing double slash");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Not expected error type",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Not expected error tag",
- RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
- assertEquals("Not expected error status code",
- 400, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.makeQNameFromIdentifier(TEST_MODULE_NAME + "//" + TEST_MODULE_REVISION));
+ assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+ assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+ ex.getErrors().get(0).getErrorTag());
}
/**
@Test
public void toSchemaExportContextFromIdentifierTest() {
final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
- this.schemaContext, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider);
+ SCHEMA_CONTEXT, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider);
assertNotNull("Export context should be parsed", exportContext);
final Module module = exportContext.getModule();
assertNotNull("Export context should contains test module", module);
- assertEquals("Returned not expected module name",
- TEST_MODULE_NAME, module.getName());
+ assertEquals("Returned not expected module name", TEST_MODULE_NAME, module.getName());
assertEquals("Returned not expected module revision",
- TEST_MODULE_REVISION, SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()));
- assertEquals("Returned not expected module namespace",
- TEST_MODULE_NAMESPACE, module.getNamespace().toString());
+ Revision.ofNullable(TEST_MODULE_REVISION), module.getRevision());
+ assertEquals("Returned not expected module namespace", TEST_MODULE_NAMESPACE, module.getNamespace().toString());
}
/**
@Test
public void toSchemaExportContextFromIdentifierNotFoundTest() {
final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
- this.schemaContext,
+ SCHEMA_CONTEXT,
"not-existing-module" + "/" + "2016-01-01",
null, sourceProvider);
*/
@Test
public void toSchemaExportContextFromIdentifierInvalidIdentifierNegativeTest() {
- try {
- ParserIdentifier.toSchemaExportContextFromIdentifier(
- this.schemaContext, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null, sourceProvider);
- fail("Test should fail due to invalid identifier supplied");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Not expected error type",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Not expected error tag",
- RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
- assertEquals("Not expected error status code",
- 400, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
+ SCHEMA_CONTEXT, TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, null, sourceProvider));
+ assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+ assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+ ex.getErrors().get(0).getErrorTag());
}
/**
@Test
public void toSchemaExportContextFromIdentifierMountPointTest() {
final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
- this.schemaContext,
+ SCHEMA_CONTEXT,
MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
- this.mountPointService, sourceProvider);
+ mountPointService, sourceProvider);
final Module module = exportContext.getModule();
assertNotNull("Export context should contains test module", module);
assertEquals("Returned not expected module name",
TEST_MODULE_NAME, module.getName());
assertEquals("Returned not expected module revision",
- TEST_MODULE_REVISION, SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()));
+ Revision.ofNullable(TEST_MODULE_REVISION), module.getRevision());
assertEquals("Returned not expected module namespace",
TEST_MODULE_NAMESPACE, module.getNamespace().toString());
}
@Test
public void toSchemaExportContextFromIdentifierMountPointNotFoundTest() {
final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
- this.schemaContext,
+ SCHEMA_CONTEXT,
MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
- this.mountPointService, sourceProvider);
+ mountPointService, sourceProvider);
assertNotNull("Export context should be parsed", exportContext);
assertNull("Not-existing module should be null", exportContext.getModule());
*/
@Test
public void toSchemaExportContextFromIdentifierMountPointInvalidIdentifierNegativeTest() {
- try {
- ParserIdentifier.toSchemaExportContextFromIdentifier(
- this.schemaContext,
- MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME,
- this.mountPointService, sourceProvider);
+ RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> ParserIdentifier.toSchemaExportContextFromIdentifier(SCHEMA_CONTEXT,
+ MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME, mountPointService,
+ sourceProvider));
- fail("Test should fail due to invalid identifier supplied");
- } catch (final RestconfDocumentedException e) {
- assertEquals("Not expected error type",
- RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
- assertEquals("Not expected error tag",
- RestconfError.ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
- assertEquals("Not expected error status code",
- 400, e.getErrors().get(0).getErrorTag().getStatusCode());
- }
+ assertEquals("Not expected error type", ErrorType.PROTOCOL, ex.getErrors().get(0).getErrorType());
+ assertEquals("Not expected error tag", ErrorTag.INVALID_VALUE,
+ ex.getErrors().get(0).getErrorTag());
}
/**
*/
@Test
public void toSchemaExportContextFromIdentifierNullIdentifierNegativeTest() {
- this.thrown.expect(NullPointerException.class);
- ParserIdentifier.toSchemaExportContextFromIdentifier(this.schemaContext, null, null, sourceProvider);
+ assertThrows(NullPointerException.class,
+ () -> ParserIdentifier.toSchemaExportContextFromIdentifier(SCHEMA_CONTEXT, null, null, sourceProvider));
}
/**
*/
@Test
public void toSchemaExportContextFromIdentifierNullSchemaContextNegativeTest() {
- this.thrown.expect(NullPointerException.class);
- ParserIdentifier.toSchemaExportContextFromIdentifier(null, TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null,
- sourceProvider);
+ assertThrows(NullPointerException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(null,
+ TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null, sourceProvider));
}
/**
*/
@Test
public void toSchemaExportContextFromIdentifierMountPointNullSchemaContextNegativeTest() {
- this.thrown.expect(NullPointerException.class);
- ParserIdentifier.toSchemaExportContextFromIdentifier(
- null,
- MOUNT_POINT_IDENT
- + "/"
- + TEST_MODULE_NAME
- + "/"
- + TEST_MODULE_REVISION,
- this.mountPointService,
- sourceProvider);
+ assertThrows(NullPointerException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(null,
+ MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, mountPointService,
+ sourceProvider));
}
/**
*/
@Test
public void toSchemaExportContextFromIdentifierNullMountPointServiceNegativeTest() {
- this.thrown.expect(NullPointerException.class);
- ParserIdentifier.toSchemaExportContextFromIdentifier(
- this.schemaContext,
- MOUNT_POINT_IDENT
- + "/"
- + TEST_MODULE_NAME
- + "/"
- + TEST_MODULE_REVISION,
- null,
- sourceProvider);
+ assertThrows(NullPointerException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
+ SCHEMA_CONTEXT, MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION, null,
+ sourceProvider));
}
- /**
- * Negative test of of getting <code>SchemaExportContext</code> when <code>SchemaContext</code> behind mount
- * point is <code>null</code>. Test is expected to fail with <code>NullPointerException</code>.
- */
@Test
public void toSchemaExportContextFromIdentifierNullSchemaContextBehindMountPointNegativeTest() {
- this.thrown.expect(NullPointerException.class);
- ParserIdentifier.toSchemaExportContextFromIdentifier(
- this.schemaContext,
- "/"
- + RestconfConstants.MOUNT
- + "/"
- + TEST_MODULE_NAME
- + "/"
- + TEST_MODULE_REVISION,
- this.mockMountPointService,
- sourceProvider);
+ assertThrows(IllegalStateException.class, () -> ParserIdentifier.toSchemaExportContextFromIdentifier(
+ SCHEMA_CONTEXT, "/yang-ext:mount/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
+ mockMountPointService, sourceProvider));
}
/**
*/
@Test
public void invokeRpcTest() {
- final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
- INVOKE_RPC, this.schemaContext, Optional.absent());
+ final InstanceIdentifierContext result = ParserIdentifier.toInstanceIdentifier(
+ INVOKE_RPC, SCHEMA_CONTEXT, Optional.empty());
// RPC schema node
final QName rpcQName = result.getSchemaNode().getQName();
assertEquals("rpc-test", rpcQName.getLocalName());
// other fields
- assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, schemaContext), result.getInstanceIdentifier());
+ assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, SCHEMA_CONTEXT), result.getInstanceIdentifier());
assertEquals(null, result.getMountPoint());
- assertEquals(this.schemaContext, result.getSchemaContext());
+ assertEquals(SCHEMA_CONTEXT, result.getSchemaContext());
}
/**
*/
@Test
public void invokeRpcOnMountPointTest() {
- final InstanceIdentifierContext<?> result = ParserIdentifier.toInstanceIdentifier(
- MOUNT_POINT_IDENT + "/" + INVOKE_RPC, this.schemaContext, Optional.of(this.mountPointService));
+ final InstanceIdentifierContext result = ParserIdentifier.toInstanceIdentifier(
+ MOUNT_POINT_IDENT + "/" + INVOKE_RPC, SCHEMA_CONTEXT, Optional.of(mountPointService));
// RPC schema node
final QName rpcQName = result.getSchemaNode().getQName();
assertEquals("rpc-test", rpcQName.getLocalName());
// other fields
- assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, schemaContext), result.getInstanceIdentifier());
- assertEquals(this.mountPoint, result.getMountPoint());
- assertEquals(this.schemaContextOnMountPoint, result.getSchemaContext());
+ assertEquals(IdentifierCodec.deserialize(INVOKE_RPC, SCHEMA_CONTEXT), result.getInstanceIdentifier());
+ assertEquals(mountPoint, result.getMountPoint());
+ assertEquals(SCHEMA_CONTEXT_ON_MOUNT_POINT, result.getSchemaContext());
+ }
+
+ /**
+ * Test Action.
+ * Verify if Action schema node was found.
+ */
+ @Test
+ public void invokeActionTest() {
+ final InstanceIdentifierContext result = ParserIdentifier
+ .toInstanceIdentifier(INVOKE_ACTION, SCHEMA_CONTEXT, 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, SCHEMA_CONTEXT), result.getInstanceIdentifier());
+ assertNull(result.getMountPoint());
+ assertSame(SCHEMA_CONTEXT, 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, SCHEMA_CONTEXT,
+ Optional.of(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, SCHEMA_CONTEXT), result.getInstanceIdentifier());
+ assertEquals(mountPoint, result.getMountPoint());
+ assertEquals(SCHEMA_CONTEXT_ON_MOUNT_POINT, result.getSchemaContext());
}
}