001/* 002 * (C) Copyright 2017 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Funsho David 018 * 019 */ 020 021package org.nuxeo.directory.test; 022 023import org.nuxeo.ecm.core.test.StorageConfiguration; 024import org.nuxeo.runtime.test.runner.FeaturesRunner; 025import org.nuxeo.runtime.test.runner.RuntimeFeature; 026import org.nuxeo.runtime.test.runner.RuntimeHarness; 027 028 029/** 030 * Description of the specific capabilities of a directory for tests, and helper methods. 031 * 032 * @since 9.2 033 */ 034public class DirectoryConfiguration { 035 036 public static final String DIRECTORY_PROPERTY = "nuxeo.test.directory"; 037 038 public static final String DIRECTORY_SQL = "sql"; 039 040 public static final String DIRECTORY_MONGODB = "mongodb"; 041 042 public static final String SQL_TEMPLATE_CONTRIB = "OSGI-INF/test-directory-sql-contrib.xml"; 043 044 public static final String MONGODB_TEMPLATE_CONTRIB = "OSGI-INF/test-directory-mongodb-contrib.xml"; 045 046 protected String directoryType; 047 048 protected StorageConfiguration storageConfiguration; 049 050 public DirectoryConfiguration(StorageConfiguration storageConfiguration) { 051 this.storageConfiguration = storageConfiguration; 052 directoryType = StorageConfiguration.defaultSystemProperty(DIRECTORY_PROPERTY, 053 storageConfiguration.isVCS() ? DIRECTORY_SQL : storageConfiguration.getCoreType()); 054 } 055 056 public void deployContrib(FeaturesRunner runner) throws Exception { 057 String contribName; 058 switch (directoryType) { 059 case DIRECTORY_SQL: 060 contribName = SQL_TEMPLATE_CONTRIB; 061 break; 062 case DIRECTORY_MONGODB: 063 contribName = MONGODB_TEMPLATE_CONTRIB; 064 break; 065 default: 066 // Fallback on SQL template directory by default if directoryType unknown 067 contribName = SQL_TEMPLATE_CONTRIB; 068 break; 069 } 070 071 RuntimeHarness harness = runner.getFeature(RuntimeFeature.class).getHarness(); 072 harness.deployContrib("org.nuxeo.ecm.directory.tests", contribName); 073 } 074 075 public void init() { 076 // nothing for now as the storage configuration always initialize necessary properties for JDBC tests, 077 // use this method for specific initialization (for example a mock LDAP server) 078 } 079}