001: //$Id: DDTTestDataExceptionTest.java 276 2007-06-18 22:07:19Z jg_hamburg $
002: /********************************************************************************
003: * DDTUnit, a Datadriven Approach to Unit- and Moduletesting
004: * Copyright (c) 2004, Joerg and Kai Gellien
005: * All rights reserved.
006: *
007: * The Software is provided under the terms of the Common Public License 1.0
008: * as provided with the distribution of DDTUnit in the file cpl-v10.html.
009: * Redistribution and use in source and binary forms, with or without
010: * modification, are permitted provided that the following conditions
011: * are met:
012: *
013: * + Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * + Redistributions in binary form must reproduce the above
017: * copyright notice, this list of conditions and the following
018: * disclaimer in the documentation and/or other materials provided
019: * with the distribution.
020: *
021: * + Neither the name of the authors or DDTUnit, nor the
022: * names of its contributors may be used to endorse or promote
023: * products derived from this software without specific prior
024: * written permission.
025: *
026: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
027: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
028: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
029: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
030: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
031: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
032: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
033: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
034: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
035: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
036: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037: ********************************************************************************/package junitx.ddtunit.data;
038:
039: import junit.framework.TestCase;
040: import junitx.ddtunit.util.ClassAnalyser;
041: import junitx.ddtunit.util.DDTConfiguration;
042: import junitx.framework.Assert;
043:
044: /**
045: * Test exceptional behavior of DDTDataRepository.
046: *
047: * @author jg
048: */
049: public class DDTTestDataExceptionTest extends TestCase {
050:
051: private static final String LF = "\n";
052:
053: /**
054: * Checks if a DDTTestDataException is raised if no dataSet is found.
055: */
056: public void testRetrievalOfEmptyClusterDataSet() {
057: String resource = "/resourceThatDoesNotExists.mypost";
058: String clusterId = "myClusterIdThatDoesNotExists";
059: try {
060: DDTDataRepository.getInstance().get(resource, clusterId);
061: fail("A DDTTestDataException should be thrown on empty lusterDataSet retrieval");
062: } catch (DDTTestDataException ex) {
063: String expectedMessage = "Error on behalf of xml test resource."
064: + LF
065: + "Caused by:java.io.FileNotFoundException - /resourceThatDoesNotExists.mypost (No such file or directory)";
066: assertEquals("Wrong message of caught exception",
067: expectedMessage, ex.getMessage());
068: }
069: }
070:
071: /**
072: * Check that a DDTTestDataException is raised if a parsing error occures.<br/>
073: * This test will allways be true on non-validating parsers.<br/> On use of
074: * validating parser this test throws an exception that actually will be
075: * caught by DDTUnit as defined in xml resource.
076: */
077: public void testParsingErrorBehavior() {
078: String resource = ResourceNameFactory.getInstance().getName(
079: ClassAnalyser.classPackage(this ), "DefectXMLTest");
080: assertEquals("Wrong resource path",
081: "/junitx/ddtunit/data/DDT-DefectXMLTest.xml", resource);
082: String clusterId = "DbRepositoryAccessTest";
083: try {
084: DDTDataRepository.getInstance().get(resource, clusterId);
085: DDTConfiguration config = DDTConfiguration.getInstance();
086: if (config.isActiveParserValidation()
087: && config.isActiveXmlValidation()) {
088: fail("A DDTTestDataException should be thrown on empty ClusterDataSet retrieval");
089: }
090: } catch (DDTTestDataException ex) {
091: String expectedMessage = "No testdata provided for class id 'DbRepositoryAccessTest' in testresource '/junitx/ddtunit/data/DDT-DefectXMLTest.xml'"
092: + LF
093: + "Check if referred class id in xml resources matches definition of "
094: + LF
095: + " initTestData(resource, classId) inside of your testclass.";
096: Assert.assertEquals("Wrong message of caught exception",
097: expectedMessage, ex.getMessage());
098: }
099: }
100: }
|