Author: tchemit Date: 2008-04-05 20:37:32 +0000 (Sat, 05 Apr 2008) New Revision: 363 Removed: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHandlerFactory.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractVCSFileStatesModel.java trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/MethodTest.java trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/RepositoryStateTest.java trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSFileStateManagerTest.java trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSHandlerTest.java trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSInitTest.java trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSLocalData.java trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSLocalDataContext.java trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSStateTest.java trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSTest.java Log: refactor PRovider, Handler and Connexion Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHandlerFactory.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHandlerFactory.java 2008-04-05 20:37:17 UTC (rev 362) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHandlerFactory.java 2008-04-05 20:37:32 UTC (rev 363) @@ -1,138 +0,0 @@ -/* *##% -* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, -* Benjamin Poussin, Tony Chemit -* -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*##%*/ -package org.codelutin.vcs; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import static org.codelutin.i18n.I18n._; -import org.codelutin.util.StringUtil; - -import java.util.ArrayList; -import java.util.List; -import java.util.ServiceLoader; - -/** - * TODO - * - * @author chemit - * @see VCSConfig - * @see VCSHandler - */ -@org.codelutin.i18n.I18nable -public class VCSHandlerFactory { - - static protected final Log log = LogFactory.getLog(VCSHandlerFactory.class); - - static private VCSHandlerFactory instance; - - /** current config to use */ - private VCSConfig config; - - /** current vcs handler to use */ - private VCSHandler handler; - - /** providers availables */ - private List<VCSProvider> providers; - - - public static VCSHandlerFactory getInstance() { - if (instance == null) { - instance = new VCSHandlerFactory(); - } - return instance; - } - - public static VCSConfig getConfig() { - VCSHandlerFactory factory = getInstance(); - assertConfigIsNotNull(factory.config); - return factory.config; - } - - public static void setConfig(VCSConfig value) { - getInstance().config = value; - } - - public static VCSHandler getHandler() { - final VCSHandlerFactory factory = getInstance(); - if (factory.handler == null) { - synchronized (factory) { - factory.handler = newHandler(getConfig()); - } - } - return factory.handler; - } - - /** - * instanciate a new handler, using a previously instanciate handler config. - * <p/> - * the method will produce a runtime exception if config is null and not init. - * - * @param config config to use - * @return the new handler instance - */ - public static VCSHandler newHandler(VCSConfig config) { - VCSHandlerFactory factory = getInstance(); - - assertConfigIsInit(config); - VCSProvider<?, ?> provider = factory.getProvider(config.getType().name().toUpperCase()); - if (provider == null) { - throw new IllegalArgumentException("could not find a provider for type " + config.getType()); - } - return provider.newInstance(getConfig()); - } - - private VCSHandlerFactory() { - long t0 = System.nanoTime(); - providers = new ArrayList<VCSProvider>(); - for (VCSProvider provider : ServiceLoader.load(VCSProvider.class)) { - providers.add(provider); - if (log.isDebugEnabled()) { - log.debug("find " + provider); - } - } - log.info("found " + providers.size() + " provider(s) " + providers.toString() + " in " + StringUtil.convertTime(t0, System.nanoTime())); - for (VCSProvider provider : providers) { - log.info(provider.getName() + " [" + provider + ']'); - } - } - - private VCSProvider getProvider(String type) { - for (VCSProvider provider : providers) { - if (type.equals(provider.getName().toUpperCase())) { - return provider; - } - } - throw new IllegalArgumentException("could not found a provier for " + config); - } - - private static void assertConfigIsNotNull(VCSConfig vcsConfig) { - if (vcsConfig == null) { - throw new VCSRuntimeException(_("lutinvcs.error.init.no.config", VCSHandlerFactory.class.getName())); - } - } - - private static void assertConfigIsInit(VCSConfig config) { - assertConfigIsNotNull(config); - if (!config.isInit()) { - throw new VCSRuntimeException(_("lutinvcs.error.init.config", config)); - } - } - -} \ No newline at end of file Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractVCSFileStatesModel.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractVCSFileStatesModel.java 2008-04-05 20:37:17 UTC (rev 362) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractVCSFileStatesModel.java 2008-04-05 20:37:32 UTC (rev 363) @@ -1,280 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, -* Benjamin Poussin, Tony Chemit -* -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package org.codelutin.vcs.ui.model; - -import static org.codelutin.i18n.I18n._; -import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSFileState; -import org.codelutin.vcs.VCSState; - -import javax.swing.ListSelectionModel; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -/** - * Simple Table model to display list of VCSFileState - * - * @author chemit - */ -public abstract class AbstractVCSFileStatesModel extends javax.swing.table.AbstractTableModel { - - protected final String name; - - protected List<VCSFileState> data; - - protected final String[] columnNames; - - private static final long serialVersionUID = 4697917831388337369L; - - protected AbstractVCSFileStatesModel(String name, String[] columnNames) { - super(); - this.name = name; - this.columnNames = columnNames; - } - - public List<VCSFileState> getData() { - return data; - } - - public String getName() { - return name; - } - - public int getColumnCount() { - return columnNames.length; - } - - public int getRowCount() { - return data == null ? 0 : data.size(); - } - - /*@Override - public Class<?> getColumnClass(int columnIndex) { - return String.class; - }*/ - - @Override - public String getColumnName(int columnIndex) { - return _(columnNames[columnIndex]); - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - // read only data - return false; - } - - @Override - public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - // read only data - } - - - public void setData(List<VCSFileState> states) { - if (data != null) { - data.clear(); - data.addAll(states); - } else { - data = new ArrayList<VCSFileState>(states); - } - fireTableDataChanged(); - } - - public void addData(VCSFileState... states) { - if (data != null) { - data.addAll(Arrays.asList(states)); - } else { - data = new ArrayList<VCSFileState>(Arrays.asList(states)); - } - fireTableDataChanged(); - } - - public void removeData(VCSFileState... states) { - if (isEmpty()) { - return; - } - data.removeAll(Arrays.asList(states)); - fireTableDataChanged(); - } - - protected boolean isEmpty() { - return data == null || data.isEmpty(); - } - - public void clear() { - if (isEmpty()) { - return; - } - data.clear(); - fireTableDataChanged(); - } - - public VCSFileState[] getData(VCSAction action) { - if (isEmpty()) { - return new VCSFileState[0]; - } - List<VCSFileState> list = new ArrayList<VCSFileState>(data); - for (Iterator<VCSFileState> it = list.iterator(); it.hasNext();) { - VCSFileState fileState = it.next(); - List<VCSAction> actions = fileState.getState().getActions(); - if (!actions.contains(action)) { - it.remove(); - } - } - return list.toArray(new VCSFileState[list.size()]); - } - - /** - * restrict in model, only lines with given action enabled - * - * @param action current action to filter - * @param selectionModel current selection where to filter - * @param reset if <code>true</code> means take - */ - public void select(VCSAction action, ListSelectionModel selectionModel, boolean reset) { - if (isEmpty()) { - return; - } - selectionModel.setValueIsAdjusting(true); - if (reset) { - selectionModel.clearSelection(); - } - for (int i = 0; i < data.size(); i++) { - VCSFileState fileState = data.get(i); - List<VCSAction> actions = fileState.getState().getActions(); - if (reset) { - if (actions.contains(action)) { - selectionModel.addSelectionInterval(i, i); - } - } else if (!actions.contains(action)) { - selectionModel.removeSelectionInterval(i, i); - } - } - selectionModel.setValueIsAdjusting(false); - } - - public VCSFileState[] getData(VCSState action) { - if (isEmpty()) { - return new VCSFileState[0]; - } - List<VCSFileState> list = new ArrayList<VCSFileState>(data); - for (Iterator<VCSFileState> it = list.iterator(); it.hasNext();) { - VCSFileState fileState = it.next(); - if (!action.equals(fileState.getState())) { - it.remove(); - } - } - return list.toArray(new VCSFileState[list.size()]); - } - - public VCSState[] getStates() { - if (isEmpty()) { - return new VCSState[0]; - } - List<VCSState> result = new ArrayList<VCSState>(); - for (VCSFileState vcsFileState : data) { - VCSState state = vcsFileState.getState(); - if (state != null && !result.contains(state)) { - result.add(state); - } - } - return result.toArray(new VCSState[result.size()]); - } - - public VCSAction[] getActions() { - if (isEmpty()) { - return new VCSAction[0]; - } - List<VCSAction> result = new ArrayList<VCSAction>(); - for (VCSState vcsFileState : getStates()) { - List<VCSAction> action = vcsFileState.getActions(); - for (VCSAction vcsAction : action) { - if (vcsAction != null && !result.contains(vcsAction)) { - result.add(vcsAction); - } - } - } - return result.toArray(new VCSAction[result.size()]); - } - - public VCSFileState[] getData(ListSelectionModel selectionModel) { - if (isEmpty() || selectionModel.isSelectionEmpty()) { - return new VCSFileState[0]; - } - List<VCSFileState> list = new ArrayList<VCSFileState>(); - for (int i = 0, max = size(); i < max; i++) { - if (selectionModel.isSelectedIndex(i)) { - list.add(data.get(i)); - } - } - return list.toArray(new VCSFileState[list.size()]); - } - - public VCSAction[] getActions(ListSelectionModel selectionModel) { - if (isEmpty() || selectionModel.isSelectionEmpty()) { - return new VCSAction[0]; - } - List<VCSAction> result = new ArrayList<VCSAction>(); - for (VCSState vcsFileState : getStates(selectionModel)) { - List<VCSAction> action = vcsFileState.getActions(); - for (VCSAction vcsAction : action) { - if (vcsAction != null && !result.contains(vcsAction)) { - result.add(vcsAction); - } - } - } - return result.toArray(new VCSAction[result.size()]); - } - - public VCSState[] getStates(ListSelectionModel selectionModel) { - if (isEmpty() || selectionModel.isSelectionEmpty()) { - return new VCSState[0]; - } - List<VCSState> result = new ArrayList<VCSState>(); - for (int i = 0, max = size(); i < max; i++) { - if (selectionModel.isSelectedIndex(i)) { - VCSFileState vcsFileState = data.get(i); - VCSState state = vcsFileState.getState(); - if (state != null && !result.contains(state)) { - result.add(state); - } - } - } - return result.toArray(new VCSState[result.size()]); - } - - - @Override - public String toString() { - return super.toString() + "<name:" + name + ", size:" + (isEmpty() ? "0" : size()) + '>'; - } - - public void refresh(VCSState... states) { - //TODO launch refreshaction on given states - - } - - - public int size() { - return data.size(); - } -} \ No newline at end of file Deleted: trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/MethodTest.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/MethodTest.java 2008-04-05 20:37:17 UTC (rev 362) +++ trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/MethodTest.java 2008-04-05 20:37:32 UTC (rev 363) @@ -1,19 +0,0 @@ -/** - * # #% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * # #% - */ -package org.codelutin.vcs; - -/** @author chemit */ -public @interface MethodTest { -} Deleted: trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/RepositoryStateTest.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/RepositoryStateTest.java 2008-04-05 20:37:17 UTC (rev 362) +++ trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/RepositoryStateTest.java 2008-04-05 20:37:32 UTC (rev 363) @@ -1,68 +0,0 @@ -package org.codelutin.vcs; - -import static org.codelutin.vcs.VCSType.SVN; - -import java.io.File; -import java.util.List; - -public class RepositoryStateTest extends VCSTest { - static protected int start, last; - - static protected int[] interval; - - static protected VCSLocalDataContext context; - - protected void setUpVars() { - vcsType = SVN; - resetConfiguration = true; - } - - @Override - protected void initConfig() throws Exception { - super.initConfig(); - context = new VCSLocalDataContext(getLocalDatabaseFile()); - initVCS(); - } - - protected void tearDownVars() throws Exception { - resetConfiguration = null; - vcsType = null; - disposeVCS(); - } - - // ///////////////////////////////////////////////////////////////////////// - // / Demarrage du scenario - // ///////////////////////////////////////////////////////////////////////// - - static List<File> list, list2; - - static VCSState state; - - static long rev1, rev2, rev3; - - @MethodTest - public final void testObtainFileState() { - //fail("Not yet implemented"); // TODO - } - - // ///////////////////////////////////////////////////////////////////////// - // / Methodes utiles - // ///////////////////////////////////////////////////////////////////////// - - protected void setCommand(VCSState stateToTest, String command) { - setCommand(start, last, stateToTest, command); - } - - protected void setCommand(int pStart, int pLast, VCSState stateToTest, - String command) { - state = stateToTest; - if (!(pStart == start && pLast == last)) { - start = pStart; - last = pLast; - interval = context.getIndex(pStart, pLast); - } - log.info("[state:" + state + "] [" + command + "] on interval [" - + start + "," + last + "]"); - } - -} Deleted: trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSFileStateManagerTest.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSFileStateManagerTest.java 2008-04-05 20:37:17 UTC (rev 362) +++ trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSFileStateManagerTest.java 2008-04-05 20:37:32 UTC (rev 363) @@ -1,251 +0,0 @@ -package org.codelutin.vcs; - -import static org.codelutin.vcs.VCSLocalData.FILE; -import static org.codelutin.vcs.VCSState.MISSING; -import static org.codelutin.vcs.VCSState.MODIFIED; -import static org.codelutin.vcs.VCSState.OUT_OF_DATE; -import static org.codelutin.vcs.VCSState.OUT_OF_DATE_AND_MODIFIED; -import static org.codelutin.vcs.VCSState.UNKNOWN; -import static org.codelutin.vcs.VCSState.UNVERSIONNED; -import static org.codelutin.vcs.VCSState.UP_TO_DATE; - -import java.io.File; -import static java.io.File.separator; -import java.util.ArrayList; -import static java.util.Arrays.asList; -import java.util.List; - -/** - * VCSFileStateManager Tester. - * - * @author <Authors name> - * @version 1.0 - * @since <pre>10/14/2007</pre> - */ -public class VCSFileStateManagerTest extends VCSTest { - - static protected int start, last; - static protected int[] interval; - - static protected VCSHandler svnhandler; - static protected VCSLocalDataContext context; - - protected void setUpVars() { - vcsType = VCSType.SVN; - resetConfiguration = true; - } - - @Override - protected void initConfig() throws Exception { - super.initConfig(); - context = new VCSLocalDataContext(getLocalDatabaseFile()); - - initVCS(); - - } - - protected void tearDownVars() throws Exception { - resetConfiguration = null; - vcsType = null; - disposeVCS(); - } - - /////////////////////////////////////////////////////////////////////////// - /// Demarrage du scenario - /////////////////////////////////////////////////////////////////////////// - - static List<File> list, list2; - static List<VCSFileState> listS, list2S; - static VCSState state; - static long rev1, rev2, rev3; - - @MethodTest - public void testUnknowState() throws Exception { - - // get n files unexisiting files and assert state is unknown - setCommand(0, 2, UNKNOWN, ""); - - list = context.getFile(VCSLocalData.FILE, interval); - - listS = new ArrayList<VCSFileState>(); - for (File file : list) - listS.add(VCSFileStateManager.getState(handler, false, file)); - list2S = asList(VCSFileStateManager.getState(handler, false, list)); - assertEquals(listS, list2S); - - assertFileState(list, listS, null, false); - - assertFileState(list, listS, state, true); - - listS = new ArrayList<VCSFileState>(); - for (File file : list) - listS.add(VCSFileStateManager.getState(handler, true, file)); - - assertFileState(list, asList( - VCSFileStateManager.getState(handler, true, list)), state, true); - - list2 = context.getFile(VCSLocalData.FILE, "subdir" + separator, - interval); - - assertFileState(list2, list2S, state, true); - - } - - @MethodTest - public void testUnversionnedState() throws Exception { - - // create n files and assert that state is unversionned - setCommand(UNVERSIONNED, ""); - - list = context.create(VCSLocalData.FILE, interval); - assertFileState(list, listS, state, true); - - list2 = context.create(VCSLocalData.FILE, "subdir" + separator, - interval); - assertFileState(list2, list2S, state, true); - } - - @MethodTest - public void testUpToDateState() throws Exception { - - // add n files and assert to state is up to date - - setCommand(UP_TO_DATE, ""); - - //list = context.getFile(VCSLocalData.FILE, interval); - - rev1 = handler.add(list, FILE.getCommitMessage("add", this)); - - assertFileState(list, listS, state, true); - } - - @MethodTest - public void testMissingState() throws Exception { - - // delete locally 5 file and assert to state is missing - - setCommand(MISSING, ""); - - //list = context.getFile(VCSLocalData.FILE, interval); - - context.delete(VCSLocalData.FILE, interval); - - assertFileState(list, listS, state, true); - - for (File file : list) handler.update(file); - - assertFileState(list, listS, UP_TO_DATE, true); - - } - - - @MethodTest - public void testModifiedState() throws Exception { - - // modify 5 file and assert to state is modified - - setCommand(MODIFIED, ""); - - //list = context.getFile(VCSLocalData.FILE, interval); - - for (File file : list) modifyFile(file, 10, 'a'); - - listS = asList(VCSFileStateManager.getState(handler, true, list)); - assertFileState(list, listS, state, true); - - handler.revert(list); - listS = asList(VCSFileStateManager.getState(handler, true, list)); - assertFileState(list, listS, UP_TO_DATE, true); - } - - - @MethodTest - public void testOutOfDateState() throws Exception { - - // commit n files, revert to first version and assert to state is - // out to date - - setCommand(OUT_OF_DATE, ""); - - //list = context.getFile(VCSLocalData.FILE, interval); - - for (File file : list) modifyFile(file, 10, 'a'); - listS = asList(VCSFileStateManager.getState(handler, true, list)); - assertFileState(list, listS, MODIFIED, true); - - /*rev2 = handler.commit(list, FILE.getCommitMessage("commit one", this)); - - final SVNRevision revision = SVNRevision.create(rev1); - - for (File file : list) handler.update(file, revision); - - //listS = asList(VCSFileStateManager.getFileState(true, handler, list)); - assertFileState(list, listS, state, true); - - context.delete(VCSLocalData.FILE, interval); - - //listS = asList(VCSFileStateManager.getFileState(true, handler, list)); - assertFileState(list, listS, MISSING, true); - - for (File file : list) handler.update(file, revision); - - //listS = asList(VCSFileStateManager.getFileState(true, handler, list)); - assertFileState(list, listS, state, true); - */ - - } - - @MethodTest - public void testOutOfDateAndModifiedState() throws Exception { - - // modified n files, revert to first version and assert to state is out - // to date - - setCommand(OUT_OF_DATE_AND_MODIFIED, ""); - - //list = context.getFile(VCSLocalData.FILE, interval); - - for (File file : list) modifyFile(file, 20, 'b'); - - //listS = asList(VCSFileStateManager.getFileState(true, handler, list)); - assertFileState(list, listS, state, true); - - //final SVNRevision revision = SVNRevision.create(rev1); - - handler.revert(list); - - //listS = asList(VCSFileStateManager.getFileState(true, handler, list)); - assertFileState(list, listS, OUT_OF_DATE, true); - - for (File file : list) modifyFile(file, 15, 'c'); - - //listS = asList(VCSFileStateManager.getFileState(true, handler, list)); - assertFileState(list, listS, state, true); - - handler.revert(list); - - //listS = asList(VCSFileStateManager.getFileState(true, handler, list)); - assertFileState(list, listS, OUT_OF_DATE, true); - } - - /////////////////////////////////////////////////////////////////////////// - /// Methodes utiles - /////////////////////////////////////////////////////////////////////////// - - protected void setCommand(VCSState stateToTest, String command) { - setCommand(start, last, stateToTest, command); - } - - protected void setCommand(int pStart, int pLast, VCSState stateToTest, - String command) { - state = stateToTest; - if (!(pStart == start && pLast == last)) { - start = pStart; - last = pLast; - interval = context.getIndex(pStart, pLast); - } - - log.info("[state:" + state + "] [" + command + "] on interval [" + start + "," + last + "]"); - } - -} Deleted: trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSHandlerTest.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSHandlerTest.java 2008-04-05 20:37:17 UTC (rev 362) +++ trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSHandlerTest.java 2008-04-05 20:37:32 UTC (rev 363) @@ -1,582 +0,0 @@ -package org.codelutin.vcs; - - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * This junit test class tests all methods of the implementation of a VCSHandler <code>XXX</code> (says CVS, or SVN) - * The VCSType used is junit_<code>XXX</code> - * The remote database is name is isis-fish-vcs-test_junit - * The local database name is isis-fish-vcs-test_junit_<code>XXX</code> - */ -public abstract class VCSHandlerTest extends VCSTest { - - //static protected final String patternFile = "_file_{0}.txt"; - //static protected final String patternDirectory = "_directory_{0}.txt"; - - private static int start, last; - private static int[] interval; - - static protected VCSLocalDataContext context; - - protected void setUpVars() { - resetConfiguration = true; - } - - @Override - protected void initConfig() throws Exception { - super.initConfig(); - context = new VCSLocalDataContext(getLocalDatabaseFile()); - } - - protected void tearDownVars() { - resetConfiguration = null; - vcsType = null; - } - - //TODO Should test configuration ? - - /////////////////////////////////////////////////////////////////////////////////////////// - /// Tests des cas limites - /////////////////////////////////////////////////////////////////////////////////////////// - - @MethodTest - public void testAddWithNullFileList() throws Exception { - try { - handler.add(null, VCSLocalData.FILE.getCommitMessage("add", this)); - fail(); - } catch (VCSRuntimeException e) { - assertTrue(true); - } - } - - @MethodTest - public void testAddUnExistantFiles() throws Exception { - // try to add non existing file - - List<File> files = context.getFile(VCSLocalData.FILE, 0, 1); - - long rev = handler.add(files, VCSLocalData.FILE.getCommitMessage("add unexistant ", this)); - assertEquals(rev, -1); - - } - - - @MethodTest - public void testAddUnExistantFilesWithNoCommit() throws Exception { - try { - handler.add(null, null); - fail(); - } catch (VCSRuntimeException e) { - assertTrue(true); - } - } - - @MethodTest - public void testDeleteNullFileList() throws Exception { - try { - handler.delete(null, ""); - fail(); - } catch (VCSRuntimeException e) { - assertTrue(true); - } - } - - @MethodTest - public void testDeleteNullFileListWithNocommit() throws Exception { - try { - handler.delete(null, null); - fail(); - } catch (VCSRuntimeException e) { - assertTrue(true); - } - } - - /////////////////////////////////////////////////////////////////////////////////////////// - /// Preparation repository et working copy - /////////////////////////////////////////////////////////////////////////////////////////// - - @MethodTest - public void testCreateRemoteDatabaseDirectory() throws Exception { - - // assert remote database does not exists - try { - handler.deleteRemoteDir(VCSLocalData.DIRECTORY.getCommitMessage("deldir remote", this), ""); - } catch (VCSException e) { - // this is ok for this time :) - // we just wants to be sure the remote database directory does not exists any longer - } - - // create remote directory - handler.makeRemoteDir(VCSLocalData.DIRECTORY.getCommitMessage("mkdir remote", this), ""); - - // assert remote directory exist now - - } - - @MethodTest - public void testCheckoutDatabaseDirectory() throws Exception { - - handler.deleteWorkingCopy(); - - // assert local directory not exists - assertFalse(getLocalDatabaseFile().exists()); - - handler.initWorkingCopy(); - - // assert directory exists and contains vcs configuration directory in this file - assertTrue(getLocalDatabaseFile().exists()); - - assertTrue(new File(getLocalDatabaseFile(), handler.getConfLocalDirname()).exists()); - - } - - /////////////////////////////////////////////////////////////////////////////////////////// - /// Demarrage du scenario - /////////////////////////////////////////////////////////////////////////////////////////// - - static List<File> list; - - @MethodTest - public void testAddFiles() throws Exception { - setCommand(0, 4, "add with commit"); - list = context.create(VCSLocalData.FILE, interval); - assertState(list, VCSState.UNVERSIONNED); - - handler.add(list, VCSLocalData.FILE.getCommitMessage("add", this)); - - assertState(list, VCSState.UP_TO_DATE); - - } - - @MethodTest - public void testAddDirectories() throws Exception { - setCommand(0, 4, "add with commit"); - list = context.create(VCSLocalData.DIRECTORY, interval); - assertState(list, VCSState.UNVERSIONNED); - - - handler.add(list, VCSLocalData.DIRECTORY.getCommitMessage("add", this)); - - assertState(list, VCSState.UP_TO_DATE); - } - - @MethodTest - public void testAddFilesWithNoCommit() throws Exception { - setCommand(5, 9, "add with no commit"); - list = context.create(VCSLocalData.FILE, interval); - assertState(list, VCSState.UNVERSIONNED); - - handler.add(list, null); - - assertState(list, VCSState.UNKNOWN); - } - - @MethodTest - public void testAddDirectoriesWithNoCommit() throws Exception { - list = context.create(VCSLocalData.DIRECTORY, interval); - assertState(list, VCSState.UNVERSIONNED); - - handler.add(list, null); - - assertState(list, VCSState.UNKNOWN); - } - - @MethodTest - public void testCommitAddFiles() throws Exception { - setCommand(5, 9, "commit unadded"); - list = context.getFile(VCSLocalData.FILE, interval); - assertState(list, VCSState.UNKNOWN); - - handler.commit(list, VCSLocalData.FILE.getCommitMessage("commit unadded", this)); - - assertState(list, VCSState.UP_TO_DATE); - } - - @MethodTest - public void testCommitAddDirectories() throws Exception { - list = context.getFile(VCSLocalData.DIRECTORY, interval); - assertState(list, VCSState.UNKNOWN); - - handler.commit(list, VCSLocalData.DIRECTORY.getCommitMessage("commit unadded", this)); - - assertState(list, VCSState.UP_TO_DATE); - } - - @MethodTest - public void testDeleteFiles() throws Exception { - setCommand(7, 9, "delete with commit"); - list = context.getFile(VCSLocalData.FILE, interval); - assertState(list, VCSState.UP_TO_DATE); - - handler.delete(list, VCSLocalData.FILE.getCommitMessage("delete", this)); - - assertState(list, VCSState.UNKNOWN); - } - - @MethodTest - public void testDeleteDirectories() throws Exception { - list = context.getFile(VCSLocalData.DIRECTORY, interval); - assertState(list, VCSState.UP_TO_DATE); - - handler.delete(list, VCSLocalData.DIRECTORY.getCommitMessage("delete", this)); - - assertState(list, VCSState.UNKNOWN); - } - - @MethodTest - public void testDeleteFilesWithNocommit() throws Exception { - setCommand(4, 6, "delete with no commit"); - list = context.getFile(VCSLocalData.FILE, interval); - assertState(list, VCSState.UP_TO_DATE); - - handler.delete(list, null); - - assertState(list, VCSState.UNKNOWN); - } - - - @MethodTest - public void testDeleteDirectoriesWithNocommit() throws Exception { - list = context.getFile(VCSLocalData.DIRECTORY, interval); - assertState(list, VCSState.UP_TO_DATE); - - handler.delete(list, null); - - assertState(list, VCSState.UNKNOWN); - - } - - @MethodTest - public void testCommitDeleteFiles() throws Exception { - setCommand(4, 6, "commit undeleted"); - list = context.getFile(VCSLocalData.FILE, interval); - assertState(list, VCSState.UNKNOWN); - - handler.commit(list, VCSLocalData.FILE.getCommitMessage("commit undeleted", this)); - - // when commit a deleted file, we do not delete locally file - // => so this is a unversioned file - assertState(list, VCSState.UNVERSIONNED); - - // we delete files by hand... - context.delete(VCSLocalData.FILE, interval); - - } - - @MethodTest - public void testCommitDeleteDirectories() throws Exception { - list = context.getFile(VCSLocalData.DIRECTORY, interval); - assertState(list, VCSState.UNKNOWN); - - handler.commit(list, VCSLocalData.DIRECTORY.getCommitMessage("commit undeleted", - this)); - - // when commit a deleted directory, direcotry is deleted !!! Find why ? - assertState(list, VCSState.UNKNOWN); - } - - @MethodTest - public void testGetLocalStorageNames() throws Exception { - - // at this point of the scenario, we only have a [0-3] - // (files/directories) left on local and remote - setCommand(0, 3, "getLocalStorageNames"); - - List<String> excepted = new ArrayList<String>(); - - list = context.getFile(VCSLocalData.FILE, interval); - //list.addAll(context.getFile(VCSLocalData.DIRECTORY, interval)); - for (File f : list) if (f.isFile()) excepted.add(f.getName()); - - List<String> list2 = - handler.getLocalStorageNames(getLocalDatabaseFile()); - - assertEquals(excepted.size(), list2.size()); - - for (String filename : excepted) { - assertTrue("should have found a " + filename + - " file in result but we do not! ", - list2.contains(filename)); - } - - } - - @MethodTest - public void testGetRemoteStorageNames() throws Exception { - - // at this point of the scenario, we only have a [0-3] - // (files/directories) left on local and remote - setCommand(0, 3, "getRemoteStorageNames"); - - list = context.getFile(VCSLocalData.FILE, interval); - //list.addAll(context.getFile(VCSLocalData.DIRECTORY, interval)); - - List<String> list2 = - handler.getRemoteStorageNames(getLocalDatabaseFile()); - - assertEquals(list.size(), list2.size()); - - // we can not know the style of encoded remote name ? - //for (File f : list) assertTrue(list2.contains(f)); - } - - @MethodTest - public void testIsOnRemote() throws Exception { - - // at this point of the scenario, we only have a [0-3] - // (files/directories) left on local and remote - setCommand(0, 3, "isOnRemote"); - - list = context.getFile(VCSLocalData.FILE, interval); - list.addAll(context.getFile(VCSLocalData.DIRECTORY, interval)); - - for (File f : list) assertTrue(handler.isOnRemote(f)); - - assertFalse(handler.isOnRemote(new File(getLocalDatabaseFile(), - "nonExistingFile"))); - - } - - @MethodTest - public void testRevert() throws Exception { - - // at this point of the scenario, we only have a [0-3] - // (files/directories) left on local and remote - setCommand(0, 3, "revert"); - - //TODO we only test on file (I don't think you can have - // a modified directory ? should be check...) - list = context.getFile(VCSLocalData.FILE, interval); - - assertState(list, VCSState.UP_TO_DATE); - - handler.revert(list); - - // revert on a normal file should have no effect - assertState(list, VCSState.UP_TO_DATE); - - for (File f : list) { - // we know that file is 0, change it to 10 (with 10 a for example) - modifyFile(f, 10); - } - assertState(list, VCSState.MODIFIED); - - handler.revert(list); - - // we came back to file with size = 0 - - assertState(list, VCSState.UP_TO_DATE); - for (File f : list) assertEquals(f.length(), 0); - - // a non existing file can not be revert of course.... - File file = new File(getLocalDatabaseFile(), "nonExistingFile"); - try { - handler.revert(this.getOneFileAsList(file)); - fail(); - } catch (VCSException e) { - assertTrue(true); - } - - // now file exists, but still can not revert it since it is not - // versionned - file.createNewFile(); - try { - handler.revert(this.getOneFileAsList(file)); - fail(); - } catch (VCSException e) { - assertTrue(true); - } finally { - file.delete(); - } - } - - @MethodTest - public void testUpdate() throws Exception { - - // at this point of the scenario, we only have a [0-3] (files/directories) left on local and remote - setCommand(0, 3, "update"); - - //TODO we only test on file (I don't think you can have a modified directory ? should be check...) - list = context.getFile(VCSLocalData.FILE, interval); - - assertState(list, VCSState.UP_TO_DATE); - - File f = list.get(0); - - handler.update(f); - - // update a non remoted modfied file should have no effect - assertState(list, VCSState.UP_TO_DATE); - - // we know that file is 0, change it to 10 (with 10 a for example) - modifyFile(f, 20); - - // file is modified now - assertState(f, VCSState.MODIFIED); - - // we can not update a modifed file - try { - handler.update(f); - fail(); - } catch (VCSException e) { - assertTrue(true); - } - - Object fileRevision = handler.getRevision(f); - - // delete file - VCSLocalData.FILE.delete(f); - - // update it from remote vcs - handler.update(f); - - // back to normal after update - assertState(f, VCSState.UP_TO_DATE); - - assertEquals(fileRevision, handler.getRevision(f)); - - // a non existing file can not be revert of course.... - File file = new File(getLocalDatabaseFile(), "nonExistingFile"); - try { - handler.revert(this.getOneFileAsList(file)); - fail(); - } catch (VCSException e) { - assertTrue(true); - } - - // now file exists, but still can not revert it since it is not versionned - file.createNewFile(); - try { - handler.revert(this.getOneFileAsList(file)); - fail(); - } catch (VCSException e) { - assertTrue(true); - } finally { - file.delete(); - } - - } - - - @MethodTest - public void testIsUpToDate() throws Exception { - - // at this point of the scenario, we only have a [0-3] (files/directories) left on local and remote - setCommand(0, 3, "isUpToDate"); - - list = context.getFile(VCSLocalData.FILE, interval); - - assertTrue(list.size() > 0); - - assertState(list, VCSState.UP_TO_DATE); - - for (File f : list) assertTrue(handler.isUpToDate(f)); - - File f = list.get(0); - - Object oldRev = handler.getRevision(f); - - // modify file : so file is no more upTodate - modifyFile(f, 30); - - assertFalse(handler.isUpToDate(f)); - - // commit file - handler.commit(getOneFileAsList(f), VCSLocalData.FILE.getCommitMessage("commit for test", this)); - - assertTrue(handler.isUpToDate(f)); - - // delete file from local working copy, so file is no more upToDate - VCSLocalData.FILE.delete(f); - - assertFalse(handler.isUpToDate(f)); - - // go back to previous version - handler.update(f, oldRev); - - // now local file is out up to date : older revision than on remote repository - assertFalse(handler.isUpToDate(f)); - - // delete file from remote repository, so file is no more upToDate - try { - handler.delete(getOneFileAsList(f), VCSLocalData.FILE.getCommitMessage("delete", this)); - // we can not delete a non updated file - fail(); - } catch (VCSException e) { - assertTrue(true); - handler.revert(getOneFileAsList(f)); - } - - // go back to head - handler.update(f); - - assertTrue(handler.isUpToDate(f)); - - handler.delete(getOneFileAsList(f), VCSLocalData.FILE.getCommitMessage("delete", this)); - - assertFalse(handler.isUpToDate(f)); - - // read file : file is uptodate - - f.createNewFile(); - - handler.add(getOneFileAsList(f), VCSLocalData.FILE.getCommitMessage("readd", this)); - - assertTrue(handler.isUpToDate(f)); - - // a non existing file can not be up to date of course... - File file = new File(getLocalDatabaseFile(), "nonExistingFile"); - assertFalse(handler.isUpToDate(file)); - - // now file exists, but still not up to date - file.createNewFile(); - try { - assertFalse(handler.isUpToDate(file)); - } finally { - file.delete(); - } - } - - /////////////////////////////////////////////////////////////////////////////////////////// - /// Suppression du repository et working copy - /////////////////////////////////////////////////////////////////////////////////////////// - - @MethodTest - public void testDeleteRemoteDir() throws Exception { - - // delete remote directory - handler.deleteRemoteDir(VCSLocalData.DIRECTORY.getCommitMessage("deldir remote", this), ""); - - // assert remote directory doe not exist any more - - } - - @MethodTest - public void testDeleteWorkingCopy() throws Exception { - - handler.deleteWorkingCopy(); - - // assert local directory does not exists any longer - assertFalse(getLocalDatabaseFile().exists()); - - } - - /////////////////////////////////////////////////////////////////////////////////////////// - /// M�thodes utiles - /////////////////////////////////////////////////////////////////////////////////////////// - - protected void setCommand(int start, int last, String command) { - if (!(start == VCSHandlerTest.start && last == VCSHandlerTest.last)) { - VCSHandlerTest.start = start; - VCSHandlerTest.last = last; - VCSHandlerTest.interval = context.getIndex(start, last); - } - - log.info("[" + command + "] on interval [" + VCSHandlerTest.start + "," + VCSHandlerTest.last + "]"); - } - - -} \ No newline at end of file Deleted: trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSInitTest.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSInitTest.java 2008-04-05 20:37:17 UTC (rev 362) +++ trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSInitTest.java 2008-04-05 20:37:32 UTC (rev 363) @@ -1,134 +0,0 @@ -/* *##% -* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, -* Benjamin Poussin, Tony Chemit -* -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*##%*/ -package org.codelutin.vcs; - -import junit.framework.TestCase; -import org.codelutin.i18n.I18n; - - -/** - * Test vcs properties at init time. TODO Redo it with new init proccess - * - * @author chemit - * @version 1.0 - * @since <pre>12/09/2007</pre> - */ -public class VCSInitTest extends TestCase { - - static { - // init i18n - I18n.init(); - } - - public void testFirstLaunchWithCVS() throws Exception { -// init = new OldVCSInit( -// VCSType.CVS, -// new VersionNumber(1,1,0), -// null -// ); -// assertTrue(init.oldVCSProperties.isEmpty()); -// assertFalse(init.oldVCSProperties.isFull()); -// assertFalse(init.newVCSProperties.isEmpty()); -// assertFalse(init.newVCSProperties.isFull()); -// assertTrue(init.newVCSProperties.isSafe()); -// -// assertFalse(init.isTypeChanged()); -// assertFalse(init.needMigration()); -// assertEquals(init.newVCSProperties.getProperty(VCS_TYPE_REPO), VCSTypeRepo.NONE); - } - - public void testFirstLaunchWithSVN_onHEAD() throws Exception { -// init = new OldVCSInit( -// VCSType.SVN, -// new VersionNumber(1,1,0), -// null -// ); -// assertTrue(init.oldVCSProperties.isEmpty()); -// assertFalse(init.oldVCSProperties.isFull()); -// assertFalse(init.newVCSProperties.isEmpty()); -// assertFalse(init.newVCSProperties.isFull()); -// assertTrue(init.newVCSProperties.isSafe()); -// -// assertFalse(init.isTypeChanged()); -// assertFalse(init.needMigration()); -// assertEquals(init.newVCSProperties.getProperty(VCS_TYPE_REPO), VCSTypeRepo.HEAD); - } - - public void testFirstLaunchWithSVN_onTAG() throws Exception { -// init = new OldVCSInit( -// VCSType.SVN, -// new VersionNumber(3,0,19), -// null -// ); -// assertTrue(init.oldVCSProperties.isEmpty()); -// assertFalse(init.oldVCSProperties.isFull()); -// assertFalse(init.newVCSProperties.isEmpty()); -// assertFalse(init.newVCSProperties.isFull()); -// assertTrue(init.newVCSProperties.isSafe()); -// -// assertFalse(init.isTypeChanged()); -// assertFalse(init.needMigration()); -// assertEquals(VCSTypeRepo.TAG,init.newVCSProperties.getProperty(VCS_TYPE_REPO)); - } - - public void testPreviousWasCVSNewIsCVS() throws Exception { -// URI uri = getClass().getResource("/.isis-config-3_cvs").toURI(); -// init = new OldVCSInit( -// VCSType.CVS, -// new VersionNumber(1,1,0), -// uri -// ); -// assertFalse(init.oldVCSProperties.isEmpty()); -// assertFalse(init.oldVCSProperties.isFull()); -// assertFalse(init.newVCSProperties.isEmpty()); -// assertFalse(init.newVCSProperties.isFull()); -// assertTrue(init.newVCSProperties.isSafe()); -// -// assertFalse(init.isTypeChanged()); -// assertFalse(init.needMigration()); -// assertEquals(VCSTypeRepo.NONE,init.newVCSProperties.getProperty(VCS_TYPE_REPO)); - } - - public void testPreviousWasCVSNewIsSVN() throws Exception { -// URI uri = getClass().getResource("/.isis-config-3_cvs").toURI(); -// init = new OldVCSInit( -// VCSType.SVN, -// new VersionNumber(1,1,0), -// uri -// ); -// assertFalse(init.oldVCSProperties.isEmpty()); -// assertFalse(init.oldVCSProperties.isFull()); -// assertFalse(init.newVCSProperties.isEmpty()); -// assertFalse(init.newVCSProperties.isFull()); -// assertTrue(init.newVCSProperties.isSafe()); -// -// assertTrue(init.isTypeChanged()); -// assertTrue(init.needMigration()); -// assertEquals(VCSTypeRepo.HEAD,init.newVCSProperties.getProperty(VCS_TYPE_REPO)); - } - - public void testPreviousWasSVNNewIsTAG() throws Exception { - //TODO - } - - public void testPreviousWasSVNNewIsHEAD() throws Exception { - //TODO - } -} Deleted: trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSLocalData.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSLocalData.java 2008-04-05 20:37:17 UTC (rev 362) +++ trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSLocalData.java 2008-04-05 20:37:32 UTC (rev 363) @@ -1,112 +0,0 @@ -package org.codelutin.vcs; - -import junit.framework.TestCase; -import org.codelutin.util.FileUtil; - -import java.io.File; -import java.io.IOException; -import static java.text.MessageFormat.format; - -/** - * Util for our local files and directories with a pattern for name, - * when VCSHandlerTest operation (exist, create, delete). - * - * @see VCSHandlerTest - */ -public enum VCSLocalData { - - DIRECTORY("_directory_{0}", "{0} directory by test {1}#{2} at {3}") { - - boolean delete(File f) throws IOException { - return FileUtil.deleteRecursively(f) && f.delete(); - } - boolean create(File f) throws IOException { - return f.mkdirs(); - } - }, - - FILE("_file_{0}.txt", "{0} file by test {1}#{2} at {3}") { - - boolean delete(File f) throws IOException { - return f.delete(); - } - boolean create(File f) throws IOException { - if (!f.getParentFile().exists()) f.getParentFile().mkdirs(); - return f.createNewFile(); - } - }; - - abstract boolean create(File f) throws IOException; - - abstract boolean delete(File f) throws IOException; - - private String pattern; - - private String commitPattern; - - VCSLocalData(String pattern, String commitPattern) { - this.commitPattern = commitPattern; - this.pattern = pattern; - } - - public boolean exists(File root, int... index) { - for (int i : index) - if (!getFile(root, i).exists()) return false; - return true; - } - - public File getFile(File root, int index) { - return new File(root, format(pattern, index)); - } - - public File[] getFile(File root, int... index) { - File[] result = new File[index.length]; - for (int i1 = 0; i1 < index.length; i1++) { - int i = index[i1]; - result[i1] = getFile(root, i); - } - return result; - } - - public void create(File root, int... index) throws IOException { - for (int anIndex : index) create(getFile(root, anIndex)); - - } - - public void create(File root, String prefix, int... index) throws IOException { - for (int anIndex : index) create(getFile(root, prefix, anIndex)); - - } - - private File getFile(File root, String prefix, int anIndex) { - return new File(root, prefix + format(pattern, anIndex)); - } - - public String getFilename(String prefix, int anIndex) { - return prefix + format(pattern, anIndex); - } - - public boolean delete(File root, int index) throws IOException { - final File file = getFile(root, index); - return delete(file); - } - - public boolean delete(File root, int... index) throws IOException { - for (int i : index) - if (!delete(root, i)) return false; - return true; - } - - public String getCommitMessage(String command, TestCase test) { - return format(commitPattern, command, test.getClass(), test.getName(), new java.util.Date()); - } - - public File[] getFile(File root, String prefix, int[] index) { - File[] result = new File[index.length]; - for (int i1 = 0; i1 < index.length; i1++) { - int i = index[i1]; - result[i1] = getFile(root, prefix, i); - } - return result; - } -} Deleted: trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSLocalDataContext.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSLocalDataContext.java 2008-04-05 20:37:17 UTC (rev 362) +++ trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSLocalDataContext.java 2008-04-05 20:37:32 UTC (rev 363) @@ -1,60 +0,0 @@ -package org.codelutin.vcs; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class VCSLocalDataContext { - - File root; - private List<File> result; - - - public VCSLocalDataContext(File root) { - this.root = root; - } - - public boolean exist(VCSLocalData type, int... index) { - return type.exists(root, index); - } - - public List<File> getFile(VCSLocalData type, int... index) { - final File[] files = type.getFile(root, index); - if (result == null) result = new ArrayList<File>(); - else result.clear(); - result.addAll(Arrays.asList(files)); - List<File> res = new ArrayList<File>(); - res.addAll(result); - return res; - } - - public List<File> create(VCSLocalData type, int... index) throws IOException { - type.create(root, index); - return getFile(type, index); - } - - public List<File> create(VCSLocalData type, String prefix, int... index) throws IOException { - type.create(root, prefix, index); - return getFile(type, prefix, index); - } - - public List<File> getFile(VCSLocalData type, String prefix, int[] index) { - final File[] files = type.getFile(root, prefix, index); - List<File> res = new ArrayList<File>(); - res.addAll(Arrays.asList(files)); - return res; - } - - public void delete(VCSLocalData type, int... index) throws IOException { - type.delete(root, index); - } - - public int[] getIndex(int first, int last) { - final int size = last - first; - int[] result = new int[size + 1]; - for (int i = 0; i <= size; i++) result[i] = i + first; - return result; - } -} Deleted: trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSStateTest.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSStateTest.java 2008-04-05 20:37:17 UTC (rev 362) +++ trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSStateTest.java 2008-04-05 20:37:32 UTC (rev 363) @@ -1,235 +0,0 @@ -package org.codelutin.vcs; - -import junit.framework.Assert; -import org.codelutin.util.FileUtil; -import static org.codelutin.vcs.VCSState.UNVERSIONNED_OR_MISSING; -import static org.codelutin.vcs.VCSType.SVN; -import org.codelutin.vcs.util.VCSHelper; - -import java.io.File; -import static java.io.File.separator; -import java.util.ArrayList; -import java.util.List; - -public class VCSStateTest extends VCSTest { - static protected int start, last; - - static protected int[] interval; - - static protected VCSLocalDataContext context; - - protected void setUpVars() { - VCSTest.vcsType = SVN; - VCSTest.resetConfiguration = true; - } - - @Override - protected void initConfig() throws Exception { - super.initConfig(); - context = new VCSLocalDataContext(getLocalDatabaseFile()); - - initVCS(); - } - - protected void tearDownVars() throws Exception { - VCSTest.resetConfiguration = null; - VCSTest.vcsType = null; - disposeVCS(); - } - - // ///////////////////////////////////////////////////////////////////////// - // / Demarrage du scenario - // ///////////////////////////////////////////////////////////////////////// - - static List<File> list, list2; - - static VCSState state; - - static long rev1, rev2, rev3; - - @MethodTest - public void testRemotePathFromLocalFile() throws Exception { - - // get n files unexisiting files and assert state is unknown - setCommand(0, 2, VCSState.UNKNOWN, "conversion from local file to " - + "remote module path"); - - list = context.getFile(VCSLocalData.FILE, interval); - - for (int i = 0; i < list.size(); i++) { - Assert.assertEquals(VCSHelper.getRemoteRelativePath(list.get(i), VCSTest.handler), - VCSLocalData.FILE.getFilename("", i)); - } - - list2 = context.create(VCSLocalData.FILE, "subdir" + separator, interval); - for (int i = 0; i < list2.size(); i++) { - String expected = VCSHelper.getRemoteRelativePath(list2.get(i), - VCSTest.handler); - String actual = VCSHelper.convertToRemoteName(VCSLocalData.FILE - .getFilename("subdir" + File.separator, i)); - System.out.println("excepted " + expected + " actual " + actual); - Assert.assertEquals(expected, VCSHelper.convertToRemoteName(actual)); - } - FileUtil.deleteRecursively(new File(VCSHandlerFactory.getConfig().getLocalDatabasePath(), "subdir")); - } - - @MethodTest - public void testUnknowState() throws Exception { - - // get n files unexisiting files and assert state is unknown - setCommand(0, 2, VCSState.UNKNOWN, ""); - - list = context.getFile(VCSLocalData.FILE, interval); - VCSTest.assertState(list, state); - - list2 = context.getFile(VCSLocalData.FILE, "subdir" + separator, interval); - VCSTest.assertState(list2, state); - } - - @MethodTest - public void testUnversionnedState() throws Exception { - - // create n files and assert that state is unversionned - setCommand(VCSState.UNVERSIONNED, ""); - - context.create(VCSLocalData.FILE, interval); - VCSTest.assertState(list, state); - } - - @MethodTest - public void testUnversionnedOrMissingState() throws Exception { - - // create n files and assert that state is unversionned - setCommand(VCSState.UNVERSIONNED_OR_MISSING, ""); - - context.create(VCSLocalData.FILE, "subdir" + separator, interval); - VCSTest.assertState(list2, UNVERSIONNED_OR_MISSING); - } - - @MethodTest - public void testUpToDateState() throws Exception { - - // add n files and assert to state is up to date - - setCommand(VCSState.UP_TO_DATE, ""); - - rev1 = VCSTest.handler.add(new ArrayList<File>(list), - VCSLocalData.FILE.getCommitMessage("add", this)); - - VCSTest.assertState(list, state); - - } - - @MethodTest - public void testMissingState() throws Exception { - - // delete locally 5 file and assert to state is missing - - setCommand(VCSState.MISSING, ""); - - context.delete(VCSLocalData.FILE, interval); - VCSTest.assertState(list, state); - - update(list); - VCSTest.assertState(list, VCSState.UP_TO_DATE); - final File subdir = new File(VCSTest.databaseDirectory, "subdir"); - context.create(VCSLocalData.FILE, "subdir" + separator, interval); - VCSTest.handler.add(getOneFileAsList(subdir), VCSLocalData.FILE.getCommitMessage( - "add sub files", this)); - - VCSTest.handler.add(list2, VCSLocalData.FILE.getCommitMessage("add sub files", this)); - VCSTest.assertState(list2, VCSState.UP_TO_DATE); - - FileUtil.deleteRecursively(subdir); - - context.create(VCSLocalData.FILE, "subdir" + separator, interval); - - VCSTest.assertState(list2, UNVERSIONNED_OR_MISSING); - - } - - @MethodTest - public void testModifiedState() throws Exception { - - // modify 5 file and assert to state is modified - - setCommand(VCSState.MODIFIED, ""); - - modifyFile(list, 30, 'h'); - VCSTest.assertState(list, state); - - VCSTest.handler.revert(list); - VCSTest.assertState(list, VCSState.UP_TO_DATE); - } - - @MethodTest - public void testOutOfDateState() throws Exception { - - // commit n files, revert to first version and assert to state is - // out to date - - setCommand(VCSState.OUT_OF_DATE, ""); - - modifyFile(list, 45, 'j'); - VCSTest.assertState(list, VCSState.MODIFIED); - - /*rev2 = VCSTest.handler.commit(list, VCSLocalData.FILE.getCommitMessage("commit one", this)); - final SVNRevision revision = SVNRevision.create(rev1); - - update(list, revision); - VCSTest.assertState(list, state); - - context.delete(VCSLocalData.FILE, interval); - VCSTest.assertState(list, VCSState.MISSING); - - update(list, revision); - VCSTest.assertState(list, state);*/ - - } - - @MethodTest - public void testOutOfDateAndModifiedState() throws Exception { - - // modified n files, revert to first version and assert to state is out - // to date - - setCommand(VCSState.OUT_OF_DATE_AND_MODIFIED, ""); - - modifyFile(list, 14, 'n'); - - VCSTest.assertState(list, state); - - VCSTest.handler.revert(list); - - VCSTest.assertState(list, VCSState.OUT_OF_DATE); - - modifyFile(list, 46, 'o'); - - VCSTest.assertState(list, state); - - VCSTest.handler.revert(list); - - VCSTest.assertState(list, VCSState.OUT_OF_DATE); - } - - // ///////////////////////////////////////////////////////////////////////// - // / Methodes utiles - // ///////////////////////////////////////////////////////////////////////// - - protected void setCommand(VCSState stateToTest, String command) { - setCommand(start, last, stateToTest, command); - } - - protected void setCommand(int pStart, int pLast, VCSState stateToTest, - String command) { - state = stateToTest; - if (!(pStart == start && pLast == last)) { - start = pStart; - last = pLast; - interval = context.getIndex(pStart, pLast); - } - VCSTest.log.info("[state:" + state + "] [" + command + "] on interval [" - + start + "," + last + "]"); - } - -} \ No newline at end of file Deleted: trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSTest.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSTest.java 2008-04-05 20:37:17 UTC (rev 362) +++ trunk/lutinvcs/lutinvcs-core/src/test/java/org/codelutin/vcs/VCSTest.java 2008-04-05 20:37:32 UTC (rev 363) @@ -1,324 +0,0 @@ -package org.codelutin.vcs; - -import junit.framework.TestCase; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.log.LutinLogFactory; -import org.codelutin.util.FileUtil; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** - * abstract test for a vcs should be implements by any new vcs handler - * - * @author chemit - */ -public abstract class VCSTest extends TestCase { - - static protected Boolean resetConfiguration; - - static protected VCSType vcsType; - - /** method to be invoked before first test */ - protected abstract void setUpVars(); - - /** - * method to be inocked after last test - * - * @throws Exception TODO - */ - protected abstract void tearDownVars() throws Exception; - - /** flag to says we have already invoked setVars method */ - static protected boolean init = false; - - static protected VCSConfig config; - - static protected File databaseDirectory; - - static protected File oldConfig; - - static protected VCSHandler handler; - - static protected int nbTests; - - static protected int currentTest = 0; - - static { - System.setProperty("org.apache.commons.logging.LogFactory", LutinLogFactory.class.getName()); - } - - protected static Log log = LogFactory.getLog(VCSTest.class); - - protected void resetConfig() throws Exception { - log.info(" process " + currentTest + "/" + nbTests + " tests for " - + getClass()); - tearDownVars(); - log.info(" == pause for one second, waiting for next test..."); - Thread.sleep(100); - nbTests = currentTest = 0; - config = null; - handler = null; - databaseDirectory = null; - init = false; - - // push back previous configuration file - String path = oldConfig.getAbsolutePath(); - FileUtil.copy(oldConfig, new File(path.substring(0, path.length() - 4))); - oldConfig.delete(); - } - - private static String originalLocalDatabaseName; - private static String originalRemoteDatabaseName; - - protected void initConfig() throws Exception { - try { - setUpVars(); - - long timestamp = System.nanoTime(); - - nbTests = getNbTests(); - - log.info("[" + timestamp + "] found " + nbTests + " tests for " + getClass()); - - File dConfig = new File(System.getProperty("user.home"), ".isis-config-3"); - - if (dConfig.exists()) { - oldConfig = new File(dConfig.getParentFile(), dConfig.getName() + "_old"); - FileUtil.copy(dConfig, oldConfig); - } - - //IsisFish.init(); - //TODO force type load(vcsType); - - //config = IsisContext.get().getVcsConfig(); - config = null; - - String lname = config.getLocalDatabasePath().getName(); - String rname = config.getRemoteDatabase(); - if (originalLocalDatabaseName == null) { - originalLocalDatabaseName = lname; - originalRemoteDatabaseName = rname; - } else { - lname = originalLocalDatabaseName; - rname = originalRemoteDatabaseName; - } - //IsisVcsConfig.LOCAL_DATABASE_PROPERTY_KEY.setCurrentValue(lname + timestamp); - - //IsisVcsConfig.REMOTE_DATABASE_PROPERTY_KEY.setCurrentValue( rname + timestamp); - - try { - config.validate(); - - } catch (VCSRuntimeException e) { - log.fatal("Fill missing properties in configuration file [" - + config.getSource() + "]"); - System.exit(1); - } - - assertTrue(config.isInit()); - - handler = VCSHandlerFactory.getHandler(); - //handler = IsisContext.get().getVCSHanler(); - - assertNotNull(handler); - - databaseDirectory = config.getLocalDatabasePath(); - - log.info("localDatabase : [" + databaseDirectory + "]"); - log.info("remoteDatabase : [" + config.getRemoteDatabasePath() - + "]"); - log.info("remote url : [" + handler.getRemoteUrl() + "]"); - log.debug("handler : " + handler); - init = true; - } catch (Exception e) { - log.error("could not load Default VCSHandler ", e); - fail(); - } - } - - protected void postInitConfig() throws VCSException { - // init root of working copy (check it out if it the first use) - handler.initWorkingCopy(); - assertTrue(databaseDirectory != null && databaseDirectory.exists()); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - if (!init) { - initConfig(); - } - currentTest++; - log.debug(" (" + currentTest + "/" + nbTests + ") : " + this); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - log.debug(" (" + currentTest + "/" + nbTests + ") : " + this); - if (currentTest == nbTests) - resetConfig(); - } - - protected int getNbTests() { - int result = 0; - for (java.lang.reflect.Method method : getClass().getMethods()) - if (method.isAnnotationPresent(MethodTest.class)) - result++; - - assertTrue("find no test methods marked with annotation " - + MethodTest.class + "in class " + getClass(), result > 0); - return result; - } - - protected MethodTest getMethodTest() { - try { - - return getClass().getMethod(getName()).getAnnotation( - MethodTest.class); - - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - } - - protected File getLocalDatabaseFile() { - return VCSHandlerFactory.getConfig().getLocalDatabasePath(); - } - - protected void update(List<File> list) throws VCSException { - for (File file : list) - handler.update(file); - } - - protected void update(List<File> list, VCSRevision revision) - throws VCSException { - for (File file : list) - handler.update(file, revision); - } - - public static void assertState(List<File> files, VCSState status) - throws VCSException { - for (File file : files) { - final VCSState state = handler.getState(file, new ArrayList()); - if (state != status) - fail("state required [" + status + "] but found [" + state - + "] for files " + file); - } - } - - public static void assertFileState(List<File> list, - List<VCSFileState> files, VCSState status, boolean synch) - throws VCSException { - if (synch) - VCSFileStateManager.doSynch(handler, list); - VCSState state; - for (VCSFileState file : files) { - try { - state = file.getState(); - if (state != status) - fail("state required [" + status + "] but found [" + state - + "] for files " + file); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - public static void assertState(File file, VCSState status) - throws VCSException { - final VCSState vcsStatus = handler.getState(file, new ArrayList()); - if (vcsStatus != status) - fail("state required [" + status + "] but found [" + vcsStatus - + "] for file " + file); - } - - protected void modifyFile(List<File> f) throws IOException { - modifyFile(f, 10, 'a'); - for (File file : f) { - modifyFile(file, 10, 'a'); - } - } - - protected void modifyFile(List<File> f, int newSize) throws IOException { - modifyFile(f, newSize, 'b'); - } - - protected void modifyFile(List<File> f, int newSize, char c) - throws IOException { - for (File file : f) - modifyFile(file, newSize, c); - } - - protected void modifyFile(File f, int newSize) throws IOException { - modifyFile(f, newSize, 'a'); - } - - protected void modifyFile(File f, int newSize, char c) throws IOException { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < newSize; i++) - sb.append(c); - FileUtil.writeString(f, sb.toString()); - } - - protected List<File> getOneFileAsList(File f) { - List<File> result = new ArrayList<File>(); - result.add(f); - return result; - } - - // ///////////////////////////////////////////////////////////////////////// - // / Preparation repository et working copy - // ///////////////////////////////////////////////////////////////////////// - protected void initVCS() throws VCSException { - // assert remote database does not exists - try { - handler.deleteRemoteDir(VCSLocalData.DIRECTORY.getCommitMessage("deldir remote", - this), ""); - } catch (VCSException e) { - // this is ok for this time :) - // we just wants to be sure the remote database directory does not - // exists any longer - } - - // create remote directory - handler.makeRemoteDir(VCSLocalData.DIRECTORY.getCommitMessage("mkdir remote", this), - ""); - - handler.deleteWorkingCopy(); - - // assert local directory not exists - assertFalse(getLocalDatabaseFile().exists()); - - handler.initWorkingCopy(); - - // assert directory exists and contains vcs configuration directory in - // this file - assertTrue(getLocalDatabaseFile().exists()); - assertTrue(new File(getLocalDatabaseFile(), handler - .getConfLocalDirname()).exists()); - } - - // ///////////////////////////////////////////////////////////////////////// - // / Suppression du repository et working copy - // ///////////////////////////////////////////////////////////////////////// - - protected void disposeVCS() throws Exception { - - // delete remote directory - handler.deleteRemoteDir(VCSLocalData.DIRECTORY.getCommitMessage("deldir remote", - this), ""); - - // delete local working copy - handler.deleteWorkingCopy(); - - // assert local directory does not exists any longer - assertFalse(getLocalDatabaseFile().exists()); - - } - -}