Return-Path: X-Original-To: apmail-zest-commits-archive@minotaur.apache.org Delivered-To: apmail-zest-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5157818498 for ; Fri, 31 Jul 2015 02:58:42 +0000 (UTC) Received: (qmail 96976 invoked by uid 500); 31 Jul 2015 02:58:42 -0000 Delivered-To: apmail-zest-commits-archive@zest.apache.org Received: (qmail 96938 invoked by uid 500); 31 Jul 2015 02:58:42 -0000 Mailing-List: contact commits-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list commits@zest.apache.org Received: (qmail 96904 invoked by uid 99); 31 Jul 2015 02:58:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Jul 2015 02:58:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 17184DF9F2; Fri, 31 Jul 2015 02:58:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: niclas@apache.org To: commits@zest.apache.org Date: Fri, 31 Jul 2015 02:59:08 -0000 Message-Id: <982109f16b1642538cf11654467309ce@git.apache.org> In-Reply-To: <5417ada664c9445f83dd797fa0423974@git.apache.org> References: <5417ada664c9445f83dd797fa0423974@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [28/81] [abbrv] [partial] zest-java git commit: First round of changes to move to org.apache.zest namespace. http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 deleted file mode 100644 index 027404f..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/Something.java +++ /dev/null @@ -1,27 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index 63153c4..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/SomethingMixin.java +++ /dev/null @@ -1,32 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index dbe1076..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/StartMixin.java +++ /dev/null @@ -1,22 +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. - */ -package org.qi4j.api.mixin; - -public abstract class StartMixin implements Startable -{} http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 deleted file mode 100644 index 3603ca2..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/Startable.java +++ /dev/null @@ -1,28 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index 22705b6..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/Vehicle.java +++ /dev/null @@ -1,31 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index ad19d46..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/VehicleMixin.java +++ /dev/null @@ -1,22 +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. - */ -package org.qi4j.api.mixin; - -public abstract class VehicleMixin -{} http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 deleted file mode 100644 index d761d1a..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/DecoratorMixinTest.java +++ /dev/null @@ -1,91 +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. - */ -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 builder = module.newTransientBuilder( View1.class ); - builder.use( model ); - return builder.newInstance(); - } -// END SNIPPET: create - - public View2 createView2( FooModel model ) - { - TransientBuilder builder = module.newTransientBuilder( View2.class ); - builder.use( model ); - return builder.newInstance(); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 deleted file mode 100644 index bf74db4..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModel.java +++ /dev/null @@ -1,36 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index 1ad5aee..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModelImpl.java +++ /dev/null @@ -1,41 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index eca17f3..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/FooModelInvocationHandler.java +++ /dev/null @@ -1,47 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index a890433..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/View1.java +++ /dev/null @@ -1,43 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index 4033072..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/decoratorMixin/View2.java +++ /dev/null @@ -1,40 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index cd2a668..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/partial/Car.java +++ /dev/null @@ -1,30 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index 830cb74..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/partial/CrashResultMixin.java +++ /dev/null @@ -1,23 +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. - */ -package org.qi4j.api.mixin.partial; - -public class CrashResultMixin implements Crashable -{ -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 deleted file mode 100644 index 7ca07d0..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/partial/Crashable.java +++ /dev/null @@ -1,23 +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. - */ -package org.qi4j.api.mixin.partial; - -public interface Crashable -{ -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 deleted file mode 100644 index e8119da..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/partial/SpeedLocation.java +++ /dev/null @@ -1,28 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index 3f2cf6d..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/partial/SpeedMixin.java +++ /dev/null @@ -1,33 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index 4fa3597..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/partial/Vehicle.java +++ /dev/null @@ -1,26 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index d8a8dcc..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/Cargo.java +++ /dev/null @@ -1,36 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index 4bb059a..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/CargoMixin.java +++ /dev/null @@ -1,46 +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. - */ -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/061ddaa0/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 deleted file mode 100644 index f348aee..0000000 --- a/core/api/src/test/java/org/qi4j/api/mixin/privateMixin/CargoState.java +++ /dev/null @@ -1,30 +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. - */ -package org.qi4j.api.mixin.privateMixin; - -import org.qi4j.api.property.Property; - -// START SNIPPET: private -public interface CargoState -{ - Property origin(); - Property destination(); -} - -// END SNIPPET: private \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 deleted file mode 100644 index 56cdcec..0000000 --- a/core/api/src/test/java/org/qi4j/api/object/ObjectBuilderTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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/061ddaa0/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 deleted file mode 100644 index bd0e8e9..0000000 --- a/core/api/src/test/java/org/qi4j/api/property/PropertyErrorTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 foo(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 deleted file mode 100644 index 7042639..0000000 --- a/core/api/src/test/java/org/qi4j/api/service/DocumentationSupport.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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> services; - - public MyDemoService locateImportantService() - { - for( ServiceReference 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 - { - @Override - public void afterActivation( ServiceReference activated ) - throws Exception - { - // Activation code - } - - @Override - public void beforePassivation( ServiceReference 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/061ddaa0/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 deleted file mode 100644 index 991ff73..0000000 --- a/core/api/src/test/java/org/qi4j/api/unitofwork/RemovalTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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 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 test(); - } - - private PidRegulator createPidRegulator( UnitOfWork uow ) - throws UnitOfWorkCompletionException - { - EntityBuilder 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 p(); - - Property i(); - - Property d(); - - Property maxD(); - - Property minimum(); - - Property maximum(); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 deleted file mode 100644 index 21212ae..0000000 --- a/core/api/src/test/java/org/qi4j/api/unitofwork/UnitOfWorkTemplateTest.java +++ /dev/null @@ -1,73 +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. - */ -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() - { - @Override - protected Void withUnitOfWork( UnitOfWork uow ) - throws RuntimeException - { - new EntityBuilderTemplate( TestEntity.class ) - { - @Override - protected void build( TestEntity prototype ) - { - prototype.name().set( "Rickard" ); - } - }.newInstance( module ); - - return null; - } - }.withModule( module ); - } - - interface TestEntity - extends EntityComposite - { - Property name(); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 deleted file mode 100644 index 85be327..0000000 --- a/core/api/src/test/java/org/qi4j/api/util/ClassesTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * 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> interfaces = new HashSet>(); - interfaces.add( B.class ); - Set> 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 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 - .>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'", - Classes.simpleGenericNameOf( Generics.class.getMethod( "wildcard" ).getGenericReturnType() ), - equalTo( "Iterable" ) ); - - 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 wildcard(); - - } - - interface Type1 - extends Type2 - { - } - - interface Type2 - extends Type3 - { - - TYPE1 type1(); - - TYPE2 type2(); - - } - - interface Type3 - { - - TYPE type(); - - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 deleted file mode 100644 index 32595b2..0000000 --- a/core/api/src/test/java/org/qi4j/api/value/DocumentationSupport.java +++ /dev/null @@ -1,298 +0,0 @@ -/* - * 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 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 dataSource = Arrays.asList( AcmeValue.values() ); - ByteArrayOutputStream targetStream = new ByteArrayOutputStream(); - - // START SNIPPET: stream - // (1) - Iterable 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 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 dataSource = Arrays.asList( AcmeValue.values() ); - StringWriter outputWriter = new StringWriter(); - - // START SNIPPET: io - // (1) - Iterable queryResult = dataSource; // Eg. Entities converted to Values - Writer writer = outputWriter; // Eg. to pipe data to another process or to a file - - // (2) - Function 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 values = new ArrayList(); - - // (5) - Function 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 valuesModuleFinder = new Function() - { - @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 builder = module.newValueBuilder( SomeValue.class ); - builder.prototype().foo().set( "bar" ); - return builder.newInstance(); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 deleted file mode 100644 index 420d48e..0000000 --- a/core/api/src/test/java/org/qi4j/api/value/ValueBuilderTemplateTest.java +++ /dev/null @@ -1,84 +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. - */ -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.class ) - { - @Override - protected void build( TestValue prototype ) - { - prototype.name().set( "Rickard" ); - } - }.newInstance( module ); - } - - interface TestValue - extends ValueComposite - { - Property name(); - } - - class TestBuilder - extends ValueBuilderTemplate - { - 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/061ddaa0/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 deleted file mode 100644 index 1c545a4..0000000 --- a/core/api/src/test/java/org/qi4j/api/value/ValueCompositeTest.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - * 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 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 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 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 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 anotherBuilder = module.newValueBuilder( AnotherValue.class ); - anotherBuilder.prototype().val1().set( "Val1" ); - AnotherValue anotherValue = anotherBuilder.newInstance(); - - ValueBuilder 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 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 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 builder = module.newValueBuilder( SomeValue.class ); - builder.prototype().anotherList().get().add( module.newValue( AnotherValue.class ) ); - ValueBuilder 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 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 builder = module.newValueBuilder( SomeValue.class ); - builder.prototype().anotherList().get().add( module.newValue( AnotherValue.class ) ); - ValueBuilder 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 entityBuilder = unitOfWork.newEntityBuilder( SomeEntity.class ); - entityBuilder.instance().someValue().set( some ); - SomeEntity entity = entityBuilder.newInstance(); - - ValueBuilder 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 some(); - - @UseDefaults - Property other(); - - @UseDefaults - Property number(); - - @UseDefaults - Property> xyzzyList(); - - @UseDefaults - Property another(); - - @UseDefaults - Property> anotherList(); - - @UseDefaults - Property testEnum(); - } - - public interface AnotherValue - extends ValueComposite - { - @UseDefaults - Property val1(); - } - - public interface AssociationValue - extends ValueComposite - { - @Optional - Association some(); - - ManyAssociation manySome(); - } - - public interface SomeEntity - extends EntityComposite - { - Property someValue(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/061ddaa0/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 new file mode 100644 index 0000000..6ed5ff6 --- /dev/null +++ b/core/api/src/test/resources/org/apache/zest/api/configuration/MyService.properties @@ -0,0 +1,16 @@ +# 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