1 /* 2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package catalog; 25 26 import static catalog.CatalogTestUtils.DEFER_FALSE; 27 import static catalog.CatalogTestUtils.DEFER_TRUE; 28 import static catalog.CatalogTestUtils.getCatalogPath; 29 import static javax.xml.catalog.CatalogFeatures.Feature.DEFER; 30 import static javax.xml.catalog.CatalogManager.catalog; 31 32 import java.lang.reflect.Method; 33 34 import javax.xml.catalog.Catalog; 35 import javax.xml.catalog.CatalogFeatures; 36 37 import org.testng.Assert; 38 import org.testng.annotations.DataProvider; 39 import org.testng.annotations.Listeners; 40 import org.testng.annotations.Test; 41 42 /* 43 * @test 44 * @bug 8077931 45 * @summary This case tests whether the catalogs specified in delegateSystem, 46 * delegatePublic, delegateURI and nextCatalog entries are used lazily 47 * in resolution via defer feature. 48 * @compile ../../libs/catalog/CatalogTestUtils.java 49 */ 50 @Listeners({jaxp.library.FilePolicy.class}) 51 public class DeferFeatureTest { 52 53 @Test(dataProvider = "catalog-countOfLoadedCatalogFile") 54 public void testDeferFeature(Catalog catalog, int catalogCount) 55 throws Exception { 56 Assert.assertEquals(loadedCatalogCount(catalog), catalogCount); 57 } 58 59 @DataProvider(name = "catalog-countOfLoadedCatalogFile") 60 private Object[][] data() { 61 return new Object[][]{ 62 // By default, alternative catalogs are not loaded. 63 {createCatalog(CatalogFeatures.defaults()), 0}, 64 // Alternative catalogs are not loaded when DEFER is set to true. 65 {createCatalog(createDeferFeature(DEFER_TRUE)), 0}, 66 // The 3 alternative catalogs are not pre-loaded 67 //when DEFER is set to false. 68 {createCatalog(createDeferFeature(DEFER_FALSE)), 3}}; 69 } 70 71 private CatalogFeatures createDeferFeature(String defer) { 72 return CatalogFeatures.builder().with(DEFER, defer).build(); 73 } 74 75 private Catalog createCatalog(CatalogFeatures feature) { 76 return catalog(feature, getCatalogPath("deferFeature.xml")); 77 } 78 79 private int loadedCatalogCount(Catalog catalog) throws Exception { 80 Method method = catalog.getClass().getDeclaredMethod( 81 "loadedCatalogCount"); 82 method.setAccessible(true); 83 return (int) method.invoke(catalog); 84 } 85 }