Search in sources :

Example 1 with PropertyMap

use of com.yahoo.processing.request.properties.PropertyMap in project vespa by vespa-engine.

the class PropertyMapTestCase method testArrayCloning.

@Test
public void testArrayCloning() {
    PropertyMap map = new PropertyMap();
    byte[] byteArray = new byte[] { 2, 4, 7 };
    map.set("byteArray", byteArray);
    PropertyMap mapClone = map.clone();
    assertArrayEquals(byteArray, (byte[]) mapClone.get("byteArray"));
    assertTrue("Array was cloned", mapClone.get("byteArray") != byteArray);
}
Also used : PropertyMap(com.yahoo.processing.request.properties.PropertyMap) Test(org.junit.Test)

Example 2 with PropertyMap

use of com.yahoo.processing.request.properties.PropertyMap in project vespa by vespa-engine.

the class SubPropertiesTestCase method testSubProperties.

@Test
public void testSubProperties() {
    PropertyMap map = new PropertyMap() {

        {
            set("a.e", "1");
            set("a.f", 2);
            set("b.e", "3");
            set("f", 3);
            set("e", "2");
            set("d", "a");
        }
    };
    SubProperties sub = new SubProperties("a", map);
    assertEquals("1", sub.get("e"));
    assertEquals(2, sub.get("f"));
    assertNull(sub.get("d"));
    assertEquals(new HashSet<>(Arrays.asList("e", "f")), sub.listProperties("").keySet());
}
Also used : PropertyMap(com.yahoo.processing.request.properties.PropertyMap) SubProperties(com.yahoo.search.query.properties.SubProperties) Test(org.junit.Test)

Example 3 with PropertyMap

use of com.yahoo.processing.request.properties.PropertyMap in project vespa by vespa-engine.

the class PropertyMapTestCase method testCloning.

public void testCloning() {
    PropertyMap map = new PropertyMap();
    map.set("clonable", new ClonableObject());
    map.set("nonclonable", new NonClonableObject());
    map.set("clonableArray", new ClonableObject[] { new ClonableObject() });
    map.set("nonclonableArray", new NonClonableObject[] { new NonClonableObject() });
    map.set("clonableList", Collections.singletonList(new ClonableObject()));
    map.set("nonclonableList", Collections.singletonList(new NonClonableObject()));
    assertNotNull(map.get("clonable"));
    assertNotNull(map.get("nonclonable"));
    PropertyMap mapClone = map.clone();
    assertTrue(map.get("clonable") != mapClone.get("clonable"));
    assertTrue(map.get("nonclonable") == mapClone.get("nonclonable"));
    assertTrue(map.get("clonableArray") != mapClone.get("clonableArray"));
    assertTrue(first(map.get("clonableArray")) != first(mapClone.get("clonableArray")));
    assertTrue(first(map.get("nonclonableArray")) == first(mapClone.get("nonclonableArray")));
}
Also used : PropertyMap(com.yahoo.processing.request.properties.PropertyMap)

Example 4 with PropertyMap

use of com.yahoo.processing.request.properties.PropertyMap in project vespa by vespa-engine.

the class PropertyMapTestCase method testObjectCloning.

@Test
public void testObjectCloning() {
    PropertyMap map = new PropertyMap();
    map.set("clonable", new ClonableObject());
    map.set("publicClonable", new PublicClonableObject());
    map.set("nonclonable", new NonClonableObject());
    map.set("clonableArray", new ClonableObject[] { new ClonableObject() });
    map.set("publicClonableArray", new ClonableObject[] { new ClonableObject() });
    map.set("nonclonableArray", new NonClonableObject[] { new NonClonableObject() });
    map.set("clonableList", Collections.singletonList(new ClonableObject()));
    map.set("nonclonableList", Collections.singletonList(new NonClonableObject()));
    assertNotNull(map.get("clonable"));
    assertNotNull(map.get("nonclonable"));
    PropertyMap mapClone = map.clone();
    assertTrue(map.get("clonable") != mapClone.get("clonable"));
    assertTrue(map.get("publicClonable") != mapClone.get("publicClonable"));
    assertTrue(map.get("nonclonable") == mapClone.get("nonclonable"));
    assertTrue(map.get("clonableArray") != mapClone.get("clonableArray"));
    assertTrue(first(map.get("clonableArray")) != first(mapClone.get("clonableArray")));
    assertTrue(map.get("publicClonableArray") != mapClone.get("publicClonableArray"));
    assertTrue(first(map.get("publicClonableArray")) != first(mapClone.get("publicClonableArray")));
    assertTrue(first(map.get("nonclonableArray")) == first(mapClone.get("nonclonableArray")));
}
Also used : PropertyMap(com.yahoo.processing.request.properties.PropertyMap) Test(org.junit.Test)

Example 5 with PropertyMap

use of com.yahoo.processing.request.properties.PropertyMap in project vespa by vespa-engine.

the class RequestTestCase method testProperties.

