Revision: 47270
Author:   uhommes
Date:     2014-11-27 11:06:27 +0100 (Thu, 27 Nov 2014)
Log Message:
-----------
REPO-1141 add test case for BasicUpdater

Modified Paths:
--------------
    hippo-cms7/tools/migrator/trunk/pom.xml
    
hippo-cms7/tools/migrator/trunk/src/main/java/org/onehippo/cms7/repository/migration/BasicUpdater.java
    
hippo-cms7/tools/migrator/trunk/src/main/java/org/onehippo/cms7/repository/migration/Main.java
    
hippo-cms7/tools/migrator/trunk/src/main/resources/org/onehippo/cms7/repository/migration/usage.txt

Added Paths:
-----------
    
hippo-cms7/tools/migrator/trunk/src/test/java/org/onehippo/cms7/repository/migration/BasicUpdaterTest.java

Modified: hippo-cms7/tools/migrator/trunk/pom.xml
===================================================================
--- hippo-cms7/tools/migrator/trunk/pom.xml     2014-11-27 09:47:07 UTC (rev 
47269)
+++ hippo-cms7/tools/migrator/trunk/pom.xml     2014-11-27 10:06:27 UTC (rev 
47270)
@@ -108,6 +108,12 @@
         <version>${h2.version}</version>
         <scope>test</scope>
       </dependency>
+      <dependency>
+        <groupId>org.onehippo.cms7</groupId>
+        <artifactId>hippo-repository-testutils</artifactId>
+        <version>2.27.00-SNAPSHOT</version>
+        <scope>test</scope>
+      </dependency>
    </dependencies>
   </dependencyManagement>
 
@@ -137,6 +143,10 @@
       <groupId>com.h2database</groupId>
       <artifactId>h2</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.onehippo.cms7</groupId>
+      <artifactId>hippo-repository-testutils</artifactId>
+    </dependency>
   </dependencies>
 
   <build>
@@ -203,8 +213,8 @@
             <configuration>
               <excludes combine.children="append">
                 <!-- no comments supported -->
-                
<exclude>src/main/resources/org/onehippo/cms7/repository/maintenance/usage.txt</exclude>
-                
<exclude>src/main/resources/org/onehippo/cms7/repository/maintenance/migration.properties</exclude>
+                
<exclude>src/main/resources/org/onehippo/cms7/repository/migration/usage.txt</exclude>
+                
<exclude>src/main/resources/org/onehippo/cms7/repository/migration/migration.properties</exclude>
               </excludes>
             </configuration>
           </plugin>

Modified: 
hippo-cms7/tools/migrator/trunk/src/main/java/org/onehippo/cms7/repository/migration/BasicUpdater.java
===================================================================
--- 
hippo-cms7/tools/migrator/trunk/src/main/java/org/onehippo/cms7/repository/migration/BasicUpdater.java
      2014-11-27 09:47:07 UTC (rev 47269)
+++ 
hippo-cms7/tools/migrator/trunk/src/main/java/org/onehippo/cms7/repository/migration/BasicUpdater.java
      2014-11-27 10:06:27 UTC (rev 47270)
