54ebd60de51983f199096343102ab728efe26305
[controller.git] / opendaylight / netconf / config-netconf-connector / src / test / java / org / opendaylight / controller / netconf / confignetconfconnector / operations / editconfig / ReplaceEditConfigStrategyTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Matchers.anyString;
13 import static org.mockito.Mockito.*;
14
15 import java.util.Map;
16
17 import javax.management.Attribute;
18 import javax.management.ObjectName;
19
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.mockito.Mock;
23 import org.mockito.MockitoAnnotations;
24 import org.opendaylight.controller.config.util.ConfigTransactionClient;
25 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
26
27 import com.google.common.collect.Sets;
28
29 public class ReplaceEditConfigStrategyTest {
30
31     @Mock
32     private ConfigTransactionClient ta;
33
34     @Before
35     public void setUp() throws Exception {
36         MockitoAnnotations.initMocks(this);
37         doNothing().when(ta).destroyConfigBean(anyString(), anyString());
38         doReturn(mockON()).when(ta).lookupConfigBean(anyString(), anyString());
39         doNothing().when(ta).setAttribute(any(ObjectName.class), anyString(), any(Attribute.class));
40     }
41
42     @Test
43     public void test() throws Exception {
44         ReplaceEditConfigStrategy strat = new ReplaceEditConfigStrategy();
45
46         Map<String, AttributeConfigElement> map = EditConfigTest.getSimpleAttributes();
47
48         doReturn(Sets.newHashSet(mockON(), mockON())).when(ta).lookupConfigBeans();
49
50         strat.executeConfiguration("m1", "i1", map, ta);
51
52         verify(ta).lookupConfigBean(anyString(), anyString());
53         verify(ta).setAttribute(any(ObjectName.class), anyString(), any(Attribute.class));
54     }
55
56     ObjectName mockON() {
57         ObjectName mock = mock(ObjectName.class);
58         doReturn("mockON").when(mock).toString();
59         return mock;
60     }
61
62 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.