@Test
public void testProperties() {
    Properties p = new PropertyMap();
    p.set("a", "a1");
    Request r = new Request(p);
    r.properties().set("b", "b1");
    assertEquals(2, r.properties().listProperties().size());
    assertEquals("a1", r.properties().get("a"));
    assertEquals("b1", r.properties().get("b"));
    assertEquals("b1", r.properties().get("b", "default"));
    assertEquals("default", r.properties().get("c", "default"));
    assertNull(r.properties().get("c"));
    assertEquals("b1", r.properties().get(new CompoundName("b")));
    assertEquals("b1", r.properties().get(new CompoundName("b"), "default"));
    assertEquals("default", r.properties().get(new CompoundName("c"), "default"));
    assertNull(r.properties().get(new CompoundName("c")));
    assertEquals("b1", r.properties().getString("b"));
    assertEquals("b1", r.properties().getString("b", "default"));
    assertEquals("default", r.properties().getString("c", "default"));
    assertEquals(null, r.properties().getString("c"));
    assertEquals("b1", r.properties().getString(new CompoundName("b")));
    assertEquals("b1", r.properties().getString(new CompoundName("b"), "default"));
    assertEquals("default", r.properties().getString(new CompoundName("c"), "default"));
    assertEquals(null, r.properties().getString(new CompoundName("c")));
    r.properties().set("i", 7);
    assertEquals(7, (int) r.properties().getInteger("i"));
    assertEquals(7, (int) r.properties().getInteger("i", 3));
    assertEquals(3, (int) r.properties().getInteger("n", 3));
    assertNull(r.properties().getInteger("n"));
    assertEquals(7, (int) r.properties().getInteger(new CompoundName("i")));
    assertEquals(7, (int) r.properties().getInteger(new CompoundName("i"), 3));
    assertEquals(3, (int) r.properties().getInteger(new CompoundName("n"), 3));
    assertNull(r.properties().getInteger("n"));
    r.properties().set(new CompoundName("l"), 7);
    assertEquals(7, (long) r.properties().getLong("l"));
    assertEquals(7, (long) r.properties().getLong("l", 3l));
    assertEquals(3, (long) r.properties().getLong("m", 3l));
    assertNull(r.properties().getInteger("m"));
    assertEquals(7, (long) r.properties().getLong(new CompoundName("l")));
    assertEquals(7, (long) r.properties().getLong(new CompoundName("l"), 3l));
    assertEquals(3, (long) r.properties().getLong(new CompoundName("m"), 3l));
    assertNull(r.properties().getInteger("m"));
    r.properties().set("d", 7.3);
    assertEquals(7.3, r.properties().getDouble("d"));
    assertEquals(7.3, r.properties().getDouble("d", 3.4d));
    assertEquals(3.4, r.properties().getDouble("f", 3.4d));
    assertNull(r.properties().getDouble("f"));
    assertEquals(7.3, r.properties().getDouble(new CompoundName("d")));
    assertEquals(7.3, r.properties().getDouble(new CompoundName("d"), 3.4d));
    assertEquals(3.4, r.properties().getDouble(new CompoundName("f"), 3.4d));
    assertNull(r.properties().getDouble("f"));
    r.properties().set("o", true);
    assertEquals(true, r.properties().getBoolean("o"));
    assertEquals(true, r.properties().getBoolean("o", true));
    assertEquals(true, r.properties().getBoolean("g", true));
    assertEquals(false, r.properties().getBoolean("g"));
    assertEquals(true, r.properties().getBoolean(new CompoundName("o")));
    assertEquals(true, r.properties().getBoolean(new CompoundName("o"), true));
    assertEquals(true, r.properties().getBoolean(new CompoundName("g"), true));
    assertEquals(false, r.properties().getBoolean("g"));
    r.properties().set(new CompoundName("x.y"), "x1.y1");
    r.properties().set("x.z", "x1.z1");
    assertEquals(8, r.properties().listProperties().size());
    assertEquals(0, r.properties().listProperties("a").size());
    assertEquals(0, r.properties().listProperties(new CompoundName("a")).size());
    assertEquals(0, r.properties().listProperties(new CompoundName("none")).size());
    assertEquals(2, r.properties().listProperties(new CompoundName("x")).size());
    assertEquals(2, r.properties().listProperties("x").size());
}
Also used : CompoundName(com.yahoo.processing.request.CompoundName) PropertyMap(com.yahoo.processing.request.properties.PropertyMap) Request(com.yahoo.processing.Request) Properties(com.yahoo.processing.request.Properties) Test(org.junit.Test)

Aggregations

PropertyMap (com.yahoo.processing.request.properties.PropertyMap)5 Test (org.junit.Test)4 Request (com.yahoo.processing.Request)1 CompoundName (com.yahoo.processing.request.CompoundName)1 Properties (com.yahoo.processing.request.Properties)1 SubProperties (com.yahoo.search.query.properties.SubProperties)1