/* * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.neutron.mapper.mapping.rule; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.Test; import org.opendaylight.groupbasedpolicy.neutron.mapper.test.NeutronEntityFactory; import org.opendaylight.groupbasedpolicy.neutron.mapper.test.PolicyAssert; import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Description; 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.tenants.tenant.policy.Contract; 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.subject.feature.instances.ClassifierInstance; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.DirectionIngress; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.EthertypeV4; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.ProtocolTcp; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule; public class SingleRuleContractTest { @Test public void testConstructorAndGetters() { SecurityRule secRule = NeutronEntityFactory.securityRuleWithoutGroupIds( "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", EthertypeV4.class, DirectionIngress.class, ProtocolTcp.class, 8010, 8020); int subjectAndRuleOrder = 1; SingleRuleContract singleRuleContract = new SingleRuleContract(secRule, subjectAndRuleOrder, new Description( "contractDescription"), MappingUtils.ALLOW_ACTION_CHOICE); SingleClassifierRule singleClsfRule = singleRuleContract.getSingleClassifierRule(); assertNotNull(singleClsfRule); ClassifierInstance clsfInstance = singleClsfRule.getClassifierInstance(); assertNotNull(clsfInstance); assertEquals(clsfInstance, SecRuleEntityDecoder.getClassifierInstance(secRule)); ClassifierRef clsfRef = singleClsfRule.getClassifierRef(); assertNotNull(clsfRef); assertEquals(clsfRef, SecRuleEntityDecoder.getClassifierRef(secRule)); Rule rule = singleClsfRule.getRule(); assertNotNull(rule); PolicyAssert.assertRule(rule, secRule, subjectAndRuleOrder + 180); assertEquals(rule, singleRuleContract.getRule()); Subject subject = singleRuleContract.getSubject(); assertNotNull(subject); PolicyAssert.assertSubjectWithOneRule(subject, secRule); Clause clause = singleRuleContract.getClause(); assertNotNull(clause); PolicyAssert.assertClauseWithOneSubject(clause, secRule); Contract contract = singleRuleContract.getContract(); assertNotNull(contract); PolicyAssert.assertContract(contract, secRule); } }