polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject polygene-java git commit: POLYGENE-122 : Adding name to Null constraint on set() method on Property of Transient instance.
Date Thu, 19 Apr 2018 03:38:24 GMT
Repository: polygene-java
Updated Branches:
  refs/heads/develop ecee06b46 -> 71bad2987


POLYGENE-122 : Adding name to Null constraint on set() method on Property of Transient instance.


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/71bad298
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/71bad298
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/71bad298

Branch: refs/heads/develop
Commit: 71bad2987ddd6d13d88e38efb6ff6bfc1398385e
Parents: ecee06b
Author: niclas <niclas@hedhman.org>
Authored: Thu Apr 19 11:32:17 2018 +0800
Committer: niclas <niclas@hedhman.org>
Committed: Thu Apr 19 11:32:17 2018 +0800

----------------------------------------------------------------------
 .../constraint/ConstraintViolationException.java   | 17 ++++++++++-------
 .../runtime/injection/DependencyModel.java         |  9 ++-------
 .../runtime/property/PropertyInstance.java         | 11 ++++++++++-
 .../apache/polygene/api/common/OptionalTest.java   | 16 ++++++++++++++--
 4 files changed, 36 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/71bad298/core/api/src/main/java/org/apache/polygene/api/constraint/ConstraintViolationException.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/constraint/ConstraintViolationException.java
b/core/api/src/main/java/org/apache/polygene/api/constraint/ConstraintViolationException.java
index 83f9a8c..8a81840 100644
--- a/core/api/src/main/java/org/apache/polygene/api/constraint/ConstraintViolationException.java
+++ b/core/api/src/main/java/org/apache/polygene/api/constraint/ConstraintViolationException.java
@@ -190,14 +190,17 @@ public class ConstraintViolationException extends IllegalArgumentException
                            : instanceTypes.stream()
                                           .map( this::nameOf )
                                           .collect( Collectors.joining( "," ) );
-            String name;
-            if( longNames )
+            String name = "";
+            if( primaryType != null )
             {
-                name = primaryType.getName();
-            }
-            else
-            {
-                name = primaryType.getSimpleName();
+                if( longNames )
+                {
+                    name = primaryType.getName();
+                }
+                else
+                {
+                    name = primaryType.getSimpleName();
+                }
             }
             Object[] args = new Object[]{ name, instanceToString, identity, types };
             MessageFormat formatter = new MessageFormat( compositePattern, locale );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/71bad298/core/runtime/src/main/java/org/apache/polygene/runtime/injection/DependencyModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/injection/DependencyModel.java
b/core/runtime/src/main/java/org/apache/polygene/runtime/injection/DependencyModel.java
index 0c72658..acdbdb1 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/injection/DependencyModel.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/injection/DependencyModel.java
@@ -261,10 +261,7 @@ public final class DependencyModel
 
             if( injectionProvider == null && !optional )
             {
-                String message =
-                    "[Module " + resolution.module()
-                        .name() + "] Non-optional @" + rawInjectionClass.getName() + " was
not bound in " + injectedClass
-                        .getName();
+                String message = "[Module " + resolution.module().name() + "] Non-optional
@" + rawInjectionClass.getName() + " was not bound in " + injectedClass.getName();
                 throw new ConstructionException( message );
             }
         }
@@ -301,9 +298,7 @@ public final class DependencyModel
         if( injectedValue == null && !optional )
         {
             String simpleName = injectionAnnotation.annotationType().getSimpleName();
-            String message = "[Module " + context.module().name() + "] Non-optional @" +
-                             simpleName + " " + injectionType.toString() +
-                             " was null in " + injectedClass.getName();
+            String message = "[Module " + context.module().name() + "] Non-optional @" +
simpleName + " " + injectionType.toString() + " was null in " + injectedClass.getName();
             if( simpleName.toLowerCase().contains( "service" )
                 && !isServiceInjectionProvider() )
             {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/71bad298/core/runtime/src/main/java/org/apache/polygene/runtime/property/PropertyInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/property/PropertyInstance.java
b/core/runtime/src/main/java/org/apache/polygene/runtime/property/PropertyInstance.java
index 4ea4ea3..ac012f2 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/property/PropertyInstance.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/property/PropertyInstance.java
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import org.apache.polygene.api.composite.Composite;
+import org.apache.polygene.api.constraint.ConstraintViolationException;
 import org.apache.polygene.api.property.Property;
 import org.apache.polygene.api.property.PropertyDescriptor;
 import org.apache.polygene.api.property.PropertyWrapper;
@@ -97,7 +98,15 @@ public class PropertyInstance<T>
             throw new IllegalStateException( "Property [" + model.qualifiedName() + "] is
immutable." );
         }
 
-        model.checkConstraints( aNewValue );
+        try
+        {
+            model.checkConstraints( aNewValue );
+        }
+        catch( ConstraintViolationException e )
+        {
+            e.setInstanceString( model.qualifiedName().toString() );
+            throw e;
+        }
 
         value = aNewValue;
     }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/71bad298/core/runtime/src/test/java/org/apache/polygene/api/common/OptionalTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/polygene/api/common/OptionalTest.java b/core/runtime/src/test/java/org/apache/polygene/api/common/OptionalTest.java
index be120db..3ff597a 100644
--- a/core/runtime/src/test/java/org/apache/polygene/api/common/OptionalTest.java
+++ b/core/runtime/src/test/java/org/apache/polygene/api/common/OptionalTest.java
@@ -42,8 +42,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 /**
  * Tests for @Optional
  */
-public class OptionalTest
-    extends AbstractPolygeneTest
+public class OptionalTest extends AbstractPolygeneTest
 {
     public void assemble( ModuleAssembly module )
         throws AssemblyException
@@ -101,6 +100,19 @@ public class OptionalTest
     }
 
     @Test
+    public void givenMandatoryPropertyWhenSettingPropertyToNullOnBuiltInstanceThenException()
+    {
+        TransientBuilder<TestComposite2> builder = transientBuilderFactory.newTransientBuilder(
TestComposite2.class );
+        builder.prototype().mandatoryProperty().set( "Hello" );
+        builder.prototype().optionalProperty().set( "World" );
+        TestComposite2 testComposite2 = builder.newInstance();
+        testComposite2.optionalProperty().set( null );
+        assertThrows( ConstraintViolationException.class, () -> {
+            testComposite2.mandatoryProperty().set( null );
+        } );
+    }
+
+    @Test
     public void givenOptionalAssociationWhenOptionalMissingThenNoException()
         throws Exception
     {


Mime
View raw message