Project

General

Profile

« Previous | Next » 

Revision 4719

Added by daigle over 15 years ago

Create a propertyService.getTestInstance method to facilitate unit tests

View differences:

test/edu/ucsb/nceas/MCTestCase.java
99 99
				new SortedProperties("build/tests/test.properties");
100 100
			testProperties.load();
101 101
			String metacatContextDir = testProperties.getProperty("metacat.contextDir");
102
			PropertyService.getInstance(metacatContextDir + "/WEB-INF");
102
			PropertyService.getTestInstance(metacatContextDir + "/WEB-INF");
103
//			PropertyService.getInstance();
103 104
		    String printDebugString = PropertyService.getProperty("test.printdebug");
104 105
		    printDebug = Boolean.parseBoolean(printDebugString);
105 106

  
test/edu/ucsb/nceas/metacat/clientview/ClientViewHelperTest.java
61 61
        if (DOWNLOAD_DATA_DOCID.equals("")) 
62 62
            fail("Please set the class property DOWNLOAD_DATA_DOCID before running this test.");
63 63
        
64
        PropertyService.getInstance(PATH_TO_PROPERTIES);
64
//        PropertyService.getInstance(PATH_TO_PROPERTIES);
65
        PropertyService.getInstance();
65 66
        
66 67
        clientViewBean = new ClientView();
67 68
        clientViewBean.setUsername(USR);
test/edu/ucsb/nceas/metacattest/QuerySpecificationTest.java
94 94
    {
95 95
  	  try
96 96
  	  {
97
		  PropertyService.getInstance("build/tests");
97
//		  PropertyService.getInstance("build/tests");
98
		  PropertyService.getInstance();
98 99
  		  MetacatUtil.pathsForIndexing 
99 100
  		         = MetacatUtil.getOptionList(PropertyService.getProperty("xml.indexPaths"));
100 101
  	  }
......
121 122
    {
122 123
        super.setUp();
123 124
        try {
124
  		  	PropertyService.getInstance("build/tests");
125
//  		  	PropertyService.getInstance("build/tests");
126
  		  	PropertyService.getInstance();
125 127
            String xmlfile = "./test/query.xml";
126 128
            xml = new FileReader(new File(xmlfile));
127 129
        } catch (FileNotFoundException e) {
test/edu/ucsb/nceas/metacattest/UploadIPCCDataTest.java
81 81
	  {
82 82
		  try
83 83
		  {
84
			  PropertyService.getInstance("build/tests");
84
//			  PropertyService.getInstance("build/tests");
85
			  PropertyService.getInstance();
85 86
			  MetacatUtil.pathsForIndexing 
86 87
			         = MetacatUtil.getOptionList(PropertyService.getProperty("xml.indexPaths"));
87 88
		  }
test/edu/ucsb/nceas/metacattest/BuildIndexTest.java
78 78
	/* Initialize properties */
79 79
	static {
80 80
		try {
81
			PropertyService.getInstance("build/tests");
81
//			PropertyService.getInstance("build/tests");
82
			PropertyService.getInstance();
82 83
			MetacatUtil.pathsForIndexing = MetacatUtil.getOptionList(PropertyService
83 84
					.getProperty("xml.indexPaths"));
84 85
		} catch (Exception e) {
......
104 105
	public void setUp() {
105 106
		try {
106 107
			DatabaseService.getInstance();
107
			PropertyService.getInstance("build/tests");
108
//			PropertyService.getInstance("build/tests");
109
			PropertyService.getInstance();
108 110
			metacatUrl = PropertyService.getProperty("test.metacatUrl");
109 111
		} catch (ServiceException se) {
110 112
			fail(se.getMessage());
src/edu/ucsb/nceas/metacat/service/PropertyService.java
77 77
	private static String authMetaDataFilePath = null;
78 78
	private static PropertiesMetaData authMetaData = null;
79 79
	
80
	private static boolean testInstance = false;
81
	private static String testConfigDir = null;
80 82
	
81 83
	private static Logger logMetacat = Logger.getLogger(PropertyService.class);
82 84

  
......
100 102
	/**
101 103
	 * Get the single instance of PropertyService.
102 104
	 * 
103
	 * @param servletContext the context we will use to get relative paths
104 105
	 * @return the single instance of PropertyService
105 106
	 */
106 107
	public static PropertyService getInstance() throws ServiceException {
......
111 112
		return propertyService;
112 113
	}
113 114
	
115
	/**
116
	 * Get the single instance of PropertyService for test purposes.  In this
117
	 * case, we allow the configuration directory to be passed in.
118
	 * 
119
	 * @param configDir the configuration directory we need to look in
120
	 * @return the single instance of PropertyService
121
	 */
122
	public static PropertyService getTestInstance(String configDir) throws ServiceException {
123
		if (propertyService == null) {
124
			
125
			testInstance = true;
126
			testConfigDir = configDir;
127
			
128
			propertyService = new PropertyService();
129
		}
130
		return propertyService;
131
	}
132
	
114 133
	public boolean refreshable() {
115 134
		return true;
116 135
	}
......
137 156
		
138 157
		logMetacat.debug("Initializing PropertyService");
139 158
		
140
		String configDir = ServiceService.getRealConfigDir();
159
		String configDir;
160
		if (testInstance) {
161
			configDir = testConfigDir;
162
		} else {
163
			configDir = ServiceService.getRealConfigDir();
164
		}
141 165

  
142 166
		// mainProperties will hold the primary configuration values for metacat.
143 167
		mainPropertiesFilePath = configDir + FileUtil.getFS() + MAIN_CONFIG_NAME;

Also available in: Unified diff