/** * Deactivation of scopes. * * <p>Rules: * * <p>- scope siblings != unit siblings - scope parents != unit parents - siblings with diff. * scopes deactivate each other - a scope is deactivated if itself or any of it's parent scopes * are deactivated */ @Test public void testDeactivation() { DialogState dialogState = new DialogState(dialog, new NoopContext(), new NoopStateCoordination()); assertTrue( "Unit should be active by default", dialogState.isWithinActiveScope(processAttributes)); assertFalse( "Unit should be deactive by default", dialogState.isWithinActiveScope(recoveryAttributes)); dialogState.activateScope(recoveryAttributes); assertTrue("Unit should be active", dialogState.isWithinActiveScope(recoveryAttributes)); assertFalse("Unit should be inactive", dialogState.isWithinActiveScope(processAttributes)); }
/** Test resolution of statements across scope hierarchy */ @Test public void testStatementResolution() { DialogState dialogState = new DialogState(dialog, new NoopContext(), new NoopStateCoordination()); // statement resolved form parent scope dialogState.setStatement(basicAttributes, "foo", "bar"); String statement = dialogState.getContext(processAttributes).resolve("foo"); assertNotNull("Statement should be resolved from parent scope", statement); assertEquals("bar", statement); // child scope overrides statement dialogState.setStatement(processAttributes, "foo", "anotherBar"); statement = dialogState.getContext(processAttributes).resolve("foo"); assertEquals("anotherBar", statement); // collect statement across scopes LinkedList<String> statements = dialogState.getContext(processAttributes).collect("foo"); assertTrue("Expected two statement for key 'foo'", statements.size() == 2); assertTrue( "Expected correct statement values in right order", statements.get(0).equals("anotherBar")); assertTrue("Expected correct statement values in right order", statements.get(1).equals("bar")); }