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 org.apache.jdo.tck.pc.company.Person; 21 import org.apache.jdo.tck.query.QueryElementHolder; 22 import org.apache.jdo.tck.query.QueryTest; 23 import org.apache.jdo.tck.util.BatchTestRunner; 24 25 /** 26 *<B>Title:</B> Mixed parameters. 27 *<BR> 28 *<B>Keywords:</B> query 29 *<BR> 30 *<B>Assertion ID:</B> A14.6.3-2. 31 *<BR> 32 *<B>Assertion Description: </B> 33 * Parameters must all be declared explicitly via declareParameters 34 * or all be declared implicitly in the filter. 35 */ 36 public class MixedParameters extends QueryTest { 37 38 /** */ 39 private static final String ASSERTION_FAILED = 40 "Assertion A14.6.3-2 (MixedParameters) failed: "; 41 42 /** 43 * The array of invalid queries which may be executed as 44 * single string queries and as API queries. 45 */ 46 private static final QueryElementHolder[] INVALID_QUERIES = { 47 new QueryElementHolder( 48 /*UNIQUE*/ null, 49 /*RESULT*/ null, 50 /*INTO*/ null, 51 /*FROM*/ Person.class, 52 /*EXCLUDE*/ null, 53 /*WHERE*/ "firstname == param", 54 /*VARIABLES*/ null, 55 /*PARAMETERS*/ null, 56 /*IMPORTS*/ null, 57 /*GROUP BY*/ null, 58 /*ORDER BY*/ null, 59 /*FROM*/ null, 60 /*TO*/ null), 61 new QueryElementHolder( 62 /*UNIQUE*/ null, 63 /*RESULT*/ null, 64 /*INTO*/ null, 65 /*FROM*/ Person.class, 66 /*EXCLUDE*/ null, 67 /*WHERE*/ "firstname == param1 && lastname == :param2", 68 /*VARIABLES*/ null, 69 /*PARAMETERS*/ "String param1", 70 /*IMPORTS*/ null, 71 /*GROUP BY*/ null, 72 /*ORDER BY*/ null, 73 /*FROM*/ null, 74 /*TO*/ null) 75 }; 76 77 /** 78 * The array of valid queries which may be executed as 79 * single string queries and as API queries. 80 */ 81 private static final QueryElementHolder[] VALID_QUERIES = { 82 new QueryElementHolder( 83 /*UNIQUE*/ null, 84 /*RESULT*/ null, 85 /*INTO*/ null, 86 /*FROM*/ Person.class, 87 /*EXCLUDE*/ null, 88 /*WHERE*/ "firstname == param", 89 /*VARIABLES*/ null, 90 /*PARAMETERS*/ "String param", 91 /*IMPORTS*/ null, 92 /*GROUP BY*/ null, 93 /*ORDER BY*/ null, 94 /*FROM*/ null, 95 /*TO*/ null), 96 new QueryElementHolder( 97 /*UNIQUE*/ null, 98 /*RESULT*/ null, 99 /*INTO*/ null, 100 /*FROM*/ Person.class, 101 /*EXCLUDE*/ null, 102 /*WHERE*/ "firstname == :param", 103 /*VARIABLES*/ null, 104 /*PARAMETERS*/ null, 105 /*IMPORTS*/ null, 106 /*GROUP BY*/ null, 107 /*ORDER BY*/ null, 108 /*FROM*/ null, 109 /*TO*/ null) 110 }; 111 112 /** 113 * The <code>main</code> is called when the class 114 * is directly executed from the command line. 115 * @param args The arguments passed to the program. 116 */ 117 public static void main(String[] args) { 118 BatchTestRunner.run(MixedParameters.class); 119 } 120 121 /** */ 122 public void testPositive() { 123 for (int i = 0; i < VALID_QUERIES.length; i++) { 124 compileAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], true); 125 compileSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], true); 126 } 127 } 128 129 public void testNegative() { 130 for (int i = 0; i < INVALID_QUERIES.length; i++) { 131 compileAPIQuery(ASSERTION_FAILED, INVALID_QUERIES[i], false); 132 compileSingleStringQuery(ASSERTION_FAILED, INVALID_QUERIES[i], 133 false); 134 } 135 } 136 }