Bug 8228 - metadata service fix made cleaner
[groupbasedpolicy.git] / renderers / vpp / src / test / java / org / opendaylight / groupbasedpolicy / renderer / vpp / policy / acl / AccessListUtilTest.java
1 /*
2  * Copyright (c) 2016 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.groupbasedpolicy.renderer.vpp.policy.acl;
10
11 import java.util.List;
12 import java.util.stream.Collectors;
13
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mockito;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.PolicyContext;
20 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22
23 import com.google.common.base.Optional;
24
25 public class AccessListUtilTest extends TestResources {
26
27     private PolicyContext ctx;
28     private MountedDataBrokerProvider mountedDataProviderMock;
29     private DataBroker mountPointDataBroker;
30
31     @Before
32     public void init() {
33         ctx = super.createPolicyContext();
34         mountedDataProviderMock = Mockito.mock(MountedDataBrokerProvider.class);
35         mountPointDataBroker = Mockito.mock(DataBroker.class);
36         Mockito.when(mountedDataProviderMock.getDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
37             .thenReturn(Optional.of(mountPointDataBroker));
38     }
39
40     @Test
41     public void resolveAclsOnInterfaceTest() {
42         // TODO add more checking
43         AclManager aclManager = new AclManager(mountedDataProviderMock);
44         List<AccessListWrapper> acls =
45                 aclManager.resolveAclsOnInterface(rendererEndpoint(l2AddrEp2).build().getKey(), ctx);
46         Assert.assertEquals(2, acls.size());
47         Assert.assertEquals(2, acls.stream().map(AccessListWrapper::getDirection).collect(Collectors.toSet()).size());
48         acls.stream().forEach(ace -> {
49             // allow peer + deny rest of tenant net + permit external
50             if (ace instanceof IngressAccessListWrapper) {
51                 Assert.assertEquals(3, ace.readRules().size());
52             } else if (ace instanceof EgressAccessListWrapper) {
53                 Assert.assertEquals(3, ace.readRules().size());
54             }
55         });
56     }
57 }