2020package org .apache .polygene .library .constraints ;
2121
2222import org .apache .polygene .api .common .Optional ;
23+ import org .apache .polygene .api .composite .TransientBuilder ;
2324import org .apache .polygene .api .constraint .ConstraintViolationException ;
25+ import org .apache .polygene .api .mixin .Mixins ;
26+ import org .apache .polygene .api .mixin .NoopMixin ;
2427import org .apache .polygene .api .property .Property ;
2528import org .apache .polygene .bootstrap .AssemblyException ;
2629import org .apache .polygene .bootstrap .ModuleAssembly ;
@@ -83,6 +86,27 @@ public void givenInvalidHostNameWhenSettingPropertyExpectConstrainViolation()
8386 } );
8487 }
8588
89+ @ Test
90+ public void givenInvalidHostNameWhenConstructingExpectConstrainViolation ()
91+ throws Exception
92+ {
93+ TransientBuilder <SomeValue > builder = transientBuilderFactory .newTransientBuilder ( SomeValue .class );
94+ assertThrows ( ConstraintViolationException .class , () -> {
95+ builder .prototype ().hostPort ().set ( "1:2:3_i:1234" );
96+ builder .newInstance ();
97+ } );
98+ }
99+
100+ @ Test
101+ public void givenInvalidHostNameWhenCallingServiceExpectConstrainViolation ()
102+ throws Exception
103+ {
104+ SomeService someService = serviceFinder .findService ( SomeService .class ).get ();
105+ assertThrows ( ConstraintViolationException .class , () -> {
106+ someService .doSomething ( "1:2:3_i:1234" );
107+ } );
108+ }
109+
86110 @ Test
87111 public void givenInvalidPortNumberWhenSettingPropertyExpectConstrainViolation ()
88112 throws Exception
@@ -114,6 +138,7 @@ public void assemble( ModuleAssembly module )
114138 throws AssemblyException
115139 {
116140 module .transients ( SomeValue .class );
141+ module .services ( SomeService .class );
117142 }
118143
119144 public interface SomeValue
@@ -122,4 +147,10 @@ public interface SomeValue
122147 @ Optional
123148 Property <String > hostPort ();
124149 }
150+
151+ @ Mixins ( NoopMixin .class )
152+ public interface SomeService
153+ {
154+ void doSomething (@ HostPort String hostPort );
155+ }
125156}
0 commit comments