You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2016/02/02 01:36:11 UTC

[14/15] isis git commit: ISIS-993: converting GridNormalizer into a service.

http://git-wip-us.apache.org/repos/asf/isis/blob/63d03d29/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/grid/BS3GridTest.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/grid/BS3GridTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/grid/BS3GridTest.java
new file mode 100644
index 0000000..3d9d6b2
--- /dev/null
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/grid/BS3GridTest.java
@@ -0,0 +1,154 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.core.metamodel.services.grid;
+
+import java.util.Arrays;
+import java.util.Map;
+
+import javax.xml.bind.Marshaller;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.layout.bootstrap3.BS3Col;
+import org.apache.isis.applib.layout.bootstrap3.BS3Grid;
+import org.apache.isis.applib.layout.bootstrap3.BS3Row;
+import org.apache.isis.applib.layout.bootstrap3.BS3Tab;
+import org.apache.isis.applib.layout.bootstrap3.BS3TabGroup;
+import org.apache.isis.applib.layout.common.ActionLayoutData;
+import org.apache.isis.applib.layout.common.CollectionLayoutData;
+import org.apache.isis.applib.layout.common.DomainObjectLayoutData;
+import org.apache.isis.applib.layout.common.FieldSet;
+import org.apache.isis.applib.layout.common.PropertyLayoutData;
+import org.apache.isis.applib.services.jaxb.JaxbService;
+import org.apache.isis.core.metamodel.services.grid.bootstrap3.GridNormalizerServiceBS3;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class BS3GridTest {
+
+    private JaxbService jaxbService;
+    private GridServiceDefault gridServiceDefault;
+    private GridNormalizerServiceBS3 gridNormalizerServiceBS3;
+
+    @Before
+    public void setUp() throws Exception {
+        jaxbService = new JaxbService.Simple();
+        gridServiceDefault = new GridServiceDefault();
+        gridNormalizerServiceBS3 = new GridNormalizerServiceBS3();
+        gridServiceDefault.gridNormalizerServices = Arrays.<GridNormalizerService>asList(gridNormalizerServiceBS3);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+
+    }
+
+    @Test
+    public void xxx() throws Exception {
+
+        final BS3Grid bs3Grid = new BS3Grid();
+
+        // header
+        final BS3Row headerRow = bs3Grid.getRows().get(0);
+        final BS3Col headerCol = (BS3Col) headerRow.getCols().get(0);
+        headerCol.setSpan(12);
+
+        final DomainObjectLayoutData objectLayoutData = new DomainObjectLayoutData();
+        headerCol.setDomainObject(objectLayoutData);
+
+        final ActionLayoutData deleteActionLayoutData = new ActionLayoutData();
+        deleteActionLayoutData.setId("delete");
+        headerCol.setActions(Lists.<ActionLayoutData>newArrayList());
+        headerCol.getActions().add(deleteActionLayoutData);
+
+        // content
+        final BS3Row contentRow = new BS3Row();
+        bs3Grid.getRows().add(contentRow);
+
+        final BS3Col contentCol = (BS3Col) contentRow.getCols().get(0);
+        contentCol.setSpan(12);
+
+        // a tabgroup containing a 'Common' tab
+        final BS3TabGroup tabGroup = new BS3TabGroup();
+        contentCol.getTabGroups().add(tabGroup);
+        BS3Tab bs3Tab = tabGroup.getTabs().get(0);
+        bs3Tab.setName("Common");
+
+        // with a left col...
+        final BS3Row tabRow = bs3Tab.getRows().get(0);
+        final BS3Col tabLeftCol = (BS3Col) tabRow.getCols().get(0);
+        tabLeftCol.setSpan(6);
+
+        // containing a fieldset
+        final FieldSet leftPropGroup = new FieldSet("General");
+        tabLeftCol.setFieldSets(Lists.<FieldSet>newArrayList());
+        tabLeftCol.getFieldSets().add(leftPropGroup);
+        leftPropGroup.setName("General");
+
+        // with a single property
+        final PropertyLayoutData namePropertyLayoutData = leftPropGroup.getProperties().get(0);
+        namePropertyLayoutData.setNamed("name");
+
+        // and its associated action
+        final ActionLayoutData updateNameActionLayoutData = new ActionLayoutData();
+        updateNameActionLayoutData.setId("updateName");
+        namePropertyLayoutData.setActions(Lists.<ActionLayoutData>newArrayList());
+        namePropertyLayoutData.getActions().add(updateNameActionLayoutData);
+
+        // and the tab also has a right col...
+        final BS3Col tabRightCol = (BS3Col) tabRow.getCols().get(0);
+        tabRightCol.setSpan(6);
+
+        // containing a collection
+        final CollectionLayoutData similarToColl = new CollectionLayoutData();
+        tabRightCol.setCollections(Lists.<CollectionLayoutData>newArrayList());
+        tabRightCol.getCollections().add(similarToColl);
+        similarToColl.setId("similarTo");
+
+        final String schemaLocations = gridServiceDefault.tnsAndSchemaLocation(bs3Grid);
+        String xml = jaxbService.toXml(bs3Grid,
+                ImmutableMap.<String,Object>of(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocations));
+        System.out.println(xml);
+
+        BS3Grid bs3Pageroundtripped = jaxbService.fromXml(BS3Grid.class, xml);
+        String xmlRoundtripped = jaxbService.toXml(bs3Pageroundtripped,
+                ImmutableMap.<String,Object>of(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocations));
+        assertThat(xml, is(equalTo(xmlRoundtripped)));
+
+
+        System.out.println("==========");
+
+        dumpXsd(bs3Grid);
+    }
+
+    protected void dumpXsd(final BS3Grid bs3Page) {
+        Map<String, String> schemas = jaxbService.toXsd(bs3Page, JaxbService.IsisSchemas.INCLUDE);
+        for (Map.Entry<String, String> entry : schemas.entrySet()) {
+            System.out.println(entry.getKey() + ":");
+            System.out.println(entry.getValue());
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/63d03d29/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/grid/FCGridTest.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/grid/FCGridTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/grid/FCGridTest.java
new file mode 100644
index 0000000..5cb1ed6
--- /dev/null
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/grid/FCGridTest.java
@@ -0,0 +1,126 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.core.metamodel.services.grid;
+
+import java.util.Arrays;
+import java.util.Map;
+
+import javax.xml.bind.Marshaller;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.layout.common.ActionLayoutData;
+import org.apache.isis.applib.layout.common.CollectionLayoutData;
+import org.apache.isis.applib.layout.common.FieldSet;
+import org.apache.isis.applib.layout.common.PropertyLayoutData;
+import org.apache.isis.applib.layout.fixedcols.FCColumn;
+import org.apache.isis.applib.layout.fixedcols.FCGrid;
+import org.apache.isis.applib.layout.fixedcols.FCTab;
+import org.apache.isis.applib.layout.fixedcols.FCTabGroup;
+import org.apache.isis.applib.services.jaxb.JaxbService;
+import org.apache.isis.core.metamodel.services.grid.fixedcols.GridNormalizerServiceFC;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class FCGridTest {
+
+    private JaxbService jaxbService;
+    private GridServiceDefault gridServiceDefault;
+    private GridNormalizerServiceFC gridNormalizerServiceFC;
+
+    @Before
+    public void setUp() throws Exception {
+        jaxbService = new JaxbService.Simple();
+        gridServiceDefault = new GridServiceDefault();
+        gridNormalizerServiceFC = new GridNormalizerServiceFC();
+        gridServiceDefault.gridNormalizerServices = Arrays.<GridNormalizerService>asList(gridNormalizerServiceFC);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+
+    }
+
+    @Test
+    public void xxx() throws Exception {
+
+        final FCGrid fcPage = new FCGrid();
+
+        fcPage.setTabGroups(Lists.<FCTabGroup>newArrayList());
+        fcPage.getTabGroups().add(new FCTabGroup());
+        FCTabGroup tabGroup = fcPage.getTabGroups().get(0);
+        FCTab FCTab = tabGroup.getTabs().get(0);
+        FCTab.setName("Common");
+        FCColumn left = FCTab.getLeft();
+
+        FieldSet leftPropGroup = new FieldSet();
+        left.setFieldSets(Lists.<FieldSet>newArrayList());
+        left.getFieldSets().add(leftPropGroup);
+        leftPropGroup.setName("General");
+
+        CollectionLayoutData similarToColl = new CollectionLayoutData();
+        left.setCollections(Lists.<CollectionLayoutData>newArrayList());
+        left.getCollections().add(similarToColl);
+        similarToColl.setId("similarTo");
+
+        left.getFieldSets().add(new FieldSet("General"));
+        PropertyLayoutData namePropertyLayoutData = new PropertyLayoutData("name");
+        left.getFieldSets().get(0).getProperties().add(namePropertyLayoutData);
+
+        ActionLayoutData updateNameActionLayoutData = new ActionLayoutData();
+        updateNameActionLayoutData.setId("updateName");
+        namePropertyLayoutData.setActions(Lists.<ActionLayoutData>newArrayList());
+        namePropertyLayoutData.getActions().add(updateNameActionLayoutData);
+
+        ActionLayoutData deleteActionLayoutData = new ActionLayoutData();
+        deleteActionLayoutData.setId("delete");
+        fcPage.setActions(Lists.<ActionLayoutData>newArrayList());
+        fcPage.getActions().add(deleteActionLayoutData);
+
+        final String schemaLocations = gridServiceDefault.tnsAndSchemaLocation(fcPage);
+        String xml = jaxbService.toXml(fcPage,
+                ImmutableMap.<String,Object>of(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocations));
+        System.out.println(xml);
+
+        FCGrid fcPageRoundtripped = jaxbService.fromXml(FCGrid.class, xml);
+        String xmlRoundtripped = jaxbService.toXml(fcPageRoundtripped,
+                ImmutableMap.<String,Object>of(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocations));
+        assertThat(xml, is(equalTo(xmlRoundtripped)));
+
+
+        System.out.println("==========");
+
+        dumpXsd(fcPage);
+    }
+
+    protected void dumpXsd(final FCGrid fcPage) {
+        Map<String, String> schemas = jaxbService.toXsd(fcPage, JaxbService.IsisSchemas.INCLUDE);
+        for (Map.Entry<String, String> entry : schemas.entrySet()) {
+            System.out.println(entry.getKey() + ":");
+            System.out.println(entry.getValue());
+        }
+    }
+}
\ No newline at end of file