From graffito-commits-return-686-apmail-incubator-graffito-commits-archive=www.apache.org@incubator.apache.org Mon May 22 20:08:54 2006 Return-Path: Delivered-To: apmail-incubator-graffito-commits-archive@www.apache.org Received: (qmail 50782 invoked from network); 22 May 2006 20:08:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 May 2006 20:08:54 -0000 Received: (qmail 63157 invoked by uid 500); 22 May 2006 20:08:54 -0000 Mailing-List: contact graffito-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: graffito-dev@incubator.apache.org Delivered-To: mailing list graffito-commits@incubator.apache.org Received: (qmail 63146 invoked by uid 99); 22 May 2006 20:08:54 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 May 2006 13:08:54 -0700 X-ASF-Spam-Status: No, hits=0.6 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 May 2006 13:08:53 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 1021C1A9846; Mon, 22 May 2006 13:08:33 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r408739 - in /incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic: ./ AllTests.java AtomicTest.java NullAtomicTest.java Date: Mon, 22 May 2006 20:08:32 -0000 To: graffito-commits@incubator.apache.org From: clombart@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060522200833.1021C1A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: clombart Date: Mon May 22 13:08:31 2006 New Revision: 408739 URL: http://svn.apache.org/viewvc?rev=408739&view=rev Log: (empty) Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AllTests.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AtomicTest.java incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/NullAtomicTest.java Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AllTests.java URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AllTests.java?rev=408739&view=auto ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AllTests.java (added) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AllTests.java Mon May 22 13:08:31 2006 @@ -0,0 +1,45 @@ +/* ======================================================================== + * 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. + * ======================================================================== + */ +package org.apache.portals.graffito.jcr.persistence.atomic; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup; + + +/** + * Package level tests. + * + * @author Alexandru Popescu + */ +public class AllTests { + + public static Test suite() { + return new RepositoryLifecycleTestSetup(buildSuite()); + } + + public static Test buildSuite() { + TestSuite suite= new TestSuite("Test for org.apache.portals.graffito.jcr.persistence.atomic"); + //$JUnit-BEGIN$ + suite.addTestSuite(AtomicTest.class); + suite.addTestSuite(NullAtomicTest.class); + //$JUnit-END$ + + return suite; + } +} Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AtomicTest.java URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AtomicTest.java?rev=408739&view=auto ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AtomicTest.java (added) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/AtomicTest.java Mon May 22 13:08:31 2006 @@ -0,0 +1,148 @@ +/* ======================================================================== + * 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. + * ======================================================================== + */ +package org.apache.portals.graffito.jcr.persistence.atomic; + +import java.io.ByteArrayInputStream; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.Date; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup; +import org.apache.portals.graffito.jcr.TestBase; +import org.apache.portals.graffito.jcr.persistence.PersistenceManager; +import org.apache.portals.graffito.jcr.testmodel.Atomic; + +/** + * Test Atomic perisstence fields + * + * @author Christophe Lombart + */ +public class AtomicTest extends TestBase +{ + private final static Log log = LogFactory.getLog(AtomicTest.class); + + /** + *

Defines the test case name for junit.

