1313 * See the License for the specific language governing permissions and
1414 * limitations under the License.
1515 */
16- package org .apache .brooklyn .camp .brooklyn .dsl ;
16+ package org .apache .brooklyn .camp .brooklyn .spi . dsl ;
1717
1818import static org .testng .Assert .assertEquals ;
1919
2020import java .util .concurrent .Callable ;
21+ import java .util .concurrent .ExecutionException ;
2122
2223import org .apache .brooklyn .api .entity .Entity ;
2324import org .apache .brooklyn .api .mgmt .Task ;
2425import org .apache .brooklyn .api .sensor .AttributeSensor ;
2526import org .apache .brooklyn .camp .brooklyn .AbstractYamlTest ;
26- import org .apache .brooklyn .camp .brooklyn .spi .dsl .DslCallable ;
27+ import org .apache .brooklyn .camp .brooklyn .spi .dsl .methods .DslTestObjects .DslTestCallable ;
28+ import org .apache .brooklyn .camp .brooklyn .spi .dsl .methods .DslTestObjects .DslTestSupplierWrapper ;
29+ import org .apache .brooklyn .camp .brooklyn .spi .dsl .methods .DslTestObjects .TestDslSupplier ;
30+ import org .apache .brooklyn .camp .brooklyn .spi .dsl .methods .DslTestObjects .TestDslSupplierValue ;
31+ import org .apache .brooklyn .camp .brooklyn .spi .dsl .methods .custom .UserSuppliedPackageType ;
2732import org .apache .brooklyn .config .ConfigKey ;
2833import org .apache .brooklyn .core .config .ConfigKeys ;
2934import org .apache .brooklyn .core .entity .EntityInternal ;
3237import org .apache .brooklyn .entity .stock .BasicApplication ;
3338import org .apache .brooklyn .entity .stock .BasicEntity ;
3439import org .apache .brooklyn .test .Asserts ;
35- import org .apache .brooklyn .util .core .task .DeferredSupplier ;
36- import org .apache .brooklyn .util .core .task .ImmediateSupplier ;
3740import org .apache .brooklyn .util .guava .Maybe ;
3841import org .testng .annotations .Test ;
3942
4043import com .google .common .base .Function ;
4144import com .google .common .collect .Iterables ;
4245
4346// Doesn't test executing the DSL from different contexts (i.e. fetching the config from children inheriting it)
44- public class DslYamlBlockingTest extends AbstractYamlTest {
47+ public class DslYamlTest extends AbstractYamlTest {
4548 private static final ConfigKey <Object > DEST = ConfigKeys .newConfigKey (Object .class , "dest" );
4649 private static final ConfigKey <Object > DEST2 = ConfigKeys .newConfigKey (Object .class , "dest2" );
4750 private static final ConfigKey <Object > DEST3 = ConfigKeys .newConfigKey (Object .class , "dest3" );
@@ -501,15 +504,46 @@ public void testDslFunctionRegexReplacementWithDeferredArg() throws Exception {
501504 assertEquals (replacementFn .apply ("Broooklyn" ), "Brooklyn" );
502505 }
503506
507+ public static class InaccessibleType {
508+ public static void isEvaluated () {}
509+ }
510+
511+ @ Test
512+ public void testDeferredDslInaccessibleCall () throws Exception {
513+ final Entity app = createAndStartApplication (
514+ "services:" ,
515+ "- type: " + BasicApplication .class .getName (),
516+ " brooklyn.config:" ,
517+ " dest: $brooklyn:config(\" targetValue\" ).isEvaluated()" );
518+ app .config ().set (ConfigKeys .newConfigKey (InaccessibleType .class , "targetValue" ), new InaccessibleType ());
519+ try {
520+ getConfigEventually (app , DEST );
521+ Asserts .shouldHaveFailedPreviously ("Outside of allowed package scope" );
522+ } catch (ExecutionException e ) {
523+ Asserts .expectedFailureContains (e , "(outside allowed package scope)" );
524+ }
525+ }
526+
527+ @ Test
528+ public void testDeferredDslUserSuppliedPackage () throws Exception {
529+ final Entity app = createAndStartApplication (
530+ "services:" ,
531+ "- type: " + BasicApplication .class .getName (),
532+ " brooklyn.config:" ,
533+ " dest: $brooklyn:config(\" targetValue\" ).isEvaluated()" );
534+ app .config ().set (ConfigKeys .newConfigKey (UserSuppliedPackageType .class , "targetValue" ), new UserSuppliedPackageType ());
535+ assertEquals (getConfigEventually (app , DEST ), Boolean .TRUE );
536+ }
537+
504538 @ Test
505539 public void testDeferredDslChainingOnConfig () throws Exception {
506540 final Entity app = createAndStartApplication (
507541 "services:" ,
508542 "- type: " + BasicApplication .class .getName (),
509543 " brooklyn.config:" ,
510- " targetEntity : $brooklyn:self()" ,
511- " dest: $brooklyn: config(\" targetEntity \" ).getId()" );
512- assertEquals (getConfigEventually (app , DEST ), app . getId () );
544+ " dest : $brooklyn:config( \" targetValue \" ).isSupplierEvaluated()" );
545+ app . config (). set ( ConfigKeys . newConfigKey ( TestDslSupplierValue . class , "targetValue" ), new TestDslSupplierValue () );
546+ assertEquals (getConfigEventually (app , DEST ), Boolean . TRUE );
513547 }
514548
515549 @ Test
@@ -534,10 +568,10 @@ public void testDeferredDslChainingOnSensor() throws Exception {
534568 "services:" ,
535569 "- type: " + BasicApplication .class .getName (),
536570 " brooklyn.config:" ,
537- " dest: $brooklyn:attributeWhenReady(\" targetEntity \" ).getId ()" );
538- AttributeSensor <Entity > targetEntitySensor = Sensors .newSensor (Entity .class , "targetEntity " );
539- app .sensors ().set (targetEntitySensor , app );
540- assertEquals (getConfigEventually (app , DEST ), app . getId () );
571+ " dest: $brooklyn:attributeWhenReady(\" targetValue \" ).isSupplierEvaluated ()" );
572+ AttributeSensor <TestDslSupplierValue > targetValueSensor = Sensors .newSensor (TestDslSupplierValue .class , "targetValue " );
573+ app .sensors ().set (targetValueSensor , new TestDslSupplierValue () );
574+ assertEquals (getConfigEventually (app , DEST ), Boolean . TRUE );
541575 }
542576
543577 @ Test (groups ="WIP" )
@@ -567,42 +601,6 @@ public void testDeferredDslChainingOnNullConfig() throws Exception {
567601 }
568602 }
569603
570- public static class DslTestSupplierWrapper {
571- private Object supplier ;
572-
573- public DslTestSupplierWrapper (Object supplier ) {
574- this .supplier = supplier ;
575- }
576-
577- public Object getSupplier () {
578- return supplier ;
579- }
580- }
581-
582- public static class TestDslSupplierValue {
583- public boolean isSupplierEvaluated () {
584- return true ;
585- }
586- }
587-
588- public static class TestDslSupplier implements DeferredSupplier <Object >, ImmediateSupplier <Object > {
589- private Object value ;
590-
591- public TestDslSupplier (Object value ) {
592- this .value = value ;
593- }
594-
595- @ Override
596- public Object get () {
597- return getImmediately ().get ();
598- }
599-
600- @ Override
601- public Maybe <Object > getImmediately () {
602- return Maybe .of (value );
603- }
604- }
605-
606604 @ Test
607605 public void testDeferredDslChainingWithCustomSupplier () throws Exception {
608606 final Entity app = createAndStartApplication (
@@ -615,23 +613,6 @@ public void testDeferredDslChainingWithCustomSupplier() throws Exception {
615613 assertEquals (getConfigEventually (app , DEST ), Boolean .TRUE );
616614 }
617615
618- public static class DslTestCallable implements DslCallable , DeferredSupplier <TestDslSupplier >, ImmediateSupplier <TestDslSupplier > {
619-
620- @ Override
621- public Maybe <TestDslSupplier > getImmediately () {
622- throw new IllegalStateException ("Not to be called" );
623- }
624-
625- @ Override
626- public TestDslSupplier get () {
627- throw new IllegalStateException ("Not to be called" );
628- }
629-
630- public boolean isSupplierCallable () {
631- return true ;
632- }
633- }
634-
635616 @ Test
636617 public void testDeferredDslChainingWithCustomCallable () throws Exception {
637618 final Entity app = createAndStartApplication (
0 commit comments