X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Faction%2FActionTest.java;h=edcb3e2761fd1e8e02117eecb96c4685fa47d5fc;hp=4fd59790034d413034f7c4209e473c357f2aefa7;hb=73e969cf365dd78772596c71e940ae44fe2f22d3;hpb=678adf2ca80a0bbbff9953e9372695184e415aac diff --git a/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java b/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java index 4fd5979003..edcb3e2761 100644 --- a/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java +++ b/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java @@ -1,12 +1,10 @@ - /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013-2014 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.controller.sal.action; import org.opendaylight.controller.sal.core.ConstructionException; @@ -17,22 +15,11 @@ import java.util.List; import org.junit.Test; import org.junit.Assert; -import org.opendaylight.controller.sal.action.Action; -import org.opendaylight.controller.sal.action.Controller; -import org.opendaylight.controller.sal.action.Output; -import org.opendaylight.controller.sal.action.PopVlan; -import org.opendaylight.controller.sal.action.PushVlan; -import org.opendaylight.controller.sal.action.SetDlSrc; -import org.opendaylight.controller.sal.action.SetNwDst; -import org.opendaylight.controller.sal.action.SetNwSrc; -import org.opendaylight.controller.sal.action.SetNwTos; -import org.opendaylight.controller.sal.action.SetTpDst; -import org.opendaylight.controller.sal.action.SetTpSrc; -import org.opendaylight.controller.sal.action.SetVlanCfi; -import org.opendaylight.controller.sal.action.SetVlanId; -import org.opendaylight.controller.sal.action.SetVlanPcp; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; +import org.opendaylight.controller.sal.core.Property; +import org.opendaylight.controller.sal.core.Tables; +import org.opendaylight.controller.sal.core.Tier; import org.opendaylight.controller.sal.utils.EtherTypes; import org.opendaylight.controller.sal.utils.NodeConnectorCreator; import org.slf4j.Logger; @@ -103,6 +90,24 @@ public class ActionTest { action = new PushVlan(EtherTypes.QINQ, 0x4, -1, 2000); Assert.assertFalse(action.isValid()); + + // OF 1.3 PUSH_VLAN test. + for (EtherTypes tag: EtherTypes.values()) { + int t = tag.intValue(); + boolean valid = + (tag == EtherTypes.VLANTAGGED || tag == EtherTypes.QINQ); + PushVlan pv = new PushVlan(tag); + Assert.assertEquals(valid, pv.isValid()); + if (valid) { + Assert.assertEquals(t, pv.getTag()); + } + + pv = new PushVlan(t); + Assert.assertEquals(valid, pv.isValid()); + if (valid) { + Assert.assertEquals(t, pv.getTag()); + } + } } @Test @@ -190,8 +195,11 @@ public class ActionTest { action = new SetTpDst(65535); Assert.assertTrue(action.isValid()); + action = new SetTpSrc(0); + Assert.assertTrue(action.isValid()); + action = new SetTpDst(0); - Assert.assertFalse(action.isValid()); + Assert.assertTrue(action.isValid()); action = new SetTpSrc(-1); Assert.assertFalse(action.isValid()); @@ -264,4 +272,89 @@ public class ActionTest { .createNodeConnector((short) 5, node)))); Assert.assertFalse(actions.contains(new Controller())); } + + @Test + public void testMetadata() { + Property tier1 = new Tier(1); + Property tier2 = new Tier(2); + Property table1 = new Tables((byte)0x7f); + Action a1 = new PopVlan(); + List resprops = null; + resprops = a1.getMetadatas(); + // This should be an empty list + Assert.assertTrue(resprops.isEmpty()); + a1.setMetadata("tier1", tier1); + a1.setMetadata("tier2", tier2); + a1.setMetadata("table1", table1); + resprops = a1.getMetadatas(); + // Check for the number of elements in it + Assert.assertTrue(resprops.size() == 3); + // Check if the elements are in it + Assert.assertTrue(resprops.contains(tier1)); + Assert.assertTrue(resprops.contains(tier2)); + Assert.assertTrue(resprops.contains(table1)); + // Check for single elements retrieve + Assert.assertTrue(a1.getMetadata("tier1").equals(tier1)); + Assert.assertTrue(a1.getMetadata("tier2").equals(tier2)); + Assert.assertTrue(a1.getMetadata("table1").equals(table1)); + // Now remove an element and make sure the remaining are + // correct + a1.removeMetadata("tier1"); + + resprops = a1.getMetadatas(); + // Check for the number of elements in it + Assert.assertTrue(resprops.size() == 2); + // Check if the elements are in it + Assert.assertFalse(resprops.contains(tier1)); + Assert.assertTrue(resprops.contains(tier2)); + Assert.assertTrue(resprops.contains(table1)); + // Check for single elements retrieve + Assert.assertTrue(a1.getMetadata("table1").equals(table1)); + Assert.assertTrue(a1.getMetadata("tier2").equals(tier2)); + Assert.assertNull(a1.getMetadata("tier1")); + + // Check for an element never existed + Assert.assertNull(a1.getMetadata("table100")); + + // Remove them all + a1.removeMetadata("tier2"); + a1.removeMetadata("table1"); + + // Remove also a non-existent one + a1.removeMetadata("table100"); + + resprops = a1.getMetadatas(); + // Check there are no elements left + Assert.assertTrue(resprops.size() == 0); + + // Now check for exception on setting null values + try { + a1.setMetadata("foo", null); + // The line below should never be reached + Assert.assertTrue(false); + } catch (NullPointerException nue) { + // NPE should be raised for null value + Assert.assertTrue(true); + } + + // Now check on using null key + try { + a1.setMetadata(null, table1); + // The line below should never be reached + Assert.assertTrue(false); + } catch (NullPointerException nue) { + // NPE should be raised for null value + Assert.assertTrue(true); + } + + // Now check on using null key and null value + try { + a1.setMetadata(null, null); + // The line below should never be reached + Assert.assertTrue(false); + } catch (NullPointerException nue) { + // NPE should be raised for null value + Assert.assertTrue(true); + } + } }