Andrew Brown | db45705 | 2015-02-21 15:41:58 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * File name: SegmentedClientTest.java |
| 3 | * |
| 4 | * Purpose: Test SegmentedClient functionality. |
| 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 com.intel.jndn.mock.MockFace; |
| 13 | import java.io.IOException; |
| 14 | import net.named_data.jndn.Data; |
| 15 | import net.named_data.jndn.Interest; |
| 16 | import net.named_data.jndn.Name; |
| 17 | import net.named_data.jndn.Name.Component; |
| 18 | import net.named_data.jndn.OnInterest; |
| 19 | import net.named_data.jndn.transport.Transport; |
| 20 | import net.named_data.jndn.util.Blob; |
| 21 | import org.junit.Test; |
| 22 | import static org.junit.Assert.*; |
| 23 | |
| 24 | /** |
| 25 | * Test SegmentedClient functionality. |
| 26 | * |
| 27 | * @author Andrew Brown <andrew.brown@intel.com> |
| 28 | */ |
| 29 | public class SegmentedClientTest { |
| 30 | |
| 31 | /** |
| 32 | * Test of getSync method, of class SegmentedClient. |
| 33 | */ |
| 34 | @Test |
| 35 | public void testGetSync() throws Exception { |
| 36 | MockFace face = new MockFace(); |
| 37 | face.registerPrefix(new Name("/segmented/data"), new OnInterest() { |
| 38 | private int count = 0; |
| 39 | private int max = 9; |
| 40 | |
| 41 | @Override |
| 42 | public void onInterest(Name prefix, Interest interest, Transport transport, long registeredPrefixId) { |
| 43 | Data data = new Data(interest.getName()); |
| 44 | if (!SegmentedClient.hasSegment(data.getName())) { |
| 45 | data.getName().appendSegment(0); |
| 46 | } |
| 47 | data.getMetaInfo().setFinalBlockId(Component.fromNumberWithMarker(max, 0x00)); |
| 48 | data.setContent(new Blob(".")); |
| 49 | try { |
| 50 | transport.send(data.wireEncode().buf()); |
| 51 | } catch (IOException e) { |
| 52 | fail(e.getMessage()); |
| 53 | } |
| 54 | } |
| 55 | }, null); |
| 56 | |
| 57 | Data data = SegmentedClient.getDefault().getSync(face, new Name("/segmented/data").appendSegment(0)); |
| 58 | assertEquals(10, data.getContent().size()); |
| 59 | } |
| 60 | } |