You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2015/07/31 04:47:47 UTC
[28/51] [abbrv] [partial] zest-java git commit: Revert "First round
of changes to move to org.apache.zest namespace."
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/Something.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/Something.java b/core/api/src/test/java/org/qi4j/api/mixin/Something.java
new file mode 100644
index 0000000..027404f
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/Something.java
@@ -0,0 +1,27 @@
+/*
+ * 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.qi4j.api.mixin;
+
+// START SNIPPET: something
+@Mixins( SomethingMixin.class )
+public interface Something
+{}
+// END SNIPPET: something
+
+
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/SomethingMixin.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/SomethingMixin.java b/core/api/src/test/java/org/qi4j/api/mixin/SomethingMixin.java
new file mode 100644
index 0000000..63153c4
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/SomethingMixin.java
@@ -0,0 +1,32 @@
+/*
+ * 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.qi4j.api.mixin;
+
+// START SNIPPET: something
+public class SomethingMixin
+ implements Something
+{
+ // State is allowed.
+
+ public void doSomething()
+ {
+ // do stuff...
+ }
+}
+// END SNIPPET: something
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/StartMixin.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/StartMixin.java b/core/api/src/test/java/org/qi4j/api/mixin/StartMixin.java
new file mode 100644
index 0000000..dbe1076
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/StartMixin.java
@@ -0,0 +1,22 @@
+/*
+ * 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.qi4j.api.mixin;
+
+public abstract class StartMixin implements Startable
+{}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/Startable.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/Startable.java b/core/api/src/test/java/org/qi4j/api/mixin/Startable.java
new file mode 100644
index 0000000..3603ca2
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/Startable.java
@@ -0,0 +1,28 @@
+/*
+ * 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.qi4j.api.mixin;
+
+// START SNIPPET: mixins
+public interface Startable
+{
+ boolean start();
+ void stop();
+}
+
+// END SNIPPET: mixins
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/Vehicle.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/Vehicle.java b/core/api/src/test/java/org/qi4j/api/mixin/Vehicle.java
new file mode 100644
index 0000000..22705b6
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/Vehicle.java
@@ -0,0 +1,31 @@
+/*
+ * 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.qi4j.api.mixin;
+
+// START SNIPPET: mixins
+public interface Vehicle
+{
+ void turn(float angle);
+
+ void accelerate(float acceleration);
+
+ // more methods
+}
+
+// END SNIPPET: mixins
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/VehicleMixin.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/VehicleMixin.java b/core/api/src/test/java/org/qi4j/api/mixin/VehicleMixin.java
new file mode 100644
index 0000000..ad19d46
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/VehicleMixin.java
@@ -0,0 +1,22 @@
+/*
+ * 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.qi4j.api.mixin;
+
+public abstract class VehicleMixin
+{}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/DecoratorMixinTest.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/DecoratorMixinTest.java b/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/DecoratorMixinTest.java
new file mode 100644
index 0000000..d761d1a
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/DecoratorMixinTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.qi4j.api.mixin.decoratorMixin;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import org.junit.Test;
+import org.qi4j.api.composite.TransientBuilder;
+import org.qi4j.bootstrap.AssemblyException;
+import org.qi4j.bootstrap.ModuleAssembly;
+import org.qi4j.test.AbstractQi4jTest;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class DecoratorMixinTest extends AbstractQi4jTest
+{
+ // START SNIPPET: assembly
+ @Override
+ public void assemble( ModuleAssembly module )
+ throws AssemblyException
+ {
+ module.transients( View1.class );
+ module.transients( View2.class );
+ module.transients( FooModel.class );
+ }
+// END SNIPPET: assembly
+
+// START SNIPPET: test
+
+ @Test
+ public void testDecoration()
+ {
+ FooModelImpl model = new FooModelImpl( "Init" );
+ View1 view1 = createView1( model );
+ View2 view2 = createView2( model );
+ assertThat( view1.bar(), equalTo( "Init" ) );
+ assertThat( view2.bar(), equalTo( "Init" ) );
+ model.setBar( "New Value" );
+ assertThat( view1.bar(), equalTo( "New Value" ) );
+ assertThat( view2.bar(), equalTo( "New Value" ) );
+ }
+// END SNIPPET: test
+
+ @Test
+ public void testDecorationWithGenericMixin()
+ {
+ InvocationHandler handler = new FooModelInvocationHandler("Init");
+ ClassLoader cl = getClass().getClassLoader();
+ FooModel model = (FooModel) Proxy.newProxyInstance( cl, new Class[]{ FooModel.class }, handler );
+ View1 view1 = createView1( model );
+ View2 view2 = createView2( model );
+ assertThat( view1.bar(), equalTo( "Init" ) );
+ assertThat( view2.bar(), equalTo( "Init" ) );
+ model.setBar( "New Value" );
+ assertThat( view1.bar(), equalTo( "New Value" ) );
+ assertThat( view2.bar(), equalTo( "New Value" ) );
+ }
+
+ // START SNIPPET: create
+ public View1 createView1( FooModel model )
+ {
+ TransientBuilder<View1> builder = module.newTransientBuilder( View1.class );
+ builder.use( model );
+ return builder.newInstance();
+ }
+// END SNIPPET: create
+
+ public View2 createView2( FooModel model )
+ {
+ TransientBuilder<View2> builder = module.newTransientBuilder( View2.class );
+ builder.use( model );
+ return builder.newInstance();
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModel.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModel.java b/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModel.java
new file mode 100644
index 0000000..bf74db4
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModel.java
@@ -0,0 +1,36 @@
+/*
+ * 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.qi4j.api.mixin.decoratorMixin;
+
+import org.qi4j.api.composite.DecoratorMixin;
+import org.qi4j.api.mixin.Mixins;
+
+// START SNIPPET: decorator
+@Mixins(DecoratorMixin.class)
+// START SNIPPET: plain
+public interface FooModel
+// END SNIPPET: decorator
+{
+ String getBar();
+ void setBar(String value);
+// END SNIPPET: plain
+
+// START SNIPPET: plain
+}
+// END SNIPPET: plain
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModelImpl.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModelImpl.java b/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModelImpl.java
new file mode 100644
index 0000000..1ad5aee
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModelImpl.java
@@ -0,0 +1,41 @@
+/*
+ * 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.qi4j.api.mixin.decoratorMixin;
+
+public class FooModelImpl
+ implements FooModel
+{
+ private String bar;
+
+ public FooModelImpl( String bar )
+ {
+ this.bar = bar;
+ }
+
+ @Override
+ public String getBar()
+ {
+ return bar;
+ }
+
+ public void setBar( String bar )
+ {
+ this.bar = bar;
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModelInvocationHandler.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModelInvocationHandler.java b/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModelInvocationHandler.java
new file mode 100644
index 0000000..eca17f3
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModelInvocationHandler.java
@@ -0,0 +1,47 @@
+/*
+ * 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.qi4j.api.mixin.decoratorMixin;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+public class FooModelInvocationHandler
+ implements InvocationHandler
+{
+ private String value;
+
+ public FooModelInvocationHandler( String value )
+ {
+ this.value = value;
+ }
+
+ @Override
+ public Object invoke( Object proxy, Method method, Object[] args )
+ throws Throwable
+ {
+ if(method.getName().equals( "hashCode" ))
+ return hashCode();
+ if(method.getName().equals( "equals" ))
+ return equals(args[0]);
+ if(args==null || args.length==0)
+ return value;
+ value = (String) args[0];
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/View1.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/View1.java b/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/View1.java
new file mode 100644
index 0000000..a890433
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/View1.java
@@ -0,0 +1,43 @@
+/*
+ * 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.qi4j.api.mixin.decoratorMixin;
+
+import org.qi4j.api.injection.scope.This;
+import org.qi4j.api.mixin.Mixins;
+
+// START SNIPPET: decorator
+@Mixins(View1.Mixin.class)
+public interface View1
+{
+ String bar();
+
+ public class Mixin
+ implements View1
+ {
+ @This
+ FooModel model;
+
+ @Override
+ public String bar()
+ {
+ return model.getBar();
+ }
+ }
+}
+// END SNIPPET: decorator
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/View2.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/View2.java b/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/View2.java
new file mode 100644
index 0000000..4033072
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/View2.java
@@ -0,0 +1,40 @@
+/*
+ * 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.qi4j.api.mixin.decoratorMixin;
+
+import org.qi4j.api.injection.scope.This;
+import org.qi4j.api.mixin.Mixins;
+
+@Mixins(View2.Mixin.class)
+public interface View2
+{
+ String bar();
+ public class Mixin
+ implements View2
+ {
+ @This
+ FooModel model;
+
+ @Override
+ public String bar()
+ {
+ return model.getBar();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/partial/Car.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/partial/Car.java b/core/api/src/test/java/org/qi4j/api/mixin/partial/Car.java
new file mode 100644
index 0000000..cd2a668
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/partial/Car.java
@@ -0,0 +1,30 @@
+/*
+ * 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.qi4j.api.mixin.partial;
+
+import org.qi4j.api.mixin.Mixins;
+import org.qi4j.api.mixin.StartMixin;
+import org.qi4j.api.mixin.Startable;
+
+// START SNIPPET: partial
+@Mixins( { StartMixin.class, SpeedMixin.class, CrashResultMixin.class } )
+public interface Car extends Startable, Vehicle
+{}
+
+// END SNIPPET: partial
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/partial/CrashResultMixin.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/partial/CrashResultMixin.java b/core/api/src/test/java/org/qi4j/api/mixin/partial/CrashResultMixin.java
new file mode 100644
index 0000000..830cb74
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/partial/CrashResultMixin.java
@@ -0,0 +1,23 @@
+/*
+ * 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.qi4j.api.mixin.partial;
+
+public class CrashResultMixin implements Crashable
+{
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/partial/Crashable.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/partial/Crashable.java b/core/api/src/test/java/org/qi4j/api/mixin/partial/Crashable.java
new file mode 100644
index 0000000..7ca07d0
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/partial/Crashable.java
@@ -0,0 +1,23 @@
+/*
+ * 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.qi4j.api.mixin.partial;
+
+public interface Crashable
+{
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/partial/SpeedLocation.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/partial/SpeedLocation.java b/core/api/src/test/java/org/qi4j/api/mixin/partial/SpeedLocation.java
new file mode 100644
index 0000000..e8119da
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/partial/SpeedLocation.java
@@ -0,0 +1,28 @@
+/*
+ * 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.qi4j.api.mixin.partial;
+
+// START SNIPPET: partial
+public interface SpeedLocation
+{
+ void turn(float angle);
+
+ void accelerate(float acceleration);
+}
+// END SNIPPET: partial
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/partial/SpeedMixin.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/partial/SpeedMixin.java b/core/api/src/test/java/org/qi4j/api/mixin/partial/SpeedMixin.java
new file mode 100644
index 0000000..3f2cf6d
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/partial/SpeedMixin.java
@@ -0,0 +1,33 @@
+/*
+ * 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.qi4j.api.mixin.partial;
+
+// START SNIPPET: partial
+public abstract class SpeedMixin
+ implements SpeedLocation
+{
+ // state for speed
+
+ public void accelerate( float acceleration )
+ {
+ // logic
+ }
+}
+
+// END SNIPPET: partial
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/partial/Vehicle.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/partial/Vehicle.java b/core/api/src/test/java/org/qi4j/api/mixin/partial/Vehicle.java
new file mode 100644
index 0000000..4fa3597
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/partial/Vehicle.java
@@ -0,0 +1,26 @@
+/*
+ * 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.qi4j.api.mixin.partial;
+
+// START SNIPPET: partial
+public interface Vehicle extends SpeedLocation, Crashable
+{
+}
+
+// END SNIPPET: partial
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/Cargo.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/Cargo.java b/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/Cargo.java
new file mode 100644
index 0000000..d8a8dcc
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/Cargo.java
@@ -0,0 +1,36 @@
+/*
+ * 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.qi4j.api.mixin.privateMixin;
+
+import org.qi4j.api.entity.EntityComposite;
+import org.qi4j.api.mixin.Mixins;
+
+// START SNIPPET: private
+@Mixins( CargoMixin.class )
+public interface Cargo extends EntityComposite
+{
+ String origin();
+
+ String destination();
+
+ void changeDestination( String newDestination );
+
+}
+
+// END SNIPPET: private
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/CargoMixin.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/CargoMixin.java b/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/CargoMixin.java
new file mode 100644
index 0000000..4bb059a
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/CargoMixin.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.qi4j.api.mixin.privateMixin;
+
+import org.qi4j.api.injection.scope.This;
+
+// START SNIPPET: private
+public abstract class CargoMixin
+ implements Cargo
+{
+ @This
+ private CargoState state;
+
+ public String origin()
+ {
+ return state.origin().get();
+ }
+
+ public String destination()
+ {
+ return state.destination().get();
+ }
+
+ public void changeDestination( String newDestination )
+ {
+ state.destination().set( newDestination );
+ }
+}
+
+// END SNIPPET: private
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/CargoState.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/CargoState.java b/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/CargoState.java
new file mode 100644
index 0000000..f348aee
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/CargoState.java
@@ -0,0 +1,30 @@
+/*
+ * 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.qi4j.api.mixin.privateMixin;
+
+import org.qi4j.api.property.Property;
+
+// START SNIPPET: private
+public interface CargoState
+{
+ Property<String> origin();
+ Property<String> destination();
+}
+
+// END SNIPPET: private
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/object/ObjectBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/object/ObjectBuilderTest.java b/core/api/src/test/java/org/qi4j/api/object/ObjectBuilderTest.java
new file mode 100644
index 0000000..56cdcec
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/object/ObjectBuilderTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2010, Rickard Öberg. All Rights Reserved.
+ *
+ * Licensed 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.qi4j.api.object;
+
+import org.junit.Test;
+import org.qi4j.api.injection.scope.Uses;
+import org.qi4j.bootstrap.AssemblyException;
+import org.qi4j.bootstrap.ModuleAssembly;
+import org.qi4j.test.AbstractQi4jTest;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * JAVADOC
+ */
+public class ObjectBuilderTest
+ extends AbstractQi4jTest
+{
+ public void assemble( ModuleAssembly module )
+ throws AssemblyException
+ {
+ module.objects( A.class, B.class, C.class, D.class );
+ }
+
+ @Test
+ public void testNotProvidedUses()
+ {
+ A a = module.newObject( A.class );
+ assertNotNull( a );
+ assertNotNull( a.b );
+ assertNotNull( a.b.c );
+ assertNotNull( a.b.c.d );
+ }
+
+ public static class A
+ {
+ @Uses
+ B b;
+ }
+
+ public static class B
+ {
+ @Uses
+ C c;
+ }
+
+ public static class C
+ {
+ @Uses
+ D d;
+ }
+
+ public static class D
+ {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/property/PropertyErrorTest.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/property/PropertyErrorTest.java b/core/api/src/test/java/org/qi4j/api/property/PropertyErrorTest.java
new file mode 100644
index 0000000..bd0e8e9
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/property/PropertyErrorTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2008, Rickard Öberg. All Rights Reserved.
+ *
+ * Licensed 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.qi4j.api.property;
+
+import org.junit.Test;
+import org.qi4j.api.constraint.ConstraintViolationException;
+import org.qi4j.api.entity.EntityComposite;
+import org.qi4j.api.unitofwork.UnitOfWork;
+import org.qi4j.bootstrap.AssemblyException;
+import org.qi4j.bootstrap.ModuleAssembly;
+import org.qi4j.test.AbstractQi4jTest;
+import org.qi4j.test.EntityTestAssembler;
+
+/**
+ * Error messages for Properties
+ */
+public class PropertyErrorTest
+ extends AbstractQi4jTest
+{
+ public void assemble( ModuleAssembly module )
+ throws AssemblyException
+ {
+ new EntityTestAssembler().assemble( module );
+ module.entities( PersonEntity.class );
+ }
+
+ @Test( expected = ConstraintViolationException.class )
+ public void givenEntityWithNonOptionPropertyWhenInstantiatedThenException()
+ throws Exception
+ {
+ UnitOfWork unitOfWork = module.newUnitOfWork();
+ try
+ {
+ PersonEntity person = unitOfWork.newEntity( PersonEntity.class );
+
+ unitOfWork.complete();
+ }
+ finally
+ {
+ unitOfWork.discard();
+ }
+ }
+
+ interface PersonEntity
+ extends EntityComposite
+ {
+ Property<String> foo();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/service/DocumentationSupport.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/service/DocumentationSupport.java b/core/api/src/test/java/org/qi4j/api/service/DocumentationSupport.java
new file mode 100644
index 0000000..7042639
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/service/DocumentationSupport.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved.
+ *
+ * Licensed 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.qi4j.api.service;
+
+import java.util.List;
+import org.qi4j.api.activation.Activators;
+import org.qi4j.api.injection.scope.Service;
+import org.qi4j.api.mixin.Mixins;
+import org.qi4j.api.service.qualifier.ServiceTags;
+import org.qi4j.bootstrap.Assembler;
+import org.qi4j.bootstrap.AssemblyException;
+import org.qi4j.bootstrap.ModuleAssembly;
+import org.qi4j.bootstrap.ServiceDeclaration;
+
+public class DocumentationSupport
+ implements Assembler
+{
+ // START SNIPPET: tag
+ // START SNIPPET: instantiateOnStartup
+ @Override
+ public void assemble( ModuleAssembly module )
+ throws AssemblyException
+ {
+ ServiceDeclaration service = module.addServices( MyDemoService.class );
+ // END SNIPPET: tag
+ service.instantiateOnStartup();
+ // END SNIPPET: instantiateOnStartup
+ // START SNIPPET: tag
+ service.taggedWith( "Important", "Drain" );
+ // END SNIPPET: tag
+ }
+
+ private static class MyDemoService
+ {
+ }
+
+ private static class MyOtherDemoService
+ {
+ // START SNIPPET: UseTag
+ @Service
+ private List<ServiceReference<MyDemoService>> services;
+
+ public MyDemoService locateImportantService()
+ {
+ for( ServiceReference<MyDemoService> ref : services )
+ {
+ ServiceTags serviceTags = ref.metaInfo( ServiceTags.class );
+ if( serviceTags.hasTag( "Important" ) )
+ {
+ return ref.get();
+ }
+ }
+ return null;
+ }
+ // END SNIPPET: UseTag
+ }
+
+ // START SNIPPET: activation1
+ @Mixins( MyActivationMixin.class )
+ public static interface MyActivationDemoService
+ extends ServiceComposite, ServiceActivation
+ {
+ }
+
+ public static class MyActivationMixin
+ implements ServiceActivation
+ {
+ @Override
+ public void activateService()
+ throws Exception
+ {
+ // Activation code
+ }
+
+ @Override
+ public void passivateService()
+ throws Exception
+ {
+ // Passivation code
+ }
+ }
+ // END SNIPPET: activation1
+
+ // START SNIPPET: activation2
+ @Activators( MyActivator.class )
+ public static interface MyOtherActivationDemoService
+ extends ServiceComposite
+ {
+ }
+
+ public static class MyActivator
+ extends ServiceActivatorAdapter<MyOtherActivationDemoService>
+ {
+ @Override
+ public void afterActivation( ServiceReference<MyOtherActivationDemoService> activated )
+ throws Exception
+ {
+ // Activation code
+ }
+
+ @Override
+ public void beforePassivation( ServiceReference<MyOtherActivationDemoService> passivating )
+ throws Exception
+ {
+ // Passivation code
+ }
+ }
+ // END SNIPPET: activation2
+
+ static class Activation3
+ implements Assembler
+ {
+ // START SNIPPET: activation3
+ @Override
+ public void assemble( ModuleAssembly module )
+ {
+ module.services( MyDemoService.class ).withActivators( MyActivator.class );
+ }
+ // END SNIPPET: activation3
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/unitofwork/RemovalTest.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/unitofwork/RemovalTest.java b/core/api/src/test/java/org/qi4j/api/unitofwork/RemovalTest.java
new file mode 100644
index 0000000..991ff73
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/unitofwork/RemovalTest.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2009 Niclas Hedhman.
+ *
+ * Licensed 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.qi4j.api.unitofwork;
+
+import org.junit.Test;
+import org.qi4j.api.common.Optional;
+import org.qi4j.api.entity.EntityBuilder;
+import org.qi4j.api.entity.EntityComposite;
+import org.qi4j.api.property.Property;
+import org.qi4j.bootstrap.AssemblyException;
+import org.qi4j.bootstrap.ModuleAssembly;
+import org.qi4j.test.AbstractQi4jTest;
+import org.qi4j.test.EntityTestAssembler;
+
+public class RemovalTest
+ extends AbstractQi4jTest
+{
+ public void assemble( ModuleAssembly module )
+ throws AssemblyException
+ {
+ module.entities( TestEntity.class );
+ module.entities( PidRegulator.class );
+ new EntityTestAssembler().assemble( module );
+ }
+
+ @Test
+ public void givenEntityIsCreatedAndUnitOfWorkIsNotCompletedWhenEntityIsRemoveThenSuccessfulRemoval()
+ throws Exception
+ {
+ UnitOfWork uow = module.newUnitOfWork();
+ try
+ {
+ EntityBuilder<TestEntity> builder = uow.newEntityBuilder( TestEntity.class, "123" );
+ builder.instance().test().set( "habba" );
+ TestEntity test = builder.newInstance();
+ uow.remove( test );
+ uow.complete();
+ }
+ finally
+ {
+ uow.discard();
+ }
+ }
+
+ @Test
+ public void givenStandardPidRegulatorWhenNoChangeInInputExpectOutputToGoTowardsMinimum()
+ throws Exception
+ {
+ UnitOfWork uow = module.newUnitOfWork();
+ PidRegulator regulator = null;
+ try
+ {
+ regulator = createPidRegulator( uow );
+ }
+ finally
+ {
+ if( regulator != null )
+ {
+ uow.remove( regulator );
+ }
+ // TODO: This problem is related to that uow.remove() has a bug.
+ // If the Entity is both created and removed in the same session, then the remove() should simply remove
+ // the entity from the internal UoW holding area, and not set the REMOVED status.
+
+ // Probably that UnitOfWorkInstance.remove() should also call instanceCache.remove(), but the question is
+ // then what is an InstanceKey vs EntityReference
+ uow.complete();
+ }
+ }
+
+ public interface TestEntity
+ extends EntityComposite
+ {
+ @Optional
+ Property<String> test();
+ }
+
+ private PidRegulator createPidRegulator( UnitOfWork uow )
+ throws UnitOfWorkCompletionException
+ {
+ EntityBuilder<PidRegulator> builder = uow.newEntityBuilder( PidRegulator.class );
+ PidRegulator prototype = builder.instance();
+ prototype.p().set( 1.0f );
+ prototype.i().set( 10f );
+ prototype.d().set( 0.1f );
+ prototype.maxD().set( 10f );
+ prototype.maximum().set( 100f );
+ prototype.minimum().set( 0f );
+ PidRegulator regulator = builder.newInstance();
+
+ return regulator;
+ }
+
+ // @Mixins( { PidRegulatorAlgorithmMixin.class } )
+ public interface PidRegulator
+ extends PidParameters, EntityComposite
+ {
+ }
+
+ public interface PidParameters
+ {
+ Property<Float> p();
+
+ Property<Float> i();
+
+ Property<Float> d();
+
+ Property<Float> maxD();
+
+ Property<Float> minimum();
+
+ Property<Float> maximum();
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/unitofwork/UnitOfWorkTemplateTest.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/unitofwork/UnitOfWorkTemplateTest.java b/core/api/src/test/java/org/qi4j/api/unitofwork/UnitOfWorkTemplateTest.java
new file mode 100644
index 0000000..21212ae
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/unitofwork/UnitOfWorkTemplateTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.qi4j.api.unitofwork;
+
+import org.junit.Test;
+import org.qi4j.api.entity.EntityBuilderTemplate;
+import org.qi4j.api.entity.EntityComposite;
+import org.qi4j.api.property.Property;
+import org.qi4j.bootstrap.AssemblyException;
+import org.qi4j.bootstrap.ModuleAssembly;
+import org.qi4j.test.AbstractQi4jTest;
+import org.qi4j.test.EntityTestAssembler;
+
+/**
+ * TODO
+ */
+public class UnitOfWorkTemplateTest
+ extends AbstractQi4jTest
+{
+ @Override
+ public void assemble( ModuleAssembly module )
+ throws AssemblyException
+ {
+ new EntityTestAssembler().assemble( module );
+ module.entities( TestEntity.class );
+ }
+
+ @Test
+ public void testTemplate()
+ throws UnitOfWorkCompletionException
+ {
+ new UnitOfWorkTemplate<Void, RuntimeException>()
+ {
+ @Override
+ protected Void withUnitOfWork( UnitOfWork uow )
+ throws RuntimeException
+ {
+ new EntityBuilderTemplate<TestEntity>( TestEntity.class )
+ {
+ @Override
+ protected void build( TestEntity prototype )
+ {
+ prototype.name().set( "Rickard" );
+ }
+ }.newInstance( module );
+
+ return null;
+ }
+ }.withModule( module );
+ }
+
+ interface TestEntity
+ extends EntityComposite
+ {
+ Property<String> name();
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/util/ClassesTest.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/util/ClassesTest.java b/core/api/src/test/java/org/qi4j/api/util/ClassesTest.java
new file mode 100644
index 0000000..85be327
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/util/ClassesTest.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 2008, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2012, Paul Merlin.
+ *
+ * Licensed 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.qi4j.api.util;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Test;
+import org.qi4j.functional.Iterables;
+import org.qi4j.functional.Specification;
+import org.qi4j.functional.Specifications;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.qi4j.api.util.Classes.interfacesOf;
+import static org.qi4j.api.util.Classes.interfacesWithMethods;
+import static org.qi4j.functional.Iterables.count;
+
+/**
+ * Tests for Classes
+ */
+public class ClassesTest
+{
+
+ @Test
+ public void givenClassWithInterfacesWhenInterfacesOfThenGetCorrectSet()
+ {
+ assertThat( "one interface returned", count( interfacesOf( A.class ) ), equalTo( 1L ) );
+ assertThat( "two interface returned", count( interfacesOf( B.class ) ), equalTo( 2L ) );
+ assertThat( "tree interface returned", count( interfacesOf( C.class ) ), equalTo( 4L ) );
+ }
+
+ @Test
+ public void givenClassWithInterfacesWhenGetInterfacesWithMethodsThenGetCorrectSet()
+ {
+ HashSet<Class<?>> interfaces = new HashSet<Class<?>>();
+ interfaces.add( B.class );
+ Set<Class<?>> types = interfacesWithMethods( interfaces );
+ assertThat( "one interface returned", types.size(), equalTo( 1 ) );
+ assertThat( "correct interface returned", types.contains( B.class ), is( true ) );
+ }
+
+ @Test
+ public void givenClassesWithInterfacesWhenGetInterfacesWithMethodsThenGetCorrectSet()
+ {
+ Iterable<Type> types = Iterables.filter( Methods.HAS_METHODS, interfacesOf( C.class ) );
+ assertThat( "one interface returned", count( types ), equalTo( 1L ) );
+ assertThat( "correct interface returned", Iterables.matchesAny( (Specification) Specifications.in( B.class ), Iterables
+ .<Class<?>>cast( types ) ), is( true ) );
+ }
+
+ @Test
+ public void givenClassNameWhenToUriThenUriIsReturned()
+ {
+ assertThat( "URI is correct", Classes.toURI( A.class ), equalTo( "urn:qi4j:type:org.qi4j.api.util.ClassesTest-A" ) );
+ }
+
+ @Test
+ public void givenUriWhenToClassNameThenClassNameIsReturned()
+ {
+ assertThat( "Class name is correct", Classes.toClassName( "urn:qi4j:type:org.qi4j.api.util.ClassesTest-A" ), equalTo( "org.qi4j.api.util.ClassesTest$A" ) );
+ }
+
+ @Test
+ public void givenGenericTypeWithWildCardWhenGetRawClassThenCorrectTypeIsReturned()
+ throws NoSuchMethodException
+ {
+ Type returnType = Generics.class.getMethod( "wildcard" ).getGenericReturnType();
+ Type wildcardType = ( (ParameterizedType) returnType ).getActualTypeArguments()[ 0];
+ assertThat( "Return type is A", Classes.RAW_CLASS.map( wildcardType ), equalTo( (Class) A.class ) );
+ }
+
+ @Test
+ public void givenTypeVariableWhenResolveThenResolved()
+ {
+ for( Method method : Type1.class.getMethods() )
+ {
+ Type type = method.getGenericReturnType();
+ TypeVariable typeVariable = (TypeVariable) type;
+ Type resolvedType = Classes.resolveTypeVariable( typeVariable, method.getDeclaringClass(), Type1.class );
+ System.out.println( type + "=" + resolvedType );
+ switch( method.getName() )
+ {
+ case "type":
+ assertThat( resolvedType, equalTo( (Type) String.class ) );
+ break;
+ case "type1":
+ assertThat( resolvedType, equalTo( (Type) String.class ) );
+ break;
+ case "type2":
+ assertThat( resolvedType, equalTo( (Type) Long.class ) );
+ break;
+ }
+ }
+ }
+
+ @Test
+ public void givenGenericTypeWhenGetSimpleGenericNameThenCorrectStringIsReturned()
+ throws NoSuchMethodException
+ {
+ assertThat( "Simple Generic Name is 'A'",
+ Classes.simpleGenericNameOf( A.class ),
+ equalTo( "A" ) );
+ assertThat( "Simple Generic Name is 'B'",
+ Classes.simpleGenericNameOf( B.class ),
+ equalTo( "B" ) );
+ assertThat( "Simple Generic Name is 'C'",
+ Classes.simpleGenericNameOf( C.class ),
+ equalTo( "C" ) );
+
+ assertThat( "Simple Generic Name is 'Generics'",
+ Classes.simpleGenericNameOf( Generics.class ),
+ equalTo( "Generics" ) );
+ assertThat( "Simple Generic Name is 'Iterable<? extends A>'",
+ Classes.simpleGenericNameOf( Generics.class.getMethod( "wildcard" ).getGenericReturnType() ),
+ equalTo( "Iterable<? extends A>" ) );
+
+ assertThat( "Simple Generic Name is 'Type1'",
+ Classes.simpleGenericNameOf( Type1.class ),
+ equalTo( "Type1" ) );
+ assertThat( "Simple Generic Name is 'TYPE'",
+ Classes.simpleGenericNameOf( Type1.class.getMethod( "type" ).getGenericReturnType() ),
+ equalTo( "TYPE" ) );
+ assertThat( "Simple Generic Name is 'TYPE1'",
+ Classes.simpleGenericNameOf( Type1.class.getMethod( "type1" ).getGenericReturnType() ),
+ equalTo( "TYPE1" ) );
+ assertThat( "Simple Generic Name is 'TYPE2'",
+ Classes.simpleGenericNameOf( Type1.class.getMethod( "type2" ).getGenericReturnType() ),
+ equalTo( "TYPE2" ) );
+
+ assertThat( "Simple Generic Name is 'Type2'",
+ Classes.simpleGenericNameOf( Type2.class ),
+ equalTo( "Type2" ) );
+ assertThat( "Simple Generic Name is 'TYPE'",
+ Classes.simpleGenericNameOf( Type2.class.getMethod( "type" ).getGenericReturnType() ),
+ equalTo( "TYPE" ) );
+ assertThat( "Simple Generic Name is 'TYPE1'",
+ Classes.simpleGenericNameOf( Type2.class.getMethod( "type1" ).getGenericReturnType() ),
+ equalTo( "TYPE1" ) );
+ assertThat( "Simple Generic Name is 'TYPE2'",
+ Classes.simpleGenericNameOf( Type2.class.getMethod( "type2" ).getGenericReturnType() ),
+ equalTo( "TYPE2" ) );
+
+ assertThat( "Simple Generic Name is 'Type3'",
+ Classes.simpleGenericNameOf( Type3.class ),
+ equalTo( "Type3" ) );
+ assertThat( "Simple Generic Name is 'TYPE'",
+ Classes.simpleGenericNameOf( Type3.class.getMethod( "type" ).getGenericReturnType() ),
+ equalTo( "TYPE" ) );
+ }
+
+ interface A
+ {
+ }
+
+ interface B
+ extends A
+ {
+
+ public void doStuff();
+
+ }
+
+ interface C
+ extends A, B
+ {
+ }
+
+ interface Generics
+ {
+
+ Iterable<? extends A> wildcard();
+
+ }
+
+ interface Type1
+ extends Type2<String, Long>
+ {
+ }
+
+ interface Type2<TYPE1, TYPE2>
+ extends Type3<TYPE1>
+ {
+
+ TYPE1 type1();
+
+ TYPE2 type2();
+
+ }
+
+ interface Type3<TYPE>
+ {
+
+ TYPE type();
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/value/DocumentationSupport.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/value/DocumentationSupport.java b/core/api/src/test/java/org/qi4j/api/value/DocumentationSupport.java
new file mode 100644
index 0000000..32595b2
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/value/DocumentationSupport.java
@@ -0,0 +1,298 @@
+/*
+ * Copyright (c) 2013, Paul Merlin. All Rights Reserved.
+ *
+ * Licensed 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.qi4j.api.value;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.qi4j.api.injection.scope.Service;
+import org.qi4j.api.property.Property;
+import org.qi4j.api.structure.Application;
+import org.qi4j.api.structure.Module;
+import org.qi4j.api.type.CollectionType;
+import org.qi4j.bootstrap.ApplicationAssembler;
+import org.qi4j.bootstrap.ApplicationAssembly;
+import org.qi4j.bootstrap.ApplicationAssemblyFactory;
+import org.qi4j.bootstrap.Assembler;
+import org.qi4j.bootstrap.AssemblyException;
+import org.qi4j.bootstrap.Energy4Java;
+import org.qi4j.bootstrap.ModuleAssembly;
+import org.qi4j.functional.Function;
+import org.qi4j.io.Inputs;
+import org.qi4j.io.Outputs;
+import org.qi4j.io.Transforms;
+import org.qi4j.test.AbstractQi4jTest;
+import org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Snippets:
+ * - default : default ValueSerialization
+ * - service : assembled service ValueSerialization
+ * - lookup : ValueSerialization values module finder
+ */
+public class DocumentationSupport
+ extends AbstractQi4jTest
+{
+
+ @Before
+ public void injectToThis()
+ {
+ module.injectTo( this );
+ }
+
+ // START SNIPPET: default
+ // START SNIPPET: service
+ public interface SomeValue // (1)
+ {
+
+ Property<String> foo();
+ }
+
+ @Override
+ public void assemble( ModuleAssembly module )
+ throws AssemblyException
+ {
+ module.values( SomeValue.class ); // (2)
+ // END SNIPPET: default
+ new OrgJsonValueSerializationAssembler().assemble( module ); // (3)
+ // START SNIPPET: default
+ }
+ // END SNIPPET: default
+ // END SNIPPET: service
+
+ @Test
+ // START SNIPPET: default
+ public void defaultValueSerialization()
+ {
+ SomeValue someValue = someNewValueInstance( module ); // (3)
+ String json = someValue.toString(); // (4)
+ SomeValue someNewValue = module.newValueFromSerializedState( SomeValue.class, json ); // (5)
+ // END SNIPPET: default
+
+ assertThat( json, equalTo( "{\"foo\":\"bar\"}" ) );
+ assertThat( someNewValue, equalTo( someValue ) );
+
+ // START SNIPPET: default
+ }
+ // END SNIPPET: default
+ // START SNIPPET: service
+ @Service
+ private ValueSerializer valueSerializer; // (4)
+ @Service
+ private ValueDeserializer valueDeserializer; // (4)
+
+ // END SNIPPET: service
+ @Test
+ // START SNIPPET: service
+ public void assembledDefaultServiceSerialization()
+ {
+ SomeValue someValue = someNewValueInstance( module ); // (5)
+ String json = valueSerializer.serialize( someValue ); // (6)
+ SomeValue someNewValue = valueDeserializer.deserialize( SomeValue.class, json ); // (7)
+ // END SNIPPET: service
+
+ assertThat( json, equalTo( "{\"foo\":\"bar\"}" ) );
+ assertThat( someNewValue, equalTo( someValue ) );
+
+ // START SNIPPET: service
+ }
+ // END SNIPPET: service
+
+ static enum AcmeValue
+ {
+
+ foo, bar
+ }
+
+ @Test
+ // START SNIPPET: stream
+ public void assembledServiceStreamingSerialization()
+ {
+ // END SNIPPET: stream
+
+ List<AcmeValue> dataSource = Arrays.asList( AcmeValue.values() );
+ ByteArrayOutputStream targetStream = new ByteArrayOutputStream();
+
+ // START SNIPPET: stream
+ // (1)
+ Iterable<AcmeValue> data = dataSource; // Eg. Entities converted to Values
+ OutputStream output = targetStream; // Eg. streaming JSON over HTTP
+
+ // (2)
+ valueSerializer.serialize( data, output );
+ // END SNIPPET: stream
+
+ byte[] serialized = targetStream.toByteArray();
+ ByteArrayInputStream sourceStream = new ByteArrayInputStream( serialized );
+
+ // START SNIPPET: stream
+ // (3)
+ InputStream input = sourceStream; // Eg. reading incoming JSON
+
+ // (4)
+ List<AcmeValue> values = valueDeserializer.deserialize( CollectionType.listOf( AcmeValue.class ), input );
+ // END SNIPPET: stream
+
+ assertThat( values, equalTo( dataSource ) );
+
+ // START SNIPPET: stream
+ }
+ // END SNIPPET: stream
+
+ @Test
+ // START SNIPPET: io
+ public void assembledServiceIOSerialization()
+ throws IOException
+ {
+ // END SNIPPET: io
+
+ List<AcmeValue> dataSource = Arrays.asList( AcmeValue.values() );
+ StringWriter outputWriter = new StringWriter();
+
+ // START SNIPPET: io
+ // (1)
+ Iterable<AcmeValue> queryResult = dataSource; // Eg. Entities converted to Values
+ Writer writer = outputWriter; // Eg. to pipe data to another process or to a file
+
+ // (2)
+ Function<AcmeValue, String> serialize = valueSerializer.serialize();
+
+ // (3)
+ Inputs.iterable( queryResult ).transferTo( Transforms.map( serialize, Outputs.text( writer ) ) );
+ // END SNIPPET: io
+
+ String string = writer.toString();
+ StringReader inputReader = new StringReader( string );
+
+ // START SNIPPET: io
+ // (4)
+ Reader reader = inputReader;
+ List<AcmeValue> values = new ArrayList<AcmeValue>();
+
+ // (5)
+ Function<String, AcmeValue> deserialize = valueDeserializer.deserialize( AcmeValue.class );
+
+ // Deserialization of a collection of AcmeValue from a String.
+ // One serialized AcmeValue per line.
+ // (6)
+ Inputs.text( reader ).transferTo( Transforms.map( deserialize, Outputs.collection( values ) ) );
+ // END SNIPPET: io
+
+ assertThat( dataSource, equalTo( values ) );
+
+ // START SNIPPET: io
+ }
+ // END SNIPPET: io
+
+ @Test
+ // TODO Move to SPI !
+ // TODO Include in each ValueSerialization extensions documentation
+ public void assembledWithValuesModuleSerialization()
+ throws Exception
+ {
+ Application app = new Energy4Java().newApplication( new ApplicationAssembler()
+ {
+ @Override
+ public ApplicationAssembly assemble( ApplicationAssemblyFactory applicationFactory )
+ throws AssemblyException
+ {
+ Assembler[][][] pancakes = new Assembler[][][]
+ {
+ {
+ {
+ new Assembler()
+ {
+ @Override
+ public void assemble( ModuleAssembly valuesModule )
+ throws AssemblyException
+ {
+ valuesModule.layer().setName( "SINGLE-Layer" );
+ valuesModule.setName( "VALUES-Module" );
+
+ valuesModule.values( SomeValue.class );
+ }
+ }
+ },
+ {
+ new Assembler()
+ {
+ @Override
+ public void assemble( ModuleAssembly servicesModule )
+ throws AssemblyException
+ {
+ servicesModule.setName( "SERVICES-Module" );
+
+ Function<Application, Module> valuesModuleFinder = new Function<Application, Module>()
+ {
+ @Override
+ public Module map( Application app )
+ {
+ return app.findModule( "SINGLE-Layer", "VALUES-Module" );
+ }
+ };
+ new OrgJsonValueSerializationAssembler().
+ withValuesModuleFinder( valuesModuleFinder ).
+ assemble( servicesModule );
+ }
+ }
+ }
+ }
+ };
+ return applicationFactory.newApplicationAssembly( pancakes );
+ }
+ } );
+ app.activate();
+ try
+ {
+ Module valuesModule = app.findModule( "SINGLE-Layer", "VALUES-Module" );
+ SomeValue someValue = someNewValueInstance( valuesModule );
+
+ Module servicesModule = app.findModule( "SINGLE-Layer", "SERVICES-Module" );
+ ValueSerialization valueSerialization = servicesModule.findService( ValueSerialization.class ).get();
+
+ String json = valueSerialization.serialize( someValue );
+ assertThat( json, equalTo( "{\"foo\":\"bar\"}" ) );
+
+ SomeValue someNewValue = valueSerialization.deserialize( SomeValue.class, json );
+ assertThat( someNewValue, equalTo( someValue ) );
+ }
+ finally
+ {
+ app.passivate();
+ }
+ }
+
+ private SomeValue someNewValueInstance( Module module )
+ {
+ ValueBuilder<SomeValue> builder = module.newValueBuilder( SomeValue.class );
+ builder.prototype().foo().set( "bar" );
+ return builder.newInstance();
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/value/ValueBuilderTemplateTest.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/value/ValueBuilderTemplateTest.java b/core/api/src/test/java/org/qi4j/api/value/ValueBuilderTemplateTest.java
new file mode 100644
index 0000000..420d48e
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/value/ValueBuilderTemplateTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.qi4j.api.value;
+
+import org.junit.Test;
+import org.qi4j.api.property.Property;
+import org.qi4j.bootstrap.AssemblyException;
+import org.qi4j.bootstrap.ModuleAssembly;
+import org.qi4j.test.AbstractQi4jTest;
+
+/**
+ * TODO
+ */
+public class ValueBuilderTemplateTest
+ extends AbstractQi4jTest
+{
+ @Override
+ public void assemble( ModuleAssembly module )
+ throws AssemblyException
+ {
+ module.values( TestValue.class );
+ }
+
+ @Test
+ public void testTemplate()
+ {
+ new TestBuilder( "Rickard" ).newInstance( module );
+ }
+
+ @Test
+ public void testAnonymousTemplate()
+ {
+ new ValueBuilderTemplate<TestValue>( TestValue.class )
+ {
+ @Override
+ protected void build( TestValue prototype )
+ {
+ prototype.name().set( "Rickard" );
+ }
+ }.newInstance( module );
+ }
+
+ interface TestValue
+ extends ValueComposite
+ {
+ Property<String> name();
+ }
+
+ class TestBuilder
+ extends ValueBuilderTemplate<TestValue>
+ {
+ String name;
+
+ TestBuilder( String name )
+ {
+ super( TestValue.class );
+ this.name = name;
+ }
+
+ @Override
+ protected void build( TestValue prototype )
+ {
+ prototype.name().set( name );
+ }
+ }
+
+ ;
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/java/org/qi4j/api/value/ValueCompositeTest.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/qi4j/api/value/ValueCompositeTest.java b/core/api/src/test/java/org/qi4j/api/value/ValueCompositeTest.java
new file mode 100644
index 0000000..1c545a4
--- /dev/null
+++ b/core/api/src/test/java/org/qi4j/api/value/ValueCompositeTest.java
@@ -0,0 +1,308 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ *
+ * Licensed 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.qi4j.api.value;
+
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.qi4j.api.association.Association;
+import org.qi4j.api.association.ManyAssociation;
+import org.qi4j.api.common.Optional;
+import org.qi4j.api.common.UseDefaults;
+import org.qi4j.api.constraint.ConstraintViolationException;
+import org.qi4j.api.entity.EntityBuilder;
+import org.qi4j.api.entity.EntityComposite;
+import org.qi4j.api.property.Property;
+import org.qi4j.api.unitofwork.UnitOfWork;
+import org.qi4j.api.unitofwork.UnitOfWorkCompletionException;
+import org.qi4j.bootstrap.AssemblyException;
+import org.qi4j.bootstrap.ModuleAssembly;
+import org.qi4j.library.constraints.annotation.MaxLength;
+import org.qi4j.test.AbstractQi4jTest;
+import org.qi4j.test.EntityTestAssembler;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests for ValueComposites
+ */
+public class ValueCompositeTest
+ extends AbstractQi4jTest
+{
+
+ @Override
+ public void assemble( ModuleAssembly module )
+ throws AssemblyException
+ {
+ module.values( SomeValue.class, AnotherValue.class, AssociationValue.class );
+ module.entities( SomeEntity.class );
+ new EntityTestAssembler().assemble( module );
+ }
+
+ @Test( expected = IllegalStateException.class )
+ public void testImmutabilityOfValueComposite()
+ {
+ ValueBuilder<SomeValue> builder = module.newValueBuilder( SomeValue.class );
+ SomeValue some = builder.prototype();
+ some.other().set( "test" );
+ some = builder.newInstance();
+ some.other().set( "test2" );
+ }
+
+ @Test
+ public void testCreationOfValueComposite()
+ {
+ ValueBuilder<SomeValue> builder = module.newValueBuilder( SomeValue.class );
+ SomeValue some = builder.prototype();
+ some.other().set( "test" );
+ builder.newInstance();
+
+ // Check that @UseDefaults works for ValueComposites
+ assertEquals( "{\"val1\":\"\"}", some.another().get().toString() );
+ }
+
+ @Test
+ public void testEqualityOfValueComposite()
+ {
+ ValueBuilder<SomeValue> builder = module.newValueBuilder( SomeValue.class );
+ SomeValue prototype = builder.prototype();
+ prototype.other().set( "test" );
+ SomeValue instance = builder.newInstance();
+ SomeValue other = builder.newInstance();
+ Assert.assertFalse( "Instances should not be the same.", instance == other );
+ Assert.assertEquals( "Equal values.", instance, other );
+ }
+
+ @Test
+ public void testHashcodeOfValueComposite()
+ {
+ ValueBuilder<SomeValue> builder = module.newValueBuilder( SomeValue.class );
+ SomeValue prototype = builder.prototype();
+ prototype.other().set( "test" );
+ SomeValue instance = builder.newInstance();
+ SomeValue other = builder.newInstance();
+ Assert.assertFalse( "Instances should not be the same.", instance == other );
+ Assert.assertEquals( "Equal values.", instance.hashCode(), other.hashCode() );
+ }
+
+ @Test
+ public void testModifyValue()
+ {
+ ValueBuilder<AnotherValue> anotherBuilder = module.newValueBuilder( AnotherValue.class );
+ anotherBuilder.prototype().val1().set( "Val1" );
+ AnotherValue anotherValue = anotherBuilder.newInstance();
+
+ ValueBuilder<SomeValue> builder = module.newValueBuilder( SomeValue.class );
+ SomeValue prototype = builder.prototype();
+ prototype.some().set( "foo" );
+ prototype.other().set( "test" );
+ prototype.xyzzyList().get().add( "blah" );
+ prototype.another().set( anotherValue );
+ SomeValue instance = builder.newInstance();
+
+ assertThat( "List has value blah", instance.xyzzyList().get().get( 0 ), equalTo( "blah" ) );
+
+ // Modify value
+ builder = module.newValueBuilderWithPrototype( instance );
+ builder.prototype().some().set( "bar" );
+ instance = builder.newInstance();
+
+ assertThat( "Other is set to test", instance.other().get(), equalTo( "test" ) );
+ assertThat( "List has value blah", instance.xyzzyList().get().get( 0 ), equalTo( "blah" ) );
+ assertThat( "AnotherValue.val1 has value Val1", instance.another().get().val1().get(), equalTo( "Val1" ) );
+
+ // Modify value again using method 2
+ builder = module.newValueBuilderWithPrototype( instance );
+ builder.prototype().other().set( "test2" );
+ instance = builder.newInstance();
+
+ assertThat( "Other is set to test2", instance.other().get(), equalTo( "test2" ) );
+ assertThat( "Some is set to bar", instance.some().get(), equalTo( "bar" ) );
+ }
+
+ @Test( expected = ConstraintViolationException.class )
+ public void givenValueWhenModifyToIncorrectValueThenThrowConstraintException()
+ {
+ ValueBuilder<SomeValue> builder = module.newValueBuilder( SomeValue.class );
+ SomeValue prototype = builder.prototype();
+ prototype.some().set( "foo" );
+ SomeValue instance = builder.newInstance();
+
+ builder = module.newValueBuilderWithPrototype( instance );
+ builder.prototype().some().set( "123456" );
+ }
+
+ @Test
+ public void givenValueWithListOfValueWhenPrototypeThenListedValuesAreEditable()
+ {
+ ValueBuilder<SomeValue> builder = module.newValueBuilder( SomeValue.class );
+ builder.prototype().anotherList().get().add( module.newValue( AnotherValue.class ) );
+ SomeValue some = builder.newInstance();
+
+ builder = module.newValueBuilderWithPrototype( some );
+ builder.prototype().anotherList().get().get( 0 ).val1().set( "Foo" );
+ builder.prototype().anotherList().get().add( module.newValue( AnotherValue.class ) );
+ some = builder.newInstance();
+
+ assertThat( "Val1 has been set", some.anotherList().get().get( 0 ).val1().get(), equalTo( "Foo" ) );
+
+ try
+ {
+ some.anotherList().get().get( 0 ).val1().set( "Bar" );
+ Assert.fail( "Should not be allowed to modify value" );
+ }
+ catch( IllegalStateException e )
+ {
+ // Ok
+ }
+ }
+
+ @Test
+ public void givenEntityWhenUpdateValueThenValueIsSet()
+ throws UnitOfWorkCompletionException
+ {
+ ValueBuilder<SomeValue> builder = module.newValueBuilder( SomeValue.class );
+ builder.prototype().anotherList().get().add( module.newValue( AnotherValue.class ) );
+ ValueBuilder<AnotherValue> valueBuilder = module.newValueBuilder( AnotherValue.class );
+ valueBuilder.prototype().val1().set( "Foo" );
+ builder.prototype().another().set( valueBuilder.newInstance() );
+ builder.prototype().number().set( 42L );
+ SomeValue some = builder.newInstance();
+
+ UnitOfWork unitOfWork = module.newUnitOfWork();
+ try
+ {
+ EntityBuilder<SomeEntity> entityBuilder = unitOfWork.newEntityBuilder( SomeEntity.class );
+ entityBuilder.instance().someValue().set( some );
+ SomeEntity entity = entityBuilder.newInstance();
+
+ assertThat( "Value has been set", entity.someValue().get().another().get().val1().get(), equalTo( "Foo" ) );
+
+ unitOfWork.complete();
+ }
+ finally
+ {
+ unitOfWork.discard();
+ }
+ }
+
+ @Test
+ public void givenValueWithAssociationsWhenNewUoWThenCanRead()
+ throws UnitOfWorkCompletionException
+ {
+ ValueBuilder<SomeValue> builder = module.newValueBuilder( SomeValue.class );
+ builder.prototype().anotherList().get().add( module.newValue( AnotherValue.class ) );
+ ValueBuilder<AnotherValue> valueBuilder = module.newValueBuilder( AnotherValue.class );
+ valueBuilder.prototype().val1().set( "Foo" );
+ builder.prototype().another().set( valueBuilder.newInstance() );
+ builder.prototype().number().set( 42L );
+ SomeValue some = builder.newInstance();
+
+ UnitOfWork unitOfWork = module.newUnitOfWork();
+ AssociationValue associationValue;
+ try
+ {
+ EntityBuilder<SomeEntity> entityBuilder = unitOfWork.newEntityBuilder( SomeEntity.class );
+ entityBuilder.instance().someValue().set( some );
+ SomeEntity entity = entityBuilder.newInstance();
+
+ ValueBuilder<AssociationValue> associationBuilder = module.newValueBuilder( AssociationValue.class );
+ associationBuilder.prototype().some().set( entity );
+ associationValue = associationBuilder.newInstance();
+
+ String json = associationValue.toString();
+
+ unitOfWork.complete();
+
+ unitOfWork = module.newUnitOfWork();
+
+ AssociationValue newAssociationValue = module.newValueFromSerializedState( AssociationValue.class, json );
+
+ Assert.assertEquals( associationValue.some().get(), newAssociationValue.some().get() );
+ }
+ finally
+ {
+ unitOfWork.discard();
+ }
+
+ // Should allow the toString() to print the entityRefs.
+ System.out.println( associationValue.toString() );
+ try
+ {
+ associationValue.some().get();
+ fail( "Should have thrown an exception" );
+ }
+ catch( Exception e )
+ {
+ // Ok
+ }
+ }
+
+ public enum TestEnum
+ {
+ somevalue, anothervalue
+ }
+
+ public interface SomeValue
+ extends ValueComposite
+ {
+ @UseDefaults
+ @MaxLength( 5 )
+ Property<String> some();
+
+ @UseDefaults
+ Property<String> other();
+
+ @UseDefaults
+ Property<Long> number();
+
+ @UseDefaults
+ Property<List<String>> xyzzyList();
+
+ @UseDefaults
+ Property<AnotherValue> another();
+
+ @UseDefaults
+ Property<List<AnotherValue>> anotherList();
+
+ @UseDefaults
+ Property<TestEnum> testEnum();
+ }
+
+ public interface AnotherValue
+ extends ValueComposite
+ {
+ @UseDefaults
+ Property<String> val1();
+ }
+
+ public interface AssociationValue
+ extends ValueComposite
+ {
+ @Optional
+ Association<SomeEntity> some();
+
+ ManyAssociation<SomeEntity> manySome();
+ }
+
+ public interface SomeEntity
+ extends EntityComposite
+ {
+ Property<SomeValue> someValue();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a789141d/core/api/src/test/resources/org/apache/zest/api/configuration/MyService.properties
----------------------------------------------------------------------
diff --git a/core/api/src/test/resources/org/apache/zest/api/configuration/MyService.properties b/core/api/src/test/resources/org/apache/zest/api/configuration/MyService.properties
deleted file mode 100644
index 6ed5ff6..0000000
--- a/core/api/src/test/resources/org/apache/zest/api/configuration/MyService.properties
+++ /dev/null
@@ -1,16 +0,0 @@
-# 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.
-
-me = { name : Niclas, address={ street1 : "Henan Lu 555", street2 : "Block 15", city : { cityName : "Shanghai", country : { countryName : "China" } } } }
\ No newline at end of file