blob: 2db9071d30ba45b96c7b1a4f1566dae4b8392a79 [file] [log] [blame]
Andrew Browndb457052015-02-21 15:41:58 -08001/*
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 */
10package com.intel.jndn.utils;
11
12import com.intel.jndn.mock.MockFace;
13import java.io.IOException;
14import net.named_data.jndn.Data;
15import net.named_data.jndn.Interest;
16import net.named_data.jndn.Name;
17import net.named_data.jndn.Name.Component;
18import net.named_data.jndn.OnInterest;
19import net.named_data.jndn.transport.Transport;
20import net.named_data.jndn.util.Blob;
21import org.junit.Test;
22import static org.junit.Assert.*;
23
24/**
25 * Test SegmentedClient functionality.
26 *
27 * @author Andrew Brown <andrew.brown@intel.com>
28 */
29public 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}