1.1 --- a/json/src/main/java/net/java/html/json/ComputedProperty.java Thu Jul 31 14:37:06 2014 +0200
1.2 +++ b/json/src/main/java/net/java/html/json/ComputedProperty.java Thu Jul 31 15:35:28 2014 +0200
1.3 @@ -71,4 +71,5 @@
1.4 @Retention(RetentionPolicy.SOURCE)
1.5 @Target(ElementType.METHOD)
1.6 public @interface ComputedProperty {
1.7 + boolean deep() default false;
1.8 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/json/src/test/java/net/java/html/json/DeepChangeTest.java Thu Jul 31 15:35:28 2014 +0200
2.3 @@ -0,0 +1,105 @@
2.4 +/**
2.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2.6 + *
2.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
2.8 + *
2.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
2.10 + * Other names may be trademarks of their respective owners.
2.11 + *
2.12 + * The contents of this file are subject to the terms of either the GNU
2.13 + * General Public License Version 2 only ("GPL") or the Common
2.14 + * Development and Distribution License("CDDL") (collectively, the
2.15 + * "License"). You may not use this file except in compliance with the
2.16 + * License. You can obtain a copy of the License at
2.17 + * http://www.netbeans.org/cddl-gplv2.html
2.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
2.19 + * specific language governing permissions and limitations under the
2.20 + * License. When distributing the software, include this License Header
2.21 + * Notice in each file and include the License file at
2.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
2.23 + * particular file as subject to the "Classpath" exception as provided
2.24 + * by Oracle in the GPL Version 2 section of the License file that
2.25 + * accompanied this code. If applicable, add the following below the
2.26 + * License Header, with the fields enclosed by brackets [] replaced by
2.27 + * your own identifying information:
2.28 + * "Portions Copyrighted [year] [name of copyright owner]"
2.29 + *
2.30 + * Contributor(s):
2.31 + *
2.32 + * The Original Software is NetBeans. The Initial Developer of the Original
2.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
2.34 + *
2.35 + * If you wish your version of this file to be governed by only the CDDL
2.36 + * or only the GPL Version 2, indicate your decision by adding
2.37 + * "[Contributor] elects to include this software in this distribution
2.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
2.39 + * single choice of license, a recipient has the option to distribute
2.40 + * your version of this file under either the CDDL, the GPL Version 2 or
2.41 + * to extend the choice of license to its licensees as provided above.
2.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
2.43 + * Version 2 license, then the option applies only if the new code is
2.44 + * made subject to such option by the copyright holder.
2.45 + */
2.46 +package net.java.html.json;
2.47 +
2.48 +import java.util.Map;
2.49 +import net.java.html.BrwsrCtx;
2.50 +import net.java.html.json.MapModelTest.MapTechnology;
2.51 +import net.java.html.json.MapModelTest.One;
2.52 +import org.apidesign.html.context.spi.Contexts;
2.53 +import org.apidesign.html.json.spi.Technology;
2.54 +import org.apidesign.html.json.spi.Transfer;
2.55 +import static org.testng.Assert.*;
2.56 +import org.testng.annotations.BeforeMethod;
2.57 +import org.testng.annotations.Test;
2.58 +
2.59 +/**
2.60 + *
2.61 + * @author Jaroslav Tulach <jtulach@netbeans.org>
2.62 + */
2.63 +public class DeepChangeTest {
2.64 + private MapTechnology t;
2.65 + private BrwsrCtx c;
2.66 +
2.67 + @BeforeMethod public void initTechnology() {
2.68 + t = new MapTechnology();
2.69 + c = Contexts.newBuilder().register(Technology.class, t, 1).
2.70 + register(Transfer.class, t, 1).build();
2.71 + }
2.72 +
2.73 + @Model(className = "MyX", properties = {
2.74 + @Property(name = "one", type = MyY.class),
2.75 + @Property(name = "all", type = MyY.class, array = true)
2.76 + })
2.77 + static class X {
2.78 + @ComputedProperty(deep = true)
2.79 + static String oneName(MyY one) {
2.80 + return one.getValue();
2.81 + }
2.82 + }
2.83 + @Model(className = "MyY", properties = {
2.84 + @Property(name = "value", type = String.class)
2.85 + })
2.86 + static class Y {
2.87 + }
2.88 +
2.89 + @Test public void isThereABinding() throws Exception {
2.90 + MyX p = Models.bind(
2.91 + new MyX(new MyY("Ahoj"), new MyY("Hi"), new MyY("Hello")
2.92 + ), c).applyBindings();
2.93 +
2.94 + Map m = (Map)Models.toRaw(p);
2.95 + Object v = m.get("oneName");
2.96 + assertNotNull(v, "Value should be in the map");
2.97 + assertEquals(v.getClass(), One.class, "It is instance of One");
2.98 + One o = (One)v;
2.99 + assertEquals(o.changes, 0, "No changes so far");
2.100 + assertTrue(o.pb.isReadOnly(), "Derived property");
2.101 + assertEquals(o.get(), "Ahoj");
2.102 +
2.103 + p.getOne().setValue("Nazdar");
2.104 +
2.105 + assertEquals(o.get(), "Nazdar");
2.106 + assertEquals(o.changes, 1, "One change so far");
2.107 + }
2.108 +}