View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.base;
17  
18  import org.apache.log4j.PropertyConfigurator;
19  import org.kuali.ole.docstore.DocStoreConstants;
20  import org.kuali.ole.docstore.discovery.service.SolrServerManager;
21  import org.kuali.ole.docstore.util.DocStoreEnvUtil;
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import java.io.BufferedReader;
26  import java.io.File;
27  import java.io.FileReader;
28  import java.io.IOException;
29  import java.net.URL;
30  import java.util.Properties;
31  
32  /**
33   * User: Peri Subrahmanya
34   * Date: 3/30/11
35   * Time: 11:43 AM
36   * To change this template use File | Settings | File Templates.
37   */
38  public abstract class BaseTestCase {
39      protected            DocStoreEnvUtil docStoreEnvUtil = new DocStoreEnvUtil();
40      private static final Logger          LOG             = LoggerFactory.getLogger(BaseTestCase.class);
41  
42      public BaseTestCase() {
43          try {
44              URL resource = getClass().getResource("/org/kuali/ole/log4j.properties");
45              File file = new File(resource.toURI());
46              PropertyConfigurator.configure(resource);
47              System.getProperties().put("app.environment", "local");
48              docStoreEnvUtil.setVendor("derby");
49              docStoreEnvUtil.setProperties(new Properties());
50              docStoreEnvUtil.initTestEnvironment();
51              docStoreEnvUtil.printEnvironment();
52              System.setProperty("OLE_DOCSTORE_USE_DISCOVERY", Boolean.FALSE.toString());
53          } catch (Exception e) {
54              LOG.info("Exception : " + e);
55          }
56      }
57  
58      protected void setUp() throws Exception {
59          try {
60              String path = getClass().getClassLoader().getResource(".").getPath();
61              //PropertyConfigurator.configure("log4j.properties");
62              docStoreEnvUtil.initTestEnvironment();
63              docStoreEnvUtil.printEnvironment();
64              System.getProperties().put("app.environment", "local");
65             // System.getProperties().put("docstore.properties.home", DocStoreConstants.TEST_DOC_STORE_PROP_HOME);
66              System.setProperty("OLE_DOCSTORE_USE_DISCOVERY", Boolean.FALSE.toString());
67              //  System.setProperty(SolrServerManager.SOLR_SERVER_EMBEDDED, "true");
68          }
69          catch (Exception e) {
70              LOG.info(e.getMessage() , e);
71          }
72  
73      }
74  
75      public String readFile(File file) throws IOException {
76          BufferedReader reader = new BufferedReader(new FileReader(file));
77          String line = null;
78          StringBuilder stringBuilder = new StringBuilder();
79          String ls = System.getProperty("line.separator");
80          while ((line = reader.readLine()) != null) {
81              stringBuilder.append(line);
82              stringBuilder.append(ls);
83          }
84          return stringBuilder.toString();
85      }
86  
87  }