Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.internal.node.server;
00018
00019 import static org.junit.Assert.assertEquals;
00020 import static org.junit.Assert.assertTrue;
00021
00022 import java.util.Collection;
00023 import java.util.Map;
00024
00025 import org.junit.Before;
00026 import org.junit.Test;
00027 import org.ros.namespace.GraphName;
00028
00029 import com.google.common.collect.Maps;
00030
00034 public class ParameterServerTest {
00035
00036 private ParameterServer server;
00037
00038 @Before
00039 public void setup() {
00040 server = new ParameterServer();
00041 }
00042
00043 @Test
00044 public void testGetNonExistent() {
00045 assertEquals(null, server.get(GraphName.of("/foo")));
00046 assertEquals(null, server.get(GraphName.of("/foo/bar")));
00047 }
00048
00049 @Test
00050 public void testSetAndGetShallow() {
00051 server.set(GraphName.of("/foo"), "bloop");
00052 assertEquals("bloop", server.get(GraphName.of("/foo")));
00053 }
00054
00055 @Test
00056 public void testSetAndGetDeep() {
00057 server.set(GraphName.of("/foo/bar"), "bloop");
00058 assertEquals("bloop", server.get(GraphName.of("/foo/bar")));
00059 }
00060
00061 @Test
00062 public void testSetAndGet() {
00063 server.set(GraphName.of("/foo"), "bloop");
00064 assertEquals("bloop", server.get(GraphName.of("/foo")));
00065 server.set(GraphName.of("/foo/bar"), "bloop");
00066 assertEquals("bloop", server.get(GraphName.of("/foo/bar")));
00067 server.set(GraphName.of("/foo/bar/baz"), "bloop");
00068 assertEquals("bloop", server.get(GraphName.of("/foo/bar/baz")));
00069 }
00070
00071 @Test
00072 public void testSetDeepAndGetShallow() {
00073 server.set(GraphName.of("/foo/bar"), "bloop");
00074 Map<String, Object> expected = Maps.newHashMap();
00075 expected.put("bar", "bloop");
00076 assertEquals(expected, server.get(GraphName.of("/foo")));
00077 }
00078
00079 @Test
00080 public void testSetOverwritesMap() {
00081 server.set(GraphName.of("/foo/bar"), "bloop");
00082 assertEquals("bloop", server.get(GraphName.of("/foo/bar")));
00083 server.set(GraphName.of("/foo"), "bloop");
00084 assertEquals("bloop", server.get(GraphName.of("/foo")));
00085 }
00086
00087 @Test
00088 public void testSetAndGetFloat() {
00089 GraphName name = GraphName.of("/foo/bar");
00090 server.set(name, 0.42f);
00091 assertEquals(0.42, (Double) server.get(name), 0.1);
00092 }
00093
00094 @Test
00095 public void testDeleteShallow() {
00096 GraphName name = GraphName.of("/foo");
00097 server.set(name, "bloop");
00098 server.delete(name);
00099 assertEquals(null, server.get(name));
00100 }
00101
00102 @Test
00103 public void testDeleteDeep() {
00104 GraphName name = GraphName.of("/foo/bar");
00105 server.set(name, "bloop");
00106 server.delete(name);
00107 assertEquals(null, server.get(name));
00108 }
00109
00110 @Test
00111 public void testHas() {
00112 server.set(GraphName.of("/foo/bar/baz"), "bloop");
00113 assertTrue(server.has(GraphName.of("/foo/bar/baz")));
00114 assertTrue(server.has(GraphName.of("/foo/bar")));
00115 assertTrue(server.has(GraphName.of("/foo")));
00116 assertTrue(server.has(GraphName.of("/")));
00117 }
00118
00119 @Test
00120 public void testGetNames() {
00121 GraphName name1 = GraphName.of("/foo/bar/baz");
00122 server.set(name1, "bloop");
00123 GraphName name2 = GraphName.of("/testing");
00124 server.set(name2, "123");
00125 Collection<GraphName> names = server.getNames();
00126 assertEquals(2, names.size());
00127 assertTrue(names.contains(name1));
00128 assertTrue(names.contains(name2));
00129 }
00130
00131 }