blob: 0ac93b53891483d187079f71c63e7f62478b5aa1 [file] [log] [blame]
Andrew Brown3f2521a2015-01-17 22:10:15 -08001/*
2 * File name: ClientTest.java
3 *
4 * Purpose: Test Client.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 org.junit.After;
13import org.junit.AfterClass;
14import org.junit.Before;
15import org.junit.BeforeClass;
16import org.junit.Test;
17import static org.junit.Assert.*;
18import com.intel.jndn.mock.MockTransport;
19import net.named_data.jndn.Data;
20import net.named_data.jndn.Face;
21import net.named_data.jndn.Name;
22import net.named_data.jndn.util.Blob;
23
24/**
25 *
26 * @author Andrew Brown <andrew.brown@intel.com>
27 */
28public class ClientTest {
29
30 @Test
31 public void testGetSync() {
32 // setup face
33 MockTransport transport = new MockTransport();
34 Face face = new Face(transport, null);
35
36 // setup return data
37 Data response = new Data(new Name("/a/b/c"));
38 response.setContent(new Blob("..."));
39 transport.respondWith(response);
40
41 // retrieve data
42 Client client = new Client();
43 Data data = client.getSync(face, new Name("/a/b/c"));
44 assertEquals(new Blob("...").buf(), data.getContent().buf());
45 }
46
47 @Test
48 public void testGetAsync() throws InterruptedException {
49 // setup face
50 MockTransport transport = new MockTransport();
51 Face face = new Face(transport, null);
52
53 // setup return data
54 Data response = new Data(new Name("/a/b/c"));
55 response.setContent(new Blob("..."));
56 transport.respondWith(response);
57
58 // retrieve data
59 Client client = new Client();
60 ClientObserver observer = client.get(face, new Name("/a/b/c"));
61
62 // wait
63 while(observer.responses() == 0){
64 Thread.sleep(10);
65 }
66 Data data = (Data) observer.getFirst().getPacket();
67 assertEquals(new Blob("...").buf(), data.getContent().buf());
68 }
69}