Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.drools.guvnor.server.util;
 /*
  * Copyright 2005 JBoss Inc
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
This is only to be used for testing, eg in hosted mode, or unit tests.

Author(s):
Michael Neale
    public static Repository repository;
    public static Session getSession() throws Exception {
        return getSession(true);
    }
    public static synchronized Session getSession(boolean erase) {
    	try {
	        if ( == null) {
	            if (erase) {
	                File repoDir = new File("repository");
	                ..println("DELETE test repo dir: " + repoDir.getAbsolutePath());
	                RepositorySessionUtil.deleteDirrepoDir );
	                ..println("TEST repo dir deleted.");
	            }
	            JCRRepositoryConfigurator config = new JackrabbitRepositoryConfigurator();
                String home = System.getProperty("guvnor.repository.dir");
	             = config.getJCRRepository(home);
	            Session testSession = .login(
	                                                                     new SimpleCredentials("alan_parsons""password".toCharArray()));
	            RulesRepositoryAdministrator admin = new RulesRepositoryAdministrator(testSession);
	            if (erase && admin.isRepositoryInitialized()) {
	                admin.clearRulesRepository( );
	            }
	            config.setupRulesRepositorytestSession );
	            return testSession;
	        } else {
	            return .login(
	                             new SimpleCredentials("alan_parsons""password".toCharArray()));
	        }
    	} catch (RepositoryException e) {
    		throw new IllegalStateException(e);
    	}
    }
New to GrepCode? Check out our FAQ X