2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.openflow.ofswitch.config;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.doReturn;
14 import java.util.Collections;
15 import org.junit.After;
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.ArgumentCaptor;
21 import org.mockito.Captor;
22 import org.mockito.Mock;
23 import org.mockito.Mockito;
24 import org.mockito.runners.MockitoJUnitRunner;
25 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
26 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
27 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
28 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
29 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
30 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
31 import org.opendaylight.openflowplugin.api.OFConstants;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
44 * Test for {@link DefaultConfigPusher}.
46 @RunWith(MockitoJUnitRunner.class)
47 public class DefaultConfigPusherTest {
48 private DefaultConfigPusher defaultConfigPusher;
49 private static final InstanceIdentifier<Node> NODE_IID = InstanceIdentifier.create(Nodes.class)
50 .child(Node.class, new NodeKey(new NodeId("testnode:1")));
52 private NodeConfigService nodeConfigService;
54 private DataTreeModification<FlowCapableNode> dataTreeModification;
56 private ArgumentCaptor<SetConfigInput> setConfigInputCaptor;
59 public void setUp() throws Exception {
60 doReturn(RpcResultBuilder.success().buildFuture()).when(nodeConfigService).setConfig(any());
61 defaultConfigPusher = new DefaultConfigPusher(nodeConfigService, Mockito.mock(DataBroker.class));
62 final DataTreeIdentifier<FlowCapableNode> identifier =
63 new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, NODE_IID);
64 Mockito.when(dataTreeModification.getRootPath()).thenReturn(identifier);
65 Mockito.when(dataTreeModification.getRootNode()).thenReturn(Mockito.mock(DataObjectModification.class));
66 Mockito.when(dataTreeModification.getRootNode().getModificationType()).thenReturn(ModificationType.WRITE);
70 public void testOnDataTreeChanged() {
71 defaultConfigPusher.onDataTreeChanged(Collections.singleton(dataTreeModification));
72 Mockito.verify(nodeConfigService).setConfig(setConfigInputCaptor.capture());
73 final SetConfigInput captured = setConfigInputCaptor.getValue();
74 Assert.assertEquals(SwitchConfigFlag.FRAGNORMAL.toString(), captured.getFlag());
75 Assert.assertEquals(OFConstants.OFPCML_NO_BUFFER, captured.getMissSearchLength());
76 Assert.assertEquals(NODE_IID, captured.getNode().getValue());
80 public void tearDown() {
81 defaultConfigPusher.close();