1 /* 2 Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License, version 2.0, 6 as published by the Free Software Foundation. 7 8 This program is also distributed with certain software (including 9 but not limited to OpenSSL) that is licensed under separate terms, 10 as designated in a particular file or component or in included license 11 documentation. The authors of MySQL hereby grant you an additional 12 permission to link the program and your derivative works with the 13 separately licensed software that they have included with MySQL. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License, version 2.0, for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 */ 24 25 package testsuite.clusterj; 26 27 import java.util.Properties; 28 29 import com.mysql.clusterj.Constants; 30 31 import testsuite.clusterj.model.Employee; 32 33 public class DefaultConnectValuesTest extends AbstractClusterJModelTest { 34 35 private static final int NUMBER_TO_INSERT = 1; 36 37 @Override localSetUp()38 public void localSetUp() { 39 createSessionFactory(); 40 session = sessionFactory.getSession(); 41 createEmployeeInstances(NUMBER_TO_INSERT); 42 tx = session.currentTransaction(); 43 tx.begin(); 44 session.deletePersistentAll(Employee.class); 45 tx.commit(); 46 addTearDownClasses(Employee.class); 47 } 48 49 /** Remove the properties that can be defaulted. 50 */ 51 @Override modifyProperties()52 protected Properties modifyProperties() { 53 Properties modifiedProperties = new Properties(); 54 modifiedProperties.putAll(props); 55 modifiedProperties.remove(Constants.PROPERTY_CLUSTER_CONNECT_DELAY); 56 modifiedProperties.remove(Constants.PROPERTY_CLUSTER_CONNECT_RETRIES); 57 modifiedProperties.remove(Constants.PROPERTY_CLUSTER_CONNECT_TIMEOUT_AFTER); 58 modifiedProperties.remove(Constants.PROPERTY_CLUSTER_CONNECT_TIMEOUT_BEFORE); 59 modifiedProperties.remove(Constants.PROPERTY_CLUSTER_CONNECT_VERBOSE); 60 modifiedProperties.remove(Constants.PROPERTY_CLUSTER_DATABASE); 61 modifiedProperties.remove(Constants.PROPERTY_CLUSTER_MAX_TRANSACTIONS); 62 return modifiedProperties; 63 } 64 testFind()65 public void testFind() { 66 // first, create instances to find 67 tx = session.currentTransaction(); 68 tx.begin(); 69 70 int count = 0; 71 72 for (int i = 0; i < NUMBER_TO_INSERT; ++i) { 73 // must be done with an active transaction 74 session.makePersistent(employees.get(i)); 75 ++count; 76 } 77 tx.commit(); 78 79 tx.begin(); 80 81 for (int i = 0; i < NUMBER_TO_INSERT; ++i) { 82 // must be done with an active transaction 83 Employee e = session.find(Employee.class, i); 84 // make sure all fields were fetched 85 consistencyCheck(e); 86 // see if it is the right Employee 87 int actualId = e.getId(); 88 if (actualId != i) { 89 error("Expected Employee.id " + i + " but got " + actualId); 90 } 91 } 92 tx.commit(); 93 failOnError(); 94 } 95 } 96