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
8 package org.opendaylight.groupbasedpolicy.renderer.faas;
10 import static org.mockito.Matchers.any;
11 import static org.mockito.Mockito.doNothing;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.spy;
14 import static org.mockito.Mockito.when;
16 import java.util.concurrent.Executors;
17 import java.util.concurrent.ScheduledExecutorService;
19 import com.google.common.util.concurrent.CheckedFuture;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
26 import org.opendaylight.groupbasedpolicy.renderer.faas.test.DataChangeListenerTester;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.common.rev151013.Uuid;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantBuilder;
31 import org.opendaylight.yangtools.yang.binding.DataObject;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 public class FaasTenantManagerListenerCovrgTest {
36 private InstanceIdentifier<Tenant> tenantIid;
37 private FaasPolicyManager faasPolicyManager;
38 private FaasTenantManagerListener listener;
39 private TenantId gbpTenantId = new TenantId("gbpTenantId");
40 private Uuid faasTenantId = new Uuid("b4511aac-ae43-11e5-bf7f-feff819cdc9f");
41 private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
42 private DataChangeListenerTester tester;
43 private DataBroker dataProvider;
45 @SuppressWarnings("unchecked")
48 dataProvider = mock(DataBroker.class);
49 WriteTransaction wTx = mock(WriteTransaction.class);
50 CheckedFuture<Void, TransactionCommitFailedException> futureVoid = mock(CheckedFuture.class);
51 when(wTx.submit()).thenReturn(futureVoid);
52 doNothing().when(wTx).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
53 any(DataObject.class));
54 when(dataProvider.newWriteOnlyTransaction()).thenReturn(wTx);
56 tenantIid = mock(InstanceIdentifier.class);
57 faasPolicyManager = spy(new FaasPolicyManager(dataProvider, executor));
58 doNothing().when(faasPolicyManager).removeTenantLogicalNetwork(gbpTenantId, faasTenantId);
59 listener = new FaasTenantManagerListener(faasPolicyManager, gbpTenantId, faasTenantId, executor);
60 tester = new DataChangeListenerTester(listener);
61 tester.setRemovedPath(tenantIid);
66 public void testOnDataChanged() {
67 Tenant tenant = new TenantBuilder().setId(gbpTenantId).build();
68 tester.setDataObject(tenantIid, tenant);
69 tester.callOnDataChanged();
70 listener.executeEvent(tester.getChangeMock());