import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
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;
+import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import org.junit.Before;
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;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
/**
- * @See {@link InvokeRpcMethodTest}
- *
+ * See {@link InvokeRpcMethodTest}.
*/
public class RestconfImplTest {
this.restconfImpl.setControllerContext(controllerContext);
}
+ @Test
+ public void binaryKeyTest() {
+ final List<Byte> al = new ArrayList<>();
+ al.add(new Byte((byte) 1));
+ binaryKeyTest(al, al);
+ }
+
+ private void binaryKeyTest(final List<Byte> al, final List<Byte> al2) {
+
+ final QName keyDef = QName.create("test:key:binary", "2017-14-08", "b1");
+
+ final Map<QName, Object> 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<QName> keyDefinitions = new ArrayList<>();
+ keyDefinitions.add(keyDef);
+ RestconfImpl.isEqualUriAndPayloadKeyValues(uriKeyValues, payload, keyDefinitions);
+ }
+
+ @Test
+ public void binaryKeyFailTest() {
+ final List<Byte> al = new ArrayList<>();
+ al.add(new Byte((byte) 1));
+ final List<Byte> 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,
}
/**
- * Create notification stream for toaster module
+ * Create notification stream for toaster module.
*/
@Test
public void createNotificationStreamTest() {
}
/**
- * Subscribe for notification stream of toaster module
+ * Subscribe for notification stream of toaster module.
*/
@Test
public void subscribeToNotificationStreamTest() throws Exception {
when(uriBuilder.build()).thenReturn(new URI(""));
when(uriBuilder.scheme("ws")).thenReturn(uriBuilder);
when(uriInfo.getAbsolutePathBuilder()).thenReturn(uriBuilder);
+ final MultivaluedMap<String, String> map = mock(MultivaluedMap.class);
+ final Set<Entry<String, List<String>>> set = new HashSet<>();
+ when(map.entrySet()).thenReturn(set);
+ when(uriInfo.getQueryParameters()).thenReturn(map);
final BrokerFacade brokerFacade = mock(BrokerFacade.class);
this.restconfImpl.setBroker(brokerFacade);