Ejemplo n.º 1
0
  /** Tests that trigger is called after the value is changed */
  public void testValueChange() {
    final MyProperties props = new MyProperties();

    String path = "test.mondrian.properties.change.value";
    BooleanProperty boolProp = new BooleanProperty(props, path, false);

    assertTrue("Check property value NOT false", !boolProp.get());

    // set via the 'set' method
    final boolean prevBoolean = boolProp.set(true);
    assertEquals(false, prevBoolean);

    // now explicitly set the property
    final Object prevObject = props.setProperty(path, "false");
    assertEquals("true", prevObject);

    String v = props.getProperty(path);
    assertTrue("Check property value is null", v != null);
    assertTrue("Check property value is true", (!Boolean.valueOf(v).booleanValue()));

    final State state = new State();
    state.triggerCalled = false;
    state.triggerValue = null;

    final Trigger trigger =
        new Trigger() {
          public boolean isPersistent() {
            return false;
          }

          public int phase() {
            return Trigger.PRIMARY_PHASE;
          }

          public void execute(Property property, String value) {
            state.triggerCalled = true;
            state.triggerValue = value;
          }
        };
    boolProp.addTrigger(trigger);

    String falseStr = "false";
    props.setProperty(path, falseStr);
    assertTrue("Check trigger was called", !state.triggerCalled);

    String trueStr = "true";
    props.setProperty(path, trueStr);

    assertTrue("Check trigger was NOT called", state.triggerCalled);
    assertTrue("Check trigger value was null", (state.triggerValue != null));
    assertTrue("Check trigger value is NOT correct", state.triggerValue.equals(trueStr));
  }
Ejemplo n.º 2
0
  /** Checks that triggers are called in the correct order. */
  public void testTriggerCallOrder() {
    final MyProperties props = new MyProperties();
    String path = "test.mondrian.properties.call.order";
    BooleanProperty boolProp = new BooleanProperty(props, path, false);

    final State2 state = new State2();
    state.callCounter = 0;

    // now explicitly set the property
    props.setProperty(path, "false");

    String v = props.getProperty(path);
    assertTrue("Check property value is null", (v != null));
    assertTrue("Check property value is true", (!Boolean.valueOf(v).booleanValue()));

    // primaryOne
    Trigger primaryOneTrigger =
        new Trigger() {
          public boolean isPersistent() {
            return false;
          }

          public int phase() {
            return Trigger.PRIMARY_PHASE;
          }

          public void execute(Property property, String value) {
            state.primaryOne = state.callCounter++;
          }
        };
    boolProp.addTrigger(primaryOneTrigger);

    // secondaryOne
    Trigger secondaryOneTrigger =
        new Trigger() {
          public boolean isPersistent() {
            return false;
          }

          public int phase() {
            return Trigger.SECONDARY_PHASE;
          }

          public void execute(Property property, String value) {
            state.secondaryOne = state.callCounter++;
          }
        };
    boolProp.addTrigger(secondaryOneTrigger);

    // tertiaryOne
    Trigger tertiaryOneTrigger =
        new Trigger() {
          public boolean isPersistent() {
            return false;
          }

          public int phase() {
            return Trigger.TERTIARY_PHASE;
          }

          public void execute(Property property, String value) {
            state.tertiaryOne = state.callCounter++;
          }
        };
    boolProp.addTrigger(tertiaryOneTrigger);

    // tertiaryTwo
    Trigger tertiaryTwoTrigger =
        new Trigger() {
          public boolean isPersistent() {
            return false;
          }

          public int phase() {
            return Trigger.TERTIARY_PHASE;
          }

          public void execute(Property property, String value) {
            state.tertiaryTwo = state.callCounter++;
          }
        };
    boolProp.addTrigger(tertiaryTwoTrigger);

    // secondaryTwo
    Trigger secondaryTwoTrigger =
        new Trigger() {
          public boolean isPersistent() {
            return false;
          }

          public int phase() {
            return Trigger.SECONDARY_PHASE;
          }

          public void execute(Property property, String value) {
            state.secondaryTwo = state.callCounter++;
          }
        };
    boolProp.addTrigger(secondaryTwoTrigger);

    // primaryTwo
    Trigger primaryTwoTrigger =
        new Trigger() {
          public boolean isPersistent() {
            return false;
          }

          public int phase() {
            return Trigger.PRIMARY_PHASE;
          }

          public void execute(Property property, String value) {
            state.primaryTwo = state.callCounter++;
          }
        };
    boolProp.addTrigger(primaryTwoTrigger);

    String falseStr = "false";
    props.setProperty(path, falseStr);
    assertTrue("Check trigger was called", (state.callCounter == 0));

    String trueStr = "true";
    props.setProperty(path, trueStr);

    assertTrue("Check trigger was NOT called", (state.callCounter != 0));
    assertTrue("Check triggers was NOT called correct number of times", (state.callCounter == 6));

    // now make sure that primary are called before secondary which are
    // before tertiary
    assertTrue("Check primaryOne > secondaryOne", (state.primaryOne < state.secondaryOne));
    assertTrue("Check primaryOne > secondaryTwo", (state.primaryOne < state.secondaryTwo));
    assertTrue("Check primaryOne > tertiaryOne", (state.primaryOne < state.tertiaryOne));
    assertTrue("Check primaryOne > tertiaryTwo", (state.primaryOne < state.tertiaryTwo));

    assertTrue("Check primaryTwo > secondaryOne", (state.primaryTwo < state.secondaryOne));
    assertTrue("Check primaryTwo > secondaryTwo", (state.primaryTwo < state.secondaryTwo));
    assertTrue("Check primaryTwo > tertiaryOne", (state.primaryTwo < state.tertiaryOne));
    assertTrue("Check primaryTwo > tertiaryTwo", (state.primaryTwo < state.tertiaryTwo));

    assertTrue("Check secondaryOne > tertiaryOne", (state.secondaryOne < state.tertiaryOne));
    assertTrue("Check secondaryOne > tertiaryTwo", (state.secondaryOne < state.tertiaryTwo));

    assertTrue("Check secondaryTwo > tertiaryOne", (state.secondaryTwo < state.tertiaryOne));
    assertTrue("Check secondaryTwo > tertiaryTwo", (state.secondaryTwo < state.tertiaryTwo));

    // remove some of the triggers
    boolProp.removeTrigger(primaryTwoTrigger);
    boolProp.removeTrigger(secondaryTwoTrigger);
    boolProp.removeTrigger(tertiaryTwoTrigger);

    // reset
    state.callCounter = 0;
    state.primaryOne = 0;
    state.primaryTwo = 0;
    state.secondaryOne = 0;
    state.secondaryTwo = 0;
    state.tertiaryOne = 0;
    state.tertiaryTwo = 0;

    props.setProperty(path, falseStr);
    assertTrue("Check trigger was NOT called", (state.callCounter != 0));
    assertTrue("Check triggers was NOT called correct number of times", (state.callCounter == 3));

    // now make sure that primary are called before secondary which are
    // before tertiary
    assertTrue("Check primaryOne > secondaryOne", (state.primaryOne < state.secondaryOne));
    assertTrue("Check primaryOne > tertiaryOne", (state.primaryOne < state.tertiaryOne));

    assertTrue("Check secondaryOne > tertiaryOne", (state.secondaryOne < state.tertiaryOne));
  }