Andrew Brown | a450fad | 2015-01-22 11:24:40 -0800 | [diff] [blame] | 1 | /* |
andrewsbrown | 4feb2da | 2015-03-03 16:05:29 -0800 | [diff] [blame] | 2 | * jndn-utils |
| 3 | * Copyright (c) 2015, Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU Lesser General Public License, |
| 7 | * version 3, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT ANY |
| 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
| 12 | * more details. |
Andrew Brown | a450fad | 2015-01-22 11:24:40 -0800 | [diff] [blame] | 13 | */ |
| 14 | package com.intel.jndn.utils; |
| 15 | |
Andrew Brown | db45705 | 2015-02-21 15:41:58 -0800 | [diff] [blame] | 16 | import com.intel.jndn.utils.event.NDNObserver; |
Andrew Brown | a450fad | 2015-01-22 11:24:40 -0800 | [diff] [blame] | 17 | import com.intel.jndn.mock.MockTransport; |
Andrew Brown | 58671d9 | 2015-02-23 11:01:34 -0800 | [diff] [blame] | 18 | import java.util.logging.Logger; |
Andrew Brown | a450fad | 2015-01-22 11:24:40 -0800 | [diff] [blame] | 19 | import net.named_data.jndn.Data; |
| 20 | import net.named_data.jndn.Face; |
| 21 | import net.named_data.jndn.Interest; |
| 22 | import net.named_data.jndn.Name; |
| 23 | import net.named_data.jndn.util.Blob; |
Andrew Brown | a450fad | 2015-01-22 11:24:40 -0800 | [diff] [blame] | 24 | import org.junit.Test; |
| 25 | import static org.junit.Assert.*; |
| 26 | |
| 27 | /** |
| 28 | * Test Server.java |
| 29 | * @author Andrew Brown <andrew.brown@intel.com> |
| 30 | */ |
| 31 | public class ServerTest { |
| 32 | |
Andrew Brown | 58671d9 | 2015-02-23 11:01:34 -0800 | [diff] [blame] | 33 | /** |
| 34 | * Setup logging |
| 35 | */ |
andrewsbrown | 69d5329 | 2015-03-17 19:37:34 +0100 | [diff] [blame^] | 36 | private static final Logger logger = Logger.getLogger(SimpleClient.class.getName()); |
Andrew Brown | a450fad | 2015-01-22 11:24:40 -0800 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Test on functionality |
| 40 | * TODO more comprehensive tests with InternalFace |
| 41 | * @throws java.lang.InterruptedException |
| 42 | */ |
| 43 | @Test |
| 44 | public void testOn() throws InterruptedException { |
| 45 | // setup face |
| 46 | MockTransport transport = new MockTransport(); |
| 47 | Face face = new Face(transport, null); |
| 48 | |
| 49 | // setup server |
| 50 | NDNObserver observer = Server.getDefault().on(face, new Name("/test/server/on"), new OnServeInterest() { |
| 51 | @Override |
| 52 | public Data onInterest(Name prefix, Interest interest) { |
| 53 | Data data = new Data(interest.getName()); |
| 54 | data.setContent(new Blob("...")); |
| 55 | return data; |
| 56 | } |
| 57 | }); |
| 58 | |
| 59 | // wait for background threads to run |
| 60 | Thread.sleep(100); |
| 61 | |
| 62 | // check |
| 63 | assertEquals(1, transport.getSentInterestPackets().size()); |
| 64 | } |
| 65 | } |