From do-not-reply at jboss.org Fri Jan 29 06:38:42 2010
Content-Type: multipart/mixed; boundary="===============9051722167606023114=="
MIME-Version: 1.0
From: do-not-reply at jboss.org
To: exo-jcr-commits at lists.jboss.org
Subject: [exo-jcr-commits] exo-jcr SVN: r1622 -
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/nodetypes.
Date: Fri, 29 Jan 2010 06:38:42 -0500
Message-ID: <201001291138.o0TBcgqG023361@svn01.web.mwc.hst.phx2.redhat.com>
--===============9051722167606023114==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Author: areshetnyak
Date: 2010-01-29 06:38:41 -0500 (Fri, 29 Jan 2010)
New Revision: 1622
Added:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/=
jcr/usecases/nodetypes/TestGettingExoScriptProperty.java
Log:
EXOJCR-449 : Add test TestGettingExoScriptProperty
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/servi=
ces/jcr/usecases/nodetypes/TestGettingExoScriptProperty.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services=
/jcr/usecases/nodetypes/TestGettingExoScriptProperty.java =
(rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services=
/jcr/usecases/nodetypes/TestGettingExoScriptProperty.java 2010-01-29 11:38:=
41 UTC (rev 1622)
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see.
+ */
+package org.exoplatform.services.jcr.usecases.nodetypes;
+
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.PropertyDefinition;
+
+import org.exoplatform.services.jcr.usecases.BaseUsecasesTest;
+
+/**
+ * Created by The eXo Platform SAS.
+ * =
+ *
Date: 2010
+ *
+ * @author Alex Re=
shetnyak =
+ * @version $Id: TestGettingExoScriptProperty.java 111 2010-11-11 11:11:11=
Z rainf0x $
+ */
+public class TestGettingExoScriptProperty
+ extends BaseUsecasesTest
+{
+ =
+ public static final int ANY_PROPERTY_TYPE =3D -1;
+ =
+ public void testLoadPropertyDef() throws Exception
+ {
+ PropertyDefinition propDef =3D locatePropertyDef(session, ANY_PROPERT=
Y_TYPE, false, true, false, false);
+ =
+ System.out.println("\n\n" +propDef.getName() + "\n\n");
+ =
+ assertEquals(true, propDef.isProtected());
+ =
+ if (propDef.getName().equals("exo:script")) {
+ assertEquals(false, propDef.isProtected());
+ }
+ }
+ =
+ public void testExoScriptProperty() throws Exception
+ {
+ Node rootNode =3D session.getRootNode();
+ =
+ Node action =3D rootNode.addNode("123", "exo:scriptAction");
+ =
+ action.setProperty( "exo:name", "exo_name__value");
+ action.setProperty( "exo:lifecyclePhase", "add");
+ action.setProperty( "exo:roles", new String[] {"*"});
+ =
+ action.setProperty( "exo:script", "exo_script__value");
+ session.save();
+ =
+ PropertyDefinition[] propsDef =3D action.getPrimaryNodeType().getDec=
laredPropertyDefinitions();
+ =
+ for (PropertyDefinition pDef : propsDef)
+ {
+ if (pDef.getName().equals("exo:script")) {
+ =
+ assertEquals(pDef.isProtected(), false);
+ return;
+ }
+ }
+ =
+ fail("The property definition is not found.");
+ }
+ =
+ public void testGetPropDefFromNTM() throws Exception
+ {
+ NodeTypeManager manager =3D session.getWorkspace().getNodeTypeManage=
r();
+ =
+ NodeType nt =3D manager.getNodeType("exo:scriptAction");
+ =
+ PropertyDefinition[] propsDef =3D nt.getDeclaredPropertyDefinitions(=
);
+ =
+ for (PropertyDefinition pDef : propsDef)
+ {
+ if (pDef.getName().equals("exo:script")) {
+ assertEquals(pDef.isProtected(), false);
+ return;
+ }
+ }
+ =
+ fail("The property definition is not found.");
+ =
+ }
+
+ public static PropertyDefinition locatePropertyDef(Session session, int=
propertyType, boolean multiple,
+ boolean isProtected, boolean constraints, boolean residual) th=
rows RepositoryException
+ {
+
+ NodeTypeManager manager =3D session.getWorkspace().getNodeTypeManage=
r();
+ NodeTypeIterator types =3D manager.getAllNodeTypes();
+
+ while (types.hasNext())
+ {
+ NodeType type =3D types.nextNodeType();
+ PropertyDefinition propDefs[] =3D type.getDeclaredPropertyDefinit=
ions();
+ for (int i =3D 0; i < propDefs.length; i++)
+ {
+ PropertyDefinition propDef =3D propDefs[i];
+ =
+ System.out.println("\n\n " + propDef.getName());
+
+ if (propertyType !=3D ANY_PROPERTY_TYPE && propDef.getRequired=
Type() !=3D propertyType)
+ {
+ continue;
+ }
+
+ if (propertyType =3D=3D ANY_PROPERTY_TYPE && propDef.getRequir=
edType() =3D=3D PropertyType.UNDEFINED)
+ {
+ continue;
+ }
+
+ if (multiple && !propDef.isMultiple())
+ {
+ continue;
+ }
+ if (!multiple && propDef.isMultiple())
+ {
+ continue;
+ }
+
+ System.out.println("isProtected && !propDef.isProtected() =3D=
=3D" + (isProtected && !propDef.isProtected()));
+ if (isProtected && !propDef.isProtected())
+ {
+ continue;
+ }
+ if (!isProtected && propDef.isProtected())
+ {
+ continue;
+ }
+
+ String vc[] =3D propDef.getValueConstraints();
+ if (!constraints && vc !=3D null && vc.length > 0)
+ {
+ continue;
+ }
+ if (constraints)
+ {
+ // property def with constraints requested
+ if (vc =3D=3D null || vc.length =3D=3D 0)
+ {
+ // property def has no constraints
+ continue;
+ }
+ }
+
+ if (!residual && propDef.getName().equals("*"))
+ {
+ continue;
+ }
+
+ if (residual && !propDef.getName().equals("*"))
+ {
+ continue;
+ }
+
+ // also skip property residual property definition if there
+ // is another residual definition
+ if (residual)
+ {
+ // check if there is another residual property def
+ if (getNumResidualPropDefs(type) > 1)
+ {
+ continue;
+ }
+ }
+
+ if (!residual)
+ {
+ // if not looking for a residual property def then there
+ // must not be any residual definition at all on the node
+ // type
+ if (getNumResidualPropDefs(type) > 0)
+ {
+ continue;
+ }
+ }
+
+ return propDef;
+ }
+ }
+ return null;
+ }
+ =
+ private static int getNumResidualPropDefs(NodeType type) {
+ PropertyDefinition[] pDefs =3D type.getPropertyDefinitions();
+ int residuals =3D 0;
+ for (int j =3D 0; j < pDefs.length; j++) {
+ PropertyDefinition pDef =3D pDefs[j];
+ if (pDef.getName().equals("*")) {
+ residuals++;
+ }
+ }
+ return residuals;
+ }
+}
--===============9051722167606023114==--