andrewsbrown | 4dddd47 | 2015-04-01 14:28:46 -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 com.intel.jndn.mock.MockFace; |
| 17 | import java.io.IOException; |
| 18 | import net.named_data.jndn.Data; |
andrewsbrown | 6e2d6b7 | 2015-04-20 13:33:21 -0700 | [diff] [blame] | 19 | import net.named_data.jndn.Interest; |
andrewsbrown | 4dddd47 | 2015-04-01 14:28:46 -0700 | [diff] [blame] | 20 | import net.named_data.jndn.Name; |
| 21 | import net.named_data.jndn.util.Blob; |
| 22 | import static org.junit.Assert.*; |
| 23 | import org.junit.Test; |
| 24 | |
| 25 | /** |
| 26 | * |
| 27 | * @author Andrew Brown <andrew.brown@intel.com> |
| 28 | */ |
| 29 | public class SegmentedServerTest { |
| 30 | |
| 31 | MockFace face = new MockFace(); |
| 32 | SegmentedServer instance = new SegmentedServer(face, new Name("/test/prefix")); |
| 33 | |
| 34 | @Test |
| 35 | public void testGetPrefix() { |
| 36 | assertNotNull(instance.getPrefix()); |
| 37 | } |
| 38 | |
| 39 | @Test |
| 40 | public void testAddPipelineStage() { |
| 41 | instance.addPipelineStage(null); |
| 42 | } |
| 43 | |
| 44 | @Test |
| 45 | public void testProcessPipeline() throws Exception { |
| 46 | Data in = new Data(new Name("/test")); |
| 47 | Data out = instance.processPipeline(in); |
| 48 | assertEquals(out, in); |
| 49 | } |
| 50 | |
| 51 | @Test |
| 52 | public void testServe() throws IOException { |
| 53 | Data in = new Data(new Name("/test/prefix/serve")); |
| 54 | in.setContent(new Blob("1234")); |
| 55 | instance.serve(in); |
| 56 | Data out = SegmentedClient.getDefault().getSync(face, new Name("/test/prefix/serve")); |
| 57 | assertEquals(in.getContent(), out.getContent()); |
| 58 | assertEquals(in.getName().toUri(), out.getName().toUri()); |
| 59 | assertEquals("1234", out.getContent().toString()); |
| 60 | } |
andrewsbrown | 6e2d6b7 | 2015-04-20 13:33:21 -0700 | [diff] [blame] | 61 | |
| 62 | @Test(expected = IOException.class) |
| 63 | public void testCleanup() throws Exception{ |
| 64 | Data in = new Data(new Name("/test")); |
| 65 | in.getMetaInfo().setFreshnessPeriod(0); |
| 66 | instance.serve(in); |
| 67 | Thread.sleep(10); |
| 68 | |
| 69 | Data out = SegmentedClient.getDefault().getSync(face, new Name("/test")); |
| 70 | assertNotNull(out); |
| 71 | assertEquals(in.getName(), out.getName()); |
| 72 | |
| 73 | instance.cleanup(); |
| 74 | SegmentedClient.getDefault().getSync(face, new Name("/test")); |
| 75 | } |
| 76 | |
| 77 | @Test |
| 78 | public void testServingNoContent() throws IOException{ |
| 79 | instance.serve(new Data()); |
| 80 | } |
| 81 | |
| 82 | @Test |
| 83 | public void testWhenDataNameIsLongerThanInterestName() throws Exception{ |
| 84 | instance.serve(new Data(new Name("/test/prefix/a/b/c/1"))); |
| 85 | instance.serve(new Data(new Name("/test/prefix/a/b/c/2"))); |
| 86 | |
| 87 | Interest interest = new Interest(new Name("/test/prefix/a/b")) |
| 88 | .setChildSelector(Interest.CHILD_SELECTOR_RIGHT).setInterestLifetimeMilliseconds(100); |
| 89 | Data out = SegmentedClient.getDefault().getSync(face, interest); |
| 90 | |
| 91 | assertNotNull(out); |
| 92 | assertEquals("/test/prefix/a/b/c/1", out.getName().toUri()); |
| 93 | // note that this won't be .../c/2 since .../c/1 satisfies both the Interest |
| 94 | // name and "c" is the rightmost component (child selectors operate on the |
| 95 | // next component after the Interest name only) |
| 96 | } |
andrewsbrown | 4dddd47 | 2015-04-01 14:28:46 -0700 | [diff] [blame] | 97 | } |