import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import javax.ws.rs.core.MultivaluedMap;
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.mockito.Mockito;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
-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.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
+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.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;
*/
public class RestconfImplTest {
- private RestconfImpl restconfImpl = null;
- private static ControllerContext controllerContext = null;
+ private static SchemaContext schemaContext;
+
+ private final BrokerFacade brokerFacade = mock(BrokerFacade.class);
+ private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
+ private final RestconfImpl restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
@BeforeClass
public static void init() throws FileNotFoundException, ReactorException {
- final SchemaContext schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
-
+ schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
final Set<Module> allModules = schemaContext.getModules();
assertNotNull(allModules);
-
- controllerContext = ControllerContext.getInstance();
- controllerContext.setSchemas(schemaContext);
- }
-
- @Before
- public void initMethod() {
- this.restconfImpl = RestconfImpl.getInstance();
- this.restconfImpl.setControllerContext(controllerContext);
}
@Test
private void binaryKeyTest(final List<Byte> al, final List<Byte> al2) {
- final QName keyDef = QName.create("test:key:binary", "2017-14-08", "b1");
+ final QName keyDef = QName.create("test:key:binary", "2017-08-14", "b1");
final Map<QName, Object> uriKeyValues = new HashMap<>();
uriKeyValues.put(keyDef, al.toArray());
public void testExample() throws FileNotFoundException, ParseException {
@SuppressWarnings("rawtypes")
final NormalizedNode normalizedNodeData = TestUtils.prepareNormalizedNodeWithIetfInterfacesInterfacesData();
- final BrokerFacade brokerFacade = mock(BrokerFacade.class);
- when(brokerFacade.readOperationalData(any(YangInstanceIdentifier.class))).thenReturn(normalizedNodeData);
+ when(brokerFacade.readOperationalData(isNull())).thenReturn(normalizedNodeData);
assertEquals(normalizedNodeData,
brokerFacade.readOperationalData(null));
}
.invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
this.restconfImpl.invokeRpc("randomId", ctx, uriInfo);
this.restconfImpl.invokeRpc("ietf-netconf", ctx, uriInfo);
- verify(rpcService, times(2)).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
+ verify(rpcService, times(2)).invokeRpc(any(SchemaPath.class), isNull());
}
/**
// register test notification stream
final SchemaPath path = SchemaPath.create(
true, QName.create("http://netconfcentral.org/ns/toaster", "2009-11-20", "toastDone"));
- Notificator.createNotificationListener(Lists.newArrayList(path), identifier, "XML");
+ Notificator.createNotificationListener(Lists.newArrayList(path), identifier, "XML", controllerContext);
final UriInfo uriInfo = mock(UriInfo.class);
final UriBuilder uriBuilder = mock(UriBuilder.class);
when(map.entrySet()).thenReturn(set);
when(uriInfo.getQueryParameters()).thenReturn(map);
- final BrokerFacade brokerFacade = mock(BrokerFacade.class);
- this.restconfImpl.setBroker(brokerFacade);
-
// subscribe to stream and verify response
final NormalizedNodeContext response = this.restconfImpl.subscribeToStream(identifier, uriInfo);