Return-Path: X-Original-To: apmail-db-torque-dev-archive@www.apache.org Delivered-To: apmail-db-torque-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 80F11DCB3 for ; Wed, 12 Dec 2012 20:14:15 +0000 (UTC) Received: (qmail 47062 invoked by uid 500); 12 Dec 2012 20:14:15 -0000 Delivered-To: apmail-db-torque-dev-archive@db.apache.org Received: (qmail 47032 invoked by uid 500); 12 Dec 2012 20:14:15 -0000 Mailing-List: contact torque-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Apache Torque Developers List" Reply-To: "Apache Torque Developers List" Delivered-To: mailing list torque-dev@db.apache.org Received: (qmail 47022 invoked by uid 500); 12 Dec 2012 20:14:15 -0000 Received: (qmail 47019 invoked by uid 99); 12 Dec 2012 20:14:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Dec 2012 20:14:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Dec 2012 20:14:14 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0FD83238890B; Wed, 12 Dec 2012 20:13:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1420945 - /db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/RetrieveByPkTest.java Date: Wed, 12 Dec 2012 20:13:53 -0000 To: torque-commits@db.apache.org From: tfischer@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121212201354.0FD83238890B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tfischer Date: Wed Dec 12 20:13:52 2012 New Revision: 1420945 URL: http://svn.apache.org/viewvc?rev=1420945&view=rev Log: test the retrieveByPk methods Added: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/RetrieveByPkTest.java Added: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/RetrieveByPkTest.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/RetrieveByPkTest.java?rev=1420945&view=auto ============================================================================== --- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/RetrieveByPkTest.java (added) +++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/RetrieveByPkTest.java Wed Dec 12 20:13:52 2012 @@ -0,0 +1,119 @@ +package org.apache.torque.generated.peer; + +/* + * 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. + */ + +import java.math.BigDecimal; +import java.util.List; + +import org.apache.torque.BaseDatabaseTestCase; +import org.apache.torque.NoRowsException; +import org.apache.torque.om.NumberKey; +import org.apache.torque.om.ObjectKey; +import org.apache.torque.test.dbobject.Author; +import org.apache.torque.test.peer.AuthorPeer; + +/** + * Tests the retrieveByPk methods. + * + * @version $Id: SelectTest.java 1411555 2012-11-20 06:00:34Z tfischer $ + */ +public class RetrieveByPkTest extends BaseDatabaseTestCase +{ + private List authorList; + + @Override + public void setUp() throws Exception + { + super.setUp(); + cleanBookstore(); + authorList = insertBookstoreData(); + } + + /** + * Tests retrieveByPk using a simple primary key + * + * @throws Exception if the test fails + */ + public void testRetrieveByPk() throws Exception + { + ObjectKey primaryKey = authorList.get(1).getPrimaryKey(); + Author author = AuthorPeer.retrieveByPK(primaryKey); + assertEquals("Expected author with Id " + + authorList.get(1).getAuthorId() + + " at first position but got " + + author.getAuthorId(), + authorList.get(1).getAuthorId(), + author.getAuthorId()); + } + + /** + * Tests retrieveByPk using a non-existent primary key + * + * @throws Exception if the test fails + */ + public void testRetrieveByNonExistingPk() throws Exception + { + ObjectKey primaryKey = new NumberKey(-1); + try + { + AuthorPeer.retrieveByPK(primaryKey); + } + catch (NoRowsException e) + { + assertEquals("Failed to select a row.", e.getMessage()); + } + } + + /** + * Tests retrieveByPk using a key object with a value of null. + * + * @throws Exception if the test fails + */ + public void testRetrieveByNullValuePk() throws Exception + { + ObjectKey primaryKey = new NumberKey((BigDecimal) null); + try + { + AuthorPeer.retrieveByPK(primaryKey); + } + catch (NoRowsException e) + { + assertEquals("Failed to select a row.", e.getMessage()); + } + } + + /** + * Tests retrieveByPk using a null key. + * + * @throws Exception if the test fails + */ + public void testRetrieveByNullPk() throws Exception + { + try + { + AuthorPeer.retrieveByPK(null); + } + catch (NoRowsException e) + { + assertEquals("Failed to select a row.", e.getMessage()); + } + } + // TODO test retrieveByPks +} --------------------------------------------------------------------- To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org For additional commands, e-mail: torque-dev-help@db.apache.org