blob: 7a324abfecb082e0c71d6d18539a8d007db72e95 [file] [log] [blame]
Andrew Brown63bed362015-02-18 11:28:50 -08001/*
andrewsbrown7e6b9e82015-03-03 16:11:11 -08002 * 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.
Andrew Brown63bed362015-02-18 11:28:50 -080013 */
14package com.intel.jndn.management;
15
andrewsbrown43b96302015-03-17 21:51:43 +010016import com.intel.jndn.management.types.RibEntry;
Andrew Brown63bed362015-02-18 11:28:50 -080017import java.util.logging.Logger;
18import junit.framework.Assert;
19import net.named_data.jndn.Face;
20import net.named_data.jndn.Name;
Andrew Brown07466442015-02-24 09:07:02 -080021import net.named_data.jndn.security.KeyChain;
Andrew Brown63bed362015-02-18 11:28:50 -080022
23/**
24 * Tests to run with a local NFD as part of integration testing; will not run in
25 * the maven test phase, must be run manually.
26 *
27 * @author Andrew Brown <andrew.brown@intel.com>
28 */
29public class IntegrationSuite {
30
31 private static final Logger logger = Logger.getLogger(IntegrationSuite.class.getName());
32
Andrew Brown07466442015-02-24 09:07:02 -080033 /**
34 * Test NFD methods
35 *
36 * @param args
37 * @throws Exception
38 */
Andrew Brown63bed362015-02-18 11:28:50 -080039 public static void main(String[] args) throws Exception {
andrewsbrown458524b2015-02-23 09:10:13 -080040 Face face = new Face("localhost");
Andrew Brown07466442015-02-24 09:07:02 -080041 KeyChain keyChain = buildTestKeyChain();
42 face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName());
43
Andrew Brown63bed362015-02-18 11:28:50 -080044 Assert.assertTrue(NFD.pingLocal(face));
Andrew Brown07466442015-02-24 09:07:02 -080045
Andrew Brown63bed362015-02-18 11:28:50 -080046 // grab datasets
andrewsbrown8a32f302015-03-24 08:42:46 -070047 Assert.assertTrue(NFD.getForwarderStatus(face).getStartTimestamp() > 0);
Andrew Brown63bed362015-02-18 11:28:50 -080048 Assert.assertFalse(NFD.getFaceList(face).isEmpty());
49 Assert.assertFalse(NFD.getFibList(face).isEmpty());
50 Assert.assertFalse(NFD.getRouteList(face).isEmpty());
Andrew Brown07466442015-02-24 09:07:02 -080051
Andrew Brown63bed362015-02-18 11:28:50 -080052 // create a new route
andrewsbrown43b96302015-03-17 21:51:43 +010053 NFD.register(face, "udp4://127.0.0.1:56363", new Name("/my/test/route"), 999);
andrewsbrown9a6d7ba2015-03-24 09:53:29 -070054
andrewsbrown43b96302015-03-17 21:51:43 +010055 // check that route is created
Andrew Browndfa8fc12015-03-25 10:46:47 -070056 Thread.sleep(1000); // NFD registers the route asynchronously
andrewsbrown43b96302015-03-17 21:51:43 +010057 boolean found = false;
andrewsbrown9a6d7ba2015-03-24 09:53:29 -070058 for (RibEntry route : NFD.getRouteList(face)) {
Andrew Brown61bfc592015-03-17 14:11:36 -070059 logger.info("Found route: " + route.getName().toUri());
andrewsbrown9a6d7ba2015-03-24 09:53:29 -070060 if (route.getName().equals(new Name("/my/test/route"))) {
andrewsbrown43b96302015-03-17 21:51:43 +010061 found = true;
62 }
63 }
64 Assert.assertTrue(found);
Andrew Brown07466442015-02-24 09:07:02 -080065
Andrew Brown63bed362015-02-18 11:28:50 -080066 // remove the route
andrewsbrown43b96302015-03-17 21:51:43 +010067 NFD.unregister(face, new Name("/my/test/route"), "udp4://127.0.0.1:56363");
Andrew Brown07466442015-02-24 09:07:02 -080068 }
69
70 /**
71 * Setup the KeyChain with a default identity; TODO move this to
72 * MemoryIdentityStorage once it can handle getting/setting defaults
73 *
74 * @return
75 * @throws net.named_data.jndn.security.SecurityException
76 */
77 public static KeyChain buildTestKeyChain() throws net.named_data.jndn.security.SecurityException {
78 KeyChain keyChain = new KeyChain();
79 try {
80 keyChain.getDefaultCertificateName();
81 } catch (net.named_data.jndn.security.SecurityException e) {
82 keyChain.createIdentity(new Name("/test/identity"));
83 keyChain.getIdentityManager().setDefaultIdentity(new Name("/test/identity"));
84 }
85 return keyChain;
Andrew Brown63bed362015-02-18 11:28:50 -080086 }
87}