blob: a2b188085bf1d230ba05384bf9204c51a98d3494 [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
12import com.intel.jndn.mock.MockTransport;
13import net.named_data.jndn.Data;
14import net.named_data.jndn.Face;
15import net.named_data.jndn.Interest;
16import net.named_data.jndn.Name;
17import net.named_data.jndn.util.Blob;
18import org.apache.logging.log4j.LogManager;
19import org.apache.logging.log4j.Logger;
20import 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
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}