2 * Copyright (c) 2015 Inocybe Technologies 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
8 package org.opendaylight.ovsdb.southbound.transactions.md;
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;
16 import java.util.HashMap;
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.powermock.api.mockito.PowerMockito;
32 import org.powermock.api.support.membermodification.MemberMatcher;
33 import org.powermock.api.support.membermodification.MemberModifier;
34 import org.powermock.core.classloader.annotations.PrepareForTest;
35 import org.powermock.modules.junit4.PowerMockRunner;
37 @PrepareForTest({ OvsdbBridgeRemovedCommand.class, TyperUtils.class, SouthboundMapper.class })
38 @RunWith(PowerMockRunner.class)
39 public class OvsdbBridgeRemovedCommandTest {
40 @Mock private OvsdbBridgeRemovedCommand ovsdbBridgeRemovedCommand;
41 @Mock private OvsdbConnectionInstance key;
42 @Mock private TableUpdates updates;
43 @Mock private DatabaseSchema dbSchema;
46 public void setUp() throws Exception {
47 ovsdbBridgeRemovedCommand = mock(OvsdbBridgeRemovedCommand.class, Mockito.CALLS_REAL_METHODS);
48 MemberModifier.field(OvsdbBridgeRemovedCommand.class, "key").set(ovsdbBridgeRemovedCommand, key);
49 MemberModifier.field(OvsdbBridgeRemovedCommand.class, "updates").set(ovsdbBridgeRemovedCommand, updates);
50 MemberModifier.field(OvsdbBridgeRemovedCommand.class, "dbSchema").set(ovsdbBridgeRemovedCommand, dbSchema);
54 public void testExecute() throws Exception {
55 //suppress calls to parent get methods
56 MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeRemovedCommand.class, "getUpdates"));
57 when(ovsdbBridgeRemovedCommand.getUpdates()).thenReturn(mock(TableUpdates.class));
58 MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeRemovedCommand.class, "getDbSchema"));
59 when(ovsdbBridgeRemovedCommand.getDbSchema()).thenReturn(mock(DatabaseSchema.class));
61 PowerMockito.mockStatic(TyperUtils.class);
62 Map<UUID, Bridge> map = new HashMap<>();
63 when(TyperUtils.extractRowsRemoved(eq(Bridge.class), any(TableUpdates.class), any(DatabaseSchema.class)))
66 ReadWriteTransaction transaction = mock(ReadWriteTransaction.class);
67 ovsdbBridgeRemovedCommand.execute(transaction);
68 verify(ovsdbBridgeRemovedCommand).getUpdates();
69 verify(ovsdbBridgeRemovedCommand).getDbSchema();