Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 13466 invoked from network); 31 May 2007 11:54:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 31 May 2007 11:54:39 -0000 Received: (qmail 42029 invoked by uid 500); 31 May 2007 11:54:42 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 41988 invoked by uid 500); 31 May 2007 11:54:42 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 41971 invoked by uid 99); 31 May 2007 11:54:42 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 May 2007 04:54:42 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 May 2007 04:54:37 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 573DB1A981A; Thu, 31 May 2007 04:54:17 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r543120 - /jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/PropertyLengthTest.java Date: Thu, 31 May 2007 11:54:17 -0000 To: commits@jackrabbit.apache.org From: angela@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070531115417.573DB1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: angela Date: Thu May 31 04:54:16 2007 New Revision: 543120 URL: http://svn.apache.org/viewvc?view=rev&rev=543120 Log: test property length for all types of values Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/PropertyLengthTest.java (with props) Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/PropertyLengthTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/PropertyLengthTest.java?view=auto&rev=543120 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/PropertyLengthTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/PropertyLengthTest.java Thu May 31 04:54:16 2007 @@ -0,0 +1,150 @@ +/* + * 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.jackrabbit.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.jackrabbit.test.AbstractJCRTest; +import org.apache.jackrabbit.test.NotExecutableException; +import org.apache.jackrabbit.test.api.PropertyUtil; + +import javax.jcr.Property; +import javax.jcr.PropertyType; +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.Value; +import javax.jcr.ValueFactory; +import java.util.Calendar; + +/** + * PropertyLengthTest... + */ +public class PropertyLengthTest extends AbstractJCRTest { + + private static Logger log = LoggerFactory.getLogger(PropertyLengthTest.class); + + private static long getValueLength(Value val) throws RepositoryException { + long valLength; + if (val.getType() == PropertyType.BINARY) { + valLength = PropertyUtil.countBytes(val); + } else { + valLength = val.getString().length(); + } + return valLength; + } + + private Property getProperty(int propertyType) throws RepositoryException, NotExecutableException { + Property p = PropertyUtil.searchProp(testRootNode.getSession(), testRootNode, propertyType); + if (p == null) { + try { + Value val; + ValueFactory factory = testRootNode.getSession().getValueFactory(); + switch (propertyType) { + case PropertyType.BINARY: + val = factory.createValue("binaryValue", PropertyType.BINARY); + break; + case PropertyType.BOOLEAN: + val = factory.createValue(true); + break; + case PropertyType.DATE: + val = factory.createValue(Calendar.getInstance()); + break; + case PropertyType.DOUBLE: + val = factory.createValue(new Double(134).doubleValue()); + break; + case PropertyType.LONG: + val = factory.createValue(new Long(134).longValue()); + break; + case PropertyType.NAME: + val = factory.createValue(ntBase, PropertyType.NAME); + break; + case PropertyType.PATH: + val = factory.createValue(testRootNode.getPath(), PropertyType.PATH); + break; + case PropertyType.REFERENCE: + Node refNode = testRootNode.addNode(nodeName1); + if (refNode.canAddMixin(mixReferenceable)) { + testRootNode.addMixin(mixReferenceable); + } + testRootNode.save(); + val = factory.createValue(refNode); + break; + case PropertyType.STRING: + val = factory.createValue("StringValue"); + break; + default: + throw new IllegalArgumentException("Invalid property value type" + propertyType); + } + p = testRootNode.setProperty(propertyName1, val); + } catch (RepositoryException e) { + log.error("Unable to create Property of type " + propertyType); + throw new NotExecutableException(); + } + } + return p; + } + + private static void checkLength(Property p) throws RepositoryException { + if (p.getDefinition().isMultiple()) { + Value[] vals = p.getValues(); + long[] lengths = p.getLengths(); + for (int i = 0; i < lengths.length; i++) { + assertTrue("Wrong property length", lengths[i] == getValueLength(vals[i])); + } + } else { + assertTrue("Wrong property length", p.getLength() == getValueLength(p.getValue())); + } + } + + public void testLengthOfBinary() throws RepositoryException, NotExecutableException { + Property p = getProperty(PropertyType.BINARY); + checkLength(p); + } + + public void testLengthOfBoolean() throws RepositoryException, NotExecutableException { + Property p = getProperty(PropertyType.BOOLEAN); + checkLength(p); + } + public void testLengthOfDate() throws RepositoryException, NotExecutableException { + Property p = getProperty(PropertyType.DATE); + checkLength(p); + } + public void testLengthOfDouble() throws RepositoryException, NotExecutableException { + Property p = getProperty(PropertyType.DOUBLE); + checkLength(p); + } + public void testLengthOfLong() throws RepositoryException, NotExecutableException { + Property p = getProperty(PropertyType.LONG); + checkLength(p); + } + public void testLengthOfName() throws RepositoryException, NotExecutableException { + Property p = getProperty(PropertyType.NAME); + checkLength(p); + } + public void testLengthOfPath() throws RepositoryException, NotExecutableException { + Property p = getProperty(PropertyType.PATH); + checkLength(p); + } + public void testLengthOfReference() throws RepositoryException, NotExecutableException { + Property p = getProperty(PropertyType.REFERENCE); + checkLength(p); + } + public void testLengthOfString() throws RepositoryException, NotExecutableException { + Property p = getProperty(PropertyType.STRING); + checkLength(p); + } +} \ No newline at end of file Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/PropertyLengthTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/PropertyLengthTest.java ------------------------------------------------------------------------------ svn:keywords = author date id revision url