andrewsbrown | 39b0fc9 | 2015-05-11 13:44:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * jndn-management |
| 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.management; |
| 15 | |
| 16 | import com.intel.jndn.management.types.StrategyChoice; |
| 17 | import com.intel.jndn.mock.MockKeyChain; |
andrewsbrown | 39b0fc9 | 2015-05-11 13:44:38 -0700 | [diff] [blame] | 18 | import java.util.List; |
Andrew Brown | 37cec24 | 2015-05-11 14:24:13 -0700 | [diff] [blame] | 19 | import java.util.Random; |
andrewsbrown | 39b0fc9 | 2015-05-11 13:44:38 -0700 | [diff] [blame] | 20 | import java.util.logging.Logger; |
| 21 | import static junit.framework.Assert.assertEquals; |
| 22 | import net.named_data.jndn.Face; |
| 23 | import net.named_data.jndn.Name; |
| 24 | import net.named_data.jndn.security.KeyChain; |
| 25 | import org.junit.Test; |
| 26 | |
| 27 | /** |
| 28 | * Test strategy management on a real, local NFD |
| 29 | * |
| 30 | * @author Andrew Brown <andrew.brown@intel.com> |
| 31 | */ |
| 32 | public class StrategyTestIT { |
| 33 | |
| 34 | private static final Logger logger = Logger.getLogger(StrategyTestIT.class.getName()); |
| 35 | Name prefix; |
| 36 | Face face; |
| 37 | |
| 38 | public StrategyTestIT() throws net.named_data.jndn.security.SecurityException { |
Andrew Brown | 37cec24 | 2015-05-11 14:24:13 -0700 | [diff] [blame] | 39 | this.prefix = new Name("/test/strategy").append("random:" + new Random().nextInt()); |
andrewsbrown | 39b0fc9 | 2015-05-11 13:44:38 -0700 | [diff] [blame] | 40 | this.face = new Face("localhost"); // strategy commands only available on localhost |
| 41 | KeyChain mockKeyChain = MockKeyChain.configure(new Name("/test/server")); |
| 42 | face.setCommandSigningInfo(mockKeyChain, mockKeyChain.getDefaultCertificateName()); |
| 43 | } |
| 44 | |
| 45 | @Test |
| 46 | public void testStrategySetUnset() throws Exception { |
| 47 | List<StrategyChoice> choices = NFD.getStrategyList(face); |
| 48 | int oldSize = choices.size(); |
| 49 | |
| 50 | NFD.setStrategy(face, prefix, Strategies.CLIENT_CONTROL); |
Andrew Brown | 37cec24 | 2015-05-11 14:24:13 -0700 | [diff] [blame] | 51 | Thread.sleep(1000); // strategy takes a while to register |
| 52 | |
andrewsbrown | 39b0fc9 | 2015-05-11 13:44:38 -0700 | [diff] [blame] | 53 | choices = NFD.getStrategyList(face); |
| 54 | assertEquals(oldSize + 1, choices.size()); |
| 55 | |
| 56 | NFD.unsetStrategy(face, prefix); |
| 57 | } |
| 58 | } |