public void removeFromScope(TenantId tenant,
EndpointGroupId endpointGroup) {
synchronized (this) {
- boolean canUnsubscribe = false;
+ boolean canUnsubscribe = true;
scopeElements.remove(new EgKey(tenant, endpointGroup));
for (EgKey element : scopeElements) {
if (element.getTenantId().equals(tenant)) {
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.endpoint;
+
+import static org.mockito.Mockito.mock;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2ContextId;
+
+public class EpKeyTest {
+
+ private EpKey epKey;
+
+ private L2ContextId l2Context;
+ private MacAddress macAddress;
+
+ @Before
+ public void initialisation() {
+ l2Context = mock(L2ContextId.class);
+ macAddress = mock(MacAddress.class);
+
+ epKey = new EpKey(l2Context, macAddress);
+ }
+
+ @Test
+ public void constructorTest() {
+ Assert.assertEquals(l2Context, epKey.getL2Context());
+ Assert.assertEquals(macAddress, epKey.getMacAddress());
+ }
+
+ @Test
+ public void equalsTest() {
+ Assert.assertTrue(epKey.equals(epKey));
+ Assert.assertFalse(epKey.equals(null));
+ Assert.assertFalse(epKey.equals(new Object()));
+
+ EpKey other;
+ MacAddress macAddressOther = mock(MacAddress.class);
+ L2ContextId l2ContextIdOther = mock(L2ContextId.class);
+ other = new EpKey(l2Context, macAddressOther);
+ Assert.assertFalse(epKey.equals(other));
+ other = new EpKey(l2ContextIdOther, macAddress);
+ Assert.assertFalse(epKey.equals(other));
+ other = new EpKey(l2Context, macAddress);
+ Assert.assertTrue(epKey.equals(other));
+
+ epKey = new EpKey(l2Context, null);
+ Assert.assertFalse(epKey.equals(other));
+ epKey = new EpKey(null, macAddress);
+ Assert.assertFalse(epKey.equals(other));
+ epKey = new EpKey(null, null);
+ Assert.assertFalse(epKey.equals(other));
+ other = new EpKey(null, null);
+ Assert.assertTrue(epKey.equals(other));
+ }
+
+ @Test
+ public void toStringTest() {
+ Assert.assertNotNull(epKey.toString());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.resolver;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ConditionGroupTest {
+
+ private ConditionGroup conditionGroup;
+
+ private ConditionSet conditionSet;
+ private Set<ConditionSet> conditionSetSet;
+
+ @Before
+ public void initialisation() {
+ conditionSet = mock(ConditionSet.class);
+ conditionSetSet = Collections.singleton(conditionSet);
+
+ conditionGroup = new ConditionGroup(conditionSetSet);
+ }
+
+ @Test
+ public void constructorTest() {
+ Assert.assertTrue(conditionGroup.contains(conditionSet));
+ }
+
+ @Test
+ public void equalsTest() {
+ Assert.assertTrue(conditionGroup.equals(conditionGroup));
+ Assert.assertFalse(conditionGroup.equals(null));
+ Assert.assertFalse(conditionGroup.equals(new Object()));
+
+ ConditionSet conditionSet = mock(ConditionSet.class);
+ Set<ConditionSet> conditionSetSetOther = Collections.singleton(conditionSet);
+ ConditionGroup other;
+ other = new ConditionGroup(conditionSetSetOther);
+ Assert.assertFalse(conditionGroup.equals(other));
+ }
+
+ @Test
+ public void toStringTest() {
+ Assert.assertNotNull(conditionGroup.toString());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.resolver;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
+
+public class ConditionSetTest {
+
+ private ConditionSet conditionSet;
+
+ private ConditionName conditionName;
+ private Set<ConditionName> conditionNameSet;
+ private Set<Set<ConditionName>> anySet;
+
+ @Before
+ public void initialisation() {
+ conditionName = mock(ConditionName.class);
+ conditionNameSet = Collections.singleton(conditionName);
+ anySet = Collections.singleton(conditionNameSet);
+ conditionSet = new ConditionSet(conditionNameSet, conditionNameSet, anySet);
+ }
+
+ @Test
+ public void matchesTest() {
+ List<ConditionName> conditionNameList;
+ conditionNameList = Arrays.asList(conditionName);
+ Assert.assertFalse(conditionSet.matches(conditionNameList));
+
+ ConditionName conditionNameOther;
+ conditionNameOther = mock(ConditionName.class);
+ conditionNameList = Arrays.asList(conditionNameOther);
+ Assert.assertFalse(conditionSet.matches(conditionNameList));
+ }
+
+ @Test
+ public void equalsTest() {
+ Assert.assertTrue(conditionSet.equals(conditionSet));
+ Assert.assertFalse(conditionSet.equals(null));
+ Assert.assertFalse(conditionSet.equals(new Object()));
+
+ ConditionSet other;
+ other = ConditionSet.EMPTY;
+ Assert.assertFalse(conditionSet.equals(other));
+
+ other = new ConditionSet(conditionNameSet, Collections.<ConditionName>emptySet(),
+ Collections.<Set<ConditionName>>emptySet());
+ Assert.assertFalse(conditionSet.equals(other));
+
+ other = new ConditionSet(conditionNameSet, Collections.<ConditionName>emptySet(), anySet);
+ Assert.assertFalse(conditionSet.equals(other));
+
+ other = new ConditionSet(conditionNameSet, conditionNameSet, anySet);
+ Assert.assertTrue(conditionSet.equals(other));
+ }
+
+ @Test
+ public void toStringTest() {
+ Assert.assertNotNull(conditionSet.toString());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.resolver;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
+
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
+
+public class PolicyInfoTest {
+
+ private PolicyInfo policyInfo;
+
+ private Table<EgKey, EgKey, Policy> policyMap;
+ private EgKey consEgKey;
+ private EgKey provEgKey;
+ private Policy policy;
+
+ private Map<EgKey, Set<ConditionSet>> egConditions;
+ private Set<ConditionSet> conditionSets;
+ private EgKey condEgKey;
+ private ConditionSet conditionSet;
+
+ @Before
+ public void Initialisation() {
+ consEgKey = mock(EgKey.class);
+ provEgKey = mock(EgKey.class);
+ policy = mock(Policy.class);
+
+ policyMap = HashBasedTable.create();
+ policyMap.put(consEgKey, provEgKey, policy);
+
+ conditionSet = mock(ConditionSet.class);
+ conditionSets = new HashSet<ConditionSet>(Arrays.asList(conditionSet));
+ egConditions = new HashMap<EgKey, Set<ConditionSet>>();
+ condEgKey = mock(EgKey.class);
+ egConditions.put(condEgKey, conditionSets);
+
+ policyInfo = new PolicyInfo(policyMap, egConditions);
+ }
+
+ @Test
+ public void constructorTest() {
+ Assert.assertEquals(policyMap, policyInfo.getPolicyMap());
+ Assert.assertEquals(policy, policyInfo.getPolicy(consEgKey, provEgKey));
+ Assert.assertEquals(Policy.EMPTY, policyInfo.getPolicy(provEgKey, consEgKey));
+ Assert.assertEquals(conditionSets, policyInfo.getEgConditions(condEgKey));
+ }
+
+ @Test
+ public void getEgCondGroupTest() {
+ List<ConditionName> conditions = Collections.emptyList();
+ ConditionGroup conditionGroup;
+
+ when(conditionSet.matches(conditions)).thenReturn(false);
+ conditionGroup = policyInfo.getEgCondGroup(condEgKey, conditions);
+ Assert.assertEquals(ConditionGroup.EMPTY, conditionGroup);
+
+ when(conditionSet.matches(conditions)).thenReturn(true);
+ conditionGroup = policyInfo.getEgCondGroup(condEgKey, conditions);
+ Assert.assertTrue(conditionGroup.contains(conditionSet));
+ }
+
+ @Test
+ public void getPeersTest() {
+ Set<EgKey> peers;
+ peers = policyInfo.getPeers(consEgKey);
+ Assert.assertTrue(peers.contains(provEgKey));
+ peers = policyInfo.getPeers(provEgKey);
+ Assert.assertTrue(peers.contains(consEgKey));
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.resolver;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+
+public class PolicyScopeTest {
+
+ private PolicyScope policyScope;
+ private PolicyResolver resolver;
+ private PolicyListener listener;
+
+ @Before
+ public void initialisation() {
+ resolver = mock(PolicyResolver.class);
+ listener = mock(PolicyListener.class);
+ policyScope = new PolicyScope(resolver, listener);
+ }
+
+ @Test
+ public void constructorTest() {
+ Assert.assertEquals(listener, policyScope.getListener());
+ }
+
+ @Test
+ public void tenantTest() {
+ TenantId tenantId = mock(TenantId.class);
+
+ policyScope.addToScope(tenantId);
+ verify(resolver).subscribeTenant(tenantId);
+ Assert.assertTrue(policyScope.contains(tenantId, null));
+
+ policyScope.removeFromScope(tenantId);
+ verify(resolver).unsubscribeTenant(tenantId);
+ Assert.assertFalse(policyScope.contains(tenantId, null));
+ }
+
+ @Test
+ public void TenantEndpointGroupTest() {
+ TenantId tenantId = mock(TenantId.class);
+ EndpointGroupId endpointGroupId = mock(EndpointGroupId.class);
+
+ policyScope.addToScope(tenantId, endpointGroupId);
+ verify(resolver).subscribeTenant(tenantId);
+ Assert.assertTrue(policyScope.contains(tenantId, endpointGroupId));
+
+ policyScope.removeFromScope(tenantId, endpointGroupId);
+ verify(resolver).unsubscribeTenant(tenantId);
+ Assert.assertFalse(policyScope.contains(tenantId, endpointGroupId));
+ }
+
+ @Test
+ public void removeFromScopeTestUnsubscribeFalse() {
+ TenantId tenantId = mock(TenantId.class);
+ EndpointGroupId endpointGroupId1 = mock(EndpointGroupId.class);
+ EndpointGroupId endpointGroupId2 = mock(EndpointGroupId.class);
+
+ policyScope.addToScope(tenantId, endpointGroupId1);
+ policyScope.addToScope(tenantId, endpointGroupId2);
+ verify(resolver, times(2)).subscribeTenant(tenantId);
+ Assert.assertTrue(policyScope.contains(tenantId, endpointGroupId1));
+ Assert.assertTrue(policyScope.contains(tenantId, endpointGroupId2));
+
+ policyScope.removeFromScope(tenantId, endpointGroupId1);
+ verify(resolver, never()).unsubscribeTenant(tenantId);
+ Assert.assertFalse(policyScope.contains(tenantId, endpointGroupId1));
+ Assert.assertTrue(policyScope.contains(tenantId, endpointGroupId2));
+ }
+}