import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URI;
-import java.text.SimpleDateFormat;
+import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
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.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 (ParseException e) {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
private SchemaContext schmeaCtx;
@Test
public void notifi_leafTest() throws Exception {
- final QNameModule moduleQName =
- QNameModule.create(new URI("notifi:mod"), new SimpleDateFormat("yyyy-MM-dd").parse("2016-11-23"));
- final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(moduleQName, "notifi-leaf"));
+ final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(MODULE, "notifi-leaf"));
final DOMNotification notificationData = mock(DOMNotification.class);
- final LeafNode leaf = mockLeaf(QName.create(moduleQName, "lf"));
+ final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf"));
final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), leaf);
when(notificationData.getType()).thenReturn(schemaPathNotifi);
@Test
public void notifi_cont_leafTest() throws Exception {
- final QNameModule moduleQName =
- QNameModule.create(new URI("notifi:mod"), new SimpleDateFormat("yyyy-MM-dd").parse("2016-11-23"));
-
- final SchemaPath schemaPathNotifi =
- SchemaPath.create(false, QName.create(moduleQName, "notifi-cont"));
+ final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(MODULE, "notifi-cont"));
final DOMNotification notificationData = mock(DOMNotification.class);
- final LeafNode leaf = mockLeaf(QName.create(moduleQName, "lf"));
- final ContainerNode cont = mockCont(QName.create(moduleQName, "cont"), leaf);
+ final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf"));
+ final ContainerNode cont = mockCont(QName.create(MODULE, "cont"), leaf);
final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), cont);
when(notificationData.getType()).thenReturn(schemaPathNotifi);
@Test
public void notifi_list_Test() throws Exception {
- final QNameModule moduleQName =
- QNameModule.create(new URI("notifi:mod"), new SimpleDateFormat("yyyy-MM-dd").parse("2016-11-23"));
-
- final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(moduleQName, "notifi-list"));
+ final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(MODULE, "notifi-list"));
final DOMNotification notificationData = mock(DOMNotification.class);
- final LeafNode leaf = mockLeaf(QName.create(moduleQName, "lf"));
- final MapEntryNode entry = mockMapEntry(QName.create(moduleQName, "lst"), leaf);
- final MapNode list = mockList(QName.create(moduleQName, "lst"), entry);
- final ContainerNode cont = mockCont(QName.create(moduleQName, "cont"), list);
+ final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf"));
+ final MapEntryNode entry = mockMapEntry(QName.create(MODULE, "lst"), leaf);
+ final MapNode list = mockList(QName.create(MODULE, "lst"), entry);
+ final ContainerNode cont = mockCont(QName.create(MODULE, "cont"), list);
final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), cont);
when(notificationData.getType()).thenReturn(schemaPathNotifi);
@Test
public void notifi_grpTest() throws Exception {
- final QNameModule moduleQName =
- QNameModule.create(new URI("notifi:mod"), new SimpleDateFormat("yyyy-MM-dd").parse("2016-11-23"));
-
- final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(moduleQName, "notifi-grp"));
+ final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(MODULE, "notifi-grp"));
final DOMNotification notificationData = mock(DOMNotification.class);
- final LeafNode leaf = mockLeaf(QName.create(moduleQName, "lf"));
+ final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf"));
final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), leaf);
when(notificationData.getType()).thenReturn(schemaPathNotifi);
@Test
public void notifi_augmTest() throws Exception {
- final QNameModule moduleQName =
- QNameModule.create(new URI("notifi:mod"), new SimpleDateFormat("yyyy-MM-dd").parse("2016-11-23"));
-
- final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(moduleQName, "notifi-augm"));
+ final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(MODULE, "notifi-augm"));
final DOMNotification notificationData = mock(DOMNotification.class);
- final LeafNode leaf = mockLeaf(QName.create(moduleQName, "lf-augm"));
+ final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf-augm"));
final AugmentationNode augm = mockAugm(leaf);
final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), augm);
assertTrue(result.contains("lf-augm" + '"' + ":" + '"' + "value"));
}
- private AugmentationNode mockAugm(final LeafNode leaf) {
+ private static AugmentationNode mockAugm(final LeafNode leaf) {
final AugmentationNode augm = mock(AugmentationNode.class);
final AugmentationIdentifier augmId = new AugmentationIdentifier(SingletonSet.of(leaf.getNodeType()));
when(augm.getIdentifier()).thenReturn(augmId);
return augm;
}
- private MapEntryNode mockMapEntry(final QName entryQName, final LeafNode leaf) {
+ private static MapEntryNode mockMapEntry(final QName entryQName, final LeafNode leaf) {
final MapEntryNode entry = mock(MapEntryNode.class);
final Map<QName, Object> keyValues = new HashMap<>();
keyValues.put(leaf.getNodeType(), "value");
return entry;
}
- private MapNode mockList(final QName listQName, final MapEntryNode... entries) {
+ private static MapNode mockList(final QName listQName, final MapEntryNode... entries) {
final MapNode list = mock(MapNode.class);
when(list.getIdentifier()).thenReturn(NodeIdentifier.create(listQName));
when(list.getNodeType()).thenReturn(listQName);
return list;
}
- private ContainerNode mockCont(final QName contQName, final DataContainerChild<? extends PathArgument, ?> child) {
+ private static ContainerNode mockCont(final QName contQName, final DataContainerChild<? extends PathArgument, ?> child) {
final ContainerNode cont = mock(ContainerNode.class);
when(cont.getIdentifier()).thenReturn(NodeIdentifier.create(contQName));
when(cont.getNodeType()).thenReturn(contQName);
return cont;
}
- private LeafNode mockLeaf(final QName leafQName) {
+ private static LeafNode mockLeaf(final QName leafQName) {
final LeafNode child = mock(LeafNode.class);
when(child.getNodeType()).thenReturn(leafQName);
when(child.getIdentifier()).thenReturn(NodeIdentifier.create(leafQName));