X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FRestconfImplTest.java;h=c08b3349989469d993b880f86fc458d0e98ebef6;hb=4281bb297a90bc3c71a50d610147727ff67ea9ea;hp=7e52869165663697c64e6b194b2dcecbd5bedebd;hpb=9022d0fa776cf481564ab792c183f2495a7cdbbe;p=netconf.git diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java index 7e52869165..c08b334998 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java @@ -24,8 +24,11 @@ import com.google.common.util.concurrent.Futures; import java.io.FileNotFoundException; import java.net.URI; import java.text.ParseException; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.Set; import javax.ws.rs.core.MultivaluedHashMap; @@ -43,14 +46,20 @@ import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade; import org.opendaylight.netconf.sal.restconf.impl.ControllerContext; import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext; import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext; +import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException; +import org.opendaylight.netconf.sal.restconf.impl.RestconfError; +import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag; +import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType; import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl; import org.opendaylight.netconf.sal.streams.listeners.Notificator; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; @@ -60,8 +69,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; /** - * @See {@link InvokeRpcMethodTest} - * + * See {@link InvokeRpcMethodTest}. */ public class RestconfImplTest { @@ -85,12 +93,49 @@ public class RestconfImplTest { this.restconfImpl.setControllerContext(controllerContext); } + @Test + public void binaryKeyTest() { + final List al = new ArrayList<>(); + al.add(new Byte((byte) 1)); + binaryKeyTest(al, al); + } + + private void binaryKeyTest(final List al, final List al2) { + + final QName keyDef = QName.create("test:key:binary", "2017-14-08", "b1"); + + final Map uriKeyValues = new HashMap<>(); + uriKeyValues.put(keyDef, al.toArray()); + + final MapEntryNode payload = mock(MapEntryNode.class); + final NodeIdentifierWithPredicates nodeIdWithPred = + new NodeIdentifierWithPredicates(keyDef, keyDef, al2.toArray()); + when(payload.getIdentifier()).thenReturn(nodeIdWithPred); + + final List keyDefinitions = new ArrayList<>(); + keyDefinitions.add(keyDef); + RestconfImpl.isEqualUriAndPayloadKeyValues(uriKeyValues, payload, keyDefinitions); + } + + @Test + public void binaryKeyFailTest() { + final List al = new ArrayList<>(); + al.add(new Byte((byte) 1)); + final List al2 = new ArrayList<>(); + try { + binaryKeyTest(al, al2); + } catch (final RestconfDocumentedException e) { + final RestconfError err = e.getErrors().iterator().next(); + assertEquals(ErrorType.PROTOCOL, err.getErrorType()); + assertEquals(ErrorTag.INVALID_VALUE, err.getErrorTag()); + } + } + @SuppressWarnings("unchecked") @Test public void testExample() throws FileNotFoundException, ParseException { @SuppressWarnings("rawtypes") - final - NormalizedNode normalizedNodeData = TestUtils.prepareNormalizedNodeWithIetfInterfacesInterfacesData(); + final NormalizedNode normalizedNodeData = TestUtils.prepareNormalizedNodeWithIetfInterfacesInterfacesData(); final BrokerFacade brokerFacade = mock(BrokerFacade.class); when(brokerFacade.readOperationalData(any(YangInstanceIdentifier.class))).thenReturn(normalizedNodeData); assertEquals(normalizedNodeData, @@ -122,7 +167,7 @@ public class RestconfImplTest { } /** - * Create notification stream for toaster module + * Create notification stream for toaster module. */ @Test public void createNotificationStreamTest() { @@ -160,7 +205,7 @@ public class RestconfImplTest { } /** - * Subscribe for notification stream of toaster module + * Subscribe for notification stream of toaster module. */ @Test public void subscribeToNotificationStreamTest() throws Exception {