blob: 5e2b724a05752b96417fadc37ae80280ee5ad1bf [file] [log] [blame]
Andrew Browna450fad2015-01-22 11:24:40 -08001/*
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 */
10package com.intel.jndn.utils;
11
Andrew Browndb457052015-02-21 15:41:58 -080012import com.intel.jndn.utils.event.NDNObserver;
Andrew Browna450fad2015-01-22 11:24:40 -080013import com.intel.jndn.mock.MockTransport;
Andrew Brown58671d92015-02-23 11:01:34 -080014import java.util.logging.Logger;
Andrew Browna450fad2015-01-22 11:24:40 -080015import net.named_data.jndn.Data;
16import net.named_data.jndn.Face;
17import net.named_data.jndn.Interest;
18import net.named_data.jndn.Name;
19import net.named_data.jndn.util.Blob;
Andrew Browna450fad2015-01-22 11:24:40 -080020import org.junit.Test;
21import static org.junit.Assert.*;
22
23/**
24 * Test Server.java
25 * @author Andrew Brown <andrew.brown@intel.com>
26 */
27public class ServerTest {
28
Andrew Brown58671d92015-02-23 11:01:34 -080029 /**
30 * Setup logging
31 */
32 private static final Logger logger = Logger.getLogger(Client.class.getName());
Andrew Browna450fad2015-01-22 11:24:40 -080033
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}