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 | |
Andrew Brown | db45705 | 2015-02-21 15:41:58 -0800 | [diff] [blame] | 12 | import com.intel.jndn.utils.event.NDNObserver; |
Andrew Brown | a450fad | 2015-01-22 11:24:40 -0800 | [diff] [blame] | 13 | import com.intel.jndn.mock.MockTransport; |
Andrew Brown | 58671d9 | 2015-02-23 11:01:34 -0800 | [diff] [blame^] | 14 | import java.util.logging.Logger; |
Andrew Brown | a450fad | 2015-01-22 11:24:40 -0800 | [diff] [blame] | 15 | import net.named_data.jndn.Data; |
| 16 | import net.named_data.jndn.Face; |
| 17 | import net.named_data.jndn.Interest; |
| 18 | import net.named_data.jndn.Name; |
| 19 | import net.named_data.jndn.util.Blob; |
Andrew Brown | a450fad | 2015-01-22 11:24:40 -0800 | [diff] [blame] | 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 | |
Andrew Brown | 58671d9 | 2015-02-23 11:01:34 -0800 | [diff] [blame^] | 29 | /** |
| 30 | * Setup logging |
| 31 | */ |
| 32 | private static final Logger logger = Logger.getLogger(Client.class.getName()); |
Andrew Brown | a450fad | 2015-01-22 11:24:40 -0800 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Test on functionality |
| 36 | * TODO more comprehensive tests with InternalFace |
| 37 | * @throws java.lang.InterruptedException |
| 38 | */ |
| 39 | @Test |
| 40 | public void testOn() throws InterruptedException { |
| 41 | // setup face |
| 42 | MockTransport transport = new MockTransport(); |
| 43 | Face face = new Face(transport, null); |
| 44 | |
| 45 | // setup server |
| 46 | NDNObserver observer = Server.getDefault().on(face, new Name("/test/server/on"), new OnServeInterest() { |
| 47 | @Override |
| 48 | public Data onInterest(Name prefix, Interest interest) { |
| 49 | Data data = new Data(interest.getName()); |
| 50 | data.setContent(new Blob("...")); |
| 51 | return data; |
| 52 | } |
| 53 | }); |
| 54 | |
| 55 | // wait for background threads to run |
| 56 | Thread.sleep(100); |
| 57 | |
| 58 | // check |
| 59 | assertEquals(1, transport.getSentInterestPackets().size()); |
| 60 | } |
| 61 | } |