@@ -1,3 +1,18 @@
+/*
+ *  Copyright 2014-2014 Hippo B.V. (http://www.onehippo.com)
+ *
+ *  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.onehippo.cms7.repository.migration;
 
 import java.util.ArrayList;

Modified: 
hippo-cms7/tools/migrator/trunk/src/main/java/org/onehippo/cms7/repository/migration/Main.java
===================================================================
--- 
hippo-cms7/tools/migrator/trunk/src/main/java/org/onehippo/cms7/repository/migration/Main.java
      2014-11-27 09:47:07 UTC (rev 47269)
+++ 
hippo-cms7/tools/migrator/trunk/src/main/java/org/onehippo/cms7/repository/migration/Main.java
      2014-11-27 10:06:27 UTC (rev 47270)
@@ -52,6 +52,7 @@
                 case CONFIG : print("repository.xml"); break;
                 case MIGRATE : migrate(createMigrationRepository(options, 
properties), options); break;
                 case CLEANUP : cleanup(createMigrationRepository(options, 
properties), options); break;
+                default: print("usage.txt");
             }
         } catch (ConfigurationException e) {
             log.error("Cannot create repository config", e);

Modified: 
hippo-cms7/tools/migrator/trunk/src/main/resources/org/onehippo/cms7/repository/migration/usage.txt
===================================================================
--- 
hippo-cms7/tools/migrator/trunk/src/main/resources/org/onehippo/cms7/repository/migration/usage.txt
 2014-11-27 09:47:07 UTC (rev 47269)
+++ 
hippo-cms7/tools/migrator/trunk/src/main/resources/org/onehippo/cms7/repository/migration/usage.txt
 2014-11-27 10:06:27 UTC (rev 47270)
@@ -25,4 +25,4 @@
 
 To migrate a repository:
 
-> java -jar migration.jar migrate [--continue --cleanup]
+> java -jar migration.jar migrate [--continue]

Added: 
hippo-cms7/tools/migrator/trunk/src/test/java/org/onehippo/cms7/repository/migration/BasicUpdaterTest.java
===================================================================
--- 
hippo-cms7/tools/migrator/trunk/src/test/java/org/onehippo/cms7/repository/migration/BasicUpdaterTest.java
                          (rev 0)
+++ 
hippo-cms7/tools/migrator/trunk/src/test/java/org/onehippo/cms7/repository/migration/BasicUpdaterTest.java
  2014-11-27 10:06:27 UTC (rev 47270)
@@ -0,0 +1,101 @@
+/*
+ *  Copyright 2014-2014 Hippo B.V. (http://www.onehippo.com)
+ *
+ *  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.onehippo.cms7.repository.migration;
+
+import javax.jcr.PropertyType;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onehippo.repository.mock.MockNode;
+import org.onehippo.repository.mock.MockValueFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class BasicUpdaterTest {
+
+    private Updater updater = new TestUpdater();
+    private MockNode root;
+
+    @Before
+    public void setUp() throws Exception {
+        root = MockNode.root();
+        updater.initialize(root.getSession(), "old");
+    }
+
+    @Test
+    public void renamePropertyValue() throws Exception {
+        final ValueFactory valueFactory = root.getSession().getValueFactory();
+        root.setProperty("test", valueFactory.createValue("old:value", 
PropertyType.NAME));
+        updater.update(root);
+        assertEquals("new:value", root.getProperty("test").getString());
+    }
+
+    @Test
+    public void renamePropertyValues() throws Exception {
+        final MockValueFactory valueFactory = 
root.getSession().getValueFactory();
+        Value[] values = new Value[2];
+        values[0] = valueFactory.createValue("old:value1", PropertyType.NAME);
+        values[1] = valueFactory.createValue("old:value2", PropertyType.NAME);
+        root.setProperty("test", values);
+        updater.update(root);
+        values = root.getProperty("test").getValues();
+        assertEquals("new:value1", values[0].getString());
+        assertEquals("new:value2", values[1].getString());
+    }
+
+    @Test
+    public void renameProperty() throws Exception {
+        root.setProperty("old:name", "value");
+        updater.update(root);
+        assertFalse(root.hasProperty("old:name"));
+        assertTrue(root.hasProperty("new:name"));
+    }
+
+    @Test
+    public void renameNode() throws Exception {
+        final MockNode node = root.addNode("old:name", "nt:unstructured");
+        updater.update(node);
+        assertFalse(root.hasNode("old:name"));
+        assertTrue(root.hasNode("new:name"));
+    }
+
+    @Test
+    public void renamePrimaryType() throws Exception {
+        root.setPrimaryType("old:type");
+        updater.update(root);
+        assertEquals("new:type", root.getPrimaryNodeType().getName());
+    }
+
+    @Test
+    public void renameMixinType() throws Exception {
+        root.addMixin("old:mixin");
+        updater.update(root);
+        assertFalse(root.isNodeType("old:mixin"));
+        assertTrue(root.isNodeType("new:mixin"));
+    }
+
+    private static final class TestUpdater extends BasicUpdater {
+
+        @Override
+        protected String getNewPrefix() {
+            return "new";
+        }
+    }
+}


Property changes on: 
hippo-cms7/tools/migrator/trunk/src/test/java/org/onehippo/cms7/repository/migration/BasicUpdaterTest.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
_______________________________________________
Hippocms-svn mailing list
[email protected]
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to