blob: c0abd14be1ebe40fa629895b2f9ca465a0e5c6dd [file] [log] [blame]
andrewsbrown39b0fc92015-05-11 13:44:38 -07001/*
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 */
14package com.intel.jndn.management;
15
16import com.intel.jndn.management.types.StrategyChoice;
17import com.intel.jndn.mock.MockKeyChain;
andrewsbrown39b0fc92015-05-11 13:44:38 -070018import java.util.List;
Andrew Brown37cec242015-05-11 14:24:13 -070019import java.util.Random;
andrewsbrown39b0fc92015-05-11 13:44:38 -070020import java.util.logging.Logger;
21import static junit.framework.Assert.assertEquals;
22import net.named_data.jndn.Face;
23import net.named_data.jndn.Name;
24import net.named_data.jndn.security.KeyChain;
25import org.junit.Test;
26
27/**
28 * Test strategy management on a real, local NFD
29 *
30 * @author Andrew Brown <andrew.brown@intel.com>
31 */
32public 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 Brown37cec242015-05-11 14:24:13 -070039 this.prefix = new Name("/test/strategy").append("random:" + new Random().nextInt());
andrewsbrown39b0fc92015-05-11 13:44:38 -070040 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 Brown37cec242015-05-11 14:24:13 -070051 Thread.sleep(1000); // strategy takes a while to register
52
andrewsbrown39b0fc92015-05-11 13:44:38 -070053 choices = NFD.getStrategyList(face);
54 assertEquals(oldSize + 1, choices.size());
55
56 NFD.unsetStrategy(face, prefix);
57 }
58}