+/*
+ * Copyright (c) 2016 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.renderer.faas;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.MoreExecutors;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executor;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.faas.rev151009.logical.networks.logical.network.ProviderNetworkBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.faas.rev151009.mapped.tenants.entities.MappedEntity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.faas.rev151009.mapped.tenants.entities.MappedTenant;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.faas.rev151009.mapped.tenants.entities.mapped.entity.MappedSubnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.faas.rev151009.mapped.tenants.entities.mapped.entity.MappedSubnetBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomainBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2FloodDomainBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3Context;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3ContextBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.SubnetBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroup;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.ResolvedPolicies;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({UlnDatastoreApi.class})
+@PrepareForTest(UlnDatastoreApi.class)
public class FaasPolicyManagerCovrgTest {
private InstanceIdentifier<DataObject> policyId;
- private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change;
DataBroker dataProvider;
- private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(Runtime.getRuntime()
- .availableProcessors());
- EndpointGroupId consumerEpgId = new EndpointGroupId("consumerEpgId");
- SubnetId consumerSubnet = new SubnetId("consumerSubnet");
- SubnetId providerSubnet = new SubnetId("providerSubnet");
- EndpointGroupId providerEpgId = new EndpointGroupId("providerEpgId");
- ContractId contractId = new ContractId("contractId");
- TenantId tenantId = new TenantId("tenantId");
- Uuid faasTenantId = new Uuid("0eb98cf5-086c-4a81-8a4e-0c3b4566108b");
- Uuid faasSecRulesId = new Uuid("1eb98cf5-086c-4a81-8a4e-0c3b4566108b");
- L3ContextId l3Context = new L3ContextId("l3ContextId");
- EndpointGroupId epgId = new EndpointGroupId("epgId");
- SubnetId subnetId = new SubnetId("subnetId");
- Uuid dummyUuid1 = new Uuid("2eb98cf5-086c-4a81-8a4e-0c3b4566108b");
- Uuid dummyUuid2 = new Uuid("3eb98cf5-086c-4a81-8a4e-0c3b4566108b");
+ private final Executor executor = MoreExecutors.directExecutor();
+ private final EndpointGroupId consumerEpgId = new EndpointGroupId("consumerEpgId");
+ private final SubnetId consumerSubnet = new SubnetId("consumerSubnet");
+ private final SubnetId providerSubnet = new SubnetId("providerSubnet");
+ private final EndpointGroupId providerEpgId = new EndpointGroupId("providerEpgId");
+ private final ContractId contractId = new ContractId("contractId");
+ private final TenantId tenantId = new TenantId("tenantId");
+ private final Uuid faasTenantId = new Uuid("0eb98cf5-086c-4a81-8a4e-0c3b4566108b");
+ private final Uuid faasSecRulesId = new Uuid("1eb98cf5-086c-4a81-8a4e-0c3b4566108b");
+ private final L3ContextId l3Context = new L3ContextId("l3ContextId");
+ private final EndpointGroupId epgId = new EndpointGroupId("epgId");
+ private final SubnetId subnetId = new SubnetId("subnetId");
+ private final Uuid dummyUuid1 = new Uuid("2eb98cf5-086c-4a81-8a4e-0c3b4566108b");
+ private final Uuid dummyUuid2 = new Uuid("3eb98cf5-086c-4a81-8a4e-0c3b4566108b");
@SuppressWarnings("unchecked")
@Before
public void init() throws Exception {
policyId = mock(InstanceIdentifier.class);
- change = mock(AsyncDataChangeEvent.class);
policyId = mock(InstanceIdentifier.class);
dataProvider = mock(DataBroker.class);
CheckedFuture<Void, TransactionCommitFailedException> futureVoid =
mock(CheckedFuture.class);
when(writeTransaction.submit()).thenReturn(futureVoid);
-
- Set<InstanceIdentifier<?>> removedPaths = new HashSet<>();
- removedPaths.add(policyId);
- when(change.getRemovedPaths()).thenReturn(removedPaths);
}
@Test
public void testConstructor() throws Exception {
FaasPolicyManager other = new MockFaasPolicyManager(dataProvider, executor);
- verify(dataProvider).registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- InstanceIdentifier.builder(ResolvedPolicies.class)
- .child(ResolvedPolicy.class)
- .build(), other, AsyncDataBroker.DataChangeScope.SUBTREE);
+ verify(dataProvider).registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ InstanceIdentifier.builder(ResolvedPolicies.class).child(ResolvedPolicy.class).build()), other);
other.close();
}
when(roTx.read(LogicalDatastoreType.OPERATIONAL,
FaasIidFactory.logicalNetworksIid())).thenReturn(futureLogicalNetworks);
LogicalNetworks logicalNetworks = new LogicalNetworksBuilder()
- .setLogicalNetwork( new ArrayList<LogicalNetwork>())
+ .setLogicalNetwork(new ArrayList<LogicalNetwork>())
.build();
Optional<LogicalNetworks> optLogicalNetworks = mock(Optional.class);
when(optLogicalNetworks.isPresent()).thenReturn(true);
}
@Test
- public void testRegisterTenant_null(){
+ public void testRegisterTenant_null() {
FaasPolicyManager policyManager = spy(new FaasPolicyManager(dataProvider, executor));
doNothing().when(policyManager).registerTenant(tenantId, null);
}
@Test
- public void testIsUuid(){
+ public void testIsUuid() {
assertFalse(FaasPolicyManager.isUUid(null));
assertFalse(FaasPolicyManager.isUUid("non-matching string"));
assertTrue(FaasPolicyManager.isUUid("12345678-1234-5123-b123-0123456789ab"));
}
@Test
- public void testHandledPolicy_notEquals(){
+ public void testHandledPolicy_notEquals() {
FaasPolicyManager policyManager = new FaasPolicyManager(dataProvider, executor);
ResolvedPolicy policy = new ResolvedPolicyBuilder()
.setConsumerTenantId(new TenantId("t1"))
}
@Test
- public void testRegisterFollowedEndpointgroup(){
+ public void testRegisterFollowedEndpointgroup() {
EndpointGroupId epgId = new EndpointGroupId("epgId");
FaasPolicyManager policyManager = new FaasPolicyManager(dataProvider, executor);
}
@Test
- public void testRemoveLogicalNetwork_null(){
+ public void testRemoveLogicalNetwork_null() {
FaasPolicyManager policyManager = new FaasPolicyManager(dataProvider, executor);
policyManager.removeLogicalNetwork(null);
}
- /*@SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked")
@Test
public void testCreateLayer3LogicalNetwork() throws ReadFailedException {
- ReadOnlyTransaction roTx = mock(ReadOnlyTransaction.class);
+ ReadOnlyTransaction roTx1 = mock(ReadOnlyTransaction.class);
+ ReadOnlyTransaction roTx2 = mock(ReadOnlyTransaction.class);
CheckedFuture<Optional<ResolvedPolicies>, ReadFailedException> futureResolvedPolicies =
mock(CheckedFuture.class);
Optional<ResolvedPolicies> optResolvedPolicies = mock(Optional.class);
when(futureResolvedPolicies.checkedGet()).thenReturn(optResolvedPolicies);
- when(roTx.read(LogicalDatastoreType.OPERATIONAL,
+ when(roTx1.read(LogicalDatastoreType.OPERATIONAL,
InstanceIdentifier.builder(ResolvedPolicies.class).build())).thenReturn(
futureResolvedPolicies);
CheckedFuture<Optional<MappedSubnet>, ReadFailedException> futureMappedSubnet =
mock(CheckedFuture.class);
Optional<MappedSubnet> optMappedSubnet = mock(Optional.class);
- when(optMappedSubnet.isPresent()).thenReturn(true);
+ when(optMappedSubnet.isPresent()).thenReturn(false);
when(optMappedSubnet.get()).thenReturn(mappedSubnet);
when(futureMappedSubnet.checkedGet()).thenReturn(optMappedSubnet);
- when(roTx.read(LogicalDatastoreType.OPERATIONAL,
+ when(roTx2.read(LogicalDatastoreType.OPERATIONAL,
FaasIidFactory.mappedSubnetIid(tenantId, subnetId))).thenReturn(
futureMappedSubnet);
- when(dataProvider.newReadOnlyTransaction()).thenReturn(roTx);
+ when(dataProvider.newReadOnlyTransaction()).thenReturn(roTx1);
+ when(dataProvider.newReadOnlyTransaction()).thenReturn(roTx2);
EndpointGroup consumerEpg = new EndpointGroupBuilder().setId(consumerEpgId).build();
EndpointGroup providerEpg = new EndpointGroupBuilder().setId(providerEpgId).build();
FaasPolicyManager policyManager = new FaasPolicyManager(dataProvider, executor);
- policyManager.registerSubnetWithEpg(consumerEpgId, tenantId, consumerSubnet);
- policyManager.registerSubnetWithEpg(providerEpgId, tenantId, providerSubnet);
policyManager.createLayer3LogicalNetwork(consumerEpg, contractId, providerEpg, tenantId,
ServiceCommunicationLayer.Layer3, ExternalImplicitGroup.ProviderEpg);
- }*/
-
-
-
-
-
- private L3Context makeTestL3Context() {
- L3ContextBuilder builder = new L3ContextBuilder();
- builder.setId(l3Context);
- return builder.build();
- }
-
- private L2FloodDomain makeTestL2FloodDomain(String id, L2BridgeDomainId brdgId) {
- L2FloodDomainBuilder builder = new L2FloodDomainBuilder();
- builder.setId(new L2FloodDomainId(id));
- builder.setParent(brdgId);
- return builder.build();
- }
-
- private L2BridgeDomain makeTestBridgeDomain(String id) {
- L2BridgeDomainBuilder builder = new L2BridgeDomainBuilder();
- builder.setId(new L2BridgeDomainId(id));
- builder.setParent(l3Context);
- return builder.build();
- }
-
- private EndpointGroup makeTestEndpointGroup(EndpointGroupId epgId) {
- EndpointGroupBuilder builder = new EndpointGroupBuilder();
- builder.setId(epgId);
- return builder.build();
- }
-
- private Subnet makeTestSubnet(SubnetId subnetId, L2FloodDomainId l2FloodDomainId) {
- SubnetBuilder builder = new SubnetBuilder();
- builder.setId(subnetId);
- builder.setParent(l2FloodDomainId);
- return builder.build();
-
}
- private DataObject makeTestResolvedPolicy() {
- ResolvedPolicyBuilder builder = new ResolvedPolicyBuilder();
- builder.setConsumerEpgId(consumerEpgId);
- builder.setConsumerTenantId(tenantId);
- builder.setProviderEpgId(providerEpgId);
- builder.setProviderTenantId(tenantId);
- List<PolicyRuleGroupWithEndpointConstraints> pRulesGrpsWEp = new ArrayList<>();
- PolicyRuleGroupWithEndpointConstraintsBuilder pRulesGrpWEp = new PolicyRuleGroupWithEndpointConstraintsBuilder();
- List<PolicyRuleGroup> pRulesGrps = new ArrayList<>();
- PolicyRuleGroupBuilder pRulesGrp = new PolicyRuleGroupBuilder();
- pRulesGrp.setContractId(contractId);
- pRulesGrps.add(pRulesGrp.build());
- pRulesGrpWEp.setPolicyRuleGroup(pRulesGrps);
- pRulesGrpsWEp.add(pRulesGrpWEp.build());
- builder.setPolicyRuleGroupWithEndpointConstraints(pRulesGrpsWEp);
- return builder.build();
- }
-
- private DataObject makeTestResolvedPolicyWithImpExternalEpg() {
- ResolvedPolicyBuilder builder = new ResolvedPolicyBuilder((ResolvedPolicy) makeTestResolvedPolicy());
- builder.setExternalImplicitGroup(ExternalImplicitGroup.ConsumerEpg);
- return builder.build();
- }
}