Package io.vertx.core

Examples of io.vertx.core.MultiMap


  }

  @Test
  public void testSize()
      throws Exception {
    MultiMap mmap = new CaseInsensitiveHeaders();

    assertEquals(0, mmap.size());
    mmap.add("header", "value");
    assertEquals(1, mmap.size());
    mmap.add("header2", "value2");
    assertEquals(2, mmap.size());
    mmap.add("header", "value3");
    assertEquals(2, mmap.size());
  }
View Full Code Here


    assertEquals(2, mmap.size());
  }

  @Test
  public void testGetHashColl() {
    MultiMap mm = new CaseInsensitiveHeaders();
    String name1 = "!~AZ";
    String name2 = "!~\u0080Y";
    mm.add(name1, "value1");
    mm.add(name2, "value2");
    assertEquals(2, mm.size());
    assertEquals("value1", mm.get(name1));
    assertEquals("value2", mm.get(name2));

    mm = new CaseInsensitiveHeaders();
    name1 = "";
    name2 = "\0";
    mm.add(name1, "value1");
    mm.add(name2, "value2");
    assertEquals(2, mm.size());
    assertEquals("value1", mm.get(name1));
    assertEquals("value2", mm.get(name2));

    mm = new CaseInsensitiveHeaders();
    name1 = "AZa";
    name2 = "\u0080YA";
    mm.add(name1, "value1");
    mm.add(name2, "value2");
    assertEquals(2, mm.size());
    assertEquals("value1", mm.get(name1));
    assertEquals("value2", mm.get(name2));

    mm = new CaseInsensitiveHeaders();
    name1 = " !";
    name2 = "? ";
    assertTrue("hash error", hash(name1) == hash(name2));
    mm.add(name1, "value1");
    mm.add(name2, "value2");
    assertEquals(2, mm.size());
    assertEquals("value1", mm.get(name1));
    assertEquals("value2", mm.get(name2));

    mm = new CaseInsensitiveHeaders();
    name1 = "\u0080a";
    name2 = "Ab";
    assertTrue("hash error", hash(name1) == hash(name2));
    mm.add(name1, "value1");
    mm.add(name2, "value2");
    assertEquals(2, mm.size());
    assertEquals("value1", mm.get(name1));
    assertEquals("value2", mm.get(name2));

    // same bucket, different hash
    mm = new CaseInsensitiveHeaders();
    name1 = "A";
    name2 = "R";
    assertTrue("hash error", index(hash(name1)) == index(hash(name2)));
    mm.add(name1, "value1");
    mm.add(name2, "value2");
    assertEquals(2, mm.size());
    assertEquals("value1", mm.get(name1));
    assertEquals("value2", mm.get(name2));
  }
View Full Code Here

    assertEquals("value2", mm.get(name2));
  }

  @Test
  public void testGetAllHashColl() {
    MultiMap mm = new CaseInsensitiveHeaders();
    String name1 = "AZ";
    String name2 = "\u0080Y";
    assertTrue("hash error", hash(name1) == hash(name2));
    mm.add(name1, "value1");
    mm.add(name2, "value2");
    assertEquals(2, mm.size());
    assertEquals("[value1]", mm.getAll(name1).toString());
    assertEquals("[value2]", mm.getAll(name2).toString());

    mm = new CaseInsensitiveHeaders();
    name1 = "A";
    name2 = "R";
    assertTrue("hash error", index(hash(name1)) == index(hash(name2)));
    mm.add(name1, "value1");
    mm.add(name2, "value2");
    assertEquals(2, mm.size());
    assertEquals("[value1]", mm.getAll(name1).toString());
    assertEquals("[value2]", mm.getAll(name2).toString());
  }
View Full Code Here

    assertEquals("[value2]", mm.getAll(name2).toString());
  }

  @Test
  public void testRemoveHashColl() {
    MultiMap mm = new CaseInsensitiveHeaders();
    String name1 = "AZ";
    String name2 = "\u0080Y";
    String name3 = "RZ";
    assertTrue("hash error", hash(name1) == hash(name2));
    mm.add(name1, "value1");
    mm.add(name2, "value2");
    mm.add(name3, "value3");
    mm.add(name1, "value4");
    mm.add(name2, "value5");
    mm.add(name3, "value6");
    assertEquals(3, mm.size());
    mm.remove(name1);
    mm.remove(name2);
    assertEquals(1, mm.size());

    mm = new CaseInsensitiveHeaders();
    name1 = "A";
    name2 = "R";
    assertTrue("hash error", index(hash(name1)) == index(hash(name2)));
    mm.add(name1, "value1");
    mm.add(name2, "value2");
    assertEquals(2, mm.size());
    mm.remove(name1);
    mm.remove(name2);
    assertTrue("not empty", mm.isEmpty());
  }
View Full Code Here

    return sb.toString();
  }

  @Test
  public void testToString() {
    MultiMap mm = new CaseInsensitiveHeaders();
    assertEquals("", mm.toString());
    mm.add("Header1", "Value1");
    assertEquals("Header1: Value1\n",
        sortByLine(mm.toString()));
    mm.add("Header2", "Value2");
    assertEquals("Header1: Value1\n"
        + "Header2: Value2\n",
        sortByLine(mm.toString()));
    mm.add("Header1", "Value3");
    assertEquals("Header1: Value1\n"
        + "Header1: Value3\n"
        + "Header2: Value2\n",
        sortByLine(mm.toString()));
    mm.remove("Header1");
    assertEquals("Header2: Value2\n",
        sortByLine(mm.toString()));
    mm.set("Header2", "Value4");
    assertEquals("Header2: Value4\n",
        sortByLine(mm.toString()));
  }
View Full Code Here

   * (isn't actually used in the implementation)
   */

  @Test
  public void testMapEntrySetValue() throws Exception {
    MultiMap mmap = new CaseInsensitiveHeaders();

    mmap.add("Header", "oldvalue");

    for (Map.Entry<String, String> me:mmap) {
      me.setValue("newvalue");
    }
    assertEquals("newvalue", mmap.get("Header"));
  }
View Full Code Here

    assertEquals("newvalue", mmap.get("Header"));
  }

  @Test
  public void testMapEntryToString() throws Exception {
    MultiMap mmap = new CaseInsensitiveHeaders();

    mmap.add("Header", "value");

    assertEquals("Header: value", mmap.iterator().next().toString());
  }
View Full Code Here

    assertEquals("Header: value", mmap.iterator().next().toString());
  }

  @Test(expected = NullPointerException.class)
  public void testMapEntrySetValueNull() throws Exception {
    MultiMap mmap = new CaseInsensitiveHeaders();

    mmap.add("Header", "oldvalue");

    for (Map.Entry<String, String> me:mmap) {
      me.setValue(null);
    }
  }
View Full Code Here

    await();
  }

  @Test
  public void testHeadersCopiedAfterSend() throws Exception {
    MultiMap headers = new CaseInsensitiveHeaders();
    headers.add("foo", "bar");
    vertx.eventBus().consumer(ADDRESS1).handler(msg -> {
      assertNotSame(headers, msg.headers());
      assertEquals("bar", msg.headers().get("foo"));
      testComplete();
    });
    vertx.eventBus().send(ADDRESS1, "foo", new DeliveryOptions().setHeaders(headers));
    headers.remove("foo");
    await();
  }
View Full Code Here

TOP

Related Classes of io.vertx.core.MultiMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.