Initial opendaylight infrastructure commit!!
[controller.git] / third-party / openflowj / src / test / java / org / openflow / protocol / BasicFactoryTest.java
diff --git a/third-party/openflowj/src/test/java/org/openflow/protocol/BasicFactoryTest.java b/third-party/openflowj/src/test/java/org/openflow/protocol/BasicFactoryTest.java
new file mode 100644 (file)
index 0000000..54a9dd0
--- /dev/null
@@ -0,0 +1,40 @@
+
+/*
+ * Copyright (c) 2013 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.openflow.protocol;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+
+import org.openflow.protocol.factory.BasicFactory;
+import org.openflow.util.U16;
+
+import junit.framework.TestCase;
+
+
+
+public class BasicFactoryTest extends TestCase {
+    public void testCreateAndParse() {
+        BasicFactory factory = new BasicFactory();
+        OFMessage m = factory.getMessage(OFType.HELLO);
+        m.setVersion((byte) 1);
+        m.setType(OFType.ECHO_REQUEST);
+        m.setLength(U16.t(8));
+        m.setXid(0xdeadbeef);
+        ByteBuffer bb = ByteBuffer.allocate(1024);
+        m.writeTo(bb);
+        bb.flip();
+        bb.limit(bb.limit()-1);
+        TestCase.assertEquals(0, factory.parseMessages(bb).size());
+        bb.limit(bb.limit()+1);
+        List<OFMessage> messages = factory.parseMessages(bb);
+        TestCase.assertEquals(1, messages.size());
+        TestCase.assertTrue(messages.get(0).getType() == OFType.ECHO_REQUEST);
+    }
+}