incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1539396 - in /sling/trunk/contrib/extensions/i18n: ./ src/test/java/org/apache/sling/i18n/impl/ src/test/java/org/apache/sling/i18n/it/
Date Wed, 06 Nov 2013 16:56:04 GMT
Author: bdelacretaz
Date: Wed Nov  6 16:56:03 2013
New Revision: 1539396

URL: http://svn.apache.org/r1539396
Log:
SLING-3147 - add ResourceBundleProviderIT, that takes sling.run.modes=oak into account

Added:
    sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/Message.java
  (with props)
    sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/
    sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java
  (with props)
Modified:
    sling/trunk/contrib/extensions/i18n/   (props changed)
    sling/trunk/contrib/extensions/i18n/pom.xml
    sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java

Propchange: sling/trunk/contrib/extensions/i18n/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Nov  6 16:56:03 2013
@@ -3,6 +3,7 @@ sling
 bin
 logs
 jackrabbit-repository
+jackrabbit
 derby.log
 *.iml
 *.ipr
@@ -12,3 +13,4 @@ derby.log
 .classpath
 .externalToolBuilders
 maven-eclipse.xml
+oak

Modified: sling/trunk/contrib/extensions/i18n/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/pom.xml?rev=1539396&r1=1539395&r2=1539396&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/i18n/pom.xml (original)
+++ sling/trunk/contrib/extensions/i18n/pom.xml Wed Nov  6 16:56:03 2013
@@ -35,6 +35,13 @@
         Support for creating Java I18N ResourceBundles from repository
         resources.
     </description>
+    
+    <properties>
+        <exam.version>3.0.3</exam.version>
+        <url.version>1.5.2</url.version>
+        <org.ops4j.pax.logging.DefaultServiceLog.level>INFO</org.ops4j.pax.logging.DefaultServiceLog.level>
+        <bundle.file.name>${basedir}/target/${project.build.finalName}.jar</bundle.file.name>
+    </properties>
 
     <scm>
         <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/i18n</connection>
@@ -77,6 +84,31 @@
                     </instructions>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>integration-test</goal>
+                            <goal>verify</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <systemPropertyVariables>
+                        <org.ops4j.pax.logging.DefaultServiceLog.level>${org.ops4j.pax.logging.DefaultServiceLog.level}</org.ops4j.pax.logging.DefaultServiceLog.level>
+                        <pax.exam.log.level>${pax.exam.log.level}</pax.exam.log.level>
+                        <java.protocol.handler.pkgs>org.ops4j.pax.url</java.protocol.handler.pkgs>
+                        <bundle.file.name>${bundle.file.name}</bundle.file.name>
+                    </systemPropertyVariables>
+                    <classpathDependencyExcludes>
+                        <!-- The osgi.org dependencies cause trouble with pax exam -->
+                        <classpathDependencyExcludes>org.osgi:org.osgi.core</classpathDependencyExcludes>

+                        <classpathDependencyExcludes>org.osgi:org.osgi.compendium</classpathDependencyExcludes>

+                    </classpathDependencyExcludes>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
     <dependencies>
@@ -114,7 +146,6 @@
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
-
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
@@ -141,8 +172,14 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.paxexam.util</artifactId>
+            <version>1.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.testing</artifactId>
-            <version>2.0.6</version>
+            <version>2.0.14</version>
             <scope>test</scope>
             <exclusions>
                 <!-- slf4j simple implementation logs INFO + higher to stdout (we don't
want that behaviour) -->
@@ -165,6 +202,36 @@
             <version>1.2.13</version>
             <scope>test</scope>
         </dependency>
-    </dependencies>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-container-native</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-junit4</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-link-mvn</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.url</groupId>
+            <artifactId>pax-url-aether</artifactId>
+            <version>${url.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <version>4.2.1</version>
+            <scope>test</scope>
+        </dependency>
+      </dependencies>
 
 </project>

Modified: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java?rev=1539396&r1=1539395&r2=1539396&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java
(original)
+++ sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java
Wed Nov  6 16:56:03 2013
@@ -202,44 +202,6 @@ public class JcrResourceBundleTest exten
         getSession().save();
     }
 
-    // ---------------------------------------------------------------< test data helper
>
-
-    /**
-     * Helper class for creating test data in a generic way.
-     */
-    public static class Message {
-        public String key;
-        public String message;
-        public boolean useNodeName;
-        public String path;
-
-        public Message(String path, String key, String message, boolean useNodeName) {
-            this.path = path;
-            this.key = key;
-            this.message = message;
-            this.useNodeName = useNodeName;
-        }
-
-        private static int nodeNameCounter = 0;
-
-        public void add(Node languageNode) throws RepositoryException {
-            Node node = languageNode;
-            String[] pathElements = path.split("/");
-            for (String pathStep : pathElements) {
-                if (pathStep != null && pathStep.length() > 0) {
-                    node = node.addNode(pathStep, "nt:folder");
-                }
-            }
-            if (useNodeName) {
-                node = node.addNode(key, "sling:MessageEntry");
-            } else {
-                node = node.addNode("node" + nodeNameCounter, "sling:MessageEntry");
-                nodeNameCounter++;
-                node.setProperty("sling:key", key);
-            }
-            node.setProperty("sling:message", message);
-        }
-    }
 
     // test data to add to the repository (use linked hash map for insertion order)
     public static final Map<String, Message> MESSAGES_DE = new LinkedHashMap<String,
Message>();

