Пример #1
0
  @Test
  public void testDefaultProfile() {
    Props p = new Props();
    p.load("key1=hello\n" + "key1<one>=Hi!\n" + " \n" + "@profiles=one");

    assertEquals("Hi!", p.getValue("key1"));
    assertEquals("Hi!", p.getValue("key1", "one"));
  }
Пример #2
0
  @Test
  public void testEnvironment() {
    Props props = new Props();
    assertEquals(0, props.countTotalProperties());

    props.loadEnvironment("env");
    assertTrue(props.countTotalProperties() > 0);
  }
Пример #3
0
  @Test
  public void testProperties() throws IOException {
    Props p = loadProps("test.properties");

    assertEquals("value", p.getValue("one"));
    assertEquals("long valuein two lines", p.getValue("two"));
    assertEquals("some utf8 šđžčć", p.getValue("three"));
  }
Пример #4
0
  @Test
  public void testMultilineValue() throws IOException {
    Props p = new Props();
    p.setValueTrimLeft(true);
    p.load(readDataFile("test3.props"));

    assertEquals("\r\n\tHello from\r\n\tthe multiline\r\n\tvalue\r\n", p.getValue("email.footer"));
    assertEquals("aaa", p.getValue("email.header"));
  }
Пример #5
0
 @Test
 public void testEscapeNewValue() throws IOException {
   Props p = new Props();
   p.setEscapeNewLineValue("<br>");
   p.load(readDataFile("test.props"));
   assertEquals(
       "Snow White, pursued by a jealous queen, hides with the Dwarfs; <br>the queen feeds her a poison apple, but Prince Charming <br>awakens her with a kiss.",
       p.getValue("plot"));
 }
Пример #6
0
 @Test
 public void testIgnorePrefixWhitespace() throws IOException {
   Props p = new Props();
   p.setIgnorePrefixWhitespacesOnNewLine(false);
   p.load(readDataFile("test.props"));
   assertEquals(
       "Snow White, pursued by a jealous queen, hides with the Dwarfs; \t\tthe queen feeds her a poison apple, but Prince Charming \t\tawakens her with a kiss.",
       p.getValue("plot"));
 }
Пример #7
0
  @Test
  public void testMacros2() throws IOException {
    Props p = new Props();
    p.setValue("key1", "**${key${key3}}**");
    p.setValue("key3", "2");
    p.setValue("key2", "++++");

    assertEquals("**++++**", p.getValue("key1"));
  }
Пример #8
0
  @Test
  public void testMacroNotExist() {
    Props p = new Props();
    p.setValue("mac1", "value1");
    p.setValue("key1", "${mac1}");
    p.setValue("key2", "${mac2}");

    assertEquals("value1", p.getValue("mac1"));
    assertEquals("value1", p.getValue("key1"));
    assertEquals("${mac2}", p.getValue("key2"));
  }
Пример #9
0
  @Test
  public void testActiveProfiles() throws IOException {
    Props p = loadProps("test-actp.props");

    assertEquals("hello", p.getBaseValue("key1"));
    assertEquals("Hola!", p.getValue("key1"));
    assertEquals("world", p.getValue("key2"));

    assertEquals(1, p.getActiveProfiles().length);
    assertEquals("one.two", p.getActiveProfiles()[0]);
  }
Пример #10
0
  @Test
  public void testingWithCustomProps() {
    TestProbe probe = new TestProbe(system);
    Props childProps = Props.create(MockedChild.class);
    TestActorRef<DependentParent> parent =
        TestActorRef.create(system, Props.create(DependentParent.class, childProps));

    probe.send(parent, "pingit");

    // test some parent state change
    assertTrue(parent.underlyingActor().ponged == true || parent.underlyingActor().ponged == false);
  }
Пример #11
0
 @Test
 public void testingWithoutParent() {
   TestProbe probe = new TestProbe(system);
   ActorRef child = system.actorOf(Props.create(DependentChild.class, probe.ref()));
   probe.send(child, "ping");
   probe.expectMsg("pong");
 }
