blob: 0c2645b0f59b866696ec9d0672fb7d2e126792a5 [file] [log] [blame]
Andrew Browna450fad2015-01-22 11:24:40 -08001/*
andrewsbrown4feb2da2015-03-03 16:05:29 -08002 * 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 Browna450fad2015-01-22 11:24:40 -080013 */
14package com.intel.jndn.utils;
15
Andrew Browndb457052015-02-21 15:41:58 -080016import com.intel.jndn.utils.event.NDNObserver;
Andrew Browna450fad2015-01-22 11:24:40 -080017import com.intel.jndn.mock.MockTransport;
Andrew Brown58671d92015-02-23 11:01:34 -080018import java.util.logging.Logger;
Andrew Browna450fad2015-01-22 11:24:40 -080019import net.named_data.jndn.Data;
20import net.named_data.jndn.Face;
21import net.named_data.jndn.Interest;
22import net.named_data.jndn.Name;
23import net.named_data.jndn.util.Blob;
Andrew Browna450fad2015-01-22 11:24:40 -080024import org.junit.Test;
25import static org.junit.Assert.*;
26
27/**
28 * Test Server.java
29 * @author Andrew Brown <andrew.brown@intel.com>
30 */
31public class ServerTest {
32
Andrew Brown58671d92015-02-23 11:01:34 -080033 /**
34 * Setup logging
35 */
andrewsbrown69d53292015-03-17 19:37:34 +010036 private static final Logger logger = Logger.getLogger(SimpleClient.class.getName());
Andrew Browna450fad2015-01-22 11:24:40 -080037
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}