<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>sal-binding-broker-impl</artifactId>
public String getMessage() {\r
return message;\r
}\r
+\r
+ @Override\r
+ public boolean equals(Object o) {\r
+ if (this == o)\r
+ return true;\r
+ if (o == null || getClass() != o.getClass())\r
+ return false;\r
+\r
+ ValidationResultImpl that = (ValidationResultImpl) o;\r
+\r
+ if (success != that.success)\r
+ return false;\r
+ return message.equals(that.message);\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ int result = (success ? 1 : 0);\r
+ result = 31 * result + message.hashCode();\r
+ return result;\r
+ }\r
}\r
\r
private boolean success;\r
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
Optional<StatisticsStore> storeOpt = Optional.absent();
try {
storeOpt = rtx.read(LogicalDatastoreType.OPERATIONAL, statsIID).get();
- } catch (Exception e) {
- e.printStackTrace();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Exception thrown on reading from Datastore: {}", e.getMessage());
+ return null;
}
if (storeOpt.isPresent()) {
StatisticsStore store = storeOpt.get();
+++ /dev/null
-package org.opendaylight.groupbasedpolicy.endpoint;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentation;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-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.EndpointGroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.Endpoints;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.SetEndpointGroupConditionsInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnsetEndpointGroupConditionsInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.has.endpoint.group.conditions.EndpointGroupCondition;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L2;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L3;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-
-import com.google.common.util.concurrent.CheckedFuture;
-
-public class EndPointRpcRegistryTest {
-
- private DataBroker dataProvider;
- private RpcProviderRegistry rpcRegistry;
- private RpcRegistration<EndpointService> rpcRegistration;
- private WriteTransaction t;
- private EpRendererAugmentation epRendererAugmentation;
-
- private EndpointRpcRegistry endpointRpcRegistry;
-
- @SuppressWarnings("unchecked")
- @Before
- public void initialisation() {
- dataProvider = mock(DataBroker.class);
- rpcRegistry = mock(RpcProviderRegistry.class);
- epRendererAugmentation = mock(EpRendererAugmentation.class);
-
- t = mock(WriteTransaction.class);
- when(dataProvider.newWriteOnlyTransaction()).thenReturn(t);
- CheckedFuture<Void, TransactionCommitFailedException> f = mock(CheckedFuture.class);
- when(t.submit()).thenReturn(f);
-
- rpcRegistration = mock(RpcRegistration.class);
- when(rpcRegistry.addRpcImplementation(any(Class.class), any(RpcService.class))).thenReturn(rpcRegistration);
-
- endpointRpcRegistry = new EndpointRpcRegistry(dataProvider, rpcRegistry);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void registerTest() throws Exception {
- verify(rpcRegistry).addRpcImplementation(any(Class.class), any(RpcService.class));
- verify(t).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Endpoints.class));
- endpointRpcRegistry.register(epRendererAugmentation);
- Assert.assertEquals(1, EndpointRpcRegistry.registeredRenderers.size());
-
- endpointRpcRegistry.unregister(epRendererAugmentation);
- Assert.assertEquals(0, EndpointRpcRegistry.registeredRenderers.size());
- }
-
- @Test
- public void registerTestSafelyFail() {
- endpointRpcRegistry.register(epRendererAugmentation);
- endpointRpcRegistry.register(null);
- Assert.assertEquals(1, EndpointRpcRegistry.registeredRenderers.size());
- }
-
- @Test
- public void registerEndpointTest()throws Exception{
- endpointRpcRegistry.registerEndpoint(setRegisterEndpointVariablesForTest());
- verify(t, times(1)).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(DataObject.class), eq(true));
-
- endpointRpcRegistry.registerEndpoint(setL3AddressVariableForTest());
- verify(t, times(2)).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(DataObject.class), eq(true));
- }
-
- private RegisterEndpointInput setRegisterEndpointVariablesForTest() throws Exception{
- RegisterEndpointInputBuilder registerEndpointInputBuilder = new RegisterEndpointInputBuilder();
- registerEndpointInputBuilder.setL2Context(new L2BridgeDomainId("l2bdId"));
- registerEndpointInputBuilder.setMacAddress(new MacAddress("5E:83:39:98:4F:1B"));
- return registerEndpointInputBuilder.build();
- }
-
- private RegisterEndpointInput setL3AddressVariableForTest() {
- RegisterEndpointInputBuilder registerEndpointInputBuilder = new RegisterEndpointInputBuilder();
- List<L3Address> l3AddressList = new ArrayList<>();
- l3AddressList.add(new L3AddressBuilder().setL3Context(new L3ContextId("l3c"))
- .setIpAddress(new IpAddress(new Ipv4Address("1.1.1.1")))
- .build());
- registerEndpointInputBuilder.setL3Address(l3AddressList);
- return registerEndpointInputBuilder.build();
- }
-
- @Test
- public void registerL3PrefixEndpointTest()throws Exception{
- endpointRpcRegistry.registerL3PrefixEndpoint(setL3PrefixTestVariables());
- verify(t, atLeast(1)).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(DataObject.class));
- }
-
- private RegisterL3PrefixEndpointInput setL3PrefixTestVariables(){
- RegisterL3PrefixEndpointInputBuilder registerL3PrefixEndpointInputBuilder = new RegisterL3PrefixEndpointInputBuilder();
- registerL3PrefixEndpointInputBuilder.setL3Context(new L3ContextId("l3c"));
- registerL3PrefixEndpointInputBuilder.setIpPrefix(new IpPrefix(new Ipv4Prefix("1.1.1.0/24")));
- registerL3PrefixEndpointInputBuilder.setTenant(new TenantId("t1"));
- return registerL3PrefixEndpointInputBuilder.build();
- }
-
- @Test
- public void unregisterEndpointTest() throws Exception{
- L2 l2Mock = mock(L2.class);
- List<L2> l2List = new ArrayList<>();
- l2List.add(l2Mock);
- L3 l3Mock = mock(L3.class);
- List<L3> l3List = new ArrayList<>();
- l3List.add(l3Mock);
- UnregisterEndpointInput unregisterEndpointInputMock = mock(UnregisterEndpointInput.class);
- doReturn(l2List).when(unregisterEndpointInputMock).getL2();
- doReturn(l3List).when(unregisterEndpointInputMock).getL3();
- endpointRpcRegistry.unregisterEndpoint(unregisterEndpointInputMock);
- verify(t, times(2)).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
- }
-
- @Test
- public void setEndpointGroupConditionsTest()throws Exception{
- EndpointGroupId endpointGroupIdMock = mock(EndpointGroupId.class);
-
- EndpointGroupCondition endpointGroupConditionMock = mock(EndpointGroupCondition.class);
- List<EndpointGroupCondition> endpointGroupConditionList = new ArrayList();
- endpointGroupConditionList.add(endpointGroupConditionMock);
- SetEndpointGroupConditionsInput setEndpointGroupConditionsInputMock = mock(SetEndpointGroupConditionsInput.class);
- doReturn(endpointGroupIdMock).when(setEndpointGroupConditionsInputMock).getEndpointGroup();
- doReturn(endpointGroupConditionList).when(setEndpointGroupConditionsInputMock).getEndpointGroupCondition();
- endpointRpcRegistry.setEndpointGroupConditions(setEndpointGroupConditionsInputMock);
- verify(t, atLeast(1)).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class), any(EndpointGroupCondition.class));
- }
-
- @Test
- public void unsetEndpointGroupConditionsTest()throws Exception{
- UnsetEndpointGroupConditionsInput unsetEndpointGroupConditionsInputMock = mock(UnsetEndpointGroupConditionsInput.class);
- EndpointGroupCondition endpointGroupConditionMock = mock(EndpointGroupCondition.class);
- List<EndpointGroupCondition> endpointGroupConditionList = new ArrayList();
- endpointGroupConditionList.add(endpointGroupConditionMock);
- doReturn(mock(EndpointGroupId.class)).when(unsetEndpointGroupConditionsInputMock).getEndpointGroup();
- doReturn(endpointGroupConditionList).when(unsetEndpointGroupConditionsInputMock).getEndpointGroupCondition();
- endpointRpcRegistry.unsetEndpointGroupConditions(unsetEndpointGroupConditionsInputMock);
- verify(t, times(1)).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
- }
-}
--- /dev/null
+package org.opendaylight.groupbasedpolicy.endpoint;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+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 static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.common.util.concurrent.CheckedFuture;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentation;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+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.ConditionName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.SetEndpointGroupConditionsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.SetEndpointGroupConditionsInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnsetEndpointGroupConditionsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnsetEndpointGroupConditionsInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3AddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.has.endpoint.group.conditions.EndpointGroupCondition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.has.endpoint.group.conditions.EndpointGroupConditionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L3Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L3Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L3PrefixBuilder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class EndpointRpcRegistryTest {
+
+ private static final String L2_BD_ID = "l2bdId";
+ private static final String MAC_ADDRESS = "5E:83:39:98:4F:1B";
+ private static final String L3_CX_ID = "l3c";
+ private static final String IPv4_ADDRESS = "1.1.1.1";
+ private static final String IPv4_PREFIX = "1.1.1.0/24";
+ private static final String TENANT_ID = "t1";
+ private static final String EPG_ID = "epg_1";
+ private static final String CONDITION_NAME = "condition_1";
+
+ private DataBroker dataProvider;
+ private EpRendererAugmentation epRendererAugmentation;
+ private EndpointRpcRegistry endpointRpcRegistry;
+
+ @Before
+ public void init() {
+ dataProvider = mock(DataBroker.class);
+ epRendererAugmentation = mock(EpRendererAugmentation.class);
+ WriteTransaction wt = newWriteTransactionMock();
+ RpcProviderRegistry rpcRegistry = mock(RpcProviderRegistry.class);
+
+ endpointRpcRegistry = new EndpointRpcRegistry(dataProvider, rpcRegistry);
+ }
+
+ @Test
+ public void testConstructor() throws Exception {
+ RpcProviderRegistry rpcRegistry = mock(RpcProviderRegistry.class);
+ EndpointRpcRegistry other = new EndpointRpcRegistry(dataProvider, rpcRegistry);
+ other.close();
+ }
+
+ @Test
+ public void testRegister() throws Exception {
+ WriteTransaction wt = newWriteTransactionMock();
+
+ endpointRpcRegistry.register(epRendererAugmentation);
+ Assert.assertEquals(1, EndpointRpcRegistry.registeredRenderers.size());
+
+ endpointRpcRegistry.unregister(epRendererAugmentation);
+ Assert.assertEquals(0, EndpointRpcRegistry.registeredRenderers.size());
+ }
+
+ @Test
+ public void testRegister_SafelyFail() {
+ endpointRpcRegistry.register(epRendererAugmentation);
+ endpointRpcRegistry.register(null);
+
+ Assert.assertEquals(1, EndpointRpcRegistry.registeredRenderers.size());
+ }
+
+ @Test
+ public void testRegisterEndpoint() throws Exception {
+ WriteTransaction wt = newWriteTransactionMock();
+
+ endpointRpcRegistry.registerEndpoint(setRegisterEndpointVariablesForTest());
+
+ verify(wt, times(1)).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+ any(DataObject.class), eq(true));
+
+ endpointRpcRegistry.registerEndpoint(setL3AddressVariableForTest());
+
+ verify(wt, times(2)).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+ any(DataObject.class), eq(true));
+ }
+
+ private RegisterEndpointInput setRegisterEndpointVariablesForTest() throws Exception {
+ RegisterEndpointInputBuilder registerEndpointInputBuilder = new RegisterEndpointInputBuilder();
+ registerEndpointInputBuilder.setL2Context(new L2BridgeDomainId(L2_BD_ID));
+ registerEndpointInputBuilder.setMacAddress(new MacAddress(MAC_ADDRESS));
+ return registerEndpointInputBuilder.build();
+ }
+
+ private RegisterEndpointInput setL3AddressVariableForTest() {
+ RegisterEndpointInputBuilder registerEndpointInputBuilder = new RegisterEndpointInputBuilder();
+ List<L3Address> l3AddressList = new ArrayList<>();
+ l3AddressList.add(new L3AddressBuilder().setL3Context(new L3ContextId(L3_CX_ID))
+ .setIpAddress(new IpAddress(new Ipv4Address(IPv4_ADDRESS)))
+ .build());
+ registerEndpointInputBuilder.setL3Address(l3AddressList);
+ return registerEndpointInputBuilder.build();
+ }
+
+ @Test
+ public void testRegisterL3PrefixEndpoint() throws Exception {
+ WriteTransaction wt = newWriteTransactionMock();
+
+ endpointRpcRegistry.registerL3PrefixEndpoint(setL3PrefixTestVariables());
+
+ verify(wt, times(1)).put(eq(LogicalDatastoreType.OPERATIONAL),
+ Mockito.<InstanceIdentifier<EndpointL3Prefix>>any(), any(EndpointL3Prefix.class));
+ }
+
+ @Test
+ public void testRegisterL3PrefixEndpoint_BadData() {
+ WriteTransaction wt = newWriteTransactionMock();
+
+ endpointRpcRegistry.registerL3PrefixEndpoint(setL3PrefixTestVariables_NoIpPrefix());
+ endpointRpcRegistry.registerL3PrefixEndpoint(setL3PrefixTestVariables_NoL3Context());
+ endpointRpcRegistry.registerL3PrefixEndpoint(setL3PrefixTestVariables_NoTenant());
+
+ verify(wt, never()).put(eq(LogicalDatastoreType.OPERATIONAL),
+ Mockito.<InstanceIdentifier<EndpointL3Prefix>>any(), any(EndpointL3Prefix.class));
+ }
+
+ private RegisterL3PrefixEndpointInput setL3PrefixTestVariables() {
+ RegisterL3PrefixEndpointInputBuilder registerL3PrefixEndpointInputBuilder =
+ new RegisterL3PrefixEndpointInputBuilder();
+ registerL3PrefixEndpointInputBuilder.setL3Context(new L3ContextId(L3_CX_ID));
+ registerL3PrefixEndpointInputBuilder.setIpPrefix(new IpPrefix(new Ipv4Prefix(IPv4_PREFIX)));
+ registerL3PrefixEndpointInputBuilder.setTenant(new TenantId(TENANT_ID));
+ return registerL3PrefixEndpointInputBuilder.build();
+ }
+
+ private RegisterL3PrefixEndpointInput setL3PrefixTestVariables_NoL3Context() {
+ RegisterL3PrefixEndpointInputBuilder registerL3PrefixEndpointInputBuilder =
+ new RegisterL3PrefixEndpointInputBuilder();
+ registerL3PrefixEndpointInputBuilder.setIpPrefix(new IpPrefix(new Ipv4Prefix(IPv4_PREFIX)));
+ registerL3PrefixEndpointInputBuilder.setTenant(new TenantId(TENANT_ID));
+ return registerL3PrefixEndpointInputBuilder.build();
+ }
+
+ private RegisterL3PrefixEndpointInput setL3PrefixTestVariables_NoIpPrefix() {
+ RegisterL3PrefixEndpointInputBuilder registerL3PrefixEndpointInputBuilder =
+ new RegisterL3PrefixEndpointInputBuilder();
+ registerL3PrefixEndpointInputBuilder.setL3Context(new L3ContextId(L3_CX_ID));
+ registerL3PrefixEndpointInputBuilder.setTenant(new TenantId(TENANT_ID));
+ return registerL3PrefixEndpointInputBuilder.build();
+ }
+
+ private RegisterL3PrefixEndpointInput setL3PrefixTestVariables_NoTenant() {
+ RegisterL3PrefixEndpointInputBuilder registerL3PrefixEndpointInputBuilder =
+ new RegisterL3PrefixEndpointInputBuilder();
+ registerL3PrefixEndpointInputBuilder.setL3Context(new L3ContextId(L3_CX_ID));
+ registerL3PrefixEndpointInputBuilder.setIpPrefix(new IpPrefix(new Ipv4Prefix(IPv4_PREFIX)));
+ return registerL3PrefixEndpointInputBuilder.build();
+ }
+
+ @Test
+ public void testUnregisterEndpoint() throws Exception {
+ WriteTransaction wt = newWriteTransactionMock();
+
+ UnregisterEndpointInput unregisterEndpointInput = unregisterEndpointInput();
+
+ endpointRpcRegistry.unregisterEndpoint(unregisterEndpointInput);
+
+ verify(wt, times(2)).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
+ }
+
+ private UnregisterEndpointInput unregisterEndpointInput() {
+ L2 l2 = new L2Builder().setL2Context(new L2BridgeDomainId(L2_BD_ID))
+ .setMacAddress(new MacAddress(MAC_ADDRESS))
+ .build();
+ List<L2> l2List = new ArrayList<>();
+ l2List.add(l2);
+ L3 l3 = new L3Builder().setL3Context(new L3ContextId(L3_CX_ID))
+ .setIpAddress(new IpAddress(new Ipv4Address(IPv4_ADDRESS)))
+ .build();
+ List<L3> l3List = new ArrayList<>();
+ l3List.add(l3);
+ List<L3Prefix> l3PrefixList = new ArrayList<>();
+ l3PrefixList.add(new L3PrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix(IPv4_PREFIX))).build());
+ return new UnregisterEndpointInputBuilder().setL2(l2List).setL3(l3List).setL3Prefix(l3PrefixList).build();
+ }
+
+ @Test
+ public void testSetEndpointGroupConditions() throws Exception {
+ WriteTransaction wt = newWriteTransactionMock();
+
+ EndpointGroupId endpointGroupId = new EndpointGroupId(EPG_ID);
+ EndpointGroupCondition endpointGroupCondition =
+ new EndpointGroupConditionBuilder().setCondition(new ConditionName(CONDITION_NAME)).build();
+ List<EndpointGroupCondition> endpointGroupConditionList = new ArrayList<>();
+ endpointGroupConditionList.add(endpointGroupCondition);
+
+ SetEndpointGroupConditionsInput setEndpointGroupConditionsInput = new SetEndpointGroupConditionsInputBuilder()
+ .setEndpointGroup(endpointGroupId).setEndpointGroupCondition(endpointGroupConditionList).build();
+
+ endpointRpcRegistry.setEndpointGroupConditions(setEndpointGroupConditionsInput);
+
+ verify(wt, times(1)).put(eq(LogicalDatastoreType.OPERATIONAL),
+ Mockito.<InstanceIdentifier<EndpointGroupCondition>>any(), any(EndpointGroupCondition.class));
+ }
+
+ @Test
+ public void testUnsetEndpointGroupConditions() throws Exception {
+ WriteTransaction wt = newWriteTransactionMock();
+
+ EndpointGroupId endpointGroupId = new EndpointGroupId(EPG_ID);
+ EndpointGroupCondition endpointGroupCondition =
+ new EndpointGroupConditionBuilder().setCondition(new ConditionName(CONDITION_NAME)).build();
+ List<EndpointGroupCondition> endpointGroupConditionList = new ArrayList<>();
+ endpointGroupConditionList.add(endpointGroupCondition);
+
+ UnsetEndpointGroupConditionsInput unsetEndpointGroupConditionsInput =
+ new UnsetEndpointGroupConditionsInputBuilder().setEndpointGroup(endpointGroupId)
+ .setEndpointGroupCondition(endpointGroupConditionList)
+ .build();
+
+ endpointRpcRegistry.unsetEndpointGroupConditions(unsetEndpointGroupConditionsInput);
+
+ verify(wt, times(1)).delete(eq(LogicalDatastoreType.OPERATIONAL),
+ Mockito.<InstanceIdentifier<EndpointGroupCondition>>any());
+ }
+
+ private WriteTransaction newWriteTransactionMock() {
+ WriteTransaction wt = mock(WriteTransaction.class);
+ CheckedFuture<Void, TransactionCommitFailedException> f = mock(CheckedFuture.class);
+
+ when(dataProvider.newWriteOnlyTransaction()).thenReturn(wt);
+ when(wt.submit()).thenReturn(f);
+ return wt;
+ }
+}
--- /dev/null
+package org.opendaylight.groupbasedpolicy.resolver;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.opendaylight.groupbasedpolicy.dto.EpgKeyDto;
+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 EpgKeyDtoTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private EndpointGroupId endpointGroupId;
+ private TenantId tenantId;
+ EpgKeyDto epgKeyDto;
+
+ @Before
+ public void init() {
+ endpointGroupId = new EndpointGroupId("epg-1");
+ tenantId = new TenantId("tenant-1");
+
+ epgKeyDto = new EpgKeyDto(endpointGroupId, tenantId);
+ }
+
+ @Test
+ public void testConstructor() {
+ new EpgKeyDto(endpointGroupId, tenantId);
+ }
+
+ @Test
+ public void testConstructor_EpgIdIsNull() throws NullPointerException {
+ thrown.expect(NullPointerException.class);
+ new EpgKeyDto(null, tenantId);
+ }
+
+ @Test
+ public void testConstructor_TenantIdIsNull() throws NullPointerException {
+ thrown.expect(NullPointerException.class);
+ new EpgKeyDto(endpointGroupId, null);
+ }
+
+ @Test
+ public void testGetEpgId() {
+ assertEquals(endpointGroupId.getValue(), epgKeyDto.getEpgId().getValue());
+ }
+
+ @Test
+ public void testGetTenantId() {
+ assertEquals(tenantId.getValue(), epgKeyDto.getTenantId().getValue());
+ }
+
+ @Test
+ public void testHashCode() {
+ EpgKeyDto epgKeyDto2 = new EpgKeyDto(new EndpointGroupId("epg-1"), new TenantId("tenant-1"));
+
+ assertEquals(epgKeyDto.hashCode(), epgKeyDto2.hashCode());
+
+ }
+
+ @Test
+ public void testEquals() {
+ EpgKeyDto epgKeyDto2 = new EpgKeyDto(new EndpointGroupId("epg-1"), new TenantId("tenant-1"));
+
+ assertEquals(epgKeyDto, epgKeyDto2);
+ }
+
+}
--- /dev/null
+package org.opendaylight.groupbasedpolicy.resolver;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.test.GbpDataBrokerTest;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+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.TenantBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(DataStoreHelper.class)
+public class PolicyResolverTest extends GbpDataBrokerTest {
+
+ private DataBroker dataProvider;
+ private PolicyResolver policyResolver;
+ private final TenantId tenantId = new TenantId("tenant-1");
+
+ @Before
+ public void init() {
+ dataProvider = getDataBroker();
+ policyResolver = new PolicyResolver(dataProvider);
+ }
+
+ @After
+ public void teardown() throws Exception {
+ policyResolver.close();
+ }
+
+ @Test
+ public void testConstructor() throws Exception {
+ PolicyResolver other = new PolicyResolver(dataProvider);
+ other.close();
+ }
+
+ @Test
+ public void testSubscribeTenant_Unknown() {
+ int oldSize = policyResolver.subscribersPerTenant.count(tenantId);
+ Assume.assumeTrue(oldSize == 0);
+
+ policyResolver.subscribeTenant(tenantId);
+
+ assertEquals(policyResolver.subscribersPerTenant.count(tenantId), oldSize + 1);
+ }
+
+ @Test
+ public void testSubscribeTenant_Known() {
+ Tenant unresolvedTenant = new TenantBuilder().setId(tenantId).build();
+
+ Optional<Tenant> potentialTenant = mock(Optional.class);
+ when(potentialTenant.isPresent()).thenReturn(true);
+ when(potentialTenant.get()).thenReturn(unresolvedTenant);
+
+ PowerMockito.mockStatic(DataStoreHelper.class);
+ when(DataStoreHelper.readFromDs(eq(LogicalDatastoreType.CONFIGURATION),
+ Mockito.<InstanceIdentifier<Tenant>>any(), any(ReadOnlyTransaction.class))).thenReturn(potentialTenant);
+
+ PolicyResolver spy = spy(policyResolver);
+
+ int oldSize = spy.subscribersPerTenant.count(tenantId);
+
+ spy.subscribeTenant(tenantId);
+
+ assertEquals(spy.subscribersPerTenant.count(tenantId), oldSize + 1);
+ verify(spy).updateTenant(eq(tenantId), any(Tenant.class));
+ }
+
+ @Test
+ public void testUnsubscribeTenant() {
+ int oldSize = policyResolver.subscribersPerTenant.count(tenantId);
+ Assume.assumeTrue(oldSize == 0);
+
+ policyResolver.subscribeTenant(tenantId);
+ assertEquals(policyResolver.subscribersPerTenant.count(tenantId), oldSize + 1);
+
+ policyResolver.unsubscribeTenant(tenantId);
+ assertEquals(policyResolver.subscribersPerTenant.count(tenantId), oldSize);
+ }
+
+}
package org.opendaylight.groupbasedpolicy.resolver;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.dto.ConditionGroup;
+import org.opendaylight.groupbasedpolicy.dto.ConditionSet;
+import org.opendaylight.groupbasedpolicy.dto.EndpointConstraint;
import org.opendaylight.groupbasedpolicy.dto.Policy;
+import org.opendaylight.groupbasedpolicy.dto.RuleGroup;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.endpoint.identification.constraints.l3.endpoint.identification.constraints.PrefixConstraint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.endpoint.identification.constraints.endpoint.identification.constraints.l3.endpoint.identification.constraints.PrefixConstraintBuilder;
public class PolicyTest {
private Policy policy;
@Before
- public void initialisation() {
+ public void init() {
policy = new Policy(null);
}
@Test
- public void equalsTest() {
- Assert.assertTrue(policy.equals(policy));
- Assert.assertFalse(policy.equals(null));
- Assert.assertFalse(policy.equals(new Object()));
+ public void testGetRules() {
+ ConditionSet conditionSet = newConditionSet();
+ Set<ConditionSet> conditionSets = new HashSet<>();
+ conditionSets.add(conditionSet);
+
+ ConditionGroup fromCg = new ConditionGroup(conditionSets);
+ ConditionGroup toCg = new ConditionGroup(conditionSets);
+
+ Set<ConditionSet> conditionSetsEmpty = new HashSet<>();
+ ConditionGroup fromCgEmpty = new ConditionGroup(conditionSetsEmpty);
+ ConditionGroup toCgEmpty = new ConditionGroup(conditionSetsEmpty);
+
+ EndpointConstraint endpointConstraint = new EndpointConstraint(conditionSet, null);
+
+ List<RuleGroup> ruleGroups = new ArrayList<>();
+ ruleGroups.add(mock(RuleGroup.class));
+
+ Table<EndpointConstraint, EndpointConstraint, List<RuleGroup>> ruleMap = HashBasedTable.create(1, 1);
+ ruleMap.put(endpointConstraint, endpointConstraint, ruleGroups);
+
+ Policy p = new Policy(ruleMap);
+
+ assertTrue(p.getRules(fromCg, toCg).size() == 1);
+ assertTrue(p.getRules(fromCg, toCgEmpty).isEmpty());
+ assertTrue(p.getRules(fromCgEmpty, toCg).isEmpty());
+ assertTrue(p.getRules(fromCgEmpty, toCgEmpty).isEmpty());
+ }
+
+ @Test
+ public void testGetIpPrefixesFrom() {
+ Set<PrefixConstraint> prefixConstraints = new HashSet<>();
+ final IpPrefix ipPrefix1 = IpPrefixBuilder.getDefaultInstance("10.1.0.1/24");
+ prefixConstraints.add(new PrefixConstraintBuilder().setIpPrefix(ipPrefix1).build());
+ final IpPrefix ipPrefix2 = IpPrefixBuilder.getDefaultInstance("10.2.0.1/24");
+ prefixConstraints.add(new PrefixConstraintBuilder().setIpPrefix(ipPrefix2).build());
+ Set<IpPrefix> ipPrefixes = Policy.getIpPrefixesFrom(prefixConstraints);
+
+ assertTrue(ipPrefixes.size() == 2);
+ assertTrue(ipPrefixes.contains(ipPrefix1));
+ assertTrue(ipPrefixes.contains(ipPrefix2));
+ }
+
+ @Test
+ public void testEquals() {
Policy other = new Policy(null);
- Assert.assertTrue(policy.equals(other));
+
+ assertTrue(policy.equals(other));
}
@Test
- public void toStringTest() {
+ public void testToString() {
Assert.assertNotNull(policy.toString());
}
+
+ private ConditionSet newConditionSet(){
+ Set<ConditionName> all = new HashSet<>();
+ Set<ConditionName> none = new HashSet<>();
+ Set<Set<ConditionName>> any = new HashSet<>();
+ Set<ConditionName> any1 = new HashSet<>();
+ Set<ConditionName> any2 = new HashSet<>();
+
+ all.add(new ConditionName("condition-all-1"));
+ all.add(new ConditionName("condition-all-2"));
+
+ none.add(new ConditionName("condition-none-1"));
+ none.add(new ConditionName("condition-none-2"));
+
+ any1.add(new ConditionName("condition-any1-1"));
+ any1.add(new ConditionName("condition-any1-2"));
+ any2.add(new ConditionName("condition-any2-1"));
+ any2.add(new ConditionName("condition-any2-2"));
+ any.add(any1);
+ any.add(any2);
+
+ return new ConditionSet(all, none, any);
+ }
}
--- /dev/null
+package org.opendaylight.groupbasedpolicy.sf;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.groupbasedpolicy.dto.ValidationResultBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ParameterName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.RendererName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.parameter.type.IntBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedClassifierDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedClassifierDefinitionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValues;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.supported._int.value.fields.SupportedIntValueInRangeBuilder;
+
+public class ClassifierInstanceValidatorTest {
+
+ private static final String RENDERER = "renderer";
+ private static final String PARENT_CLASSIFIER_DEFINITION_ID = "cdId-0";
+ private static final String CLASSIFIER_DEFINITION_ID = "cdId-1";
+ private static final String PARAM_NAME = "param_name";
+ private static final String CLASSIFIER1 = "classifier1";
+ private ClassifierDefinitionId cdId;
+ private ClassifierDefinitionId parentCdId;
+ private List<SupportedParameterValues> supportedParameterValues;
+
+ @Before
+ public void init() {
+ cdId = new ClassifierDefinitionId(CLASSIFIER_DEFINITION_ID);
+ parentCdId = new ClassifierDefinitionId(PARENT_CLASSIFIER_DEFINITION_ID);
+ supportedParameterValues =
+ ImmutableList.of(
+ new SupportedParameterValuesBuilder().setParameterName(new ParameterName(PARAM_NAME))
+ .setParameterType(new IntBuilder()
+ .setSupportedIntValueInRange(ImmutableList
+ .of(new SupportedIntValueInRangeBuilder().setMin(0l).setMax(1000l).build()))
+ .build())
+ .build());
+ }
+
+ @Test
+ public void testConstructor() {
+
+ SupportedClassifierDefinition constraint = new SupportedClassifierDefinitionBuilder()
+ .setClassifierDefinitionId(cdId)
+ .setParentClassifierDefinitionId(parentCdId)
+ .setSupportedParameterValues(supportedParameterValues)
+ .build();
+ RendererName rendererName = new RendererName(RENDERER);
+
+ ClassifierInstanceValidator validator = new ClassifierInstanceValidator(constraint, rendererName);
+
+ assertEquals(CLASSIFIER_DEFINITION_ID, validator.getClassifierDefinitionId().getValue());
+ assertNotNull(validator.getParentClassifierDefinitionId());
+ assertEquals(PARENT_CLASSIFIER_DEFINITION_ID, validator.getParentClassifierDefinitionId().getValue());
+ assertEquals(RENDERER, validator.getRendererName().getValue());
+ assertEquals(supportedParameterValues.size(), validator.getSupportedParameters().size());
+ }
+
+ @Test
+ public void testConstructor_noSupportedParameters() {
+
+ SupportedClassifierDefinition constraint = new SupportedClassifierDefinitionBuilder()
+ .setClassifierDefinitionId(cdId).setParentClassifierDefinitionId(parentCdId).build();
+ RendererName rendererName = new RendererName(RENDERER);
+
+ ClassifierInstanceValidator validator = new ClassifierInstanceValidator(constraint, rendererName);
+
+ assertEquals(CLASSIFIER_DEFINITION_ID, validator.getClassifierDefinitionId().getValue());
+ assertNotNull(validator.getParentClassifierDefinitionId());
+ assertEquals(PARENT_CLASSIFIER_DEFINITION_ID, validator.getParentClassifierDefinitionId().getValue());
+ assertEquals(RENDERER, validator.getRendererName().getValue());
+ assertTrue(validator.getSupportedParameters().isEmpty());
+ }
+
+ @Test
+ public void testValidate() {
+ ClassifierInstanceBuilder ciBuilder = new ClassifierInstanceBuilder();
+ ciBuilder.setName(new ClassifierName(CLASSIFIER1));
+ ciBuilder.setParameterValue(ImmutableList
+ .of(new ParameterValueBuilder().setName(new ParameterName(PARAM_NAME)).setIntValue(100l).build()));
+
+ SupportedClassifierDefinition constraint = new SupportedClassifierDefinitionBuilder()
+ .setClassifierDefinitionId(cdId)
+ .setParentClassifierDefinitionId(parentCdId)
+ .setSupportedParameterValues(supportedParameterValues)
+ .build();
+ RendererName rendererName = new RendererName(RENDERER);
+
+ ClassifierInstanceValidator validator = new ClassifierInstanceValidator(constraint, rendererName);
+
+ assertEquals(new ValidationResultBuilder().success().build(), validator.validate(ciBuilder.build()));
+ }
+
+}
--- /dev/null
+package org.opendaylight.groupbasedpolicy.sf;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.util.concurrent.CheckedFuture;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.SubjectFeatureDefinitions;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+@SuppressWarnings({"unchecked"})
+@RunWith(MockitoJUnitRunner.class)
+public class SubjectFeatureDefinitionProviderTest {
+
+ public static final int NUM_OF_SUBJECT_FEATURE_DEFINITIONS = 5;
+
+ @Mock
+ DataBroker dataProvider;
+ @Mock
+ WriteTransaction writeTransaction;
+ @Mock
+ CheckedFuture<Void, TransactionCommitFailedException> checkedFuture;
+
+ @Before
+ public void init() {
+ when(writeTransaction.submit()).thenReturn(checkedFuture);
+ when(dataProvider.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+ }
+
+ @Test
+ public void testConstructor() throws TransactionCommitFailedException {
+ doNothing().when(writeTransaction).put(eq(LogicalDatastoreType.CONFIGURATION), any(InstanceIdentifier.class),
+ any(SubjectFeatureDefinitions.class));
+
+ SubjectFeatureDefinitionProvider provider = new SubjectFeatureDefinitionProvider(dataProvider);
+
+ assertNotNull(provider);
+ verify(dataProvider).newWriteOnlyTransaction();
+ verify(writeTransaction, times(NUM_OF_SUBJECT_FEATURE_DEFINITIONS)).put(eq(LogicalDatastoreType.CONFIGURATION),
+ any(InstanceIdentifier.class), any(SubjectFeatureDefinitions.class));
+
+ }
+
+ @Test
+ public void testClose() throws Exception {
+ doNothing().when(writeTransaction).delete(eq(LogicalDatastoreType.CONFIGURATION),
+ any(InstanceIdentifier.class));
+
+ SubjectFeatureDefinitionProvider provider = new SubjectFeatureDefinitionProvider(dataProvider);
+
+ assertNotNull(provider);
+
+ provider.close();
+
+ verify(dataProvider, times(2)).newWriteOnlyTransaction();
+ verify(writeTransaction, times(NUM_OF_SUBJECT_FEATURE_DEFINITIONS))
+ .delete(eq(LogicalDatastoreType.CONFIGURATION), any(InstanceIdentifier.class));
+
+ }
+
+}
package org.opendaylight.groupbasedpolicy.statistics;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
-import org.mockito.Mockito;
+import org.junit.rules.ExpectedException;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.statistics.rev151215.statistic.records.StatRecordsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.statistics.rev151215.statistic.records.stat.records.EpToEpStatisticBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.statistics.rev151215.statistic.records.stat.records.EpToEpStatisticKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.statistics.rev151215.statistic.records.stat.records.ep.to.ep.statistic.EpEpgToEpEpgStatistic;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.statistics.rev151215.statistic.records.stat.records.ep.to.ep.statistic.EpEpgToEpEpgStatisticBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.statistics.rev151215.statistic.records.stat.records.ep.to.ep.statistic.EpEpgToEpEpgStatisticKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.statistics.rev151215.statistic.records.stat.records.ep.to.ep.statistic.ep.epg.to.ep.epg.statistic.MatchedRuleStatisticBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.statistics.store.rev151215.statistics.store.statistic.record.StatisticKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
-
public class StatisticManagerImplTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private static final String READING_EXCEPTION_MSG = "Reading throws exception";
+
private DataBroker dataBroker;
private StatisticsManagerImpl manager;
private WriteTransaction wtx;
private ReadOnlyTransaction rtx;
+ private MacAddress srcMac;
+ private MacAddress dstMac;
+ private L2BridgeDomainId srcL2C;
+ private L2BridgeDomainId dstL2C;
+ private EndpointGroupId srcEPG;
+ private EndpointGroupId dstEPG;
+ private TenantId srcTenant;
+ private TenantId dstTenant;
+ private ContractId contract;
+ private SubjectName subject;
+ private RuleName rule;
+ private ActionName action;
+ private ClassifierName classifier;
@Before
public void init() {
- dataBroker = Mockito.mock(DataBroker.class);
- wtx = Mockito.mock(WriteTransaction.class);
- rtx = Mockito.mock(ReadOnlyTransaction.class);
- Mockito.when(dataBroker.newWriteOnlyTransaction()).thenReturn(wtx);
- Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(rtx);
+ srcMac = new MacAddress("00:00:00:00:00:01");
+ dstMac = new MacAddress("00:00:00:00:00:02");
+ srcL2C = new L2BridgeDomainId("srcL2C");
+ dstL2C = new L2BridgeDomainId("dstL2C");
+ srcEPG = new EndpointGroupId("srcEPG");
+ dstEPG = new EndpointGroupId("dstEPG");
+ srcTenant = new TenantId("srcTenant");
+ dstTenant = new TenantId("dstTenant");
+ contract = new ContractId("contract");
+ subject = new SubjectName("subject");
+ rule = new RuleName("rule");
+ action = new ActionName("action");
+ classifier = new ClassifierName("classifier");
+
+ dataBroker = mock(DataBroker.class);
+ wtx = mock(WriteTransaction.class);
+ rtx = mock(ReadOnlyTransaction.class);
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(wtx);
+ when(dataBroker.newReadOnlyTransaction()).thenReturn(rtx);
+
manager = new StatisticsManagerImpl(dataBroker);
}
@Test
- public void writeStatTest() {
- MacAddress srcMac = new MacAddress("00:00:00:00:00:01");
- MacAddress dstMac = new MacAddress("00:00:00:00:00:02");
- L2BridgeDomainId srcL2C = new L2BridgeDomainId("srcL2C");
- L2BridgeDomainId dstL2C = new L2BridgeDomainId("dstL2C");
- EndpointGroupId srcEPG = new EndpointGroupId("srcEPG");
- EndpointGroupId dstEPG = new EndpointGroupId("dstEPG");
- TenantId srcTenant = new TenantId("srcTenant");
- TenantId dstTenant = new TenantId("dstTenant");
- ContractId contract = new ContractId("contract");
- SubjectName subject = new SubjectName("subject");
- RuleName rule = new RuleName("rule");
- ActionName action = new ActionName("action");
- ClassifierName classifier = new ClassifierName("classifier");
- // input
- StatRecordsBuilder recordsBuilder = new StatRecordsBuilder();
- EpToEpStatisticBuilder epBuilder = new EpToEpStatisticBuilder();
- EpEpgToEpEpgStatisticBuilder epgBuilder = new EpEpgToEpEpgStatisticBuilder();
- epgBuilder.setSrcEpg(srcEPG)
- .setDstEpg(dstEPG)
- .setKey(new EpEpgToEpEpgStatisticKey(dstEPG, srcEPG))
- .setMatchedRuleStatistic(Collections.singletonList(new MatchedRuleStatisticBuilder()
- .setKey(new MatchedRuleStatisticKey(contract, rule, subject))
- .setContract(contract)
- .setSubject(subject)
- .setMatchedRule(rule)
- .setAction(Collections.singletonList(action))
- .setClassifier(Collections.singletonList(classifier))
- .setByteCount(25l)
- .setPacketCount(5l)
- .build()));
- epBuilder.setSrcMacAddress(srcMac)
- .setDstMacAddress(dstMac)
- .setSrcL2c(srcL2C)
- .setDstL2c(dstL2C)
- .setSrcTenant(srcTenant)
- .setDstTenant(dstTenant)
- .setKey(new EpToEpStatisticKey(dstL2C, dstMac, srcL2C, srcMac))
- .setEpEpgToEpEpgStatistic(Collections.singletonList(epgBuilder.build()));
- recordsBuilder.setEpToEpStatistic(Collections.singletonList(epBuilder.build()));
- // output
+ public void testWriteStat() {
+ StatRecords input = inputForWriting();
+ StatisticRecordKey key = new StatisticRecordKey(new RecordId(0l));
+ StatisticRecord output = outputForWriting(key);
+
+ CheckedFuture<Void, TransactionCommitFailedException> future = mock(CheckedFuture.class);
+ when(wtx.submit()).thenReturn(future);
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(wtx);
+
+ manager.writeStat(input);
+ verify(wtx).put(LogicalDatastoreType.OPERATIONAL, IidFactory.statisticRecordIid(key), output, true);
+ }
+
+ @Test
+ public void testReadStats() throws Exception {
+ List<StatisticRecord> stats = inputForReading();
+ StatRecords statRecords = outputForReading();
+
+ CheckedFuture<Optional<StatisticsStore>, ReadFailedException> future = mock(CheckedFuture.class);
+ when(future.get()).thenReturn(Optional.of(new StatisticsStoreBuilder().setStatisticRecord(stats).build()));
+ when(rtx.read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(StatisticsStore.class).build()))
+ .thenReturn(future);
+
+ StatRecords read = manager.readStats();
+
+ Assert.assertEquals(statRecords, read);
+ }
+
+ @Test
+ public void testReadStats_throwsException() throws ExecutionException, InterruptedException {
+ CheckedFuture<Optional<StatisticsStore>, ReadFailedException> future = mock(CheckedFuture.class);
+ when(future.get()).thenThrow(new RuntimeException(READING_EXCEPTION_MSG));
+ when(rtx.read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(StatisticsStore.class).build()))
+ .thenReturn(future);
+
+ thrown.expect(RuntimeException.class);
+ thrown.expectMessage(READING_EXCEPTION_MSG);
+ manager.readStats();
+ }
+
+ private List<StatisticRecord> inputForReading() {
SrcEndpointBuilder srcBuilder = new SrcEndpointBuilder();
DstEndpointBuilder dstBuilder = new DstEndpointBuilder();
srcBuilder.setMacAddress(srcMac).setL2Context(srcL2C).setTenant(srcTenant);
.setStatistic(Collections.singletonList(statBuilder.build()))
.setSrcEndpoint(srcBuilder.build())
.setDstEndpoint(dstBuilder.build());
+ List<StatisticRecord> stats = new ArrayList<>();
+ stats.add(statRecord.build());
+ statRecord.setKey(new StatisticRecordKey(new RecordId(1l)));
+ stats.add(statRecord.build());
-// manager.writeStat(recordsBuilder.build());
-// Mockito.verify(wtx).put(LogicalDatastoreType.OPERATIONAL,
-// IidFactory.statisticRecordIid(key),
-// statRecord.build());
- CheckedFuture<Void,TransactionCommitFailedException> future = Mockito.mock(CheckedFuture.class);
- Mockito.when(wtx.submit()).thenReturn(future);
- Mockito.when(dataBroker.newWriteOnlyTransaction()).thenReturn(wtx);
-
- manager.writeStat(recordsBuilder.build());
- Mockito.verify(wtx).put(LogicalDatastoreType.OPERATIONAL,
- IidFactory.statisticRecordIid(key),
- statRecord.build(), true);
+ return stats;
}
- @Test
- public void readStatsTest() {
- MacAddress srcMac = new MacAddress("00:00:00:00:00:01");
- MacAddress dstMac = new MacAddress("00:00:00:00:00:02");
- L2BridgeDomainId srcL2C = new L2BridgeDomainId("srcL2C");
- L2BridgeDomainId dstL2C = new L2BridgeDomainId("dstL2C");
- EndpointGroupId srcEPG = new EndpointGroupId("srcEPG");
- EndpointGroupId dstEPG = new EndpointGroupId("dstEPG");
- TenantId srcTenant = new TenantId("srcTenant");
- TenantId dstTenant = new TenantId("dstTenant");
- ContractId contract = new ContractId("contract");
- SubjectName subject = new SubjectName("subject");
- RuleName rule = new RuleName("rule");
- ActionName action = new ActionName("action");
- ClassifierName classifier = new ClassifierName("classifier");
- // input
+ private StatRecords outputForReading() {
+ StatRecordsBuilder recordsBuilder = new StatRecordsBuilder();
+ EpEpgToEpEpgStatisticBuilder epgBuilder = newEpEpgToEpEpgStatisticBuilder(50, 10);
+ EpToEpStatisticBuilder epBuilder = newEpToEpStatisticBuilder(Collections.singletonList(epgBuilder.build()));
+ recordsBuilder.setEpToEpStatistic(Collections.singletonList(epBuilder.build()));
+
+ return recordsBuilder.build();
+ }
+
+ private StatRecords inputForWriting() {
+ StatRecordsBuilder recordsBuilder = new StatRecordsBuilder();
+ EpEpgToEpEpgStatisticBuilder epgBuilder = newEpEpgToEpEpgStatisticBuilder(25, 5);
+ EpToEpStatisticBuilder epBuilder = newEpToEpStatisticBuilder(Collections.singletonList(epgBuilder.build()));
+ recordsBuilder.setEpToEpStatistic(Collections.singletonList(epBuilder.build()));
+
+ return recordsBuilder.build();
+ }
+
+ private StatisticRecord outputForWriting(StatisticRecordKey key) {
SrcEndpointBuilder srcBuilder = new SrcEndpointBuilder();
DstEndpointBuilder dstBuilder = new DstEndpointBuilder();
srcBuilder.setMacAddress(srcMac).setL2Context(srcL2C).setTenant(srcTenant);
.setAction(Collections.singletonList(action))
.setByteCount(25l)
.setPacketCount(5l);
- StatisticRecordKey key = new StatisticRecordKey(new RecordId(0l));
StatisticRecordBuilder statRecord = new StatisticRecordBuilder().setKey(key)
.setStatistic(Collections.singletonList(statBuilder.build()))
.setSrcEndpoint(srcBuilder.build())
.setDstEndpoint(dstBuilder.build());
- ArrayList<StatisticRecord> stats = new ArrayList<>();
- stats.add(statRecord.build());
- statRecord.setKey(new StatisticRecordKey(new RecordId(1l)));
- stats.add(statRecord.build());
- // output
- StatRecordsBuilder recordsBuilder = new StatRecordsBuilder();
- EpToEpStatisticBuilder epBuilder = new EpToEpStatisticBuilder();
- EpEpgToEpEpgStatisticBuilder epgBuilder = new EpEpgToEpEpgStatisticBuilder();
- epgBuilder.setSrcEpg(srcEPG)
+
+ return statRecord.build();
+ }
+
+ private EpEpgToEpEpgStatisticBuilder newEpEpgToEpEpgStatisticBuilder(long byteCount, long packetCount) {
+ return new EpEpgToEpEpgStatisticBuilder().setSrcEpg(srcEPG)
.setDstEpg(dstEPG)
.setKey(new EpEpgToEpEpgStatisticKey(dstEPG, srcEPG))
- .setMatchedRuleStatistic(Collections.singletonList(new MatchedRuleStatisticBuilder()
- .setKey(new MatchedRuleStatisticKey(contract, rule, subject))
- .setContract(contract)
- .setSubject(subject)
- .setMatchedRule(rule)
- .setAction(Collections.singletonList(action))
- .setClassifier(Collections.singletonList(classifier))
- .setByteCount(50l)
- .setPacketCount(10l)
- .build()));
- epBuilder.setSrcMacAddress(srcMac)
+ .setMatchedRuleStatistic(Collections.singletonList(
+ new MatchedRuleStatisticBuilder().setKey(new MatchedRuleStatisticKey(contract, rule, subject))
+ .setContract(contract)
+ .setSubject(subject)
+ .setMatchedRule(rule)
+ .setAction(Collections.singletonList(action))
+ .setClassifier(Collections.singletonList(classifier))
+ .setByteCount(byteCount)
+ .setPacketCount(packetCount)
+ .build()));
+ }
+
+ private EpToEpStatisticBuilder newEpToEpStatisticBuilder(List<EpEpgToEpEpgStatistic> list) {
+ return new EpToEpStatisticBuilder().setSrcMacAddress(srcMac)
.setDstMacAddress(dstMac)
.setSrcL2c(srcL2C)
.setDstL2c(dstL2C)
.setSrcTenant(srcTenant)
.setDstTenant(dstTenant)
.setKey(new EpToEpStatisticKey(dstL2C, dstMac, srcL2C, srcMac))
- .setEpEpgToEpEpgStatistic(Collections.singletonList(epgBuilder.build()));
- recordsBuilder.setEpToEpStatistic(Collections.singletonList(epBuilder.build()));
-
- CheckedFuture<Optional<StatisticsStore>, ReadFailedException> future = Mockito.mock(CheckedFuture.class);
- try {
- Mockito.when(future.get())
- .thenReturn(Optional.of(new StatisticsStoreBuilder().setStatisticRecord(stats).build()));
- Mockito.when(rtx.read(LogicalDatastoreType.OPERATIONAL,
- InstanceIdentifier.builder(StatisticsStore.class).build()))
- .thenReturn(future);
- StatRecords read = manager.readStats();
- Assert.assertEquals(recordsBuilder.build(), read);
- } catch (Exception e) {
- }
-
+ .setEpEpgToEpEpgStatistic(list);
}
+
}
import java.util.Collection;
+import com.google.common.collect.ImmutableList;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.Endpoints;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.Tenants;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.Renderers;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.ResolvedPolicies;
-import com.google.common.collect.ImmutableList;
-
/**
* Loads only modules of GBP and it's dependencies for data broker.
* <br>
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
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.ActionDefinitionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClauseName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContractId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ActionDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
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.L2FloodDomain;
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.policy.Contract;
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.ExternalImplicitGroup;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.Clause;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.Subject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.subject.Rule;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.endpoint.group.ProviderNamedSelector;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstance;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ClassifierInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.RendererName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.Renderers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.Renderer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedActionDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.SupportedClassifierDefinition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.FollowedTenant;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.interests.followed.tenants.followed.tenant.FollowedEndpointGroup;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public class IidFactoryTest {
private ContractId contractId;
private SubjectName subjectName;
private RuleName ruleName;
+ private RendererName rendererName;
@Before
public void initialise() {
contractId = mock(ContractId.class);
subjectName = mock(SubjectName.class);
ruleName = mock(RuleName.class);
+ rendererName = mock(RendererName.class);
}
@Test
- public void tenantIdTest() {
+ public void testTenantId() {
InstanceIdentifier<Tenant> identifier = IidFactory.tenantIid(tenantId);
Assert.assertEquals(tenantId, InstanceIdentifier.keyOf(identifier).getId());
}
@Test
- public void endpointGroupIidTest() {
+ public void testEndpointGroupIid() {
InstanceIdentifier<EndpointGroup> identifier = IidFactory.endpointGroupIid(tenantId, epgId);
Assert.assertEquals(epgId, InstanceIdentifier.keyOf(identifier).getId());
Assert.assertEquals(tenantId, identifier.firstKeyOf(Tenant.class).getId());
}
@Test
- public void contractIidTest() {
+ public void testContractIid() {
InstanceIdentifier<Contract> identifier = IidFactory.contractIid(tenantId, contractId);
Assert.assertEquals(contractId, InstanceIdentifier.keyOf(identifier).getId());
Assert.assertEquals(tenantId, identifier.firstKeyOf(Tenant.class).getId());
}
@Test
- public void subjectIidTest() {
+ public void testContractWildcardIid() {
+ InstanceIdentifier<Contract> identifier = IidFactory.contractWildcardIid(tenantId);
+ Assert.assertEquals(tenantId, identifier.firstKeyOf(Tenant.class).getId());
+ }
+
+ @Test
+ public void testSubjectIid() {
SubjectName subjectName = mock(SubjectName.class);
InstanceIdentifier<Subject> identifier = IidFactory.subjectIid(tenantId, contractId, subjectName);
Assert.assertEquals(subjectName, InstanceIdentifier.keyOf(identifier).getName());
}
@Test
- public void providerNamedSelectorIidTest() {
+ public void testProviderNamedSelectorIid() {
SelectorName providerSelectorName = mock(SelectorName.class);
InstanceIdentifier<ProviderNamedSelector> identifier = IidFactory.providerNamedSelectorIid(tenantId, epgId,
providerSelectorName);
}
@Test
- public void consumerNamedSelectorIidTest() {
+ public void testConsumerNamedSelectorIid() {
SelectorName consumerSelectorName = mock(SelectorName.class);
InstanceIdentifier<ConsumerNamedSelector> identifier = IidFactory.consumerNamedSelectorIid(tenantId, epgId,
consumerSelectorName);
}
@Test
- public void clauseIidTest() {
+ public void testClauseIid() {
ClauseName clauseName = mock(ClauseName.class);
InstanceIdentifier<Clause> identifier = IidFactory.clauseIid(tenantId, contractId, clauseName);
Assert.assertEquals(clauseName, InstanceIdentifier.keyOf(identifier).getName());
}
@Test
- public void ruleIdTest() {
+ public void testRuleId() {
InstanceIdentifier<Rule> identifier = IidFactory.ruleIid(tenantId, contractId, subjectName, ruleName);
Assert.assertEquals(ruleName, InstanceIdentifier.keyOf(identifier).getName());
Assert.assertEquals(subjectName, identifier.firstKeyOf(Subject.class).getName());
}
@Test
- public void actionInstanceIidTest() {
+ public void testActionInstanceIid() {
ActionName actionName = mock(ActionName.class);
InstanceIdentifier<ActionInstance> identifier = IidFactory.actionInstanceIid(tenantId, actionName);
Assert.assertEquals(actionName, InstanceIdentifier.keyOf(identifier).getName());
}
@Test
- public void classifierInstanceIidTest() {
+ public void testClassifierInstanceIid() {
ClassifierName classifierName = mock(ClassifierName.class);
InstanceIdentifier<ClassifierInstance> identifier = IidFactory.classifierInstanceIid(tenantId, classifierName);
Assert.assertEquals(classifierName, InstanceIdentifier.keyOf(identifier).getName());
}
@Test
- public void classifierRefIidTest() {
+ public void testClassifierRefIid() {
ClassifierName classifierRefName = mock(ClassifierName.class);
InstanceIdentifier<ClassifierRef> identifier = IidFactory.classifierRefIid(tenantId, contractId, subjectName,
ruleName, classifierRefName);
}
@Test
- public void l2FloodDomainIidTest() {
+ public void testL2FloodDomainIid() {
L2FloodDomainId l2FloodDomainId = mock(L2FloodDomainId.class);
InstanceIdentifier<L2FloodDomain> identifier = IidFactory.l2FloodDomainIid(tenantId, l2FloodDomainId);
Assert.assertEquals(l2FloodDomainId, InstanceIdentifier.keyOf(identifier).getId());
}
@Test
- public void l2BridgeDomainIidTest() {
+ public void testL2BridgeDomainIid() {
L2BridgeDomainId l2BridgeDomainId = mock(L2BridgeDomainId.class);
InstanceIdentifier<L2BridgeDomain> identifier = IidFactory.l2BridgeDomainIid(tenantId, l2BridgeDomainId);
Assert.assertEquals(l2BridgeDomainId, InstanceIdentifier.keyOf(identifier).getId());
}
@Test
- public void l3ContextIidTest() {
+ public void testL3ContextIid() {
L3ContextId l3ContextId = mock(L3ContextId.class);
InstanceIdentifier<L3Context> identifier = IidFactory.l3ContextIid(tenantId, l3ContextId);
Assert.assertEquals(l3ContextId, InstanceIdentifier.keyOf(identifier).getId());
}
@Test
- public void endpointIidTest() {
+ public void testEndpointIid() {
L2BridgeDomainId l2Context = mock(L2BridgeDomainId.class);
MacAddress macAddress = mock(MacAddress.class);
InstanceIdentifier<Endpoint> identifier = IidFactory.endpointIid(l2Context, macAddress);
}
@Test
- public void l3EndpointIidTest() {
+ public void testL3EndpointIid() {
L3ContextId l3ContextId = mock(L3ContextId.class);
IpAddress ipAddress = mock(IpAddress.class);
InstanceIdentifier<EndpointL3> identifier = IidFactory.l3EndpointIid(l3ContextId, ipAddress);
}
@Test
- public void l3EndpointIidWildcardTest() {
+ public void testL3EndpointIidWildcard() {
InstanceIdentifier<EndpointL3> identifier = IidFactory.l3EndpointsIidWildcard();
Assert.assertNotNull(identifier);
}
@Test
- public void endpointL3PrefixIidTest() {
+ public void testEndpointL3PrefixIid() {
L3ContextId l3Context = mock(L3ContextId.class);
IpPrefix ipPrefix = mock(IpPrefix.class);
InstanceIdentifier<EndpointL3Prefix> identifier = IidFactory.endpointL3PrefixIid(l3Context, ipPrefix);
}
@Test
- public void endpointIidWildcardTest() {
+ public void testEndpointIidWildcard() {
InstanceIdentifier<Endpoints> identifier = IidFactory.endpointsIidWildcard();
Assert.assertNotNull(identifier);
}
@Test
- public void subnetIidTest() {
+ public void testSubnetIid() {
SubnetId subnetId = mock(SubnetId.class);
InstanceIdentifier<Subnet> identifier = IidFactory.subnetIid(tenantId, subnetId);
Assert.assertEquals(tenantId, identifier.firstKeyOf(Tenant.class).getId());
Assert.assertEquals(subnetId, identifier.firstKeyOf(Subnet.class).getId());
}
+ @Test
+ public void testSubnetWildcardIid() {
+ InstanceIdentifier<Subnet> identifier = IidFactory.subnetWildcardIid(tenantId);
+ Assert.assertEquals(tenantId, identifier.firstKeyOf(Tenant.class).getId());
+ }
+
+ @Test
+ public void testClassifierDefinitionIid() {
+ ClassifierDefinitionId classifierDefinitionId = mock(ClassifierDefinitionId.class);
+ InstanceIdentifier<ClassifierDefinition> identifier = IidFactory.classifierDefinitionIid(
+ classifierDefinitionId);
+ Assert.assertEquals(classifierDefinitionId, identifier.firstKeyOf(ClassifierDefinition.class).getId());
+ }
+
+ @Test
+ public void testActionDefinitionIid() {
+ ActionDefinitionId actionDefinitionId = mock(ActionDefinitionId.class);
+ InstanceIdentifier<ActionDefinition> identifier = IidFactory.actionDefinitionIid(
+ actionDefinitionId);
+ Assert.assertEquals(actionDefinitionId, identifier.firstKeyOf(ActionDefinition.class).getId());
+ }
+
+ @Test
+ public void testSupportedActionDefinitionIidWildcard() {
+ InstanceIdentifier<SupportedActionDefinition>
+ identifier = IidFactory.supportedActionDefinitionIidWildcard();
+ Assert.assertNotNull(identifier);
+ }
+
+ @Test
+ public void testSupportedClassifierDefinitionIidWildcard() {
+ InstanceIdentifier<SupportedClassifierDefinition>
+ identifier = IidFactory.supportedClassifierDefinitionIidWildcard();
+ Assert.assertNotNull(identifier);
+ }
+
+ @Test
+ public void testFollowedEndpointgroupIid(){
+ InstanceIdentifier<FollowedEndpointGroup>
+ identifier = IidFactory.followedEndpointgroupIid(rendererName, tenantId, epgId);
+ Assert.assertEquals(epgId, identifier.firstKeyOf(FollowedEndpointGroup.class).getId());
+ }
+
+ @Test
+ public void testFollowedTenantIid(){
+ InstanceIdentifier<FollowedTenant>
+ identifier = IidFactory.followedTenantIid(rendererName, tenantId);
+ Assert.assertEquals(tenantId, identifier.firstKeyOf(FollowedTenant.class).getId());
+ }
+
+ @Test
+ public void testRendererIid(){
+ InstanceIdentifier<Renderer>
+ identifier = IidFactory.rendererIid(rendererName);
+ Assert.assertEquals(rendererName, identifier.firstKeyOf(Renderer.class).getName());
+ }
+
+ @Test
+ public void testRenderersIid(){
+ InstanceIdentifier<Renderers>
+ identifier = IidFactory.renderersIid();
+ Assert.assertNotNull(identifier);
+ }
+
+ @Test
+ public void testeExternalImplicitGroupIid(){
+ InstanceIdentifier<ExternalImplicitGroup>
+ identifier = IidFactory.externalImplicitGroupIid(tenantId, epgId);
+ Assert.assertEquals(epgId, identifier.firstKeyOf(ExternalImplicitGroup.class).getId());
+ }
+
}
public class SingletonTaskTest {
- public int ran = 0;
- public int finished = 0;
- public long time = 0;
+ private int ran;
+ private int finished;
+ private long time;
@Before
- public void setUp() throws Exception {
+ public void init() {
ran = 0;
finished = 0;
time = 0;
public void testDelay() throws InterruptedException {
ScheduledExecutorService ses =
Executors.newSingleThreadScheduledExecutor();
+ ran = 0;
SingletonTask st1 = new SingletonTask(ses, new Runnable() {
@Override
public void run() {
- ran += 1;
+ ran++;
time = System.nanoTime();
}
});
long start = System.nanoTime();
st1.reschedule(10, TimeUnit.MILLISECONDS);
- assertFalse("Check that task hasn't run yet", ran > 0);
+ assertFalse("Task has run already", ran > 0);
ses.shutdown();
ses.awaitTermination(5, TimeUnit.SECONDS);
- assertEquals("Check that task ran", 1, ran);
+ assertEquals("Check that task ran only once failed", 1, ran);
assertTrue("Check that time passed appropriately",
(time - start) >= TimeUnit.NANOSECONDS.convert(10, TimeUnit.MILLISECONDS));
}
@Test
public void testReschedule() throws InterruptedException {
- ScheduledExecutorService ses =
- Executors.newSingleThreadScheduledExecutor();
+ ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();
+ ran = 0;
+ time = 0;
+
+ final long EPSILON_NS = 1500000; // 1.5 ms
+ final int DELAY_MS = 20;
+ final int NUM_OF_ITERATIONS = 8;
+ final int SLEEP_MS = 5;
+ final int AWAIT_SEC = 5;
+ final int EXPECTED_PASS_TIME =
+ NUM_OF_ITERATIONS * SLEEP_MS + (DELAY_MS - SLEEP_MS);
final Object tc = this;
SingletonTask st1 = new SingletonTask(ses, new Runnable() {
+
@Override
public void run() {
synchronized (tc) {
- ran += 1;
+ ran++;
}
time = System.nanoTime();
}
});
+
long start = System.nanoTime();
- st1.reschedule(20, TimeUnit.MILLISECONDS);
- Thread.sleep(5);
- assertFalse("Check that task hasn't run yet", ran > 0);
- st1.reschedule(20, TimeUnit.MILLISECONDS);
- Thread.sleep(5);
- assertFalse("Check that task hasn't run yet", ran > 0);
- st1.reschedule(20, TimeUnit.MILLISECONDS);
- Thread.sleep(5);
- assertFalse("Check that task hasn't run yet", ran > 0);
- st1.reschedule(20, TimeUnit.MILLISECONDS);
- Thread.sleep(5);
- assertFalse("Check that task hasn't run yet", ran > 0);
- st1.reschedule(20, TimeUnit.MILLISECONDS);
- Thread.sleep(5);
- assertFalse("Check that task hasn't run yet", ran > 0);
- st1.reschedule(20, TimeUnit.MILLISECONDS);
- Thread.sleep(5);
- assertFalse("Check that task hasn't run yet", ran > 0);
- st1.reschedule(20, TimeUnit.MILLISECONDS);
- Thread.sleep(5);
- assertFalse("Check that task hasn't run yet", ran > 0);
- st1.reschedule(20, TimeUnit.MILLISECONDS);
- Thread.sleep(5);
- assertFalse("Check that task hasn't run yet", ran > 0);
+ for (int i = 0; i < NUM_OF_ITERATIONS; i++) {
+ st1.reschedule(DELAY_MS, TimeUnit.MILLISECONDS);
+ Thread.sleep(SLEEP_MS);
+ assertFalse("Task has run already", ran > 0);
+ }
ses.shutdown();
- ses.awaitTermination(5, TimeUnit.SECONDS);
+ ses.awaitTermination(AWAIT_SEC, TimeUnit.SECONDS);
- assertEquals("Check that task ran only once", 1, ran);
+ assertEquals("Check that task ran only once failed", 1, ran);
assertTrue("Check that time passed appropriately: " + (time - start),
- (time - start) >= TimeUnit.NANOSECONDS.convert(55, TimeUnit.MILLISECONDS));
+ (time - start) >= 1000000 * EXPECTED_PASS_TIME - EPSILON_NS);
}
@Test