Added: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/Message.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/Message.java?rev=1539396&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/Message.java
(added)
+++ sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/Message.java
Wed Nov  6 16:56:03 2013
@@ -0,0 +1,60 @@
+/*
+ * 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.sling.i18n.impl;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * Helper class for creating test data in a generic way.
+ */
+public class Message {
+    public String key;
+    public String message;
+    public boolean useNodeName;
+    public String path;
+
+    public Message(String path, String key, String message, boolean useNodeName) {
+        this.path = path;
+        this.key = key;
+        this.message = message;
+        this.useNodeName = useNodeName;
+    }
+
+    private static int nodeNameCounter = 0;
+
+    public void add(Node languageNode) throws RepositoryException {
+        Node node = languageNode;
+        String[] pathElements = path.split("/");
+        for (String pathStep : pathElements) {
+            if (pathStep != null && pathStep.length() > 0) {
+                node = node.addNode(pathStep, "nt:folder");
+            }
+        }
+        if (useNodeName) {
+            node = node.addNode(key, "sling:MessageEntry");
+        } else {
+            node = node.addNode("node" + nodeNameCounter, "sling:MessageEntry");
+            nodeNameCounter++;
+            node.setProperty("sling:key", key);
+        }
+        node.setProperty("sling:message", message);
+    }
+}
+

Propchange: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/Message.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/Message.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java?rev=1539396&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java
(added)
+++ sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java
Wed Nov  6 16:56:03 2013
@@ -0,0 +1,170 @@
+/*
+ * 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.sling.i18n.it;
+
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+import static org.ops4j.pax.exam.CoreOptions.bundle;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+
+import java.io.File;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import javax.inject.Inject;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.sling.i18n.ResourceBundleProvider;
+import org.apache.sling.i18n.impl.Message;
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.paxexam.util.SlingPaxOptions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.options.DefaultCompositeOption;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class ResourceBundleProviderIT {
+
+    public static final int RETRY_TIMEOUT_MSEC = 5000;
+    public static final String MSG_KEY = "foo";
+    
+    @Inject
+    private SlingRepository repository;
+    
+    @Inject
+    private ResourceBundleProvider resourceBundleProvider;
+    
+    private Session session;
+    private Node i18nRoot;
+    private Node deRoot;
+    private Node frRoot;
+    
+    @org.ops4j.pax.exam.Configuration
+    public Option[] config() {
+        final File thisProjectsBundle = new File(System.getProperty( "bundle.file.name",
"BUNDLE_FILE_NOT_SET" ));
+        return new DefaultCompositeOption(
+                SlingPaxOptions.defaultLaunchpadOptions("7-SNAPSHOT"),
+                provision(bundle(thisProjectsBundle.toURI().toString()))
+                ).getOptions();
+    }
+    
+    static abstract class Retry {
+        Retry(int timeoutMsec) {
+            final long timeout = System.currentTimeMillis() + timeoutMsec;
+            Throwable lastT = null;
+            while(System.currentTimeMillis() < timeout) {
+                try {
+                    lastT = null;
+                    exec();
+                    break;
+                } catch(Throwable t) {
+                    lastT = t;
+                }
+            }
+            
+            if(lastT != null) {
+                fail("Failed after " + timeoutMsec + " msec: " + lastT);
+            }
+        }
+        
+        protected abstract void exec() throws Exception;
+    }
+    
+    @Before
+    public void setup() throws RepositoryException {
+        session = repository.loginAdministrative(null);
+        final Node root = session.getRootNode();
+        Node libs = null;
+        if(root.hasNode("libs")) {
+           libs = root.getNode("libs"); 
+        } else {
+           libs = root.addNode("libs", "nt:unstructured"); 
+        }
+        i18nRoot = libs.addNode("i18n", "nt:unstructured");
+        deRoot = addLanguageNode(i18nRoot, "de");
+        frRoot = addLanguageNode(i18nRoot, "fr");
+        session.save();
+    }
+    
+    @After
+    public void cleanup() throws RepositoryException {
+        i18nRoot.remove();
+        session.save();
+        session.logout();
+    }
+    
+    private Node addLanguageNode(Node parent, String language) throws RepositoryException
{
+        final Node child = parent.addNode(language, "nt:folder");
+        child.addMixin("mix:language");
+        child.setProperty("jcr:language", language);
+        return child;
+    }
+    
+    private void assertMessages(final String deMessage, final String frMessage) {
+        new Retry(RETRY_TIMEOUT_MSEC) {
+            protected void exec() {
+                {
+                    final ResourceBundle de = resourceBundleProvider.getResourceBundle(Locale.GERMAN);
+                    assertNotNull(de);
+                    assertEquals(deMessage, de.getString(MSG_KEY));
+                }
+                {
+                    final ResourceBundle fr = resourceBundleProvider.getResourceBundle(Locale.FRENCH);
+                    assertNotNull(fr);
+                    assertEquals(frMessage, fr.getString(MSG_KEY));
+                }
+            }
+        };
+    }
+
+    @Test
+    public void testRepositoryName() {
+        // We could use JUnit categories to select tests, as we
+        // do in our integration tests, but let's avoid a dependency on 
+        // that in this module
+        if(System.getProperty("sling.run.modes", "").contains("oak")) {
+            assertEquals("Apache Jackrabbit Oak", repository.getDescriptor("jcr.repository.name"));
+        } else {
+            assertEquals("Jackrabbit", repository.getDescriptor("jcr.repository.name"));
+        }
+    }
+
+    @Test
+    public void testChangesDetection() throws RepositoryException {
+        new Message("", MSG_KEY, "DE_message", false).add(deRoot);
+        new Message("", MSG_KEY, "FR_message", false).add(frRoot);
+        session.save();
+        assertMessages("DE_message", "FR_message");
+        
+        new Message("", MSG_KEY, "DE_changed", false).add(deRoot);
+        new Message("", MSG_KEY, "FR_changed", false).add(frRoot);
+        session.save();
+        assertMessages("DE_changed", "FR_changed");
+    }
+}

Propchange: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/it/ResourceBundleProviderIT.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message