blob: dd75f3e06bf3a03a1cfb4bde7d4de241f3f0b95a [file] [log] [blame]
Andrew Browndb457052015-02-21 15:41:58 -08001/*
andrewsbrown4feb2da2015-03-03 16:05:29 -08002 * jndn-utils
3 * Copyright (c) 2015, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU Lesser General Public License,
7 * version 3, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12 * more details.
Andrew Browndb457052015-02-21 15:41:58 -080013 */
14package com.intel.jndn.utils;
15
16import com.intel.jndn.mock.MockFace;
17import java.io.IOException;
18import net.named_data.jndn.Data;
19import net.named_data.jndn.Interest;
20import net.named_data.jndn.Name;
21import net.named_data.jndn.Name.Component;
22import net.named_data.jndn.OnInterest;
23import net.named_data.jndn.transport.Transport;
24import net.named_data.jndn.util.Blob;
25import org.junit.Test;
26import static org.junit.Assert.*;
27
28/**
29 * Test SegmentedClient functionality.
30 *
31 * @author Andrew Brown <andrew.brown@intel.com>
32 */
33public class SegmentedClientTest {
34
35 /**
36 * Test of getSync method, of class SegmentedClient.
37 */
38 @Test
39 public void testGetSync() throws Exception {
40 MockFace face = new MockFace();
41 face.registerPrefix(new Name("/segmented/data"), new OnInterest() {
42 private int count = 0;
43 private int max = 9;
44
45 @Override
46 public void onInterest(Name prefix, Interest interest, Transport transport, long registeredPrefixId) {
47 Data data = new Data(interest.getName());
48 if (!SegmentedClient.hasSegment(data.getName())) {
49 data.getName().appendSegment(0);
50 }
51 data.getMetaInfo().setFinalBlockId(Component.fromNumberWithMarker(max, 0x00));
52 data.setContent(new Blob("."));
53 try {
54 transport.send(data.wireEncode().buf());
55 } catch (IOException e) {
56 fail(e.getMessage());
57 }
58 }
59 }, null);
60
61 Data data = SegmentedClient.getDefault().getSync(face, new Name("/segmented/data").appendSegment(0));
62 assertEquals(10, data.getContent().size());
63 }
64}