+ * @param testName The test case name. + */ + public AtomicTest(String testName) throws Exception + { + super(testName); + } + + public static Test suite() + { + // All methods starting with "test" will be executed in the test suite. + return new RepositoryLifecycleTestSetup(new TestSuite(AtomicTest.class)); + } + + + /** + * @see junit.framework.TestCase#tearDown() + */ + public void tearDown() throws Exception + { + if (getPersistenceManager().objectExists("/test")) + { + getPersistenceManager().remove("/test"); + getPersistenceManager().save(); + } + + super.tearDown(); + } + + public void testAtomicFields() + { + try + { + PersistenceManager persistenceManager = getPersistenceManager(); + Date date = new Date(); + Calendar calendar = Calendar.getInstance(); + // -------------------------------------------------------------------------------- + // Create and store an object graph in the repository + // -------------------------------------------------------------------------------- + Atomic a = new Atomic(); + a.setPath("/test"); + a.setBooleanObject(new Boolean(true)); + a.setBooleanPrimitive(true); + a.setIntegerObject(new Integer(100)); + a.setIntPrimitive(200); + a.setString("Test String"); + a.setDate(date); + + byte[] content = "Test Byte".getBytes(); + a.setByteArray(content); + a.setCalendar(calendar); + a.setDoubleObject(new Double(2.12)); + a.setDoublePrimitive(1.23); + long now = System.currentTimeMillis(); + a.setTimestamp(new Timestamp(now)); + + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("Test Stream".getBytes()); + a.setInputStream(byteArrayInputStream); + + persistenceManager.insert(a); + persistenceManager.save(); + + + // -------------------------------------------------------------------------------- + // Get the object + // -------------------------------------------------------------------------------- + a = null; + a = (Atomic) persistenceManager.getObject( "/test"); + assertNotNull("a is null", a); + assertNotNull("Boolean object is null", a.getBooleanObject()); + assertTrue("Incorrect boolean object", a.getBooleanObject().booleanValue()); + assertTrue("Incorrect boolean primitive", a.isBooleanPrimitive()); + assertNotNull("Integer Object is null", a.getIntegerObject()); + assertTrue("Incorrect Integer object", a.getIntegerObject().intValue() == 100); + assertTrue("Incorrect int primitive", a.getIntPrimitive() == 200); + assertNotNull("String object is null", a.getString()); + assertTrue("Incorrect boolean object", a.getString().equals("Test String")); + assertNotNull("Byte array object is null", a.getByteArray()); + assertTrue("Incorrect byte object", new String(a.getByteArray()).equals("Test Byte")); + + assertNotNull("date object is null", a.getDate()); + assertTrue("Invalid date", a.getDate().equals(date)); + assertNotNull("calendar object is null", a.getCalendar()); + + log.debug("Calendar : " + a.getCalendar().get(Calendar.YEAR) + "-" + a.getCalendar().get(Calendar.MONTH) + "-" + a.getCalendar().get(Calendar.DAY_OF_MONTH)); + assertTrue("Invalid calendar object", a.getCalendar().equals(calendar)); + + assertNotNull("Double object is null", a.getDoubleObject()); + assertTrue("Incorrect double object", a.getDoubleObject().doubleValue() == 2.12); + assertTrue("Incorrect double primitive", a.getDoublePrimitive() == 1.23); + + assertNotNull("Incorrect input stream primitive", a.getInputStream()); + assertNotNull("Incorrect timestamp", a.getTimestamp()); + assertTrue("Invalid timestamp value ", a.getTimestamp().getTime() == now); + + } + catch (Exception e) + { + e.printStackTrace(); + fail("Exception occurs during the unit test : " + e); + } + + } + +} \ No newline at end of file Added: incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/NullAtomicTest.java URL: http://svn.apache.org/viewvc/incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/NullAtomicTest.java?rev=408739&view=auto ============================================================================== --- incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/NullAtomicTest.java (added) +++ incubator/graffito/trunk/jcr/jcr-mapping/src/test/org/apache/portals/graffito/jcr/persistence/atomic/NullAtomicTest.java Mon May 22 13:08:31 2006 @@ -0,0 +1,133 @@ +/* ======================================================================== + * 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. + * ======================================================================== + */ +package org.apache.portals.graffito.jcr.persistence.atomic; + +import java.io.ByteArrayInputStream; +import java.util.Calendar; +import java.util.Date; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.portals.graffito.jcr.RepositoryLifecycleTestSetup; +import org.apache.portals.graffito.jcr.TestBase; +import org.apache.portals.graffito.jcr.persistence.PersistenceManager; +import org.apache.portals.graffito.jcr.testmodel.Atomic; + +/** + * Test Atomic perisstence fields + * + * @author Christophe Lombart + */ +public class NullAtomicTest extends TestBase +{ + private final static Log log = LogFactory.getLog(NullAtomicTest.class); + + /** + *

Defines the test case name for junit.

+ * @param testName The test case name. + */ + public NullAtomicTest(String testName) + { + super(testName); + } + + public static Test suite() + { + // All methods starting with "test" will be executed in the test suite. + return new RepositoryLifecycleTestSetup(new TestSuite(NullAtomicTest.class)); + } + + + /** + * @see junit.framework.TestCase#tearDown() + */ + public void tearDown() throws Exception + { + if (getPersistenceManager().objectExists("/test")) + { + getPersistenceManager().remove("/test"); + getPersistenceManager().save(); + } + + super.tearDown(); + } + + public void testNullValueAtomicFields() + { + try + { + + PersistenceManager persistenceManager = getPersistenceManager(); + + // -------------------------------------------------------------------------------- + // Create and store an object graph in the repository + // -------------------------------------------------------------------------------- + Atomic a = new Atomic(); + a.setPath("/test"); + a.setIntegerObject(new Integer(100)); + a.setDate(new Date()); + byte[] content = "Test Byte".getBytes(); + a.setByteArray(content); + a.setCalendar(Calendar.getInstance()); + a.setDoubleObject(new Double(2.12)); + a.setDoublePrimitive(1.23); + + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream("Test Stream".getBytes()); + a.setInputStream(byteArrayInputStream); + + persistenceManager.insert(a); + persistenceManager.save(); + + // -------------------------------------------------------------------------------- + // Get the object + // -------------------------------------------------------------------------------- + a = null; + a = (Atomic) persistenceManager.getObject( "/test"); + assertNotNull("a is null", a); + assertNull("Boolean object is not null", a.getBooleanObject()); + + assertFalse("Incorrect boolean primitive", a.isBooleanPrimitive()); + assertNotNull("Integer Object is null", a.getIntegerObject()); + assertTrue("Incorrect Integer object", a.getIntegerObject().intValue() == 100); + assertTrue("Incorrect int primitive", a.getIntPrimitive() == 0); + assertNull("String object is not null", a.getString()); + assertNotNull("Byte array object is null", a.getByteArray()); + assertTrue("Incorrect byte object", new String(a.getByteArray()).equals("Test Byte")); + + assertNotNull("date object is null", a.getDate()); + assertNotNull("calendar object is null", a.getCalendar()); + + assertNotNull("Double object is null", a.getDoubleObject()); + assertTrue("Incorrect double object", a.getDoubleObject().doubleValue() == 2.12); + assertTrue("Incorrect double primitive", a.getDoublePrimitive() == 1.23); + + assertNotNull("Incorrect input stream primitive", a.getInputStream()); + + + } + catch (Exception e) + { + e.printStackTrace(); + fail("Exception occurs during the unit test : " + e); + } + + } + +} \ No newline at end of file