1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.jdo.tck.query.jdoql.parameters; 19 20 import javax.jdo.JDOUserException; 21 import javax.jdo.PersistenceManager; 22 import javax.jdo.Query; 23 import javax.jdo.Transaction; 24 25 import org.apache.jdo.tck.JDO_Test; 26 import org.apache.jdo.tck.pc.mylib.PrimitiveTypes; 27 import org.apache.jdo.tck.query.QueryTest; 28 import org.apache.jdo.tck.util.BatchTestRunner; 29 30 /** 31 *<B>Title:</B> Primtive type parameter executed null value 32 *<BR> 33 *<B>Keywords:</B> query 34 *<BR> 35 *<B>Assertion ID:</B> A14.6.3-1. 36 *<BR> 37 *<B>Assertion Description: </B> 38 * If a parameter type is specified as a primitive, the parameter value 39 * passed to execute() must not be null or a JDOUserException is thrown. 40 */ 41 42 public class PrimitiveParameterPassedAsNull extends QueryTest { 43 44 /** */ 45 private static final String ASSERTION_FAILED = 46 "Assertion A14.6.3-1 (PrimitiveParameterPassedAsNull) failed: "; 47 48 /** 49 * The <code>main</code> is called when the class 50 * is directly executed from the command line. 51 * @param args The arguments passed to the program. 52 */ 53 public static void main(String[] args) { 54 BatchTestRunner.run(PrimitiveParameterPassedAsNull.class); 55 } 56 57 /** */ 58 public void testPositive() { 59 PersistenceManager pm = getPM(); 60 Transaction tx = pm.currentTransaction(); 61 tx.begin(); 62 63 Query q = pm.newQuery(PrimitiveTypes.class, "intNotNull == param"); 64 q.declareParameters("int param"); 65 try { 66 q.execute(null); 67 fail(ASSERTION_FAILED, 68 "query.execute should throw JDOUserException if the actual " + 69 "value of a primitive type parameter is null"); 70 } 71 catch (JDOUserException ex) { 72 if(debug) logger.debug("caught expected exception " + ex); 73 } 74 75 tx.commit(); 76 77 } 78 79 /** 80 * @see JDO_Test#localSetUp() 81 */ 82 protected void localSetUp() { 83 addTearDownClass(PrimitiveTypes.class); 84 loadAndPersistPrimitiveTypes(getPM()); 85 } 86 }