3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
10 package org.openflow.protocol;
12 import java.nio.ByteBuffer;
13 import java.util.List;
15 import org.openflow.protocol.factory.BasicFactory;
16 import org.openflow.util.U16;
18 import junit.framework.TestCase;
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));
30 ByteBuffer bb = ByteBuffer.allocate(1024);
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);