Initial opendaylight infrastructure commit!!
[controller.git] / third-party / openflowj / src / test / java / org / openflow / protocol / BasicFactoryTest.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.openflow.protocol;
11
12 import java.nio.ByteBuffer;
13 import java.util.List;
14
15 import org.openflow.protocol.factory.BasicFactory;
16 import org.openflow.util.U16;
17
18 import junit.framework.TestCase;
19
20
21
22 public class BasicFactoryTest extends TestCase {
23     public void testCreateAndParse() {
24         BasicFactory factory = new BasicFactory();
25         OFMessage m = factory.getMessage(OFType.HELLO);
26         m.setVersion((byte) 1);
27         m.setType(OFType.ECHO_REQUEST);
28         m.setLength(U16.t(8));
29         m.setXid(0xdeadbeef);
30         ByteBuffer bb = ByteBuffer.allocate(1024);
31         m.writeTo(bb);
32         bb.flip();
33         bb.limit(bb.limit()-1);
34         TestCase.assertEquals(0, factory.parseMessages(bb).size());
35         bb.limit(bb.limit()+1);
36         List<OFMessage> messages = factory.parseMessages(bb);
37         TestCase.assertEquals(1, messages.size());
38         TestCase.assertTrue(messages.get(0).getType() == OFType.ECHO_REQUEST);
39     }
40 }