package org.opendaylight.netconf.sal.streams.listeners;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
+import java.io.FileNotFoundException;
import java.net.URI;
-import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
import org.opendaylight.yangtools.util.SingletonSet;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
public class NotificationListenerTest {
- private static final QNameModule MODULE;
-
- static {
- try {
- MODULE = QNameModule.create(URI.create("notifi:mod"),
- SimpleDateFormatUtil.getRevisionFormat().parse("2016-11-23"));
- } catch (final ParseException e) {
- throw new ExceptionInInitializerError(e);
- }
- }
+ private static final QNameModule MODULE = QNameModule.create(URI.create("notifi:mod"), Revision.of("2016-11-23"));
+
+ private static SchemaContext schemaContext;
- private SchemaContext schmeaCtx;
+ private ControllerContext controllerContext;
+
+ @BeforeClass
+ public static void staticInit() throws FileNotFoundException {
+ schemaContext = TestUtils.loadSchemaContext("/notifications");
+ }
@Before
public void init() throws Exception {
MockitoAnnotations.initMocks(this);
- ControllerContext.getInstance().setGlobalSchema(TestUtils.loadSchemaContext("/notifications"));
- this.schmeaCtx = ControllerContext.getInstance().getGlobalSchema();
+ controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
}
@Test
final List<SchemaPath> paths = new ArrayList<>();
paths.add(schemaPathNotifi);
final List<NotificationListenerAdapter> listNotifi =
- Notificator.createNotificationListener(paths, "stream-name", NotificationOutputType.JSON.toString());
+ Notificator.createNotificationListener(paths, "stream-name", NotificationOutputType.JSON.toString(),
+ controllerContext);
final NotificationListenerAdapter notifi = listNotifi.get(0);
- notifi.setNotification(notificationData);
- notifi.setSchemaContext(this.schmeaCtx);
- final String result = notifi.prepareJson();
+ final String result = notifi.prepareJson(schemaContext, notificationData);
return Preconditions.checkNotNull(result);
}
}