Andrew Brown | a450fad | 2015-01-22 11:24:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * File name: ServerTest.java |
| 3 | * |
| 4 | * Purpose: Test Server.java |
| 5 | * |
| 6 | * © Copyright Intel Corporation. All rights reserved. |
| 7 | * Intel Corporation, 2200 Mission College Boulevard, |
| 8 | * Santa Clara, CA 95052-8119, USA |
| 9 | */ |
| 10 | package com.intel.jndn.utils; |
| 11 | |
| 12 | import com.intel.jndn.mock.MockTransport; |
| 13 | import net.named_data.jndn.Data; |
| 14 | import net.named_data.jndn.Face; |
| 15 | import net.named_data.jndn.Interest; |
| 16 | import net.named_data.jndn.Name; |
| 17 | import net.named_data.jndn.util.Blob; |
| 18 | import org.apache.logging.log4j.LogManager; |
| 19 | import org.apache.logging.log4j.Logger; |
| 20 | import org.junit.Test; |
| 21 | import static org.junit.Assert.*; |
| 22 | |
| 23 | /** |
| 24 | * Test Server.java |
| 25 | * @author Andrew Brown <andrew.brown@intel.com> |
| 26 | */ |
| 27 | public class ServerTest { |
| 28 | |
| 29 | private static final Logger logger = LogManager.getLogger(); |
| 30 | |
| 31 | /** |
| 32 | * Test on functionality |
| 33 | * TODO more comprehensive tests with InternalFace |
| 34 | * @throws java.lang.InterruptedException |
| 35 | */ |
| 36 | @Test |
| 37 | public void testOn() throws InterruptedException { |
| 38 | // setup face |
| 39 | MockTransport transport = new MockTransport(); |
| 40 | Face face = new Face(transport, null); |
| 41 | |
| 42 | // setup server |
| 43 | NDNObserver observer = Server.getDefault().on(face, new Name("/test/server/on"), new OnServeInterest() { |
| 44 | @Override |
| 45 | public Data onInterest(Name prefix, Interest interest) { |
| 46 | Data data = new Data(interest.getName()); |
| 47 | data.setContent(new Blob("...")); |
| 48 | return data; |
| 49 | } |
| 50 | }); |
| 51 | |
| 52 | // wait for background threads to run |
| 53 | Thread.sleep(100); |
| 54 | |
| 55 | // check |
| 56 | assertEquals(1, transport.getSentInterestPackets().size()); |
| 57 | } |
| 58 | } |