brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreatu...@apache.org
Subject [06/17] incubator-brooklyn git commit: switch xslt transformation to use clearer java names for the changes
Date Tue, 03 Feb 2015 11:41:37 GMT
switch xslt transformation to use clearer java names for the changes


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/282b0d86
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/282b0d86
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/282b0d86

Branch: refs/heads/master
Commit: 282b0d865cd4c833e032a6b482190e8ca4ed425a
Parents: 7cd6683
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Jan 28 12:51:07 2015 +0000
Committer: Andrea Turli <andrea.turli@gmail.com>
Committed: Tue Feb 3 11:25:06 2015 +0100

----------------------------------------------------------------------
 .../rebind/transformer/CompoundTransformer.java |  35 +++----
 .../entity/rebind/transformer/renameClass.xslt  |  35 -------
 .../entity/rebind/transformer/renameField.xslt  |  35 -------
 .../entity/rebind/transformer/renameType.xslt   |  41 --------
 .../rebind/transformer/xmlReplaceItem.xslt      |  32 ------
 .../CompoundTransformerLoaderTest.java          |   2 +-
 .../transformer/CompoundTransformerTest.java    | 105 ++++++++++++++++++-
 .../transformer/impl/XsltTransformerTest.java   |  38 ++++++-
 .../rebind/transformer/impl/renameClass.xslt    |  35 +++++++
 .../rebind/transformer/impl/renameField.xslt    |  35 +++++++
 .../rebind/transformer/impl/renameType.xslt     |  41 ++++++++
 11 files changed, 265 insertions(+), 169 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/282b0d86/core/src/main/java/brooklyn/entity/rebind/transformer/CompoundTransformer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/transformer/CompoundTransformer.java
b/core/src/main/java/brooklyn/entity/rebind/transformer/CompoundTransformer.java
index 7d1c7c8..26f6af5 100644
--- a/core/src/main/java/brooklyn/entity/rebind/transformer/CompoundTransformer.java
+++ b/core/src/main/java/brooklyn/entity/rebind/transformer/CompoundTransformer.java
@@ -103,27 +103,20 @@ public class CompoundTransformer {
          */
         // ie TagName/text()[.='foo'] with 'bar' causes <Tag1>foo</Tag1> to <Tag1>bar</Tag1>
         public Builder xmlReplaceItem(String xpathToMatch, String newValue) {
-            return xsltTransformerFromXsltFreemarkerTemplateUrl("classpath://brooklyn/entity/rebind/transformer/xmlReplaceItem.xslt",
-                ImmutableMap.of("xpath_to_match", xpathToMatch, "new_val", newValue));
-            // alternatively:
-//            return xsltTransformerRecursiveCopyWithExtraRules(
-//                "<xsl:template match=\""+xpathToMatch+"\">"
-//                    + newValue
-//                + "</xsl:template>");
+            return xsltTransformerRecursiveCopyWithExtraRules(
+                "<xsl:template match=\""+xpathToMatch+"\">"
+                    + newValue
+                + "</xsl:template>");
         }
         
         /** 
          * Replaces a tag, but while continuing to recurse.
          */
         public Builder xmlRenameTag(String xpathToMatch, String newValue) {
-            return xsltTransformerRecursiveCopyWithExtraRules(
-              "<xsl:template match=\""+xpathToMatch+"\">"
-                  + "<"+newValue+">"
-                      + "<xsl:apply-templates select=\"@*|node()\" />"
-                  + "</"+newValue+">"
-              + "</xsl:template>");
-            // alternatively:
-//            xmlReplaceItem(xpathToMatch, "<"+newValue+">"+"<xsl:apply-templates
select=\"@*|node()\" />"+"</"+newValue+">") 
+            return xmlReplaceItem(xpathToMatch, 
+                "<"+newValue+">"
+                    + "<xsl:apply-templates select=\"@*|node()\" />"
+                + "</"+newValue+">"); 
         }
 
         /** Changes the contents inside a "type" tag:
@@ -132,8 +125,10 @@ public class CompoundTransformer {
          * In brooklyn/xstream, a "type" node typically gives the name of a java or catalog
type to be used
          * when creating an instance. */
         public Builder renameType(String oldVal, String newVal) {
-            return xsltTransformerFromXsltFreemarkerTemplateUrl("classpath://brooklyn/entity/rebind/transformer/renameType.xslt",
-                ImmutableMap.of("old_val", toXstreamClassnameFormat(oldVal), "new_val", toXstreamClassnameFormat(newVal)));
+            return xmlReplaceItem("type/text()[.='"+toXstreamClassnameFormat(oldVal)+"']",
toXstreamClassnameFormat(newVal));
+            // previously this did a more complex looping, essentially
+            // <when .=oldVal>newVal</when><otherwise><apply-templates/></otherwise>
+            // but i think these are equivalent
         }
         /** Changes an XML tag matching a given old value:
          * the tag is changed to the new value.
@@ -141,8 +136,7 @@ public class CompoundTransformer {
          * In xstream many tags correspond to the java class of an object so this is a way
to change 
          * the java class (or xstream alias) of a persisted instance (or instance inside
them). */
         public Builder renameClass(String oldVal, String newVal) {
-            return xsltTransformerFromXsltFreemarkerTemplateUrl("classpath://brooklyn/entity/rebind/transformer/renameClass.xslt",
-                ImmutableMap.of("old_val", toXstreamClassnameFormat(oldVal), "new_val", toXstreamClassnameFormat(newVal)));
+            return xmlRenameTag(toXstreamClassnameFormat(oldVal), toXstreamClassnameFormat(newVal));
         }
         /** Changes an XML tag inside another tag: 
          * where the outer tag and inner tag match the values given here,
@@ -151,8 +145,7 @@ public class CompoundTransformer {
          * In stream tags corresponding to fields are contained in the tag corresponding
to the class name,
          * so this gives a way to change the name of a field which will be deserialized.
*/
         public Builder renameField(String clazz, String oldVal, String newVal) {
-            return xsltTransformerFromXsltFreemarkerTemplateUrl("classpath://brooklyn/entity/rebind/transformer/renameField.xslt",
-                ImmutableMap.of("class_name", toXstreamClassnameFormat(clazz), "old_val",
toXstreamClassnameFormat(oldVal), "new_val", toXstreamClassnameFormat(newVal)));
+            return xmlRenameTag(toXstreamClassnameFormat(clazz)+"/"+toXstreamClassnameFormat(oldVal),
toXstreamClassnameFormat(newVal));
         }
 
         private String toXstreamClassnameFormat(String val) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/282b0d86/core/src/main/resources/brooklyn/entity/rebind/transformer/renameClass.xslt
