X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=groupbasedpolicy.git;a=blobdiff_plain;f=renderers%2Fofoverlay%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fgroupbasedpolicy%2Frenderer%2Fofoverlay%2Fsf%2FActionDefinitionListenerTest.java;fp=renderers%2Fofoverlay%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fgroupbasedpolicy%2Frenderer%2Fofoverlay%2Fsf%2FActionDefinitionListenerTest.java;h=26ce912ed54abc91eb708bd62ccc32d0515bafee;hp=b9d33229c919ba82a2602de2d808b20cf8a95add;hb=e9477a4efceaa89784d1eb96d5fc6a06f44edcfa;hpb=c8d5d6270466ec2a03dd2c1154b1dce174eacebe diff --git a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ActionDefinitionListenerTest.java b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ActionDefinitionListenerTest.java index b9d33229c..26ce912ed 100755 --- a/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ActionDefinitionListenerTest.java +++ b/renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/sf/ActionDefinitionListenerTest.java @@ -1,120 +1,120 @@ -/* - * 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 rootNode; - private Set> changes; - - private DataBroker dataProvider; - - private InstanceIdentifier 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 rootPath = - new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier); - - DataTreeModification 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; - } - -} +/* + * 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 rootNode; + private Set> changes; + + private DataBroker dataProvider; + + private InstanceIdentifier 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 rootPath = + new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier); + + DataTreeModification 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; + } + +}