# HG changeset patch # User Matthias Bläsing # Date 1343560156 -7200 # Branch mb-patches3 # Node ID 2c3bff024d0d2452b2ad013583304875476b9ad9 # Parent 43a7581e2f46a7549081005cb8a2aa97defeab14 Bug 214881 - part 3 - Fix output of tests by suppressing two outputs from DatabaseMetadataQuoter (a real fix would mean pretty deep changes, that should be done after more cleanup) diff --git a/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/api/DataViewTest.java b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/api/DataViewTest.java --- a/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/api/DataViewTest.java +++ b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/api/DataViewTest.java @@ -47,6 +47,7 @@ import org.netbeans.junit.MockServices; import org.netbeans.junit.NbTestCase; import org.netbeans.modules.db.dataview.spi.DBConnectionProviderImpl; +import org.netbeans.modules.db.dataview.util.DBTestUtil; import org.netbeans.modules.db.dataview.util.DbUtil; import org.netbeans.modules.db.dataview.util.TestCaseContext; @@ -71,6 +72,7 @@ @Override protected void setUp() throws Exception { super.setUp(); + DBTestUtil.suppressSuperfluousLogging(); MockServices.setServices(new DBConnectionProviderImpl().getClass()); context = DbUtil.getContext(); dbconn = DbUtil.getDBConnection(); diff --git a/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/DataViewDBTableTest.java b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/DataViewDBTableTest.java --- a/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/DataViewDBTableTest.java +++ b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/DataViewDBTableTest.java @@ -49,6 +49,7 @@ import org.netbeans.junit.NbTestCase; import org.netbeans.modules.db.dataview.meta.DBTable; import org.netbeans.modules.db.dataview.spi.DBConnectionProviderImpl; +import org.netbeans.modules.db.dataview.util.DBTestUtil; import org.netbeans.modules.db.dataview.util.DbUtil; import org.netbeans.modules.db.dataview.util.TestCaseContext; @@ -75,6 +76,7 @@ @Override protected void setUp() throws Exception { super.setUp(); + DBTestUtil.suppressSuperfluousLogging(); MockServices.setServices(new DBConnectionProviderImpl().getClass()); context = DbUtil.getContext(); dbconn = DbUtil.getDBConnection(); diff --git a/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/DataViewTest.java b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/DataViewTest.java --- a/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/DataViewTest.java +++ b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/DataViewTest.java @@ -52,6 +52,7 @@ import org.netbeans.modules.db.dataview.meta.DBMetaDataFactory; import org.netbeans.modules.db.dataview.meta.DBTable; import org.netbeans.modules.db.dataview.spi.DBConnectionProviderImpl; +import org.netbeans.modules.db.dataview.util.DBTestUtil; import org.netbeans.modules.db.dataview.util.DbUtil; import org.netbeans.modules.db.dataview.util.TestCaseContext; import org.openide.util.Exceptions; @@ -83,6 +84,7 @@ @Override protected void setUp() throws Exception { super.setUp(); + DBTestUtil.suppressSuperfluousLogging(); MockServices.setServices(new DBConnectionProviderImpl().getClass()); context = DbUtil.getContext(); dbconn = DbUtil.getDBConnection(); diff --git a/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelperTest.java b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelperTest.java --- a/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelperTest.java +++ b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelperTest.java @@ -47,6 +47,7 @@ import org.netbeans.junit.MockServices; import org.netbeans.junit.NbTestCase; import org.netbeans.modules.db.dataview.spi.DBConnectionProviderImpl; +import org.netbeans.modules.db.dataview.util.DBTestUtil; import org.netbeans.modules.db.dataview.util.DbUtil; import org.netbeans.modules.db.dataview.util.TestCaseContext; @@ -72,6 +73,7 @@ @Override protected void setUp() throws Exception { super.setUp(); + DBTestUtil.suppressSuperfluousLogging(); MockServices.setServices(new DBConnectionProviderImpl().getClass()); context= DbUtil.getContext(); dbconn = DbUtil.getDBConnection(); diff --git a/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/util/DBTestUtil.java b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/util/DBTestUtil.java new file mode 100644 --- /dev/null +++ b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/util/DBTestUtil.java @@ -0,0 +1,83 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.db.dataview.util; + +import java.util.logging.Filter; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +public class DBTestUtil { + + /** + * Disable logging of logging messages from DatabaseMetaDataQuoter. + * + * This method is a workaround of problems in the database modules and can + * be removed, when the problem is really fixed. + * + */ + public static void suppressSuperfluousLogging() { + // TODO: Remove this code and fix the core problem + for (Handler h : Logger.getLogger("").getHandlers()) { + h.setFilter(new Filter() { + @Override + public boolean isLoggable(LogRecord lr) { + if (lr.getSourceClassName().equals("org.netbeans.api.db.sql.support.SQLIdentifiers$DatabaseMetaDataQuoter")) { + if (lr.getSourceMethodName().equals("getExtraNameChars") + && lr.getLevel() == Level.WARNING + && lr.getMessage().startsWith("DatabaseMetaData.getExtraNameCharacters() failed")) { + return false; + } else if (lr.getSourceMethodName().equals("needToQuote") + && lr.getLevel().intValue() <= Level.INFO.intValue()) { + return false; + } else { + return true; + } + } else { + return true; + } + } + }); + } + } +}