From: Vladimir Lavor Date: Mon, 5 Oct 2015 10:10:53 +0000 (+0200) Subject: Gbp coverage increased in ./neutron/mapper/mapping/rule X-Git-Tag: release/beryllium~92 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=b6b439a8821cce6b119d32ac982790651027e428;p=groupbasedpolicy.git Gbp coverage increased in ./neutron/mapper/mapping/rule - NeutronSecurityRuleAware.java (+35%, 87% overall) Signed-off-by: Vladimir Lavor Change-Id: Iecdf2dc507d76d9e58b253d7ee9ada50b3aed70c --- diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAwareTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAwareTest.java index b8539f1bb..ad9ca3fb4 100644 --- a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAwareTest.java +++ b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAwareTest.java @@ -1,12 +1,26 @@ package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import org.junit.Test; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.StatusCode; +import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.group.SecGroupDao; +import org.opendaylight.groupbasedpolicy.neutron.mapper.test.ConfigDataStoreReader; +import org.opendaylight.groupbasedpolicy.neutron.mapper.test.GbpDataBrokerTest; +import org.opendaylight.groupbasedpolicy.neutron.mapper.test.PolicyAssert; +import org.opendaylight.neutron.spi.NeutronSecurityRule; import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.Contract; -public class NeutronSecurityRuleAwareTest { +public class NeutronSecurityRuleAwareTest extends GbpDataBrokerTest { + + private static final String RULE_ID = "00000000-0000-0000-0000-000000000001"; + private static final String RULE_TENANT_ID = "00000000-0000-0000-0000-000000000002"; + private static final String RULE_GROUP_ID = "00000000-0000-0000-0000-000000000003"; @Test public final void testIsDirectionOpposite_InIn() { @@ -28,4 +42,52 @@ public class NeutronSecurityRuleAwareTest { assertTrue(NeutronSecurityRuleAware.isDirectionOpposite(Direction.Out, Direction.In)); } + @Test + public void testNeutronSecurityRuleCreatedAndDeleted() throws Exception { + DataBroker dataProvider = getDataBroker(); + SecGroupDao secGroupDao = new SecGroupDao(); + SecRuleDao secRuleDao = new SecRuleDao(); + NeutronSecurityRuleAware neutronSecurityRuleAware = + new NeutronSecurityRuleAware(dataProvider, secRuleDao, secGroupDao); + + //create security rule and put to DS + NeutronSecurityRule neutronRule = buildNeutronSecurityRule(); + assertEquals(neutronSecurityRuleAware.canCreateNeutronSecurityRule(neutronRule), + StatusCode.OK); + neutronSecurityRuleAware.neutronSecurityRuleCreated(neutronRule); + + //read security rule + PolicyAssert.assertContractExists(dataProvider, RULE_TENANT_ID, RULE_ID); + + //compare + Contract readContract = ConfigDataStoreReader.readContract(dataProvider, RULE_TENANT_ID, RULE_ID).get(); + assertNotNull(readContract); + assertEquals(readContract.getId().getValue(), RULE_ID); + + assertEquals(neutronSecurityRuleAware.canUpdateNeutronSecurityRule(neutronRule, neutronRule), + StatusCode.BAD_REQUEST); + + //delete rule + assertEquals(neutronSecurityRuleAware.canDeleteNeutronSecurityRule(neutronRule), + StatusCode.OK); + neutronSecurityRuleAware.neutronSecurityRuleDeleted(neutronRule); + PolicyAssert.assertContractNotExists(dataProvider, RULE_TENANT_ID, RULE_ID); + } + + //create neutron security rule + private NeutronSecurityRule buildNeutronSecurityRule() { + NeutronSecurityRule neutronSecurityRule = new NeutronSecurityRule(); + neutronSecurityRule.setSecurityRuleUUID(RULE_ID); + neutronSecurityRule.setSecurityRuleTenantID(RULE_TENANT_ID); + neutronSecurityRule.setSecurityRuleGroupID(RULE_GROUP_ID); + neutronSecurityRule.setSecurityRuleRemoteIpPrefix("192.0.0.1/24"); + neutronSecurityRule.setSecurityRulePortMin(1000); + neutronSecurityRule.setSecurityRulePortMax(5000); + neutronSecurityRule.setSecurityRuleProtocol("tcp"); + neutronSecurityRule.setSecurityRuleEthertype("IPv4"); + neutronSecurityRule.setSecurityRuleDirection("ingress"); + + return neutronSecurityRule; + } + }