incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r354176 - in /incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test: ./ org/ org/apache/ org/apache/portals/ org/apache/portals/graffito/ org/apache/portals/graffito/jcr/ org/apache/portals/graffito/jcr/nodemanagement/ org/apache/portals...
Date Mon, 05 Dec 2005 20:40:04 GMT
Author: clombart
Date: Mon Dec  5 12:39:58 2005
New Revision: 354176

URL: http://svn.apache.org/viewcvs?rev=354176&view=rev
Log:
Move jcr-mapping project

Added:
    incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/
    incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/log4j.properties
    incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/
    incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/
    incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/
    incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/
    incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/
    incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/
    incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/TestBase.java
    incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/impl/
    incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/impl/jackrabbit/
    incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/impl/jackrabbit/NodeTypeManagerImplTest.java

Added: incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/log4j.properties
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/log4j.properties?rev=354176&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/log4j.properties (added)
+++ incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/log4j.properties Mon Dec  5 12:39:58
2005
@@ -0,0 +1,38 @@
+/* ========================================================================
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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.
+ * ========================================================================
+ */
+
+# ------------------------------------------------------------------------
+#
+# Logging Configuration
+#
+# $Id: Log4j.properties,v 1.3 2004/12/22 20:37:04 christophe Exp $
+#
+# ------------------------------------------------------------------------
+
+log4j.rootLogger = WARN, console
+
+log4j.category.org.apache.portals.graffito.jcr.nodemanagement=DEBUG, console
+log4j.additivity.org.apache.portals.graffito.jcr.nodemanagement=false
+
+#
+# Console
+#
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+
+# Pattern to output the caller's file name and line number.
+log4j.appender.console.layout.ConversionPattern=%5p: %m%n

Added: incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/TestBase.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/TestBase.java?rev=354176&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/TestBase.java
(added)
+++ incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/TestBase.java
Mon Dec  5 12:39:58 2005
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * 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.apache.portals.graffito.jcr.nodemanagement;
+
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.nodetype.PropertyDefinition;
+
+import junit.framework.TestCase;
+import org.apache.portals.graffito.jcr.nodemanagement.impl.RepositoryConfiguration;
+import org.apache.portals.graffito.jcr.nodemanagement.impl.RepositorySessionFactory;
+
+import org.apache.portals.graffito.jcr.repository.RepositoryUtil;
+
+/** Base class of JUnit test cases.
+ *
+ * @author Oliver Kiessler
+ */
+public class TestBase  extends TestCase
+{
+    protected static Session session;
+    
+    /**
+     * Setting up the testcase.
+     *
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        if (session == null)
+        {
+            RepositoryConfiguration configuration = new RepositoryConfiguration();
+            configuration.setConfigurationFile("./src/config/jackrabbit/repository.xml");
+            configuration.setRepositoryName("repositoryTest");
+            configuration.setRepositoryPath("./target/repository");
+            session = RepositorySessionFactory.getSession(RepositorySessionFactory.JACKRABBIT,
"superuser", "superuser", configuration);
+            
+            /*RepositoryConfiguration configuration = new RepositoryConfiguration();
+            configuration.setConfigurationFile("./src/config/jeceria/jeceira.xml");
+            configuration.setRepositoryName("test");
+            session = RepositorySessionFactory.getSession(RepositorySessionFactory.JECEIRA,
null, null, configuration);*/
+        }       
+    }
+
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    public void tearDown() throws Exception
+    {
+    }
+    
+    /** Returns true if a property was found in an array of property defintions.
+     * 
+     * @param defintions PropertyDefinition[]
+     * @param propertyName Name of property to find
+     * @return true/false
+     */
+    public boolean containsPropertyDefintion(PropertyDefinition[] definitions,
+            String propertyName)
+    {
+        boolean found = false;
+        
+        if (definitions != null && definitions.length > 0)
+        {
+            for (int i = 0; i < definitions.length; i++)
+            {
+                if (definitions[i].getName().equals(propertyName))
+                {
+                    found = true;
+                }
+            }
+        }
+        
+        return found;
+    }
+}

