Repository: polygene-java
Updated Branches:
  refs/heads/develop 2035bd7a2 -> 1d75d91e4


value builder ignores constraint violations if there is no UoW - fix


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

Branch: refs/heads/develop
Commit: 04c62760a669c8bdb1a9eb064844786268d597f5
Parents: 0ef97e9
Author: tbml <[email protected]>
Authored: Sat Sep 9 23:04:51 2017 +0200
Committer: tbml <[email protected]>
Committed: Sat Sep 9 23:04:51 2017 +0200

----------------------------------------------------------------------
 .../polygene/runtime/value/ValueModel.java      | 72 ++++++++++----------
 .../constraints/ValueConstraintTest.java        | 46 +++++++++++++
 2 files changed, 82 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/04c62760/core/runtime/src/main/java/org/apache/polygene/runtime/value/ValueModel.java
----------------------------------------------------------------------
diff --git 
a/core/runtime/src/main/java/org/apache/polygene/runtime/value/ValueModel.java 
b/core/runtime/src/main/java/org/apache/polygene/runtime/value/ValueModel.java
index 3f9703e..f18bc4e 100644
--- 
a/core/runtime/src/main/java/org/apache/polygene/runtime/value/ValueModel.java
+++ 
b/core/runtime/src/main/java/org/apache/polygene/runtime/value/ValueModel.java
@@ -101,51 +101,51 @@ public final class ValueModel extends CompositeModel
                                        );
 
         // IF no UnitOfWork is active, then the Association checks shouldn't 
be done.
-        if( UnitOfWorkInstance.getCurrent().empty() )
+        if( ! UnitOfWorkInstance.getCurrent().empty() )
         {
-            return;
-        }
-        ( (ValueStateModel) stateModel ).associations().forEach(
-            associationModel ->
-            {
-                try
-                {
-                    associationModel.checkConstraints( state.associationFor( 
associationModel.accessor() ).get() );
-                }
-                catch( ConstraintViolationException e )
+            ( (ValueStateModel) stateModel ).associations().forEach(
+                associationModel ->
                 {
-                    violations.addAll( e.constraintViolations() );
+                    try
+                    {
+                        associationModel.checkConstraints( 
state.associationFor( associationModel.accessor() ).get() );
+                    }
+                    catch( ConstraintViolationException e )
+                    {
+                        violations.addAll( e.constraintViolations() );
+                    }
                 }
-            }
-                                                               );
+            );
 
-        ( (ValueStateModel) stateModel ).manyAssociations().forEach(
-            model ->
-            {
-                try
-                {
-                    model.checkAssociationConstraints( 
state.manyAssociationFor( model.accessor() ) );
-                }
-                catch( ConstraintViolationException e )
+            ( (ValueStateModel) stateModel ).manyAssociations().forEach(
+                model ->
                 {
-                    violations.addAll( e.constraintViolations() );
+                    try
+                    {
+                        model.checkAssociationConstraints( 
state.manyAssociationFor( model.accessor() ) );
+                    }
+                    catch( ConstraintViolationException e )
+                    {
+                        violations.addAll( e.constraintViolations() );
+                    }
                 }
-            }
-                                                                   );
+            );
 
-        ( (ValueStateModel) stateModel ).namedAssociations().forEach(
-            model ->
-            {
-                try
-                {
-                    model.checkAssociationConstraints( 
state.namedAssociationFor( model.accessor() ) );
-                }
-                catch( ConstraintViolationException e )
+            ( (ValueStateModel) stateModel ).namedAssociations().forEach(
+                model ->
                 {
-                    violations.addAll( e.constraintViolations() );
+                    try
+                    {
+                        model.checkAssociationConstraints( 
state.namedAssociationFor( model.accessor() ) );
+                    }
+                    catch( ConstraintViolationException e )
+                    {
+                        violations.addAll( e.constraintViolations() );
+                    }
                 }
-            }
-                                                                    );
+            );
+        }
+
         if( !violations.isEmpty() )
         {
             ConstraintViolationException exception = new 
ConstraintViolationException( violations );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/04c62760/core/runtime/src/test/java/org/apache/polygene/constraints/ValueConstraintTest.java
----------------------------------------------------------------------
diff --git 
a/core/runtime/src/test/java/org/apache/polygene/constraints/ValueConstraintTest.java
 
b/core/runtime/src/test/java/org/apache/polygene/constraints/ValueConstraintTest.java
new file mode 100644
index 0000000..0d1c8ee
--- /dev/null
+++ 
b/core/runtime/src/test/java/org/apache/polygene/constraints/ValueConstraintTest.java
@@ -0,0 +1,46 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.polygene.constraints;
+
+import org.apache.polygene.api.constraint.ConstraintViolationException;
+import org.apache.polygene.api.property.Property;
+import org.apache.polygene.api.value.ValueBuilder;
+import org.apache.polygene.bootstrap.AssemblyException;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.test.AbstractPolygeneTest;
+import org.junit.Test;
+
+public class ValueConstraintTest extends AbstractPolygeneTest {
+
+    @Test(expected = ConstraintViolationException.class)
+    public void testProhibitNewInstanceWithViolation() {
+        ValueBuilder<Value1> builder = 
valueBuilderFactory.newValueBuilder(Value1.class);
+        builder.newInstance();
+    }
+
+    public void assemble(ModuleAssembly module)
+        throws AssemblyException {
+        module.values(Value1.class);
+    }
+
+    public interface Value1 {
+        Property<String> test();
+    }
+}
\ No newline at end of file

Reply via email to