@Override public void execute(TransactionBuilder transaction) { List<Operation> operations = transaction.getOperations(); Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Bridge.class); List<Insert> inserts = TransactUtils.extractInsert(transaction, bridge.getSchema()); for (Insert insert : inserts) { OpenVSwitch ovs = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), OpenVSwitch.class); ovs.setBridges(Sets.newHashSet(TransactUtils.extractNamedUuid(insert))); transaction.add( op.mutate(ovs) .addMutation( ovs.getBridgesColumn().getSchema(), Mutator.INSERT, ovs.getBridgesColumn().getData())); } }
@SuppressWarnings("unchecked") @Test public void testExecute() throws Exception { protocolRemovedCommand = mock(ProtocolRemovedCommand.class, Mockito.CALLS_REAL_METHODS); PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(InstanceIdentifier.class)); ProtocolEntry protocol = mock(ProtocolEntry.class); when(protocol.getProtocol()) .thenAnswer( new Answer<Class<? extends OvsdbBridgeProtocolBase>>() { public Class<? extends OvsdbBridgeProtocolBase> answer(InvocationOnMock invocation) throws Throwable { return OvsdbBridgeProtocolOpenflow10.class; } }); Optional<ProtocolEntry> operationalProtocolEntryOptional = mock(Optional.class); when(operationalProtocolEntryOptional.isPresent()).thenReturn(true); when(operationalProtocolEntryOptional.get()).thenReturn(protocol); BridgeOperationalState bridgeOpState = mock(BridgeOperationalState.class); when(bridgeOpState.getProtocolEntry(any(InstanceIdentifier.class))) .thenReturn(operationalProtocolEntryOptional); MemberModifier.suppress( MemberMatcher.method(ProtocolUpdateCommand.class, "getOperationalState")); when(protocolRemovedCommand.getOperationalState()).thenReturn(bridgeOpState); InstanceIdentifier<ProtocolEntry> protocolIid = mock(InstanceIdentifier.class); removed.add(protocolIid); MemberModifier.field(ProtocolRemovedCommand.class, "removed") .set(protocolRemovedCommand, removed); MemberModifier.field(ProtocolRemovedCommand.class, "updatedBridges") .set(protocolRemovedCommand, updatedBridges); when(updatedBridges.get(any(InstanceIdentifier.class))) .thenReturn(mock(OvsdbBridgeAugmentation.class)); Operations op = (Operations) setField("op"); Mutate<GenericTableSchema> mutate = mock(Mutate.class); when(op.mutate(any(Bridge.class))).thenReturn(mutate); Column<GenericTableSchema, Set<String>> column = mock(Column.class); Bridge bridge = mock(Bridge.class); when(bridge.getProtocolsColumn()).thenReturn(column); when(column.getSchema()).thenReturn(mock(ColumnSchema.class)); when(column.getData()).thenReturn(new HashSet<String>()); when(mutate.addMutation(any(ColumnSchema.class), any(Mutator.class), any(Set.class))) .thenReturn(mutate); PowerMockito.mockStatic(TyperUtils.class); when(TyperUtils.getTypedRowWrapper(any(DatabaseSchema.class), any(Class.class))) .thenReturn(bridge); TransactionBuilder transaction = mock(TransactionBuilder.class); protocolRemovedCommand.execute(transaction); Mockito.verify(transaction).add(any(Operation.class)); }
@Override public <T extends TypedBaseTable<?>> T createTypedRowWrapper( DatabaseSchema dbSchema, Class<T> clazz) { return TyperUtils.getTypedRowWrapper(dbSchema, clazz, new Row<>()); }
// Typed row wrappers @Override public <T extends TypedBaseTable<?>> T getTypedRowWrapper( Class<T> clazz, Row<GenericTableSchema> row) { return TyperUtils.getTypedRowWrapper(vtepSchema, clazz, row); }