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
@@ -535,10 +569,10 @@ public void testDeferredDslChainingOnSensor() throws Exception {
535569 "services:" ,
536570 "- type: " + BasicApplication .class .getName (),
537571 " brooklyn.config:" ,
538- " dest: $brooklyn:attributeWhenReady(\" targetEntity \" ).getId ()" );
539- AttributeSensor <Entity > targetEntitySensor = Sensors .newSensor (Entity .class , "targetEntity " );
540- app .sensors ().set (targetEntitySensor , app );
541- assertEquals (getConfigEventually (app , DEST ), app . getId () );
572+ " dest: $brooklyn:attributeWhenReady(\" targetValue \" ).isSupplierEvaluated ()" );
573+ AttributeSensor <TestDslSupplierValue > targetValueSensor = Sensors .newSensor (TestDslSupplierValue .class , "targetValue " );
574+ app .sensors ().set (targetValueSensor , new TestDslSupplierValue () );
575+ assertEquals (getConfigEventually (app , DEST ), Boolean . TRUE );
542576 }
543577
544578 @ Test (groups ="WIP" )
@@ -568,42 +602,6 @@ public void testDeferredDslChainingOnNullConfig() throws Exception {
568602 }
569603 }
570604
571- public static class DslTestSupplierWrapper {
572- private Object supplier ;
573-
574- public DslTestSupplierWrapper (Object supplier ) {
575- this .supplier = supplier ;
576- }
577-
578- public Object getSupplier () {
579- return supplier ;
580- }
581- }
582-
583- public static class TestDslSupplierValue {
584- public boolean isSupplierEvaluated () {
585- return true ;
586- }
587- }
588-
589- public static class TestDslSupplier implements DeferredSupplier <Object >, ImmediateSupplier <Object > {
590- private Object value ;
591-
592- public TestDslSupplier (Object value ) {
593- this .value = value ;
594- }
595-
596- @ Override
597- public Object get () {
598- return getImmediately ().get ();
599- }
600-
601- @ Override
602- public Maybe <Object > getImmediately () {
603- return Maybe .of (value );
604- }
605- }
606-
607605 @ Test
608606 public void testDeferredDslChainingWithCustomSupplier () throws Exception {
609607 final Entity app = createAndStartApplication (
@@ -616,23 +614,6 @@ public void testDeferredDslChainingWithCustomSupplier() throws Exception {
616614 assertEquals (getConfigEventually (app , DEST ), Boolean .TRUE );
617615 }
618616
619- public static class DslTestCallable implements DslCallable , DeferredSupplier <TestDslSupplier >, ImmediateSupplier <TestDslSupplier > {
620-
621- @ Override
622- public Maybe <TestDslSupplier > getImmediately () {
623- throw new IllegalStateException ("Not to be called" );
624- }
625-
626- @ Override
627- public TestDslSupplier get () {
628- throw new IllegalStateException ("Not to be called" );
629- }
630-
631- public boolean isSupplierCallable () {
632- return true ;
633- }
634- }
635-
636617 @ Test
637618 public void testDeferredDslChainingWithCustomCallable () throws Exception {
638619 final Entity app = createAndStartApplication (
0 commit comments