|
Glassfish example source code file (MiniXmlParserTest.java)
The Glassfish MiniXmlParserTest.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 2009-2010 Oracle and/or its affiliates. All rights reserved. * * 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 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. 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 packager/legal/LICENSE.txt. * * GPL Classpath Exception: * 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. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * 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 don't 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. */ package com.sun.enterprise.universal.xml; import java.io.File; import java.net.*; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import com.sun.enterprise.util.HostAndPort; /** * @author bnevins */ @org.junit.Ignore // This test takes a minute to run, so I (Sahoo) have disabled it. @SuppressWarnings({"StaticNonFinalField"}) public class MiniXmlParserTest { private static File hasProfiler; private static File wrongOrder; private static File rightOrder; private static File noconfig; private static File adminport; private static File adminport2; private static File noCloseRightOrder; private static File noCloseWrongOrder; private static File noDomainName; private static File bigDomain; private static File monitoringFalse; private static File monitoringTrue; private static File monitoringNone; private static File v2DomainXml; private static File issue9127DomainXml; @BeforeClass public static void setUpClass() throws Exception { String wrongOrderString = MiniXmlParserTest.class.getClassLoader().getResource("wrongorder.xml").getPath(); wrongOrder = new File(wrongOrderString); if (!wrongOrder.exists() && wrongOrderString.indexOf("%20") >= 0) throw new RuntimeException("You can not run unit tests if " + "your workspace has a space in its path."); rightOrder = new File(MiniXmlParserTest.class.getClassLoader().getResource("rightorder.xml").getPath()); noconfig = new File(MiniXmlParserTest.class.getClassLoader().getResource("noconfig.xml").getPath()); hasProfiler = new File(MiniXmlParserTest.class.getClassLoader().getResource("hasprofiler.xml").getPath()); adminport = new File(MiniXmlParserTest.class.getClassLoader().getResource("adminport.xml").getPath()); adminport2 = new File(MiniXmlParserTest.class.getClassLoader().getResource("adminport2.xml").getPath()); noCloseRightOrder = new File( MiniXmlParserTest.class.getClassLoader().getResource("rightordernoclosedomain.xml").getPath()); noCloseWrongOrder = new File( MiniXmlParserTest.class.getClassLoader().getResource("wrongordernoclosedomain.xml").getPath()); noDomainName = new File(MiniXmlParserTest.class.getClassLoader().getResource("nodomainname.xml").getPath()); bigDomain = new File(MiniXmlParserTest.class.getClassLoader().getResource("big.xml").getPath()); monitoringFalse = new File( MiniXmlParserTest.class.getClassLoader().getResource("monitoringFalse.xml").getPath()); monitoringTrue = new File(MiniXmlParserTest.class.getClassLoader().getResource("monitoringTrue.xml").getPath()); monitoringNone = new File(MiniXmlParserTest.class.getClassLoader().getResource("monitoringNone.xml").getPath()); if (canAccessInternet()) v2DomainXml = new File(MiniXmlParserTest.class.getClassLoader().getResource("v2domain.xml").getPath()); else v2DomainXml = null; issue9127DomainXml = new File(MiniXmlParserTest.class.getClassLoader().getResource("domain9127.xml").getPath()); assertTrue(wrongOrder.exists()); assertTrue(rightOrder.exists()); assertTrue(noconfig.exists()); assertTrue(hasProfiler.exists()); assertTrue(noDomainName.exists()); } @AfterClass public static void tearDownClass() throws Exception { } // --------------------------- CONSTRUCTORS --------------------------- public MiniXmlParserTest() { } @Before public void setUp() { } @After public void tearDown() { } /** * Positive Test Case where servers appears after configs * * @throws MiniXmlParserException */ @Test public void serversAfterConfigs() { try { MiniXmlParser instance = new MiniXmlParser(wrongOrder, "server"); Map<String, String> javaConfig = instance.getJavaConfig(); List<String> jvmOptions = instance.getJvmOptions(); assertEquals("JVMOPTION1", jvmOptions.get(0)); assertEquals("JVMOPTION2", jvmOptions.get(1)); assertEquals("test", javaConfig.get("test")); } catch (MiniXmlParserException ex) { Logger.getLogger(MiniXmlParserTest.class.getName()).log(Level.SEVERE, null, ex); } } /** * Test that the correct Exception is thrown for a null xml File * * @throws MiniXmlParserException */ @Test(expected = MiniXmlParserException.class) public void nullXmlFile() throws MiniXmlParserException { new MiniXmlParser(null, "server"); } /** * Test that the correct Exception is thrown for a non-existing xml File * * @throws MiniXmlParserException */ @Test(expected = MiniXmlParserException.class) public void nonexistentFile() throws MiniXmlParserException { new MiniXmlParser(new File("."), "server"); } /** * Positive Test Case where configs appears after servers * * @throws MiniXmlParserException */ @Test public void configsAfterServers() { try { MiniXmlParser instance = new MiniXmlParser(rightOrder, "server"); Map<String, String> javaConfig = instance.getJavaConfig(); List<String> jvmOptions = instance.getJvmOptions(); assertEquals("JVMOPTION1", jvmOptions.get(0)); assertEquals("JVMOPTION2", jvmOptions.get(1)); assertEquals("test", javaConfig.get("test")); } catch (MiniXmlParserException ex) { Logger.getLogger(MiniXmlParserTest.class.getName()).log(Level.SEVERE, null, ex); } } /** * Negative Test Case where there is no "server-config" * * @throws MiniXmlParserException */ @Test(expected = MiniXmlParserException.class) public void noServerConfig() throws MiniXmlParserException { try { new MiniXmlParser(noconfig, "server"); } catch (MiniXmlParserException ex) { throw ex; } } /* * Positive test cases -- look at <system-property> */ @Test public void systemProperties() { try { MiniXmlParser instance = new MiniXmlParser(rightOrder, "server"); Map<String, String> javaConfig = instance.getJavaConfig(); List<String> jvmOptions = instance.getJvmOptions(); Map<String, String> sysProps = instance.getSystemProperties(); assertEquals("JVMOPTION1", jvmOptions.get(0)); assertEquals("JVMOPTION2", jvmOptions.get(1)); assertEquals("test", javaConfig.get("test")); assertEquals("true", sysProps.get("beforeJavaConfig")); assertEquals("true", sysProps.get("afterJavaConfig")); assertNull(sysProps.get("foo")); assertEquals(sysProps.size(), 3); } catch (MiniXmlParserException ex) { Logger.getLogger(MiniXmlParserTest.class.getName()).log(Level.SEVERE, null, ex); } } /* * Positive test case -- make sure system-property in <server> overrides the one in Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish MiniXmlParserTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.