Bump MRI upstreams
[ovsdb.git] / southbound / southbound-impl / src / test / java / org / opendaylight / ovsdb / southbound / transactions / md / OvsdbBridgeRemovedCommandTest.java
1 /*
2  * Copyright (c) 2015 Inocybe Technologies 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 package org.opendaylight.ovsdb.southbound.transactions.md;
9
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.ArgumentMatchers.eq;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.Mockito.when;
15
16 import java.util.HashMap;
17 import java.util.Map;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Mock;
22 import org.mockito.Mockito;
23 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
24 import org.opendaylight.ovsdb.lib.message.TableUpdates;
25 import org.opendaylight.ovsdb.lib.notation.UUID;
26 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
27 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
28 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
29 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
30 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.powermock.api.mockito.PowerMockito;
33 import org.powermock.api.support.membermodification.MemberMatcher;
34 import org.powermock.api.support.membermodification.MemberModifier;
35 import org.powermock.core.classloader.annotations.PrepareForTest;
36 import org.powermock.modules.junit4.PowerMockRunner;
37
38 @PrepareForTest({OvsdbBridgeRemovedCommand.class, TyperUtils.class, SouthboundMapper.class, InstanceIdentifier.class})
39 @RunWith(PowerMockRunner.class)
40 public class OvsdbBridgeRemovedCommandTest {
41     @Mock private OvsdbBridgeRemovedCommand ovsdbBridgeRemovedCommand;
42     @Mock private OvsdbConnectionInstance key;
43     @Mock private TableUpdates updates;
44     @Mock private DatabaseSchema dbSchema;
45
46     @Before
47     public void setUp() throws Exception {
48         ovsdbBridgeRemovedCommand = mock(OvsdbBridgeRemovedCommand.class, Mockito.CALLS_REAL_METHODS);
49         MemberModifier.field(OvsdbBridgeRemovedCommand.class, "key").set(ovsdbBridgeRemovedCommand, key);
50         MemberModifier.field(OvsdbBridgeRemovedCommand.class, "updates").set(ovsdbBridgeRemovedCommand, updates);
51         MemberModifier.field(OvsdbBridgeRemovedCommand.class, "dbSchema").set(ovsdbBridgeRemovedCommand, dbSchema);
52     }
53
54     @Test
55     public void testExecute() throws Exception {
56         //suppress calls to parent get methods
57         MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeRemovedCommand.class, "getUpdates"));
58         when(ovsdbBridgeRemovedCommand.getUpdates()).thenReturn(mock(TableUpdates.class));
59         MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeRemovedCommand.class, "getDbSchema"));
60         when(ovsdbBridgeRemovedCommand.getDbSchema()).thenReturn(mock(DatabaseSchema.class));
61
62         PowerMockito.mockStatic(TyperUtils.class);
63         Map<UUID, Bridge> map = new HashMap<>();
64         when(TyperUtils.extractRowsRemoved(eq(Bridge.class), any(TableUpdates.class), any(DatabaseSchema.class)))
65                 .thenReturn(map);
66
67         ReadWriteTransaction transaction = mock(ReadWriteTransaction.class);
68         ovsdbBridgeRemovedCommand.execute(transaction);
69         verify(ovsdbBridgeRemovedCommand).getUpdates();
70         verify(ovsdbBridgeRemovedCommand).getDbSchema();
71     }
72 }