Andrew Brown | db45705 | 2015-02-21 15:41:58 -0800 | [diff] [blame] | 1 | /* |
andrewsbrown | 4feb2da | 2015-03-03 16:05:29 -0800 | [diff] [blame] | 2 | * 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 Brown | db45705 | 2015-02-21 15:41:58 -0800 | [diff] [blame] | 13 | */ |
| 14 | package com.intel.jndn.utils; |
| 15 | |
| 16 | import com.intel.jndn.mock.MockFace; |
| 17 | import java.io.IOException; |
| 18 | import net.named_data.jndn.Data; |
| 19 | import net.named_data.jndn.Interest; |
| 20 | import net.named_data.jndn.Name; |
| 21 | import net.named_data.jndn.Name.Component; |
| 22 | import net.named_data.jndn.OnInterest; |
| 23 | import net.named_data.jndn.transport.Transport; |
| 24 | import net.named_data.jndn.util.Blob; |
| 25 | import org.junit.Test; |
| 26 | import static org.junit.Assert.*; |
| 27 | |
| 28 | /** |
| 29 | * Test SegmentedClient functionality. |
| 30 | * |
| 31 | * @author Andrew Brown <andrew.brown@intel.com> |
| 32 | */ |
| 33 | public 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 | } |