Added: incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/impl/jackrabbit/NodeTypeManagerImplTest.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/impl/jackrabbit/NodeTypeManagerImplTest.java?rev=354176&view=auto
==============================================================================
--- incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/impl/jackrabbit/NodeTypeManagerImplTest.java
(added)
+++ incubator/graffito/trunk/jcr/jcr-nodemanagement/src/test/org/apache/portals/graffito/jcr/nodemanagement/impl/jackrabbit/NodeTypeManagerImplTest.java
Mon Dec  5 12:39:58 2005
@@ -0,0 +1,176 @@
+/*
+ * Copyright 2000-2005 The Apache Software Foundation.
+ * 
+ * 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.apache.portals.graffito.jcr.nodemanagement.impl.jackrabbit;
+
+import java.io.FileInputStream;
+
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
+
+import junit.framework.*;
+import org.apache.portals.graffito.jcr.mapper.model.ClassDescriptor;
+import org.apache.portals.graffito.jcr.mapper.model.FieldDescriptor;
+
+import org.apache.portals.graffito.jcr.nodemanagement.TestBase;
+import org.apache.portals.graffito.jcr.nodemanagement.exception.NamespaceCreationException;
+
+/** JUnit test for NodeTypeManagerImpl.
+ *
+ * @author <a href="mailto:okiessler@apache.org">Oliver Kiessler</a>
+ */
+public class NodeTypeManagerImplTest extends TestBase {
+    
+    /** Class to test.
+     */
+    private NodeTypeManagerImpl jackrabbitNodeTypeManagerImpl
+                = new NodeTypeManagerImpl();
+    
+    /** Returns testsuite.
+     * @return suite
+     */
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite(NodeTypeManagerImplTest.class);
+        return suite;
+    }
+
+    /**
+     * Test of createNamespace method, of class org.apache.portals.graffito.jcr.nodemanagement.impl.jackrabbit.NodeTypeManagerImpl.
+     */
+    public void testCreateNamespace() throws Exception
+    {
+        getJackrabbitNodeTypeManagerImpl().createNamespace(session,
+                "test", "http://www.test.com/test-uri");
+        
+        assertEquals(session.getWorkspace().getNamespaceRegistry().getPrefix("http://www.test.com/test-uri"),
"test");
+        assertEquals(session.getWorkspace().getNamespaceRegistry().getURI("test"), "http://www.test.com/test-uri");
+        
+        boolean failed = false;
+        
+        try
+        {
+            getJackrabbitNodeTypeManagerImpl().createNamespace(session,
+                    "test", "http://www.test.com/test-uri");
+        } catch (NamespaceCreationException nce) {
+            // expected
+            failed = true;
+        }
+
+        assertTrue(failed);
+    }
+
+    /**
+     * Test of createNodeTypesFromConfiguration method, of class org.apache.portals.graffito.jcr.nodemanagement.impl.jackrabbit.NodeTypeManagerImpl.
+     * @throws java.lang.Exception 
+     */
+    public void testCreateNodeTypesFromConfiguration() throws Exception
+    {
+        getJackrabbitNodeTypeManagerImpl().createNodeTypesFromConfiguration(session,
+                new FileInputStream("./src/config/jackrabbit/nodetypes_test1.xml"));
+        
+        NodeType test1 = session.getWorkspace().getNodeTypeManager().getNodeType("graffito:test1");
+        assertNotNull(test1);
+        assertFalse(test1.isMixin());
+        assertFalse(test1.hasOrderableChildNodes());
+        assertEquals(test1.getPrimaryItemName(), "test1");
+        assertEquals(test1.getSupertypes().length, 1);
+        assertEquals(test1.getSupertypes()[0].getName(), "nt:base");
+        assertTrue(containsPropertyDefintion(test1.getPropertyDefinitions(), "graffito:testProperty"));
+    }
+    
+    /**
+     * Test of createSingleNodeType method, of class org.apache.portals.graffito.jcr.nodemanagement.impl.jackrabbit.NodeTypeManagerImpl.
+     * @throws java.lang.Exception 
+     */
+    public void testCreateSingleNodeType() throws Exception
+    {
+        ClassDescriptor classDescriptor = new ClassDescriptor();
+        classDescriptor.setClassName("test.TestClass");
+        classDescriptor.setJcrNodeType("graffito:test2");
+        classDescriptor.setJcrSuperTypes("nt:base");
+        
+        FieldDescriptor field1 = new FieldDescriptor();
+        field1.setFieldName("a");
+        field1.setJcrName("graffito:a");
+        field1.setJcrType("String");
+        classDescriptor.addFieldDescriptor(field1);
+
+        FieldDescriptor field2 = new FieldDescriptor();
+        field2.setFieldName("b");
+        field2.setJcrName("graffito:b");
+        field2.setJcrType("Long");
+        classDescriptor.addFieldDescriptor(field2);        
+
+        getJackrabbitNodeTypeManagerImpl().createSingleNodeType(session, classDescriptor);
+        
+        NodeType test2 = session.getWorkspace().getNodeTypeManager().getNodeType("graffito:test2");
+        assertNotNull(test2);
+        assertFalse(test2.isMixin());
+        assertEquals(test2.getName(), "graffito:test2");
+        assertEquals(test2.getSupertypes().length, 1);
+        assertEquals(test2.getSupertypes()[0].getName(), "nt:base");
+
+        // 2 defined in graffito:test2 and 2 inherited from nt:base
+        assertEquals(test2.getPropertyDefinitions().length, 4);
+        
+        assertTrue(containsProperty("graffito:a", test2.getPropertyDefinitions()));
+        assertTrue(containsProperty("graffito:b", test2.getPropertyDefinitions()));
+        assertTrue(containsProperty("jcr:primaryType", test2.getPropertyDefinitions()));
+        assertTrue(containsProperty("jcr:mixinTypes", test2.getPropertyDefinitions()));
+    }
+
+    /** Returns true if a given property is found in an arry of property
+     * definitions.
+     * 
+     * @param propertyName Name of property to find
+     * @param propDefs Properties of a node type
+     * @return true/false 
+     */
+    protected boolean containsProperty(String propertyName,
+            PropertyDefinition[] propDefs)
+    {
+        boolean found = false;
+        
+        for (int i = 0; i < propDefs.length; i++)
+        {
+           if (propDefs[i].getName().equals(propertyName))
+           {
+               found = true;
+               break;
+           }
+        }
+
+        return found;
+    }
+    
+    /** Getter for property jackrabbitNodeTypeManagerImpl.
+     * 
+     * @return jackrabbitNodeTypeManagerImpl
+     */
+    public NodeTypeManagerImpl getJackrabbitNodeTypeManagerImpl()
+    {
+        return jackrabbitNodeTypeManagerImpl;
+    }
+
+    /** Setter for property jackrabbitNodeTypeManagerImpl.
+     * 
+     * @param object jackrabbitNodeTypeManagerImpl
+     */
+    public void setJackrabbitNodeTypeManagerImpl(NodeTypeManagerImpl object)
+    {
+        this.jackrabbitNodeTypeManagerImpl = object;
+    }
+}



Mime
View raw message