Пример #12
0
  @Test
  public void testClone() throws IOException {
    Props p = new Props();
    p.load(readDataFile("test2.props"));

    Props p2 = p.clone();
    p2.load(readDataFile("test.props"));

    assertEquals(2, p.countTotalProperties());
    assertEquals(19, p2.countTotalProperties());

    assertEquals("/app/data", p.getValue("data.path"));
    assertEquals("/app/data2", p.getValue("data.path", "@prof1"));
    assertEquals("/foo/data3", p.getValue("data.path", "@prof2"));
  }
Пример #13
0
  @Test
  public void testProbeParentTest() throws Exception {
    // #test-TestProbe-parent
    JavaTestKit parent = new JavaTestKit(system);
    ActorRef child = parent.childActorOf(Props.create(Child.class));

    parent.send(child, "ping");
    parent.expectMsgEquals("pong");
    // #test-TestProbe-parent
  }
Пример #14
0
  @Test
  public void fabricatedParentTestsItsChildResponses() throws Exception {
    // didn't put final on these in order to make the parent fit in one line in the html docs
    // #test-fabricated-parent
    TestProbe proxy = new TestProbe(system);
    ActorRef parent = system.actorOf(Props.create(new FabricatedParentCreator(proxy)));

    proxy.send(parent, "ping");
    proxy.expectMsg("pong");
    // #test-fabricated-parent
  }
Пример #15
0
 public void exampleProdActorFactoryFunction() throws Exception {
   // #child-maker-prod
   Function<ActorRefFactory, ActorRef> maker =
       new Function<ActorRefFactory, ActorRef>() {
         @Override
         public ActorRef apply(ActorRefFactory f) throws Exception {
           return f.actorOf(Props.create(Child.class));
         }
       };
   ActorRef parent = system.actorOf(Props.create(GenericDependentParent.class, maker));
   // #child-maker-prod
 }
Пример #16
0
  private Props loadProps(Props p, String fileName) throws IOException {
    String dataFolder = this.getClass().getPackage().getName() + ".data.";
    dataFolder = dataFolder.replace('.', '/');

    InputStream is = ClassLoaderUtil.getResourceAsStream(dataFolder + fileName);
    String encoding = "UTF-8";
    if (fileName.endsWith(".properties")) {
      encoding = "ISO-8859-1";
    }
    p.load(is, encoding);
    return p;
  }
Пример #17
0
  @Test
  public void testDoubleLoadsAndResolves() {
    Props props = new Props();
    props.load("pojoBean2.val2=123");
    props.load("pojoBean2.val1=\\\\${pojo}");

    assertEquals("123", props.getValue("pojoBean2.val2"));
    // BeanTemplate resolves \${foo} to ${foo}
    // we must be sure that escaped value is not resolved.
    assertEquals("\\${pojo}", props.getValue("pojoBean2.val1"));

    props.load("pojoBean2.val1=\\\\${pojo} ${pojo}");
    assertEquals(2, props.countTotalProperties());
    assertEquals("\\${pojo} ${pojo}", props.getValue("pojoBean2.val1"));
  }
Пример #18
0
  @Test
  public void testMacroNotExistSkipEmpty() {
    Props p = new Props();
    p.setIgnoreMissingMacros(true);
    p.setSkipEmptyProps(false);
    p.setValue("mac1", "value1");
    p.setValue("key1", "${mac1}");
    p.setValue("key2", "${mac2}");

    assertEquals("value1", p.getValue("mac1"));
    assertEquals("value1", p.getValue("key1"));
    assertEquals("", p.getValue("key2"));
  }
Пример #19
0
  // #test-example
  static class Parent extends UntypedActor {
    final ActorRef child = context().actorOf(Props.create(Child.class), "child");
    boolean ponged = false;

    @Override
    public void onReceive(Object message) throws Exception {
      if ("pingit".equals(message)) {
        child.tell("ping", self());
      } else if ("pong".equals(message)) {
        ponged = true;
      } else {
        unhandled(message);
      }
    }
  }
Пример #20
0
  @Test
  public void testSystemProperties() {
    Props props = new Props();
    assertEquals(0, props.countTotalProperties());
    assertNull(props.getValue("user.dir"));

    props.loadSystemProperties("sys");
    assertTrue(props.countTotalProperties() > 0);
    assertNotNull(props.getValue("sys.user.dir"));
  }
