Andrew Brown | 3f2521a | 2015-01-17 22:10:15 -0800 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 10 | package com.intel.jndn.utils; |
| 11 | |
| 12 | import org.junit.After; |
| 13 | import org.junit.AfterClass; |
| 14 | import org.junit.Before; |
| 15 | import org.junit.BeforeClass; |
| 16 | import org.junit.Test; |
| 17 | import static org.junit.Assert.*; |
| 18 | import com.intel.jndn.mock.MockTransport; |
| 19 | import net.named_data.jndn.Data; |
| 20 | import net.named_data.jndn.Face; |
| 21 | import net.named_data.jndn.Name; |
| 22 | import net.named_data.jndn.util.Blob; |
| 23 | |
| 24 | /** |
| 25 | * |
| 26 | * @author Andrew Brown <andrew.brown@intel.com> |
| 27 | */ |
| 28 | public 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 | } |