+ @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;
+ }
+