Пример #21
0
  @Test
  public void testEmpty() throws IOException {
    Props p = new Props();
    p.setSkipEmptyProps(false);
    p.load(readDataFile("test-e.props"));

    assertEquals(2, p.countTotalProperties());
    assertEquals("good", p.getValue("ok"));
    assertEquals("", p.getValue("empty"));
  }
Пример #22
0
 @Test
 public void testingWithChildProbe() throws Exception {
   final TestProbe probe = new TestProbe(system);
   // #child-maker-test
   Function<ActorRefFactory, ActorRef> maker =
       new Function<ActorRefFactory, ActorRef>() {
         @Override
         public ActorRef apply(ActorRefFactory param) throws Exception {
           return probe.ref();
         }
       };
   ActorRef parent = system.actorOf(Props.create(GenericDependentParent.class, maker));
   // #child-maker-test
   probe.send(parent, "pingit");
   probe.expectMsg("ping");
 }
Пример #23
0
  @Test
  public void testAdd() {
    Props p = new Props();
    p.setValue("key1", "val${key2}");

    assertEquals("val${key2}", p.getValue("key1"));
    assertNull(p.getValue("key1${key2}"));

    p.setValue("key2", "hurrey\tme!");

    assertEquals("valhurrey\tme!", p.getValue("key1"));
  }
Пример #24
0
  @Test
  public void testDuplicate() throws IOException {
    Props p = new Props();
    loadProps(p, "test-dupl.props");

    assertEquals("three", p.getValue("foo"));
    assertEquals("everywhere", p.getValue("bar", "prof"));

    p = new Props();
    p.setAppendDuplicateProps(true);
    loadProps(p, "test-dupl.props");

    assertEquals("one,two,three", p.getValue("foo"));
    assertEquals("here,there,everywhere", p.getValue("bar", "prof"));
  }
Пример #25
0
  @Test
  public void testMacros() throws IOException {
    Props p = new Props();
    p.load(readDataFile("test2.props"));

    assertEquals("/app/data", p.getValue("data.path"));
    assertEquals("/app/data2", p.getValue("data.path", "@prof1"));
    assertEquals("/foo/data3", p.getValue("data.path", "@prof2"));

    assertEquals("/roo/re", p.getValue("data.path", "@p1"));
    assertEquals("/app/re", p.getValue("data.path", "@p2"));

    Properties prop = new Properties();
    p.extractProps(prop, "@prof2");
    assertEquals("/foo/data3", prop.getProperty("data.path"));
  }
Пример #26
0
  @Test
  public void testValueWithBracket() throws IOException {
    Props p = new Props();
    p.load(readDataFile("test3.props"));

    assertEquals("[email protected];[email protected]", p.getValue("email.from"));
    assertEquals("[ERROR] Got %s exceptions", p.getValue("email.subject"));
    assertEquals("line1line2line3", p.getValue("email.text"));

    p = new Props();
    p.setIgnorePrefixWhitespacesOnNewLine(false);
    p.load(readDataFile("test3.props"));

    assertEquals("[email protected];[email protected]", p.getValue("email.from"));
    assertEquals("[ERROR] Got %s exceptions", p.getValue("email.subject"));
    assertEquals("line1\tline2line3", p.getValue("email.text"));

    p = new Props();
    p.setIgnorePrefixWhitespacesOnNewLine(false);
    p.setEscapeNewLineValue("\n");
    p.load(readDataFile("test3.props"));

    assertEquals("[email protected];[email protected]", p.getValue("email.from"));
    assertEquals("[ERROR] Got %s exceptions", p.getValue("email.subject"));
    assertEquals("line1\n\tline2\nline3", p.getValue("email.text"));
  }
