-/*\r
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;\r
-\r
-import static org.mockito.Matchers.any;\r
-import static org.mockito.Matchers.eq;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.spy;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-\r
-import java.util.Set;\r
-\r
-import com.google.common.collect.ImmutableSet;\r
-import com.google.common.util.concurrent.CheckedFuture;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;\r
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;\r
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.groupbasedpolicy.api.sf.AllowActionDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedActionDefinition;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-\r
-public class ActionDefinitionListenerTest {\r
-\r
- private ActionDefinitionListener listener;\r
- private DataObjectModification<ActionDefinition> rootNode;\r
- private Set<DataTreeModification<ActionDefinition>> changes;\r
-\r
- private DataBroker dataProvider;\r
-\r
- private InstanceIdentifier<ActionDefinition> rootIdentifier;\r
-\r
- @SuppressWarnings("unchecked")\r
- @Before\r
- public void init() {\r
-\r
- dataProvider = mock(DataBroker.class);\r
-\r
- listener = spy(new ActionDefinitionListener(dataProvider));\r
-\r
- ActionDefinitionKey key = mock(ActionDefinitionKey.class);\r
-\r
- rootNode = mock(DataObjectModification.class);\r
- rootIdentifier = InstanceIdentifier.builder(SubjectFeatureDefinitions.class)\r
- .child(ActionDefinition.class, key)\r
- .build();\r
- DataTreeIdentifier<ActionDefinition> rootPath =\r
- new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);\r
-\r
- DataTreeModification<ActionDefinition> change = mock(DataTreeModification.class);\r
-\r
- when(change.getRootNode()).thenReturn(rootNode);\r
- when(change.getRootPath()).thenReturn(rootPath);\r
-\r
- changes = ImmutableSet.of(change);\r
-\r
- ActionDefinition def = new ActionDefinitionBuilder().setId(AllowActionDefinition.ID).build();\r
-\r
- when(rootNode.getDataBefore()).thenReturn(def);\r
- when(rootNode.getDataAfter()).thenReturn(def);\r
- }\r
-\r
- @Test\r
- public void testOnDataTreeChanged_Write() {\r
- when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);\r
-\r
- WriteTransaction wt = resetTransaction();\r
-\r
- listener.onDataTreeChanged(changes);\r
-\r
- verify(wt).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),\r
- any(SupportedActionDefinition.class), eq(true));\r
- }\r
-\r
- @Test\r
- public void testOnDataTreeChanged_SubtreeModified() {\r
- when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);\r
-\r
- WriteTransaction wt = resetTransaction();\r
-\r
- listener.onDataTreeChanged(changes);\r
-\r
- verify(wt).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),\r
- any(SupportedActionDefinition.class), eq(true));\r
- }\r
-\r
- @Test\r
- public void testOnDataTreeChanged_Delete() {\r
- when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);\r
-\r
- WriteTransaction wt = resetTransaction();\r
-\r
- listener.onDataTreeChanged(changes);\r
-\r
- verify(wt).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));\r
- }\r
-\r
- private WriteTransaction resetTransaction() {\r
- WriteTransaction wt = mock(WriteTransaction.class);\r
- CheckedFuture checkedFuture = mock(CheckedFuture.class);\r
- when(wt.submit()).thenReturn(checkedFuture);\r
- when(dataProvider.newWriteOnlyTransaction()).thenReturn(wt);\r
- return wt;\r
- }\r
-\r
-}\r
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.CheckedFuture;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.api.sf.AllowActionDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinitionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedActionDefinition;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class ActionDefinitionListenerTest {
+
+ private ActionDefinitionListener listener;
+ private DataObjectModification<ActionDefinition> rootNode;
+ private Set<DataTreeModification<ActionDefinition>> changes;
+
+ private DataBroker dataProvider;
+
+ private InstanceIdentifier<ActionDefinition> rootIdentifier;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void init() {
+
+ dataProvider = mock(DataBroker.class);
+
+ listener = spy(new ActionDefinitionListener(dataProvider));
+
+ ActionDefinitionKey key = mock(ActionDefinitionKey.class);
+
+ rootNode = mock(DataObjectModification.class);
+ rootIdentifier = InstanceIdentifier.builder(SubjectFeatureDefinitions.class)
+ .child(ActionDefinition.class, key)
+ .build();
+ DataTreeIdentifier<ActionDefinition> rootPath =
+ new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);
+
+ DataTreeModification<ActionDefinition> change = mock(DataTreeModification.class);
+
+ when(change.getRootNode()).thenReturn(rootNode);
+ when(change.getRootPath()).thenReturn(rootPath);
+
+ changes = ImmutableSet.of(change);
+
+ ActionDefinition def = new ActionDefinitionBuilder().setId(AllowActionDefinition.ID).build();
+
+ when(rootNode.getDataBefore()).thenReturn(def);
+ when(rootNode.getDataAfter()).thenReturn(def);
+ }
+
+ @Test
+ public void testOnDataTreeChanged_Write() {
+ when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
+
+ WriteTransaction wt = resetTransaction();
+
+ listener.onDataTreeChanged(changes);
+
+ verify(wt).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+ any(SupportedActionDefinition.class), eq(true));
+ }
+
+ @Test
+ public void testOnDataTreeChanged_SubtreeModified() {
+ when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+
+ WriteTransaction wt = resetTransaction();
+
+ listener.onDataTreeChanged(changes);
+
+ verify(wt).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+ any(SupportedActionDefinition.class), eq(true));
+ }
+
+ @Test
+ public void testOnDataTreeChanged_Delete() {
+ when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
+
+ WriteTransaction wt = resetTransaction();
+
+ listener.onDataTreeChanged(changes);
+
+ verify(wt).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
+ }
+
+ private WriteTransaction resetTransaction() {
+ WriteTransaction wt = mock(WriteTransaction.class);
+ CheckedFuture checkedFuture = mock(CheckedFuture.class);
+ when(wt.submit()).thenReturn(checkedFuture);
+ when(dataProvider.newWriteOnlyTransaction()).thenReturn(wt);
+ return wt;
+ }
+
+}