----------------------------------------------------------------------
diff --git a/core/src/main/resources/brooklyn/entity/rebind/transformer/renameClass.xslt b/core/src/main/resources/brooklyn/entity/rebind/transformer/renameClass.xslt
deleted file mode 100644
index a0800fd..0000000
--- a/core/src/main/resources/brooklyn/entity/rebind/transformer/renameClass.xslt
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
-    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.
--->
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
-
-  <xsl:output omit-xml-declaration="yes"/>
-  
-  <xsl:template match="node()|@*">
-    <xsl:copy>
-      <xsl:apply-templates select="node()|@*"/>
-    </xsl:copy>
-  </xsl:template>
-
-  <xsl:template match="${old_val}">
-    <${new_val}><xsl:apply-templates select="@*|node()" /></${new_val}>
-  </xsl:template>
-
-</xsl:stylesheet>
-

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/282b0d86/core/src/main/resources/brooklyn/entity/rebind/transformer/renameField.xslt
----------------------------------------------------------------------
diff --git a/core/src/main/resources/brooklyn/entity/rebind/transformer/renameField.xslt b/core/src/main/resources/brooklyn/entity/rebind/transformer/renameField.xslt
deleted file mode 100644
index d4b3354..0000000
--- a/core/src/main/resources/brooklyn/entity/rebind/transformer/renameField.xslt
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
-    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.
--->
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
-
-  <xsl:output omit-xml-declaration="yes"/>
-  
-  <xsl:template match="node()|@*">
-    <xsl:copy>
-      <xsl:apply-templates select="node()|@*"/>
-    </xsl:copy>
-  </xsl:template>
-
-  <xsl:template match="${class_name}/${old_val}">
-    <${new_val}><xsl:apply-templates select="@*|node()" /></${new_val}>
-  </xsl:template>
-
-</xsl:stylesheet>
-

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/282b0d86/core/src/main/resources/brooklyn/entity/rebind/transformer/renameType.xslt
----------------------------------------------------------------------
diff --git a/core/src/main/resources/brooklyn/entity/rebind/transformer/renameType.xslt b/core/src/main/resources/brooklyn/entity/rebind/transformer/renameType.xslt
deleted file mode 100644
index e53fe37..0000000
--- a/core/src/main/resources/brooklyn/entity/rebind/transformer/renameType.xslt
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
-    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.
--->
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
-
-  <xsl:output omit-xml-declaration="yes"/>
-  
-  <xsl:template match="node()|@*">
-    <xsl:copy>
-      <xsl:apply-templates select="node()|@*"/>
-    </xsl:copy>
-  </xsl:template>
-
-  <xsl:template match="type">
-    <type>
-      <xsl:copy-of select="@*"/>
-      <xsl:choose>
-        <xsl:when test=".='${old_val}'"><xsl:value-of select="'${new_val}'"/></xsl:when>
-        <xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
-      </xsl:choose>
-    </type>
-  </xsl:template>
-
-</xsl:stylesheet>
-

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/282b0d86/core/src/main/resources/brooklyn/entity/rebind/transformer/xmlReplaceItem.xslt
----------------------------------------------------------------------
diff --git a/core/src/main/resources/brooklyn/entity/rebind/transformer/xmlReplaceItem.xslt
b/core/src/main/resources/brooklyn/entity/rebind/transformer/xmlReplaceItem.xslt
deleted file mode 100644
index 8d4acc0..0000000
--- a/core/src/main/resources/brooklyn/entity/rebind/transformer/xmlReplaceItem.xslt
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
-    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.
--->
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
-
-  <xsl:output omit-xml-declaration="yes"/>
-  
-  <xsl:template match="node()|@*">
-    <xsl:copy>
-      <xsl:apply-templates select="node()|@*"/>
-    </xsl:copy>
-  </xsl:template>
-
-  <xsl:template match="${xpath_to_match}">${new_val}</xsl:template>
-
-</xsl:stylesheet>

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/282b0d86/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerLoaderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerLoaderTest.java
b/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerLoaderTest.java
index e473245..454e860 100644
--- a/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerLoaderTest.java
+++ b/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerLoaderTest.java
@@ -45,7 +45,7 @@ public class CompoundTransformerLoaderTest {
                 "  old_val: myoldname\n"+
                 "  new_val: mynewname\n"+
                 "xslt:\n"+
-                "  url: classpath://brooklyn/entity/rebind/transformer/renameType.xslt\n"+
+                "  url: classpath://brooklyn/entity/rebind/transformer/impl/renameType.xslt\n"+
                 "  substitutions:\n"+
                 "    old_val: myoldname\n"+
                 "    new_val: mynewname\n"+

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/282b0d86/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerTest.java
b/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerTest.java
index 6e7ab36..49c1005 100644
--- a/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerTest.java
+++ b/core/src/test/java/brooklyn/entity/rebind/transformer/CompoundTransformerTest.java
@@ -62,7 +62,8 @@ import com.google.common.collect.Iterables;
 public class CompoundTransformerTest extends RebindTestFixtureWithApp {
 
     private static final Logger LOG = LoggerFactory.getLogger(CompoundTransformerTest.class);
-
+    private static String NEWLINE = Os.LINE_SEPARATOR;
+    
     private File newMementoDir;
     
     @AfterMethod(alwaysRun=true)
@@ -192,6 +193,108 @@ public class CompoundTransformerTest extends RebindTestFixtureWithApp
{
         assertTrue(newPredicate.apply(newApp));
     }
     
+    @Test
+    public void testRenameTypeInXml() throws Exception {
+        CompoundTransformer transformer = CompoundTransformer.builder()
+            .renameType("mytype.Before", "mytype.After")
+            .build();
+        
+        String input = 
+                "<entity myattrib=\"myval\">"+NEWLINE+
+                "  <type myattrib2=\"myval2\">mytype.Before</type>"+NEWLINE+
+                "  <nested>"+NEWLINE+
+                "    <type myattrib3=\"myval3\">doesNotMatch</type>"+NEWLINE+
+                "    <type myattrib4=\"myval4\">partial.mytype.Before</type>"+NEWLINE+
+                "    <type myattrib5=\"myval5\">mytype.Before</type>"+NEWLINE+
+                "  </nested>"+NEWLINE+
+                "  <id>myid</id>"+NEWLINE+
+                "</entity>";
+        String expected = 
+                "<entity myattrib=\"myval\">"+NEWLINE+
+                "  <type myattrib2=\"myval2\">mytype.After</type>"+NEWLINE+
+                "  <nested>"+NEWLINE+
+                "    <type myattrib3=\"myval3\">doesNotMatch</type>"+NEWLINE+
+                "    <type myattrib4=\"myval4\">partial.mytype.Before</type>"+NEWLINE+
+                "    <type myattrib5=\"myval5\">mytype.After</type>"+NEWLINE+
+                "  </nested>"+NEWLINE+
+                "  <id>myid</id>"+NEWLINE+
+                "</entity>";
+        
+        assertSingleXmlTransformation(transformer, input, expected);
+    }
+    
+    @Test
+    public void testRenameFieldInXml() throws Exception {
+        CompoundTransformer transformer = CompoundTransformer.builder()
+            .renameField("MyClass", "myFieldBefore", "myFieldAfter")
+            .build();
+        
+        String input = 
+                "<entity myattrib=\"myval\">"+NEWLINE+
+                "  <type myattrib2=\"myval2\">mytype.Before</type>"+NEWLINE+
+                "  <config>"+NEWLINE+
+                "    <test.conf1>"+NEWLINE+
+                "      <MyClass>"+NEWLINE+
+                "        <myFieldBefore class=\"string\">myfieldval</myFieldBefore>"+NEWLINE+
+                "      </MyClass>"+NEWLINE+
+                "    </test.conf1>"+NEWLINE+
+                "    <test.conf2>"+NEWLINE+
+                "      <MyOtherClass>"+NEWLINE+
+                "        <myFieldBefore class=\"string\">myfieldval</myFieldBefore>"+NEWLINE+
+                "      </MyOtherClass>"+NEWLINE+
+                "    </test.conf2>"+NEWLINE+
+                "  </config>"+NEWLINE+
+                "</entity>";
+        String expected = 
+                "<entity myattrib=\"myval\">"+NEWLINE+
+                "  <type myattrib2=\"myval2\">mytype.Before</type>"+NEWLINE+
+                "  <config>"+NEWLINE+
+                "    <test.conf1>"+NEWLINE+
+                "      <MyClass>"+NEWLINE+
+                "        <myFieldAfter class=\"string\">myfieldval</myFieldAfter>"+NEWLINE+
+                "      </MyClass>"+NEWLINE+
+                "    </test.conf1>"+NEWLINE+
+                "    <test.conf2>"+NEWLINE+
+                "      <MyOtherClass>"+NEWLINE+
+                "        <myFieldBefore class=\"string\">myfieldval</myFieldBefore>"+NEWLINE+
+                "      </MyOtherClass>"+NEWLINE+
+                "    </test.conf2>"+NEWLINE+
+                "  </config>"+NEWLINE+
+                "</entity>";
+        
+        assertSingleXmlTransformation(transformer, input, expected);
+    }
+    
+    @Test
+    public void testRenameClassInXml() throws Exception {
+        CompoundTransformer transformer = CompoundTransformer.builder()
+            .renameClass("MyClassBefore", "MyClassAfter")
+            .build();
+
+        String input = 
+                "<entity myattrib=\"myval\">"+NEWLINE+
+                "  <type myattrib2=\"myval2\">mytype.Before</type>"+NEWLINE+
+                "  <config>"+NEWLINE+
+                "    <test.conf1>"+NEWLINE+
+                "      <MyClassBefore>"+NEWLINE+
+                "      </MyClassBefore>"+NEWLINE+
+                "    </test.conf1>"+NEWLINE+
+                "  </config>"+NEWLINE+
+                "</entity>";
+        String expected = 
+                "<entity myattrib=\"myval\">"+NEWLINE+
+                "  <type myattrib2=\"myval2\">mytype.Before</type>"+NEWLINE+
+                "  <config>"+NEWLINE+
+                "    <test.conf1>"+NEWLINE+
+                "      <MyClassAfter>"+NEWLINE+
+                "      </MyClassAfter>"+NEWLINE+
+                "    </test.conf1>"+NEWLINE+
+                "  </config>"+NEWLINE+
+                "</entity>";
+        
+        assertSingleXmlTransformation(transformer, input, expected);
+    }
+    
     protected TestApplication transformAndRebind(CompoundTransformer transformer) throws
Exception {
         RebindTestUtils.waitForPersisted(origApp);
         BrooklynMementoRawData newRawData = transform(origManagementContext, transformer);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/282b0d86/core/src/test/java/brooklyn/entity/rebind/transformer/impl/XsltTransformerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/transformer/impl/XsltTransformerTest.java
b/core/src/test/java/brooklyn/entity/rebind/transformer/impl/XsltTransformerTest.java
index cc801b2..5791dd4 100644
--- a/core/src/test/java/brooklyn/entity/rebind/transformer/impl/XsltTransformerTest.java
+++ b/core/src/test/java/brooklyn/entity/rebind/transformer/impl/XsltTransformerTest.java
@@ -28,13 +28,45 @@ import brooklyn.util.text.TemplateProcessor;
 
 import com.google.common.collect.ImmutableMap;
 
+/**
+ * Tests the low-level XSLT transformer logic.
+ * <p>
+ * Some of the tests use xslt files which are no longer used to perform type/class/field-specific
changes,
+ * but they are included here because they are still useful test cases for XSLT. 
+ */
 public class XsltTransformerTest {
 
     private static String NEWLINE = Os.LINE_SEPARATOR;
+
+    @Test
+    public void testRecursiveCopyExtraRules() throws Exception {
+        String xsltTemplate = ResourceUtils.create(XsltTransformerTest.class).getResourceAsString("classpath://brooklyn/entity/rebind/transformer/recursiveCopyWithExtraRules.xslt");
+        String xslt = TemplateProcessor.processTemplateContents(xsltTemplate, ImmutableMap.of(
+            "extra_rules", "<xsl:template match=\"nested\"><empty_nest/></xsl:template>"));
+        String input = 
+                "<entity myattrib=\"myval\">"+NEWLINE+
+                "  <type myattrib2=\"myval2\">mytype</type>"+NEWLINE+
+                "  <nested>"+NEWLINE+
+                "    <type myattrib3=\"myval3\">foo</type>"+NEWLINE+
+                "    bar"+NEWLINE+
+                "  </nested>"+NEWLINE+
+                "  <id>myid</id>"+NEWLINE+
+                "</entity>";
+        String expected = 
+                "<entity myattrib=\"myval\">"+NEWLINE+
+                "  <type myattrib2=\"myval2\">mytype</type>"+NEWLINE+
+                "  <empty_nest/>"+NEWLINE+
+                "  <id>myid</id>"+NEWLINE+
+                "</entity>";
+        
+        XsltTransformer transformer = new XsltTransformer(xslt);
+        String result = transformer.transform(input);
+        assertEquals(result, expected);
+    }
     
     @Test
     public void testRenameType() throws Exception {
-        String xsltTemplate = ResourceUtils.create(XsltTransformerTest.class).getResourceAsString("classpath://brooklyn/entity/rebind/transformer/renameType.xslt");
+        String xsltTemplate = ResourceUtils.create(XsltTransformerTest.class).getResourceAsString("classpath://brooklyn/entity/rebind/transformer/impl/renameType.xslt");
         String xslt = TemplateProcessor.processTemplateContents(xsltTemplate, ImmutableMap.of("old_val",
"mytype.Before", "new_val", "mytype.After"));
         String input = 
                 "<entity myattrib=\"myval\">"+NEWLINE+
@@ -64,7 +96,7 @@ public class XsltTransformerTest {
     
     @Test
     public void testRenameField() throws Exception {
-        String xsltTemplate = ResourceUtils.create(XsltTransformerTest.class).getResourceAsString("classpath://brooklyn/entity/rebind/transformer/renameField.xslt");
+        String xsltTemplate = ResourceUtils.create(XsltTransformerTest.class).getResourceAsString("classpath://brooklyn/entity/rebind/transformer/impl/renameField.xslt");
         String xslt = TemplateProcessor.processTemplateContents(xsltTemplate, ImmutableMap.of("class_name",
"MyClass", "old_val", "myFieldBefore", "new_val", "myFieldAfter"));
         String input = 
                 "<entity myattrib=\"myval\">"+NEWLINE+
@@ -106,7 +138,7 @@ public class XsltTransformerTest {
     
     @Test
     public void testRenameClass() throws Exception {
-        String xsltTemplate = ResourceUtils.create(XsltTransformerTest.class).getResourceAsString("classpath://brooklyn/entity/rebind/transformer/renameClass.xslt");
+        String xsltTemplate = ResourceUtils.create(XsltTransformerTest.class).getResourceAsString("classpath://brooklyn/entity/rebind/transformer/impl/renameClass.xslt");
         String xslt = TemplateProcessor.processTemplateContents(xsltTemplate, ImmutableMap.of("old_val",
"MyClassBefore", "new_val", "MyClassAfter"));
         String input = 
                 "<entity myattrib=\"myval\">"+NEWLINE+

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/282b0d86/core/src/test/resources/brooklyn/entity/rebind/transformer/impl/renameClass.xslt
----------------------------------------------------------------------
diff --git a/core/src/test/resources/brooklyn/entity/rebind/transformer/impl/renameClass.xslt
b/core/src/test/resources/brooklyn/entity/rebind/transformer/impl/renameClass.xslt
new file mode 100644
index 0000000..a0800fd
--- /dev/null
+++ b/core/src/test/resources/brooklyn/entity/rebind/transformer/impl/renameClass.xslt
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    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.
+-->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+
+  <xsl:output omit-xml-declaration="yes"/>
+  
+  <xsl:template match="node()|@*">
+    <xsl:copy>
+      <xsl:apply-templates select="node()|@*"/>
+    </xsl:copy>
+  </xsl:template>
+
+  <xsl:template match="${old_val}">
+    <${new_val}><xsl:apply-templates select="@*|node()" /></${new_val}>
+  </xsl:template>
+
+</xsl:stylesheet>
+

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/282b0d86/core/src/test/resources/brooklyn/entity/rebind/transformer/impl/renameField.xslt
----------------------------------------------------------------------
diff --git a/core/src/test/resources/brooklyn/entity/rebind/transformer/impl/renameField.xslt
b/core/src/test/resources/brooklyn/entity/rebind/transformer/impl/renameField.xslt
new file mode 100644
index 0000000..d4b3354
--- /dev/null
+++ b/core/src/test/resources/brooklyn/entity/rebind/transformer/impl/renameField.xslt
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    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.
+-->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+
+  <xsl:output omit-xml-declaration="yes"/>
+  
+  <xsl:template match="node()|@*">
+    <xsl:copy>
+      <xsl:apply-templates select="node()|@*"/>
+    </xsl:copy>
+  </xsl:template>
+
+  <xsl:template match="${class_name}/${old_val}">
+    <${new_val}><xsl:apply-templates select="@*|node()" /></${new_val}>
+  </xsl:template>
+
+</xsl:stylesheet>
+

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/282b0d86/core/src/test/resources/brooklyn/entity/rebind/transformer/impl/renameType.xslt
----------------------------------------------------------------------
diff --git a/core/src/test/resources/brooklyn/entity/rebind/transformer/impl/renameType.xslt
b/core/src/test/resources/brooklyn/entity/rebind/transformer/impl/renameType.xslt
new file mode 100644
index 0000000..e53fe37
--- /dev/null
+++ b/core/src/test/resources/brooklyn/entity/rebind/transformer/impl/renameType.xslt
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    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.
+-->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+
+  <xsl:output omit-xml-declaration="yes"/>
+  
+  <xsl:template match="node()|@*">
+    <xsl:copy>
+      <xsl:apply-templates select="node()|@*"/>
+    </xsl:copy>
+  </xsl:template>
+
+  <xsl:template match="type">
+    <type>
+      <xsl:copy-of select="@*"/>
+      <xsl:choose>
+        <xsl:when test=".='${old_val}'"><xsl:value-of select="'${new_val}'"/></xsl:when>
+        <xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
+      </xsl:choose>
+    </type>
+  </xsl:template>
+
+</xsl:stylesheet>
+


Mime
View raw message