X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-dom-it%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Ftest%2Fconnect%2Fdom%2FChangeOriginatedInDomBrokerTest.java;h=25b159b43b297eaeee8755c50688e5d0a2ff9aab;hp=ae54896c6d0faa75b40d105319e4c7b3c8b3dc1c;hb=3927509ec3ecfa32a51b725d2b7155d425f5b877;hpb=05565ac29ed2e05fef72379c2d84ca43c01799b2 diff --git a/opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/connect/dom/ChangeOriginatedInDomBrokerTest.java b/opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/connect/dom/ChangeOriginatedInDomBrokerTest.java index ae54896c6d..25b159b43b 100644 --- a/opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/connect/dom/ChangeOriginatedInDomBrokerTest.java +++ b/opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/connect/dom/ChangeOriginatedInDomBrokerTest.java @@ -11,9 +11,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import java.util.ArrayList; import java.util.Collections; -import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -23,34 +21,17 @@ import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent; import org.opendaylight.controller.sal.binding.api.data.DataChangeListener; import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest; import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpVersion; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.TllComplexAugment; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1Key; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Key; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List12Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List12Key; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.QName; @@ -59,83 +40,79 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.SettableFuture; -// FIXME: Migrate to use new Data Broker APIs +/** + * FIXME: Migrate to use new Data Broker APIs + */ @SuppressWarnings("deprecation") public class ChangeOriginatedInDomBrokerTest extends AbstractDataServiceTest { - private static final Logger LOG = LoggerFactory.getLogger(ChangeOriginatedInDomBrokerTest.class); - - private static final QName NODE_ID_QNAME = QName.create(Node.QNAME, "id"); - private static final QName FLOW_ID_QNAME = QName.create(Flow.QNAME, "id"); - private static final QName TABLE_ID_QNAME = QName.create(Table.QNAME, "id"); + protected static final Logger LOG = LoggerFactory.getLogger(ChangeOriginatedInDomBrokerTest.class); - private static final String NODE_ID = "node:1"; - private static final FlowId FLOW_ID = new FlowId("1234"); - private static final Short TABLE_ID = Short.valueOf((short) 0); + private static final QName TLL_NAME_QNAME = QName.create(TopLevelList.QNAME, "name"); + private static final QName LIST1_ATTR_STR_QNAME = QName.create(List1.QNAME, "attr-str"); - private static final NodeKey NODE_KEY = new NodeKey(new NodeId(NODE_ID)); - private static final FlowKey FLOW_KEY = new FlowKey(FLOW_ID); + private static final String TLL_NAME = "1"; + private static final int LIST11_ATTR_INT = 1234; + private static final String LIST1_ATTR_STR = "foo:foo"; - private final SettableFuture, DataObject>> modificationCapture = SettableFuture.create(); + private static final TopLevelListKey TLL_KEY = new TopLevelListKey(TLL_NAME); + private static final List1Key LIST1_KEY = new List1Key(LIST1_ATTR_STR); + private static final List11Key LIST11_KEY = new List11Key(LIST11_ATTR_INT); - private static final Map NODE_KEY_BI = Collections. singletonMap(NODE_ID_QNAME, - NODE_ID); + protected final SettableFuture, DataObject>> modificationCapture = SettableFuture.create(); - private static final InstanceIdentifier NODE_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) // - .child(Node.class, NODE_KEY).toInstance(); + private static final Map TLL_KEY_BI = Collections. singletonMap(TLL_NAME_QNAME, + TLL_NAME); - private static final Map FLOW_KEY_BI = // - ImmutableMap. of(FLOW_ID_QNAME, FLOW_ID.getValue()); + private static final InstanceIdentifier NODE_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class) // + .child(TopLevelList.class, TLL_KEY).toInstance(); - private static final Map TABLE_KEY_BI = // - ImmutableMap. of(TABLE_ID_QNAME, TABLE_ID);; + private static final Map LIST1_KEY_BI = // + ImmutableMap. of(LIST1_ATTR_STR_QNAME, LIST1_ATTR_STR);; - private static final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier FLOW_INSTANCE_ID_BI = // - org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.builder() // - .node(Nodes.QNAME) // - .nodeWithKey(Node.QNAME, NODE_KEY_BI) // - .nodeWithKey(Table.QNAME, TABLE_KEY_BI) // - .nodeWithKey(Flow.QNAME, FLOW_KEY_BI) // + private static final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier LIST1_INSTANCE_ID_BI = // + org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.builder() // + .node(Top.QNAME) // + .nodeWithKey(TopLevelList.QNAME, TLL_KEY_BI) // + .nodeWithKey(List1.QNAME, LIST1_KEY_BI) // .toInstance(); - private static final TableKey TABLE_KEY_BA = new TableKey((short) 0); - private static final InstanceIdentifier FLOWS_PATH_BA = // + private static final InstanceIdentifier LIST1_PATH_BA = // NODE_INSTANCE_ID_BA.builder() // - .augmentation(FlowCapableNode.class) // - .child(Table.class, TABLE_KEY_BA) // - .child(Flow.class) // + .augmentation(TllComplexAugment.class) // + .child(List1.class, LIST1_KEY) // .toInstance(); - private static final InstanceIdentifier FLOW_INSTANCE_ID_BA = // - FLOWS_PATH_BA.firstIdentifierOf(Table.class).child(Flow.class, FLOW_KEY); - @Test public void simpleModifyOperation() throws Exception { - assertNull(biDataService.readConfigurationData(FLOW_INSTANCE_ID_BI)); + assertNull(biDataService.readConfigurationData(LIST1_INSTANCE_ID_BI)); registerChangeListener(); - CompositeNode domflow = createTestFlow(); + CompositeNode domflow = createTestList1(); DataModificationTransaction biTransaction = biDataService.beginTransaction(); - biTransaction.putConfigurationData(FLOW_INSTANCE_ID_BI, domflow); + biTransaction.putConfigurationData(LIST1_INSTANCE_ID_BI, domflow); RpcResult biResult = biTransaction.commit().get(); assertEquals(TransactionStatus.COMMITED, biResult.getResult()); DataChangeEvent, DataObject> event = modificationCapture.get(1000,TimeUnit.MILLISECONDS); assertNotNull(event); LOG.info("Created Configuration :{}",event.getCreatedConfigurationData()); - Flow flow = (Flow) event.getCreatedConfigurationData().get(FLOW_INSTANCE_ID_BA); - assertNotNull(flow); - assertNotNull(flow.getMatch()); + List1 list1 = (List1) event.getCreatedConfigurationData().get(LIST1_PATH_BA); + assertNotNull(list1); + assertNotNull(list1.getAttrStr()); + assertNotNull(list1.getList11()); + assertNotNull(list1.getList12()); assertEquals(TransactionStatus.COMMITED, biResult.getResult()); } private void registerChangeListener() { - baDataService.registerDataChangeListener(FLOWS_PATH_BA, new DataChangeListener() { + baDataService.registerDataChangeListener(LIST1_PATH_BA, new DataChangeListener() { @Override public void onDataChanged(final DataChangeEvent, DataObject> change) { @@ -145,61 +122,18 @@ public class ChangeOriginatedInDomBrokerTest extends AbstractDataServiceTest { }); } - private CompositeNode createTestFlow() { - FlowBuilder flow = new FlowBuilder(); - flow.setKey(FLOW_KEY); - Short tableId = 0; - flow.setTableId(tableId); - MatchBuilder match = new MatchBuilder(); - match.setIpMatch(new IpMatchBuilder().setIpProto(IpVersion.Ipv4).build()); - Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder(); - // ipv4Match.setIpv4Destination(new Ipv4Prefix(cliInput.get(4))); - Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24"); - ipv4Match.setIpv4Destination(prefix); - Ipv4Match i4m = ipv4Match.build(); - match.setLayer3Match(i4m); - flow.setMatch(match.build()); - - - - // Create a drop action - /* - * Note: We are mishandling drop actions DropAction dropAction = new - * DropActionBuilder().build(); ActionBuilder ab = new ActionBuilder(); - * ab.setAction(dropAction); - */ - - DecNwTtl decNwTtl = new DecNwTtlBuilder().build(); - ActionBuilder ab = new ActionBuilder(); - ActionKey actionKey = new ActionKey(0); - ab.setKey(actionKey ); - ab.setAction(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl).build()); - - // Add our drop action to a list - List actionList = new ArrayList(); - actionList.add(ab.build()); - - // Create an Apply Action - ApplyActionsBuilder aab = new ApplyActionsBuilder(); - aab.setAction(actionList); - - // Wrap our Apply Action in an Instruction - InstructionBuilder ib = new InstructionBuilder(); - ib.setOrder(0); - ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build()); - - // Put our Instruction in a list of Instructions - InstructionsBuilder isb = new InstructionsBuilder(); - List instructions = new ArrayList(); - instructions.add(ib.build()); - isb.setInstruction(instructions); - - // Add our instructions to the flow - flow.setInstructions(isb.build()); - - flow.setPriority(2); - flow.setFlowName("Foo Name"); - CompositeNode domFlow = mappingService.toDataDom(flow.build()); - return domFlow; + private CompositeNode createTestList1() { + List1Builder l1b = new List1Builder(); + List11Builder l11b = new List11Builder(); + List12Builder l12b = new List12Builder(); + l11b.setKey(LIST11_KEY); + l11b.setAttrStr("foo:foo:foo"); + l12b.setKey(new List12Key(321)); + l12b.setAttrStr("foo:foo:bar"); + l1b.setKey(LIST1_KEY); + l1b.setList11(ImmutableList.of(l11b.build())); + l1b.setList12(ImmutableList.of(l12b.build())); + CompositeNode domList1 = mappingService.toDataDom(l1b.build()); + return domList1; } }