Пример #27
0
  @Test
  public void testNestedProfiles() throws IOException {
    Props p = new Props();
    p.load(readDataFile("test-profiles.props"));

    assertEquals("hello", p.getBaseValue("key1"));
    assertEquals("hello", p.getValue("key1"));
    assertEquals("Hi!", p.getValue("key1", "one"));
    assertEquals("Hola!", p.getValue("key1", "one.two"));
    assertEquals("world", p.getValue("key2", "one.two"));
    assertNull(p.getValue("key2", "one"));
    assertEquals("Grazias", p.getValue("key3", "one.two"));
    assertEquals("Grazias", p.getValue("key3", "one"));

    Properties prop = new Properties();
    p.extractProps(prop);
    assertEquals(3, prop.size());
    assertEquals("hello", prop.getProperty("key1"));

    prop.clear();
    p.extractProps(prop, "one");
    assertEquals(3 + 1, prop.size());
    assertEquals("Hi!", prop.getProperty("key1"));
    assertEquals("Grazias", prop.getProperty("key3"));

    prop.clear();
    p.extractProps(prop, "one.two");
    assertEquals(3 + 2, prop.size());
    assertEquals("Hola!", prop.getProperty("key1"));
    assertEquals("world", prop.getProperty("key2"));
    assertEquals("Grazias", prop.getProperty("key3"));
  }
Пример #28
0
  @Test
  public void testProfiles() throws IOException {
    Props p = new Props();
    p.load(readDataFile("test-profiles.props"));

    assertEquals("one", p.getValue("foo"));
    assertEquals("one", p.getValue("foo", "non_existing_profile"));
    assertEquals("one", p.getValue("foo", "qwe"));
    assertEquals("ten", p.getValue("bar"));

    assertEquals("12345", p.getValue("vitamine", "aaa"));

    assertEquals(8, p.countTotalProperties());

    assertNull(p.getValue("db.url"));
    assertEquals("localhost", p.getValue("db.url", "develop"));
    assertEquals("localhost", p.getValue("db.url", "develop", "deploy"));
    assertEquals("192.168.1.102", p.getValue("db.url", "deploy", "develop"));
    assertEquals("192.168.1.102", p.getValue("db.url", "deploy"));

    Properties prop = new Properties();
    p.extractBaseProps(prop);
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "non_existing");
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "aaa");
    assertEquals("12345", prop.getProperty("vitamine"));

    prop.clear();
    p.extractProps(prop, "develop");
    assertEquals("localhost", prop.getProperty("db.url"));
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "develop", "deploy");
    assertEquals("localhost", prop.getProperty("db.url"));
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "deploy", "develop");
    assertEquals("192.168.1.102", prop.getProperty("db.url"));
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "deploy");
    assertEquals("192.168.1.102", prop.getProperty("db.url"));
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.setActiveProfiles("deploy");
    p.extractSubProps(prop, "db.*");
    assertEquals(2, prop.size());
  }
Пример #29
0
  @Test
  public void testBasic() throws IOException {
    Props p = new Props();
    p.load(readDataFile("test.props"));

    assertEquals(17, p.countTotalProperties());

    assertEquals("Snow White and the Seven Dwarfs", p.getValue("story"));
    assertEquals(
        "Walt Disney's New characters in his first full-length production!", p.getValue("Tagline"));
    assertEquals("C:\\local\\snowwhite.mpg", p.getValue("file"));
    assertEquals(
        "Snow White, pursued by a jealous queen, hides with the Dwarfs; the queen feeds her a poison apple, but Prince Charming awakens her with a kiss.",
        p.getValue("plot"));

    assertEquals("45.7", p.getValue("bashful.weight"));
    assertEquals("49.5", p.getValue("doc.weight"));

    assertEquals("Čađavi Žar utf8", p.getValue("comment"));

    assertEquals("foo\tboo\rzoo\nxxx\ftoo", p.getValue("special-chars"));
    assertEquals("\\\\a", p.getValue("special2"));
    assertEquals(3, p.getValue("special2").length());

    assertNull(p.getValue("non existing"));

    Properties prop = new Properties();
    p.extractBaseProps(prop);
    assertEquals("1937{c}", prop.getProperty("year"));
    assertEquals("49.5", prop.getProperty("doc.weight"));
    assertEquals("Čađavi Žar utf8", prop.getProperty("comment"));
  }