--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public abstract class AbstractJukeboxTest {
+ protected static EffectiveModelContext JUKEBOX_SCHEMA;
+
+ @BeforeClass
+ public static void beforeClass() {
+ JUKEBOX_SCHEMA = YangParserTestUtils.parseYangResourceDirectory("/jukebox");
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ JUKEBOX_SCHEMA = null;
+ }
+}
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
-import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class RestconfDataServiceImplTest {
-
- private static final String PATH_FOR_NEW_SCHEMA_CONTEXT = "/jukebox";
-
+public class RestconfDataServiceImplTest extends AbstractJukeboxTest {
private ContainerNode buildBaseCont;
private ContainerNode buildBaseContConfig;
private ContainerNode buildBaseContOperational;
- private EffectiveModelContext contextRef;
private YangInstanceIdentifier iidBase;
private RestconfDataServiceImpl dataService;
private QName baseQName;
.node(baseQName)
.build();
- contextRef = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
-
doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
DOMDataBroker mockDataBroker = mock(DOMDataBroker.class);
doReturn(read).when(mockDataBroker).newReadOnlyTransaction();
doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
- dataService = new RestconfDataServiceImpl(() -> DatabindContext.ofModel(contextRef), mockDataBroker,
+ dataService = new RestconfDataServiceImpl(() -> DatabindContext.ofModel(JUKEBOX_SCHEMA), mockDataBroker,
mountPointService, delegRestconfSubscrService, actionService, new StreamsConfiguration(0, 1, 0, false));
doReturn(Optional.of(mountPoint)).when(mountPointService)
.getMountPoint(any(YangInstanceIdentifier.class));
- doReturn(Optional.of(FixedDOMSchemaService.of(contextRef))).when(mountPoint)
+ doReturn(Optional.of(FixedDOMSchemaService.of(JUKEBOX_SCHEMA))).when(mountPoint)
.getService(DOMSchemaService.class);
doReturn(Optional.of(mountDataBroker)).when(mountPoint).getService(DOMDataBroker.class);
doReturn(Optional.empty()).when(mountPoint).getService(NetconfDataTreeService.class);
@Test
public void testPutData() {
- final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(contextRef, iidBase);
+ final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iidBase);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
doReturn(immediateTrueFluentFuture()).when(read)
@Test
public void testPutDataWithMountPoint() {
final InstanceIdentifierContext iidContext =
- InstanceIdentifierContext.ofMountPointPath(mountPoint, contextRef, iidBase);
+ InstanceIdentifierContext.ofMountPointPath(mountPoint, JUKEBOX_SCHEMA, iidBase);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
doReturn(immediateTrueFluentFuture()).when(read)
NodeIdentifierWithPredicates.of(listQname, listKeyQname, "name of band");
doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
- final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(contextRef, iidBase);
+ final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iidBase);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, Builders.mapBuilder()
.withNodeIdentifier(new NodeIdentifier(listQname))
.withChild(Builders.mapEntryBuilder()
@Test
public void testPatchData() {
- final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(contextRef, iidBase);
+ final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iidBase);
final List<PatchEntity> entity = new ArrayList<>();
final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(iidBase)
.node(containerPlayerQname)
@Test
public void testPatchDataMountPoint() throws Exception {
- final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofMountPointPath(mountPoint, contextRef,
- iidBase);
+ final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofMountPointPath(mountPoint,
+ JUKEBOX_SCHEMA, iidBase);
final List<PatchEntity> entity = new ArrayList<>();
final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(iidBase)
.node(containerPlayerQname)
@Test
public void testPatchDataDeleteNotExist() {
- final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(contextRef, iidBase);
+ final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iidBase);
final List<PatchEntity> entity = new ArrayList<>();
final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(iidBase)
.node(containerPlayerQname)
import java.util.List;
import java.util.Optional;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
import org.opendaylight.restconf.common.patch.PatchStatusEntity;
-import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class PatchDataTransactionUtilTest {
- private static EffectiveModelContext SCHEMA;
-
+public class PatchDataTransactionUtilTest extends AbstractJukeboxTest {
@Mock
private DOMDataTreeReadWriteTransaction rwTransaction;
@Mock
private YangInstanceIdentifier targetNodeMerge;
private MapNode buildArtistList;
- @BeforeClass
- public static void beforeClass() throws Exception {
- SCHEMA = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/jukebox"));
- }
-
@Before
public void setUp() {
final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
entities.add(entityRemove);
final InstanceIdentifierContext iidContext =
- InstanceIdentifierContext.ofLocalPath(SCHEMA, instanceIdMerge);
+ InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, instanceIdMerge);
final PatchContext patchContext = new PatchContext(iidContext, entities, "patchRMRm");
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService)
entities.add(entityDelete);
final InstanceIdentifierContext iidContext =
- InstanceIdentifierContext.ofLocalPath(SCHEMA, instanceIdCreateAndDelete);
+ InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, instanceIdCreateAndDelete);
final PatchContext patchContext = new PatchContext(iidContext, entities, "patchCD");
patch(patchContext, new MdsalRestconfStrategy(mockDataBroker), true);
patch(patchContext, new NetconfRestconfStrategy(netconfService), true);
entities.add(entityDelete);
final PatchContext patchContext = new PatchContext(
- InstanceIdentifierContext.ofLocalPath(SCHEMA, instanceIdCreateAndDelete), entities, "patchD");
+ InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, instanceIdCreateAndDelete), entities, "patchD");
deleteMdsal(patchContext, new MdsalRestconfStrategy(mockDataBroker));
deleteNetconf(patchContext, new NetconfRestconfStrategy(netconfService));
}
entities.add(entityMerge);
final InstanceIdentifierContext iidContext =
- InstanceIdentifierContext.ofLocalPath(SCHEMA, instanceIdCreateAndDelete);
+ InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, instanceIdCreateAndDelete);
final PatchContext patchContext = new PatchContext(iidContext, entities, "patchM");
patch(patchContext, new MdsalRestconfStrategy(mockDataBroker), false);
patch(patchContext, new NetconfRestconfStrategy(netconfService), false);
}
- private void patch(final PatchContext patchContext, final RestconfStrategy strategy,
- final boolean failed) {
+ private static void patch(final PatchContext patchContext, final RestconfStrategy strategy, final boolean failed) {
final PatchStatusContext patchStatusContext =
- PatchDataTransactionUtil.patchData(patchContext, strategy, SCHEMA);
+ PatchDataTransactionUtil.patchData(patchContext, strategy, JUKEBOX_SCHEMA);
for (final PatchStatusEntity entity : patchStatusContext.getEditCollection()) {
if (failed) {
assertTrue("Edit " + entity.getEditId() + " failed", entity.isOk());
assertTrue(patchStatusContext.isOk());
}
- private void deleteMdsal(final PatchContext patchContext, final RestconfStrategy strategy) {
+ private static void deleteMdsal(final PatchContext patchContext, final RestconfStrategy strategy) {
final PatchStatusContext patchStatusContext =
- PatchDataTransactionUtil.patchData(patchContext, strategy, SCHEMA);
+ PatchDataTransactionUtil.patchData(patchContext, strategy, JUKEBOX_SCHEMA);
assertFalse(patchStatusContext.isOk());
assertEquals(ErrorType.PROTOCOL,
patchStatusContext.getEditCollection().get(0).getEditErrors().get(0).getErrorTag());
}
- private void deleteNetconf(final PatchContext patchContext, final RestconfStrategy strategy) {
- final PatchStatusContext patchStatusContext =
- PatchDataTransactionUtil.patchData(patchContext, strategy, SCHEMA);
+ private static void deleteNetconf(final PatchContext patchContext, final RestconfStrategy strategy) {
+ final PatchStatusContext patchStatusContext = PatchDataTransactionUtil.patchData(patchContext, strategy,
+ JUKEBOX_SCHEMA);
assertFalse(patchStatusContext.isOk());
assertEquals(ErrorType.PROTOCOL,
import com.google.common.util.concurrent.Futures;
import java.util.Optional;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class PlainPatchDataTransactionUtilTest {
- private static EffectiveModelContext SCHEMA;
-
+public class PlainPatchDataTransactionUtilTest extends AbstractJukeboxTest {
@Mock
private DOMDataTreeReadWriteTransaction readWrite;
@Mock
private YangInstanceIdentifier iidGap;
private YangInstanceIdentifier iidJukebox;
- @BeforeClass
- public static void beforeClass() throws Exception {
- SCHEMA = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/jukebox"));
- }
-
@Before
public void setUp() {
final QName qnJukebox = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
@Test
public void testPatchContainerData() {
final InstanceIdentifierContext iidContext =
- InstanceIdentifierContext.ofLocalPath(SCHEMA, iidJukebox);
+ InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iidJukebox);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, jukeboxContainerWithPlayer);
doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).merge(any(), any(),any(),
any());
- PlainPatchDataTransactionUtil.patchData(payload, new MdsalRestconfStrategy(mockDataBroker), SCHEMA);
+ PlainPatchDataTransactionUtil.patchData(payload, new MdsalRestconfStrategy(mockDataBroker), JUKEBOX_SCHEMA);
verify(readWrite).merge(LogicalDatastoreType.CONFIGURATION,
payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
- PlainPatchDataTransactionUtil.patchData(payload, new NetconfRestconfStrategy(netconfService),
- SCHEMA);
+ PlainPatchDataTransactionUtil.patchData(payload, new NetconfRestconfStrategy(netconfService), JUKEBOX_SCHEMA);
verify(netconfService).merge(LogicalDatastoreType.CONFIGURATION,
payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData(), Optional.empty());
}
@Test
public void testPatchLeafData() {
- final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(SCHEMA, iidGap);
+ final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iidGap);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, leafGap);
doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
.merge(any(), any(), any(), any());
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
- PlainPatchDataTransactionUtil.patchData(payload, new MdsalRestconfStrategy(mockDataBroker), SCHEMA);
+ PlainPatchDataTransactionUtil.patchData(payload, new MdsalRestconfStrategy(mockDataBroker), JUKEBOX_SCHEMA);
verify(readWrite).merge(LogicalDatastoreType.CONFIGURATION,
payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
- PlainPatchDataTransactionUtil.patchData(payload, new NetconfRestconfStrategy(netconfService), SCHEMA);
+ PlainPatchDataTransactionUtil.patchData(payload, new NetconfRestconfStrategy(netconfService), JUKEBOX_SCHEMA);
verify(netconfService).lock();
verify(netconfService).merge(LogicalDatastoreType.CONFIGURATION,
payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData(), Optional.empty());
@Test
public void testPatchListData() {
- final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(SCHEMA, iidJukebox);
+ final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iidJukebox);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, jukeboxContainerWithPlaylist);
doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService)
.merge(any(), any(),any(),any());
- PlainPatchDataTransactionUtil.patchData(payload, new MdsalRestconfStrategy(mockDataBroker), SCHEMA);
+ PlainPatchDataTransactionUtil.patchData(payload, new MdsalRestconfStrategy(mockDataBroker), JUKEBOX_SCHEMA);
verify(readWrite).merge(LogicalDatastoreType.CONFIGURATION, iidJukebox, payload.getData());
- PlainPatchDataTransactionUtil.patchData(payload, new NetconfRestconfStrategy(netconfService),
- SCHEMA);
+ PlainPatchDataTransactionUtil.patchData(payload, new NetconfRestconfStrategy(netconfService), JUKEBOX_SCHEMA);
verify(netconfService).merge(LogicalDatastoreType.CONFIGURATION, iidJukebox, payload.getData(),
Optional.empty());
}
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
import org.opendaylight.restconf.nb.rfc8040.WriteDataParams;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.w3c.dom.DOMException;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class PostDataTransactionUtilTest {
- private static EffectiveModelContext SCHEMA;
-
+public class PostDataTransactionUtilTest extends AbstractJukeboxTest {
@Mock
private DOMDataTreeReadWriteTransaction readWrite;
@Mock
private YangInstanceIdentifier iidList;
private MapNode buildList;
- @BeforeClass
- public static void beforeClass() throws Exception {
- SCHEMA = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/jukebox"));
- }
-
@Before
public void setUp() {
final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
.create(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseCont, Optional.empty());
Response response = PostDataTransactionUtil.postData(uriInfo, iid2, buildBaseCont,
- new MdsalRestconfStrategy(mockDataBroker), SCHEMA, WriteDataParams.empty());
+ new MdsalRestconfStrategy(mockDataBroker), JUKEBOX_SCHEMA, WriteDataParams.empty());
assertEquals(201, response.getStatus());
verify(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseCont);
response = PostDataTransactionUtil.postData(uriInfo, iid2, buildBaseCont,
- new NetconfRestconfStrategy(netconfService), SCHEMA, WriteDataParams.empty());
+ new NetconfRestconfStrategy(netconfService), JUKEBOX_SCHEMA, WriteDataParams.empty());
assertEquals(201, response.getStatus());
verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseCont, Optional.empty());
}
LogicalDatastoreType.CONFIGURATION, node, entryNode, Optional.empty());
Response response = PostDataTransactionUtil.postData(uriInfo, iidList, buildList,
- new MdsalRestconfStrategy(mockDataBroker), SCHEMA, WriteDataParams.empty());
+ new MdsalRestconfStrategy(mockDataBroker), JUKEBOX_SCHEMA, WriteDataParams.empty());
assertEquals(201, response.getStatus());
assertThat(URLDecoder.decode(response.getLocation().toString(), StandardCharsets.UTF_8),
containsString(identifier.getValue(identifier.keySet().iterator().next()).toString()));
verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, node, entryNode);
response = PostDataTransactionUtil.postData(uriInfo, iidList, buildList,
- new NetconfRestconfStrategy(netconfService), SCHEMA, WriteDataParams.empty());
+ new NetconfRestconfStrategy(netconfService), JUKEBOX_SCHEMA, WriteDataParams.empty());
assertEquals(201, response.getStatus());
assertThat(URLDecoder.decode(response.getLocation().toString(), StandardCharsets.UTF_8),
containsString(identifier.getValue(identifier.keySet().iterator().next()).toString()));
- verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, node, entryNode,
- Optional.empty());
+ verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, node, entryNode, Optional.empty());
}
@Test
RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
() -> PostDataTransactionUtil.postData(uriInfo, iid2, buildBaseCont,
- new MdsalRestconfStrategy(mockDataBroker), SCHEMA, WriteDataParams.empty()));
+ new MdsalRestconfStrategy(mockDataBroker), JUKEBOX_SCHEMA, WriteDataParams.empty()));
assertEquals(1, ex.getErrors().size());
assertThat(ex.getErrors().get(0).getErrorInfo(), containsString(domException.getMessage()));
verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseCont);
ex = assertThrows(RestconfDocumentedException.class, () -> PostDataTransactionUtil.postData(uriInfo, iid2,
- buildBaseCont, new NetconfRestconfStrategy(netconfService), SCHEMA, WriteDataParams.empty()));
+ buildBaseCont, new NetconfRestconfStrategy(netconfService), JUKEBOX_SCHEMA, WriteDataParams.empty()));
assertEquals(1, ex.getErrors().size());
assertThat(ex.getErrors().get(0).getErrorInfo(), containsString(domException.getMessage()));
import com.google.common.util.concurrent.Futures;
import java.util.Optional;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
import org.opendaylight.restconf.nb.rfc8040.WriteDataParams;
import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataServiceImpl;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class PutDataTransactionUtilTest {
- private static EffectiveModelContext SCHEMA;
-
+public class PutDataTransactionUtilTest extends AbstractJukeboxTest {
@Mock
private DOMDataTreeReadWriteTransaction readWrite;
@Mock
private YangInstanceIdentifier iid2;
private YangInstanceIdentifier iid3;
- @BeforeClass
- public static void beforeClass() throws Exception {
- SCHEMA = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/jukebox"));
- }
-
@Before
public void setUp() {
final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
@Test
public void testValidInputData() {
RestconfDataServiceImpl.validInputData(true, NormalizedNodePayload.of(
- InstanceIdentifierContext.ofLocalPath(SCHEMA, iid), buildLeaf));
+ InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iid), buildLeaf));
}
@Test
public void testValidTopLevelNodeName() {
RestconfDataServiceImpl.validTopLevelNodeName(iid, NormalizedNodePayload.of(
- InstanceIdentifierContext.ofLocalPath(SCHEMA, iid), buildLeaf));
+ InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iid), buildLeaf));
RestconfDataServiceImpl.validTopLevelNodeName(iid2, NormalizedNodePayload.of(
- InstanceIdentifierContext.ofLocalPath(SCHEMA, iid2), buildBaseCont));
+ InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iid2), buildBaseCont));
}
@Test
public void testValidTopLevelNodeNamePathEmpty() {
- final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(SCHEMA, iid);
+ final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iid);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildLeaf);
// FIXME: more asserts
@Test
public void testValidTopLevelNodeNameWrongTopIdentifier() {
- final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(SCHEMA, iid);
+ final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iid);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildLeaf);
// FIXME: more asserts
@Test
public void testValidateListKeysEqualityInPayloadAndUri() {
- final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(SCHEMA, iid3);
+ final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, iid3);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildListEntry);
RestconfDataServiceImpl.validateListKeysEqualityInPayloadAndUri(payload);
}
doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseCont);
doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
- PutDataTransactionUtil.putData(iid2, buildBaseCont, SCHEMA, new MdsalRestconfStrategy(mockDataBroker),
+ PutDataTransactionUtil.putData(iid2, buildBaseCont, JUKEBOX_SCHEMA, new MdsalRestconfStrategy(mockDataBroker),
WriteDataParams.empty());
verify(read).exists(LogicalDatastoreType.CONFIGURATION, iid2);
verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseCont);
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService)
.replace(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseCont, Optional.empty());
- PutDataTransactionUtil.putData(iid2, buildBaseCont, SCHEMA, new NetconfRestconfStrategy(netconfService),
+ PutDataTransactionUtil.putData(iid2, buildBaseCont, JUKEBOX_SCHEMA, new NetconfRestconfStrategy(netconfService),
WriteDataParams.empty());
verify(netconfService).lock();
verify(netconfService).getConfig(iid2);
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService)
.replace(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseCont, Optional.empty());
- PutDataTransactionUtil.putData(iid2, buildBaseCont, SCHEMA, new NetconfRestconfStrategy(netconfService),
+ PutDataTransactionUtil.putData(iid2, buildBaseCont, JUKEBOX_SCHEMA, new NetconfRestconfStrategy(netconfService),
WriteDataParams.empty());
verify(netconfService).getConfig(iid2);
verify(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseCont, Optional.empty());
doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid, buildLeaf);
doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
- PutDataTransactionUtil.putData(iid, buildLeaf, SCHEMA, new MdsalRestconfStrategy(mockDataBroker),
+ PutDataTransactionUtil.putData(iid, buildLeaf, JUKEBOX_SCHEMA, new MdsalRestconfStrategy(mockDataBroker),
WriteDataParams.empty());
verify(read).exists(LogicalDatastoreType.CONFIGURATION, iid);
verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid, buildLeaf);
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService)
.replace(LogicalDatastoreType.CONFIGURATION, iid, buildLeaf, Optional.empty());
- PutDataTransactionUtil.putData(iid, buildLeaf, SCHEMA, new NetconfRestconfStrategy(netconfService),
+ PutDataTransactionUtil.putData(iid, buildLeaf, JUKEBOX_SCHEMA, new NetconfRestconfStrategy(netconfService),
WriteDataParams.empty());
verify(netconfService).getConfig(iid);
verify(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid, buildLeaf, Optional.empty());
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService)
.replace(LogicalDatastoreType.CONFIGURATION, iid, buildLeaf, Optional.empty());
- PutDataTransactionUtil.putData(iid, buildLeaf, SCHEMA, new NetconfRestconfStrategy(netconfService),
+ PutDataTransactionUtil.putData(iid, buildLeaf, JUKEBOX_SCHEMA, new NetconfRestconfStrategy(netconfService),
WriteDataParams.empty());
verify(netconfService).getConfig(iid);
verify(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid, buildLeaf, Optional.empty());
.when(read).exists(LogicalDatastoreType.CONFIGURATION, iid2);
doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseContWithList);
doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
- PutDataTransactionUtil.putData(iid2, buildBaseContWithList, SCHEMA, new MdsalRestconfStrategy(mockDataBroker),
- WriteDataParams.empty());
+ PutDataTransactionUtil.putData(iid2, buildBaseContWithList, JUKEBOX_SCHEMA,
+ new MdsalRestconfStrategy(mockDataBroker), WriteDataParams.empty());
verify(read).exists(LogicalDatastoreType.CONFIGURATION, iid2);
verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseContWithList);
}
@Test
public void testPutCreateListData() {
- doReturn(immediateFluentFuture(Optional.empty())).when(netconfService)
- .getConfig(iid2);
+ doReturn(immediateFluentFuture(Optional.empty())).when(netconfService).getConfig(iid2);
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService)
.replace(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseContWithList, Optional.empty());
- PutDataTransactionUtil.putData(iid2, buildBaseContWithList, SCHEMA, new NetconfRestconfStrategy(netconfService),
- WriteDataParams.empty());
+ PutDataTransactionUtil.putData(iid2, buildBaseContWithList, JUKEBOX_SCHEMA,
+ new NetconfRestconfStrategy(netconfService), WriteDataParams.empty());
verify(netconfService).getConfig(iid2);
verify(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseContWithList,
Optional.empty());
@Test
public void testPutReplaceListData() {
- doReturn(immediateFluentFuture(Optional.of(mock(NormalizedNode.class)))).when(netconfService)
- .getConfig(iid2);
+ doReturn(immediateFluentFuture(Optional.of(mock(NormalizedNode.class)))).when(netconfService).getConfig(iid2);
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService)
.replace(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseContWithList, Optional.empty());
- PutDataTransactionUtil.putData(iid2, buildBaseContWithList, SCHEMA, new NetconfRestconfStrategy(netconfService),
- WriteDataParams.empty());
+ PutDataTransactionUtil.putData(iid2, buildBaseContWithList, JUKEBOX_SCHEMA,
+ new NetconfRestconfStrategy(netconfService), WriteDataParams.empty());
verify(netconfService).getConfig(iid2);
verify(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid2, buildBaseContWithList,
Optional.empty());
import org.opendaylight.restconf.api.query.FieldsParam;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public abstract class AbstractFieldsTranslatorTest<T> {
+public abstract class AbstractFieldsTranslatorTest<T> extends AbstractJukeboxTest {
private static final QNameModule Q_NAME_MODULE_JUKEBOX = QNameModule.create(
XMLNamespace.of("http://example.com/ns/example-jukebox"), Revision.of("2015-04-04"));
private static final QNameModule Q_NAME_MODULE_TEST_SERVICES = QNameModule.create(
@Before
public void setUp() throws Exception {
- final EffectiveModelContext schemaContextJukebox =
- YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/jukebox"));
identifierJukebox = InstanceIdentifierContext.ofStack(
- SchemaInferenceStack.ofDataTreePath(schemaContextJukebox, JUKEBOX_Q_NAME));
+ SchemaInferenceStack.ofDataTreePath(JUKEBOX_SCHEMA, JUKEBOX_Q_NAME));
final EffectiveModelContext schemaContextTestServices =
YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/test-services"));