Return-Path: X-Original-To: apmail-db-jdo-commits-archive@www.apache.org Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 56178F155 for ; Fri, 29 Mar 2013 02:19:10 +0000 (UTC) Received: (qmail 16127 invoked by uid 500); 29 Mar 2013 02:19:09 -0000 Mailing-List: contact jdo-commits-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-commits@db.apache.org Received: (qmail 16112 invoked by uid 99); 29 Mar 2013 02:19:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Mar 2013 02:19:09 +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; Fri, 29 Mar 2013 02:19:05 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5E3B223888E4; Fri, 29 Mar 2013 02:18:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1462379 - in /db/jdo/trunk/tck/src/java/org/apache/jdo/tck: JDO_Test.java api/persistencemanager/GetProperties.java Date: Fri, 29 Mar 2013 02:18:44 -0000 To: jdo-commits@db.apache.org From: clr@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130329021844.5E3B223888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: clr Date: Fri Mar 29 02:18:43 2013 New Revision: 1462379 URL: http://svn.apache.org/r1462379 Log: Add test for new PersistenceManager getProperties Added: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/GetProperties.java (with props) Modified: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/JDO_Test.java Modified: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/JDO_Test.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/JDO_Test.java?rev=1462379&r1=1462378&r2=1462379&view=diff ============================================================================== --- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/JDO_Test.java (original) +++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/JDO_Test.java Fri Mar 29 02:18:43 2013 @@ -1187,6 +1187,36 @@ public abstract class JDO_Test extends T } } + /** Appends an error if the actual value does not equal the expected value. + * Primitive values are autoboxed. Null values are ok for both expected and actual. + */ + protected void errorIfNotEqual(String message, Object expected, Object actual) { + if (expected == null) { + if (actual != null) { + appendMessage(message + " failed. expected: null; actual: " + actual); + } + } else { + if (!expected.equals(actual)) { + appendMessage(message + " failed. expected: " + expected + "; actual: " + actual); + } + } + } + + /** Appends an error if the actual value equals the unexpected value. + * Primitive values are autoboxed. Null values are ok for both unexpected and actual. + */ + protected void errorIfEqual(String message, Object unexpected, Object actual) { + if (unexpected == null) { + if (actual == null) { + appendMessage(message + " failed. unexpected: null"); + } + } else { + if (unexpected.equals(actual)) { + appendMessage(message + " failed. unexpected: " + unexpected); + } + } + } + /** * Returns collected error messages, or null if there * are none, and clears the buffer. Added: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/GetProperties.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/GetProperties.java?rev=1462379&view=auto ============================================================================== --- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/GetProperties.java (added) +++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/GetProperties.java Fri Mar 29 02:18:43 2013 @@ -0,0 +1,263 @@ +/* + * 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. + */ + +package org.apache.jdo.tck.api.persistencemanager; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import javax.jdo.JDOUserException; +import javax.jdo.PersistenceManager; +import javax.jdo.Constants; + +import org.apache.jdo.tck.JDO_Test; + +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title: Test GetProperties + *
+ *Keywords: getProperties getSupportedProperties setProperty + *
+ *Assertion IDs: + *
+ *Assertion Description: + */ + +public class GetProperties extends JDO_Test implements Constants { + + /** */ + private static final String ASSERTION_FAILED_12_19_1 = + "Assertion 12-9-1 setProperty() Set the property name to the specified value. " + + "If a vendor-specific property is not recognized, it is silently ignored. "; + private static final String ASSERTION_FAILED_12_19_2 = + "Assertion 12-9-2 setProperty() If the value for the property is not supported by the implementation, " + + "a JDOUserException is thrown. "; + private static final String ASSERTION_FAILED_12_19_3 = + "Assertion 12-9-3 getProperties() Return a map of String, " + + "Object with the properties and values currently in effect. "; + private static final String ASSERTION_FAILED_12_19_4 = + "Assertion 12-9-4 Changing the values in the map will not affect the properties in the PersistenceManager. "; + private static final String ASSERTION_FAILED_12_19_5 = + "Assertion 12-9-5 getSupportedProperties() Return the set of properties supported by this PersistenceManager. "; + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(GetProperties.class); + } + + private Collection supportedOptions; + private Set supportedProperties; + private static Set testRequiredProperties = new HashSet(); + private static Map> testOptionalProperties = new HashMap>(); + + private interface TestProperty { + void test(PersistenceManager pm, Set supportedProperties); + Object get(PersistenceManager pm); + void set(PersistenceManager pm, Object value); + } + + abstract class AbstractTestProperty implements TestProperty { + String propertyName; + Object testValue1; + Object testValue2; + AbstractTestProperty(String propertyName, Object testValue1, Object testValue2) { + this.propertyName = propertyName; + this.testValue1 = testValue1; + this.testValue2 = testValue2; + } + } + + /** For each non-api supported property, + * getProperty(XXX) should return a value + * setProperty(XXX, value1) should succeed + * getProperties() should return value1 + * setProperty(XXX, value2) should succeed + * getProperties() should return value2 + */ + abstract class AbstractNonAPITestProperty extends AbstractTestProperty { + AbstractNonAPITestProperty(String propertyName, Object testValue1, Object testValue2) { + super(propertyName, testValue1, testValue2); + } + public Object get(PersistenceManager pm) {throw new RuntimeException("not implemented");}; + public void set(PersistenceManager pm, Object value) {throw new RuntimeException("not implemented");}; + public void test(PersistenceManager pm, Set supportedProperties) { + Object result0 = pm.getProperties().get(propertyName); + errorIfEqual("getProperties().get(" + propertyName + ")", null, result0); + pm.setProperty(propertyName, testValue1); + Object result1 = pm.getProperties().get(propertyName); + errorIfNotEqual("after pm.setProperty(" + propertyName + "), getProperties().get(" + propertyName + ")", + testValue1, result1); + pm.setProperty(propertyName, testValue2); + Object result2 = pm.getProperties().get(propertyName); + errorIfNotEqual("after pm.setProperty(" + propertyName + ")" + " getProperties().get(" + propertyName + ")", + testValue1, result2); + } + } + + /** For each required property, and for each of two values + * setProperty(XXX, value1) should succeed + * getXXX() should return value1 + * setXXX(value2) should succeed + * getProperties() should return value2 + */ + abstract class AbstractAPITestProperty extends AbstractTestProperty { + AbstractAPITestProperty(String propertyName, Object testValue1, Object testValue2) { + super(propertyName, testValue1, testValue2); + } + public void test(PersistenceManager pm, Set supportedProperties) { + pm.setProperty(propertyName, testValue1); + Object result1 = get(pm); + errorIfNotEqual("after pm.setProperty(XXX), getXXX for " + propertyName, + testValue1, result1); + set(pm, testValue2); + Object result2 = pm.getProperties().get(propertyName); + errorIfNotEqual("after pm.setXXX(), getProperties.get(XXX) for " + propertyName, + testValue2, result2); + } + }; + + private TestProperty testCopyOnAttach = + new AbstractAPITestProperty(PROPERTY_COPY_ON_ATTACH, true, false) { + public Object get(PersistenceManager pm) {return pm.getCopyOnAttach();} + public void set(PersistenceManager pm, Object value) {pm.setCopyOnAttach((Boolean) value);} + }; + + private TestProperty testDatastoreReadTimeoutMillis = + new AbstractAPITestProperty(PROPERTY_DATASTORE_READ_TIMEOUT_MILLIS, 20, 40) { + public Object get(PersistenceManager pm) {return pm.getDatastoreReadTimeoutMillis();} + public void set(PersistenceManager pm, Object value) {pm.setDatastoreReadTimeoutMillis((Integer) value);} + }; + + private TestProperty testDatastoreWriteTimeoutMillis = + new AbstractAPITestProperty(PROPERTY_DATASTORE_WRITE_TIMEOUT_MILLIS, 60, 80) { + public Object get(PersistenceManager pm) {return pm.getDatastoreWriteTimeoutMillis();} + public void set(PersistenceManager pm, Object value) {pm.setDatastoreWriteTimeoutMillis((Integer) value);} + }; + + private TestProperty testMultithreaded = + new AbstractAPITestProperty(PROPERTY_MULTITHREADED, true, false) { + public Object get(PersistenceManager pm) {return pm.getMultithreaded();} + public void set(PersistenceManager pm, Object value) {pm.setMultithreaded((Boolean) value);} + }; + + private TestProperty testDetachAllOnCommit = + new AbstractAPITestProperty(PROPERTY_DETACH_ALL_ON_COMMIT, true, false) { + public Object get(PersistenceManager pm) {return pm.getDetachAllOnCommit();} + public void set(PersistenceManager pm, Object value) {pm.setDetachAllOnCommit((Boolean) value);} + }; + + private TestProperty testIgnoreCache = + new AbstractAPITestProperty(PROPERTY_IGNORE_CACHE, true, false) { + public Object get(PersistenceManager pm) {return pm.getIgnoreCache();} + public void set(PersistenceManager pm, Object value) {pm.setIgnoreCache((Boolean) value);} +}; + + private TestProperty testOptimistic = + new AbstractNonAPITestProperty(PROPERTY_OPTIMISTIC, true, false) { + public Object get(PersistenceManager pm) {return pm.getIgnoreCache();} + public void set(PersistenceManager pm, Object value) {pm.setIgnoreCache((Boolean) value);} + }; + + private TestProperty testRetainValues = + new AbstractNonAPITestProperty(PROPERTY_RETAIN_VALUES, true, false) { + }; + + private TestProperty testRestoreValues = + new AbstractNonAPITestProperty(PROPERTY_RESTORE_VALUES, true, false) { + }; + + private TestProperty testNontransactionalRead = + new AbstractNonAPITestProperty(PROPERTY_NONTRANSACTIONAL_READ, true, false) { + }; + + private TestProperty testNontransactionalWrite = + new AbstractNonAPITestProperty(PROPERTY_NONTRANSACTIONAL_WRITE, true, false) { + }; + + private Set setOf(TestProperty... testPropertys) { + Set result = new HashSet(); + for (TestProperty testProperty: testPropertys) { + result.add(testProperty); + } + return result; + } + + /** + * For each option supported by the PMF, test that + * the corresponding pm property is supported. + */ + public void testGetSupportedProperties() { + testRequiredProperties.add(testCopyOnAttach); + testRequiredProperties.add(testDetachAllOnCommit); + testRequiredProperties.add(testIgnoreCache); + testRequiredProperties.add(testOptimistic); + testRequiredProperties.add(testRetainValues); + testRequiredProperties.add(testRestoreValues); + testRequiredProperties.add(testNontransactionalRead); + testRequiredProperties.add(testNontransactionalWrite); + + testOptionalProperties.put(PROPERTY_MULTITHREADED, setOf(testMultithreaded)); + testOptionalProperties.put(OPTION_DATASTORE_TIMEOUT, + setOf(testDatastoreReadTimeoutMillis, testDatastoreWriteTimeoutMillis)); + getPM(); + + supportedOptions = pmf.supportedOptions(); + for (String supportedOption: supportedOptions) { + System.out.println("supportedOptions returned: " + supportedOption); + } + + supportedProperties = pm.getSupportedProperties(); + for (String supportedProperty: supportedProperties) { + System.out.println("supportedProperties returned: " + supportedProperty); + } + + // test required properties + for (TestProperty testProperty: testRequiredProperties) { + testProperty.test(pm, supportedProperties); + } + + Set> properties = pm.getProperties().entrySet(); + for (Map.Entry entry: properties) { + System.out.println("getProperties returned: " + entry.getKey() + ": " + entry.getValue()); + } + + // for each supported option, test the corresponding supported property + for (String supportedOption: supportedOptions) { + Set supportedOptionTestList = testOptionalProperties.get(supportedOption); + if (supportedOptionTestList != null) { + for (TestProperty supportedOptionTest: supportedOptionTestList) { + System.out.println("testing " + supportedOption); + supportedOptionTest.test(pm, supportedProperties); + } + } + } + + failOnError(); + } + + +} Propchange: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanager/GetProperties.java ------------------------------------------------------------------------------ svn:eol-style = LF