andrewsbrown | 8d5ae29 | 2015-07-01 17:38:22 -0700 | [diff] [blame^] | 1 | /* |
| 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. |
| 13 | */ |
| 14 | package com.intel.jndn.utils; |
| 15 | |
| 16 | import java.util.List; |
| 17 | import java.util.concurrent.CompletableFuture; |
| 18 | import java.util.stream.Collectors; |
| 19 | import java.util.stream.IntStream; |
| 20 | import net.named_data.jndn.Data; |
| 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 TestHelper { |
| 29 | |
| 30 | public static List<CompletableFuture<Data>> buildFutureSegments(Name name, int from, int to) { |
| 31 | return buildSegments(name, from, to).stream() |
| 32 | .map((d) -> CompletableFuture.completedFuture(d)) |
| 33 | .collect(Collectors.toList()); |
| 34 | } |
| 35 | |
| 36 | public static List<Data> buildSegments(Name name, int from, int to) { |
| 37 | return IntStream.range(0, 10).boxed() |
| 38 | .map((i) -> buildData(new Name(name).appendSegment(i), i.toString(), to - 1)) |
| 39 | .collect(Collectors.toList()); |
| 40 | } |
| 41 | |
| 42 | public static Data buildData(Name name, String content) { |
| 43 | Data data = new Data(name); |
| 44 | data.setContent(new Blob(content)); |
| 45 | |
| 46 | return data; |
| 47 | } |
| 48 | |
| 49 | public static Data buildData(Name name, String content, int finalBlockId){ |
| 50 | Data data = buildData(name, content); |
| 51 | data.getMetaInfo().setFinalBlockId(Name.Component.fromNumberWithMarker(finalBlockId, 0x00)); |
| 52 | return data; |
| 53 | } |
| 54 | } |