[Bedework-commit] naming r50 - in trunk: . src/org/bedework/naming
src/org/bedework/naming/impl/cache
src/org/bedework/naming/impl/carddav tests tests/src
tests/src/org tests/src/org/bedework tests/src/org/bedework/naming
tests/src/org/bedework/naming/test
svnadmin at bedework.org
svnadmin at bedework.org
Mon Mar 14 15:39:45 EDT 2011
Author: douglm
Date: 2011-03-14 15:39:42 -0400 (Mon, 14 Mar 2011)
New Revision: 50
Added:
trunk/appjars.xml
trunk/tests/
trunk/tests/src/
trunk/tests/src/org/
trunk/tests/src/org/bedework/
trunk/tests/src/org/bedework/naming/
trunk/tests/src/org/bedework/naming/test/
trunk/tests/src/org/bedework/naming/test/TestAbstractApi.java
Removed:
trunk/src/org/bedework/naming/test/
trunk/tests/src/org/bedework/naming/test/TestAbstractApi.java
Modified:
trunk/.classpath
trunk/build.properties
trunk/build.xml
trunk/runtest
trunk/src/org/bedework/naming/impl/cache/CachedContext.java
trunk/src/org/bedework/naming/impl/cache/ContextCache.java
trunk/src/org/bedework/naming/impl/cache/ContextCaches.java
trunk/src/org/bedework/naming/impl/cache/DbCache.java
trunk/src/org/bedework/naming/impl/cache/DbCacheCalImpl.java
trunk/src/org/bedework/naming/impl/cache/DbCacheCardImpl.java
trunk/src/org/bedework/naming/impl/carddav/CarddavContext.java
Log:
Step 1 in updating bwnaming build
Modified: trunk/.classpath
===================================================================
--- trunk/.classpath 2011-03-14 19:37:53 UTC (rev 49)
+++ trunk/.classpath 2011-03-14 19:39:42 UTC (rev 50)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="tests/src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/bw-davio-3.6.jar"/>
<classpathentry kind="lib" path="lib/commons-httpclient-3.0.jar" sourcepath="/home/douglm/drop2/apache/commons-httpclient-3.0/src"/>
Added: trunk/appjars.xml
===================================================================
--- trunk/appjars.xml (rev 0)
+++ trunk/appjars.xml 2011-03-14 19:39:42 UTC (rev 50)
@@ -0,0 +1,58 @@
+<?xml version="1.0"?>
+
+<!-- ===================================================================
+ Fetch or define extra jars for this application
+ =================================================================== -->
+<project name="extraJars" basedir="." default="">
+ <macrodef name="getExtraJars">
+ <sequential>
+ <delete dir="${org.bedework.temp.extrajars.dir}" />
+ <mkdir dir="${org.bedework.temp.extrajars.dir}" />
+
+ <property name="bedework.home"
+ location="${project.home}/../bedework" />
+
+ <!-- Generated by this project -->
+
+ <getJar lib="${org.bedework.temp.extrajars.dir}"
+ libcache="${org.bedework.libcache.dir}"
+ name="bwnaming" version="${org.bedework.bwnaming.version}"
+ projecthome="${project.home}" />
+
+ <!-- ====================== Bedework jars ============================ -->
+
+ <getJar lib="${org.bedework.temp.extrajars.dir}"
+ libcache="${org.bedework.libcache.dir}"
+ name="bw-davio" version="${org.bedework.davutil.version}"
+ projecthome="${bedework.home}/projects/davutil" />
+
+ <!-- ======================= Commons jars ============================ -->
+
+ <getJar lib="${org.bedework.temp.extrajars.dir}"
+ libcache="${org.bedework.libcache.dir}"
+ name="commons-lang" version="2.1"/>
+
+ <getJar lib="${org.bedework.temp.extrajars.dir}"
+ libcache="${org.bedework.libcache.dir}"
+ name="commons-codec" version="1.3"/>
+
+ <getJar lib="${org.bedework.temp.extrajars.dir}"
+ libcache="${org.bedework.libcache.dir}"
+ name="commons-httpclient" version="3.0"/>
+
+ <getJar lib="${org.bedework.temp.extrajars.dir}"
+ libcache="${org.bedework.libcache.dir}"
+ name="commons-ssl"/>
+
+ <getJar lib="${org.bedework.temp.extrajars.dir}"
+ libcache="${org.bedework.libcache.dir}"
+ name="commons-logging" />
+
+ <!-- ========================== Misc jars ============================ -->
+
+ <getJar lib="${org.bedework.temp.extrajars.dir}"
+ libcache="${org.bedework.libcache.dir}"
+ name="log4j" version="1.2.8"/>
+ </sequential>
+ </macrodef>
+</project>
Modified: trunk/build.properties
===================================================================
--- trunk/build.properties 2011-03-14 19:37:53 UTC (rev 49)
+++ trunk/build.properties 2011-03-14 19:39:42 UTC (rev 50)
@@ -3,11 +3,13 @@
#
# Name of this package
-edu.rpi.cmt.package.name=Bedework abstract api package
+org.bedework.package.name=Bedework abstract api package
# Version we are building
-edu.rpi.cmt.version=3.6
+org.bedework.bwnaming.version=3.7
+# Versions we import
+
# Name of generated jar file
-org.bedework.naming.jar=bwnaming
+org.bedework.bwnaming.jar=bwnaming
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2011-03-14 19:37:53 UTC (rev 49)
+++ trunk/build.xml 2011-03-14 19:39:42 UTC (rev 50)
@@ -8,41 +8,54 @@
Authors: Mike Douglass douglm rpi.edu
-->
-<project name="naming" default="build">
+<project name="naming" default="deploy">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<property environment="env"/>
- <property name="base.name" value="naming"/>
<dirname property="project.home" file="${ant.file}"/>
- <property file="${project.home}/build.properties" />
+ <property name="org.bedework.project.bwnaming"
+ location="${project.home}" />
+
+ <property name="bedework.home"
+ location="${project.home}/../bedework" />
- <property name="project.name" value="${edu.rpi.cmt.project.name}"/>
- <property name="project.version" value="${edu.rpi.cmt.version}"/>
+ <property name="build.dir" location="${bedework.home}/build"/>
+
+ <import file="${build.dir}/buildTools/deftasks.xml"/>
- <property name="source.home" location="${project.home}/src"/>
- <property name="dist.home" location="${project.home}/dist"/>
- <property name="lib.dir" location="${project.home}/lib"/>
- <property name="libapi.dir" location="${project.home}/libapi"/>
+ <deftasks/>
- <property name="runlib.dir" location="${project.home}/runlib"/>
- <property name="resources.dir" location="${project.home}/resources"/>
+ <projectDefs name="${org.bedework.package.name}"
+ version="${org.bedework.bwnaming.version}"
+ deployment-name="card"
+ />
- <property name="build.dir" location="${project.home}/build"/>
- <property name="buildjar" location="${build.dir}/buildjar.xml"/>
+ <import file="${build.dir}/loadDeployConfig.xml"/>
- <property name="org.bedework.libcache.dir"
- location="${project.home}/libcache"/>
-
- <import file="${build.dir}/getJar.xml"/>
+ <import file="${project.home}/appjars.xml" />
+
+ <property name="app.resources.dir" location="${project.home}/resources"/>
<target name="init">
- <delete dir="${lib.dir}" />
- <mkdir dir="${lib.dir}" />
+ <projectInit/>
+
+ <property name="org.bedework.project.bedework"
+ location="${project.home}/../bedework" />
- <!--
- <getJar name="junit" version="4.4" />
- -->
+ <loadDeployConfig />
+
+ <property name="generated.jar.file"
+ location="${dist.home}/${org.bedework.naming.jar}-${project.version}.jar" />
+
+ <property name="test.jar.file"
+ location="${dist.home}/${org.bedework.naming.jar}-test-${project.version}.jar" />
+ </target>
+
+ <target name="build-init" depends="init">
+ <property name="org.bedework.getjar.property.prefix"
+ value="org.bedework.appjar" />
+
<getJar name="commons-httpclient" version="3.0" />
<getJar name="commons-ssl" />
<getJar name="derby" version="10.5.3.0" />
@@ -54,42 +67,6 @@
<getJar name="bw-davio" version="3.6" project="davutil" />
<getJar name="rpiutil" version="3.6" project="rpiutil" />
-
- <mkdir dir="${dist.home}" />
-
- <property name="test.data.dir"
- location="${dist.home}/test-data" />
-
- <property name="test.reports.dir"
- location="${dist.home}/test-reports" />
-
- <property name="edu.rpi.cmt.naming.empty.dir"
- location="${dist.home}/empty-dir" />
- <mkdir dir="${edu.rpi.cmt.naming.empty.dir}" />
-
- <fileset id="empty.fileset" dir="${edu.rpi.cmt.naming.empty.dir}"
- excludes="*" />
-
- <!-- default to empty -->
- <fileset id="buildjar.resource.files" refid="empty.fileset" />
- <fileset id="buildjar.generated.java.sources" refid="empty.fileset" />
-
- <property name="generated.jar.file"
- location="${dist.home}/${org.bedework.naming.jar}-${project.version}.jar" />
-
- <property name="test.jar.file"
- location="${dist.home}/${org.bedework.naming.jar}-test-${project.version}.jar" />
-
- <!-- ==================== Compilation Classpath ==================== -->
-
- <path id="compile.classpath">
- <fileset dir="${lib.dir}">
- <include name="*.jar"/>
- </fileset>
- <fileset dir="${dist.home}">
- <include name="*.jar"/>
- </fileset>
- </path>
</target>
<target name="run.init" depends="init">
@@ -118,50 +95,9 @@
</path>
</target>
- <!-- =================================================================
- Clean out all library files from other projects and all generated
- files in preparation for a complete rebuild.
-
- Needed because switching versions leaves a load of old bedework
- generated stuff in the libraries.
- ================================================================= -->
- <target name="deep-clean" depends="clean">
- <delete dir="${lib.dir}" />
- </target>
-
- <!-- =================================================================
- Clean all generated files
- ================================================================= -->
- <target name="clean">
- <delete dir="${dist.home}" />
- <delete dir="${libapi.dir}" />
- </target>
-
- <!-- =================================================================
- Clean up after a build.
- ================================================================= -->
- <target name="cleanup">
- <delete dir="${edu.rpi.cmt.naming.empty.dir}" />
- </target>
-
- <!-- ========================== Base build Targets ===================
- Here we have one target building the classes and interfaces that make
- up the naming suite.
- ================================================================= -->
-
- <target name="clean-build" depends="clean,build"
- description="Clean and compile naming classes"/>
-
- <target name="clean-build-all" depends="clean,build-all"
- description="Clean and compile naming classes"/>
-
- <target name="build" depends="init,build-source,cleanup"
- description="Compile naming classes"/>
-
- <target name="build-all" depends="init,build-source,cleanup"
- description="Compile naming classes"/>
-
- <target name="build-source">
+ <target name="build-source" depends="build-init" >
+ <build-jar module-base="${project.home}"
+ jar-file="${generated.jar.file}" />
<!-- ==================== Sources and classes ====================== -->
<fileset id="buildjar.java.sources" dir="${source.home}" >
@@ -327,6 +263,8 @@
<arg value="${org.bedework.naming.search}" />
<arg value="${org.bedework.naming.searchAttr}" />
<arg value="${org.bedework.naming.searchVal}" />
+ <arg value="${org.bedework.naming.name}" />
+ <arg value="${org.bedework.naming.nameVal}" />
</java>
</then>
<else>
@@ -341,6 +279,8 @@
<arg value="${org.bedework.naming.search}" />
<arg value="${org.bedework.naming.searchAttr}" />
<arg value="${org.bedework.naming.searchVal}" />
+ <arg value="${org.bedework.naming.name}" />
+ <arg value="${org.bedework.naming.nameVal}" />
</java>
</else>
</if>
@@ -364,6 +304,8 @@
<arg value="${org.bedework.naming.search}" />
<arg value="${org.bedework.naming.searchAttr}" />
<arg value="${org.bedework.naming.searchVal}" />
+ <arg value="${org.bedework.naming.name}" />
+ <arg value="${org.bedework.naming.nameVal}" />
</java>
</then>
<else>
@@ -378,6 +320,8 @@
<arg value="${org.bedework.naming.search}" />
<arg value="${org.bedework.naming.searchAttr}" />
<arg value="${org.bedework.naming.searchVal}" />
+ <arg value="${org.bedework.naming.name}" />
+ <arg value="${org.bedework.naming.nameVal}" />
</java>
</else>
</if>
Modified: trunk/runtest
===================================================================
--- trunk/runtest 2011-03-14 19:37:53 UTC (rev 49)
+++ trunk/runtest 2011-03-14 19:39:42 UTC (rev 50)
@@ -15,7 +15,7 @@
ANT_HOME=`cd "$ANT_HOME" && pwd`
usage() {
- echo " $PRG help | ? | ctype uri [account password]"
+ echo " $PRG help | ? | ctype ["search" attr val ] uri [account password]"
echo ""
echo " Invokes ant to run the test for the given uri."
echo ""
@@ -42,6 +42,8 @@
ctype=$1
uri=$2
+name=
+nameVal=
search=
searchAttr=
searchVal=
@@ -57,6 +59,15 @@
uri=$2
account=$3
+
+if [ "$account" = "name" ] ; then
+ name="-name"
+ shift
+ nameVal=$3
+ shift
+fi
+
+account=$3
password=$4
if [ "$ctype" = "help" -o "$ctype" = "?" ] ; then
@@ -107,6 +118,9 @@
test_defs="$test_defs -Dorg.bedework.naming.searchAttr=$searchAttr"
test_defs="$test_defs -Dorg.bedework.naming.searchVal=$searchVal"
+test_defs="$test_defs -Dorg.bedework.naming.name=$name"
+test_defs="$test_defs -Dorg.bedework.naming.nameVal=$nameVal"
+
test_defs="$test_defs -Dorg.bedework.naming.uri=$uri"
if [ "$account" != "" ] ; then
test_defs="$test_defs -Dorg.bedework.naming.account=$account"
Modified: trunk/src/org/bedework/naming/impl/cache/CachedContext.java
===================================================================
--- trunk/src/org/bedework/naming/impl/cache/CachedContext.java 2011-03-14 19:37:53 UTC (rev 49)
+++ trunk/src/org/bedework/naming/impl/cache/CachedContext.java 2011-03-14 19:39:42 UTC (rev 50)
@@ -40,6 +40,7 @@
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
@@ -150,6 +151,18 @@
return makeNewCachedContext(common, env, cache.info, cache);
}
+ Name nm = getNameParser(name).parse(name);
+
+ if (nm.size() > 1) {
+ Object o = lookup(nm.getPrefix(0));
+
+ if (!(o instanceof Context)) {
+ throw new NameNotFoundException();
+ }
+
+ return ((Context)o).lookup(nm.getSuffix(1));
+ }
+
/* See if we cached something about this href */
CacheBinding ce = checkCache(name);
@@ -192,11 +205,27 @@
}
Object o = lookup(name);
- if (!(o instanceof CachedContext)) {
+ if (!(o instanceof Context)) {
return null;
}
- return ((CachedContext)o).list("");
+ NamingEnumeration<NameClassPair> ne = ((Context)o).list("");
+
+ if (ne == null) {
+ return null;
+ }
+
+ List<NameClassPair> cne = new ArrayList<NameClassPair>();
+
+ while (ne.hasMore()) {
+ NameClassPair ncp = ne.next();
+
+ // Should really clone this
+ ncp.setRelative(false);
+ cne.add(ncp);
+ }
+
+ return new ContextCache.CacheEnumeration(cne);
}
@Override
Modified: trunk/src/org/bedework/naming/impl/cache/ContextCache.java
===================================================================
--- trunk/src/org/bedework/naming/impl/cache/ContextCache.java 2011-03-14 19:37:53 UTC (rev 49)
+++ trunk/src/org/bedework/naming/impl/cache/ContextCache.java 2011-03-14 19:39:42 UTC (rev 50)
@@ -30,6 +30,7 @@
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
@@ -141,9 +142,17 @@
public static class CacheEnumeration implements NamingEnumeration<NameClassPair> {
//private ContextCache cache;
- private Iterator<CacheBinding> it;
+ private Iterator<NameClassPair> it;
/**
+ * @param ncps - list to enumerate
+ * @throws NamingException
+ */
+ public CacheEnumeration(final List<NameClassPair> ncps) throws NamingException {
+ it = ncps.iterator();
+ }
+
+ /**
* @param limits
* @param cache
* @throws NamingException
@@ -180,7 +189,7 @@
/* (non-Javadoc)
* @see javax.naming.NamingEnumeration#next()
*/
- public CacheBinding next() {
+ public NameClassPair next() {
if ((it == null) || !it.hasNext()) {
return null;
}
@@ -191,7 +200,7 @@
/* (non-Javadoc)
* @see java.util.Enumeration#nextElement()
*/
- public CacheBinding nextElement() {
+ public NameClassPair nextElement() {
return next();
}
Modified: trunk/src/org/bedework/naming/impl/cache/ContextCaches.java
===================================================================
--- trunk/src/org/bedework/naming/impl/cache/ContextCaches.java 2011-03-14 19:37:53 UTC (rev 49)
+++ trunk/src/org/bedework/naming/impl/cache/ContextCaches.java 2011-03-14 19:39:42 UTC (rev 50)
@@ -98,9 +98,11 @@
}
private String getDbname(final String val) {
+ String cnvName = val.replace('/', '-');
if (val.startsWith("/")) {
- return hrefCacheNamePrefix + val;
+ cnvName = cnvName.substring(1);
}
- return hrefCacheNamePrefix + "/" + val;
+
+ return hrefCacheNamePrefix + "/" + cnvName;
}
}
Modified: trunk/src/org/bedework/naming/impl/cache/DbCache.java
===================================================================
--- trunk/src/org/bedework/naming/impl/cache/DbCache.java 2011-03-14 19:37:53 UTC (rev 49)
+++ trunk/src/org/bedework/naming/impl/cache/DbCache.java 2011-03-14 19:39:42 UTC (rev 50)
@@ -4,6 +4,7 @@
import java.util.Collection;
+import javax.naming.NameClassPair;
import javax.naming.NamingException;
/** Handles the database used to store cached event information.
@@ -84,7 +85,7 @@
* @return Collection<CacheBinding>
* @throws NamingException
*/
- Collection<CacheBinding> list(final Object start,
+ Collection<NameClassPair> list(final Object start,
final Object end) throws NamingException;
/** Return all keys
Modified: trunk/src/org/bedework/naming/impl/cache/DbCacheCalImpl.java
===================================================================
--- trunk/src/org/bedework/naming/impl/cache/DbCacheCalImpl.java 2011-03-14 19:37:53 UTC (rev 49)
+++ trunk/src/org/bedework/naming/impl/cache/DbCacheCalImpl.java 2011-03-14 19:39:42 UTC (rev 50)
@@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import javax.naming.NameClassPair;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
@@ -280,7 +281,7 @@
* @return Collection<CacheBinding>
* @throws NamingException
*/
- public synchronized Collection<CacheBinding> list(final Object start,
+ public synchronized Collection<NameClassPair> list(final Object start,
final Object end) throws NamingException {
QueryResult qr = null;
@@ -289,7 +290,7 @@
qr = query(true, null, start, end);
- Collection<CacheBinding> bindings = new ArrayList<CacheBinding>();
+ Collection<NameClassPair> bindings = new ArrayList<NameClassPair>();
while (qr.rs.next()) {
bindings.add(makeBinding(qr.rs));
Modified: trunk/src/org/bedework/naming/impl/cache/DbCacheCardImpl.java
===================================================================
--- trunk/src/org/bedework/naming/impl/cache/DbCacheCardImpl.java 2011-03-14 19:37:53 UTC (rev 49)
+++ trunk/src/org/bedework/naming/impl/cache/DbCacheCardImpl.java 2011-03-14 19:39:42 UTC (rev 50)
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import javax.naming.NameClassPair;
import javax.naming.NamingException;
/** Handles the database used to store cached event information.
@@ -47,8 +48,8 @@
" RSRC_VAL LONG VARCHAR FOR BIT DATA) ";
private final static String[] createResourcesExtras = {
- "CREATE INDEX RSRC_NAME_INDEX ON RESOURCES(RSRC_NAME)",
- "CREATE INDEX RSRC_HREF_INDEX ON RESOURCES(RSRC_HREF)",
+ "CREATE UNIQUE INDEX RSRC_NAME_INDEX ON RESOURCES(RSRC_NAME)",
+ "CREATE UNIQUE INDEX RSRC_HREF_INDEX ON RESOURCES(RSRC_HREF)",
"CREATE INDEX RSRC_FN_INDEX ON RESOURCES(RSRC_FN)",
};
@@ -165,7 +166,7 @@
* @throws NamingException
*/
public synchronized void saveOrUpdate(final CacheBinding val) throws NamingException {
- put(val);
+ updateInsert(!contains(val.getNameInNamespace()), val);
}
/** Return named resource.
@@ -245,7 +246,7 @@
* @return Collection<CacheBinding>
* @throws NamingException
*/
- public synchronized Collection<CacheBinding> list(final Object start,
+ public synchronized Collection<NameClassPair> list(final Object start,
final Object end) throws NamingException {
QueryResult qr = null;
@@ -254,7 +255,7 @@
qr = query(true, null, start, end);
- Collection<CacheBinding> bindings = new ArrayList<CacheBinding>();
+ Collection<NameClassPair> bindings = new ArrayList<NameClassPair>();
while (qr.rs.next()) {
bindings.add(makeBinding(qr.rs));
Modified: trunk/src/org/bedework/naming/impl/carddav/CarddavContext.java
===================================================================
--- trunk/src/org/bedework/naming/impl/carddav/CarddavContext.java 2011-03-14 19:37:53 UTC (rev 49)
+++ trunk/src/org/bedework/naming/impl/carddav/CarddavContext.java 2011-03-14 19:39:42 UTC (rev 50)
@@ -923,6 +923,11 @@
if (respCode == HttpServletResponse.SC_UNAUTHORIZED) {
throw new AuthenticationException();
}
+
+ if (respCode == HttpServletResponse.SC_NOT_FOUND) {
+ throw new NameNotFoundException();
+ }
+
throw new NamingException("Had response " + respCode);
}
Copied: trunk/tests/src/org/bedework/naming/test (from rev 9, trunk/src/org/bedework/naming/test)
Deleted: trunk/tests/src/org/bedework/naming/test/TestAbstractApi.java
===================================================================
--- trunk/src/org/bedework/naming/test/TestAbstractApi.java 2009-08-31 14:19:58 UTC (rev 9)
+++ trunk/tests/src/org/bedework/naming/test/TestAbstractApi.java 2011-03-14 19:39:42 UTC (rev 50)
@@ -1,211 +0,0 @@
-/* **********************************************************************
- Copyright 2009 Rensselaer Polytechnic Institute. All worldwide rights reserved.
-
- Redistribution and use of this distribution in source and binary forms,
- with or without modification, are permitted provided that:
- The above copyright notice and this permission notice appear in all
- copies and supporting documentation;
-
- The name, identifiers, and trademarks of Rensselaer Polytechnic
- Institute are not used in advertising or publicity without the
- express prior written permission of Rensselaer Polytechnic Institute;
-
- DISCLAIMER: The software is distributed" AS IS" without any express or
- implied warranty, including but not limited to, any implied warranties
- of merchantability or fitness for a particular purpose or any warrant)'
- of non-infringement of any current or pending patent rights. The authors
- of the software make no representations about the suitability of this
- software for any particular purpose. The entire risk as to the quality
- and performance of the software is with the user. Should the software
- prove defective, the user assumes the cost of all necessary servicing,
- repair or correction. In particular, neither Rensselaer Polytechnic
- Institute, nor the authors of the software are liable for any indirect,
- special, consequential, or incidental damages related to the software,
- to the maximum extent the law permits.
- */
-package org.bedework.naming.test;
-
-import org.bedework.naming.impl.caldav.CaldavContext;
-
-import edu.rpi.sss.util.Args;
-
-import org.apache.log4j.Logger;
-
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.NameClassPair;
-import javax.naming.NamingEnumeration;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.DirContext;
-
-/** Test the calendar abstract api.
- * @author douglm
- *
- */
-public class TestAbstractApi {
- private transient Logger log;
-
- //private boolean debug;
-
- private String uri;
-
- private String mkCol;
-
- private String user;
-
- private String pw;
-
- //private String sp;
-
- /** List oif service providers
- *
- */
- public static final String[] sps = {
- "caldav"
- };
-
- boolean processArgs(Args args) throws Throwable {
- if (args == null) {
- return true;
- }
-
- while (args.more()) {
- if (args.ifMatch("-debug")) {
- //debug = true;
- } else if (args.ifMatch("-ndebug")) {
- //debug = false;
- } else if (args.ifMatch("-uri")) {
- uri = args.next();
- } else if (args.ifMatch("-mkcol")) {
- mkCol = args.next();
- } else if (args.ifMatch("-user")) {
- user = args.next();
- } else if (args.ifMatch("-pw")) {
- pw = args.next();
- } else {
- error("Illegal argument: " + args.current());
- usage();
- return false;
- }
- }
-
- return true;
- }
-
- /** Run the test.
- *
- * @throws Throwable
- */
- public void process() throws Throwable {
- Hashtable<String, String> env = new Hashtable<String, String>();
-
- env.put(Context.PROVIDER_URL, uri);
-
- if (user != null) {
- env.put(Context.SECURITY_PRINCIPAL, user);
- env.put(Context.SECURITY_CREDENTIALS, pw);
- }
-
- info("Open a context for " + uri);
-
- DirContext ctx = new CaldavContext(env);
-
- explore(ctx, "");
-
- if (mkCol != null) {
- Attributes attrs = new BasicAttributes();
-
- attrs.put(new BasicAttribute("CalDAV:calendar", "true"));
- ctx.createSubcontext(mkCol, attrs);
- }
-
- explore(ctx, "");
- }
-
- private void explore(DirContext ctx,
- String indent) throws Throwable {
- info("List children of the context");
-
- NamingEnumeration<NameClassPair> children = ctx.list("");
-
- if (children == null) {
- info(indent + "No children");
- } else {
- info(indent + "Found children");
-
- while (children.hasMore()) {
- NameClassPair ncp = children.next();
-
- info(indent + "name=" + ncp.getName() +
- " class=" + ncp.getClassName());
-
- if (ncp.getClassName().indexOf("Context") > 0) {
- // That seems bad. Should we always return Context as athe class?
- if (ncp.getName().length() != 0) {
- // Then it's not the current context
- DirContext childCtx = (DirContext)ctx.lookup(ncp.getName());
-
- if (childCtx != null) {
- explore(childCtx, indent + " ");
- }
- }
- }
- }
- }
- }
-
- void usage() {
- System.out.println("Usage:");
- System.out.println("args -debug");
- System.out.println(" -ndebug");
- System.out.println(" -uri uri");
- System.out.println(" set the service provider uri");
- System.out.println(" -user user");
- System.out.println(" set the login id");
- System.out.println(" -pw pw");
- System.out.println(" set the login password");
- }
-
- protected Logger getLog() {
- if (log == null) {
- log = Logger.getLogger(this.getClass());
- }
-
- return log;
- }
-
- protected void error(String msg) {
- getLog().error(msg);
- }
-
- protected void trace(String msg) {
- getLog().debug(msg);
- }
-
- protected void info(String msg) {
- getLog().info(msg);
- }
-
- /** Main
- *
- * @param args
- */
- public static void main(String[] args) {
- TestAbstractApi taa = null;
-
- try {
- taa = new TestAbstractApi();
-
- if (!taa.processArgs(new Args(args))) {
- return;
- }
-
- taa.process();
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
-}
Copied: trunk/tests/src/org/bedework/naming/test/TestAbstractApi.java (from rev 47, trunk/src/org/bedework/naming/test/TestAbstractApi.java)
===================================================================
--- trunk/tests/src/org/bedework/naming/test/TestAbstractApi.java (rev 0)
+++ trunk/tests/src/org/bedework/naming/test/TestAbstractApi.java 2011-03-14 19:39:42 UTC (rev 50)
@@ -0,0 +1,330 @@
+/* **********************************************************************
+ Copyright 2009 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+ */
+package org.bedework.naming.test;
+
+import org.bedework.naming.ParameterizedAttributeValue;
+
+import edu.rpi.sss.util.Args;
+
+import org.apache.log4j.Logger;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchResult;
+import javax.naming.spi.NamingManager;
+
+/** Test the abstract api.
+ * @author douglm
+ *
+ */
+public class TestAbstractApi {
+ private transient Logger log;
+
+ //private boolean debug;
+
+ private String uri;
+
+ private String name = "";
+
+ private String mkCol;
+
+ private String user;
+
+ private String pw;
+
+ private String ctype;
+
+ private String searchAttr;
+
+ private String searchAttrVal;
+
+ /** List oif service providers
+ *
+ */
+ public static final List<String> sps = new ArrayList<String>();
+ static {
+ sps.add("caldav");
+ sps.add("carddav");
+ sps.add("timezones");
+ };
+
+ boolean processArgs(final Args args) throws Throwable {
+ if (args == null) {
+ return true;
+ }
+
+ while (args.more()) {
+ if (args.ifMatch("-debug")) {
+ //debug = true;
+ } else if (args.ifMatch("-ndebug")) {
+ //debug = false;
+ } else if (args.ifMatch("-ctype")) {
+ ctype = args.next();
+ } else if (args.ifMatch("-uri")) {
+ uri = args.next();
+ } else if (args.ifMatch("-name")) {
+ name = args.next();
+ } else if (args.ifMatch("-mkcol")) {
+ mkCol = args.next();
+ } else if (args.ifMatch("-user")) {
+ user = args.next();
+ } else if (args.ifMatch("-pw")) {
+ pw = args.next();
+ } else if (args.ifMatch("-search")) {
+ searchAttr = args.next();
+ searchAttrVal = args.next();
+ } else if (args.current().trim().length() == 0) {
+ info("*");
+ args.next();
+ } else {
+ error("Illegal argument: " + args.current());
+ usage();
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /** Run the test.
+ *
+ * @throws Throwable
+ */
+ public void process() throws Throwable {
+ trace("***************ctype = " + ctype);
+ if (ctype == null) {
+ error("Must set connection type");
+ return;
+ }
+
+ if (!sps.contains(ctype)) {
+ error("Invalid connection type: " + ctype);
+ return;
+ }
+
+ URL u = getClass().getResource("/" + ctype + "Context.properties");
+ Properties p = new Properties();
+ p.load(new FileInputStream(new File(u.toURI())));
+
+ Hashtable<String, String> env = new Hashtable<String, String>();
+
+ for (Object name: p.keySet()) {
+ String key = (String)name;
+ env.put(key, p.getProperty(key));
+ }
+
+ env.put(Context.PROVIDER_URL, uri);
+
+ if (user != null) {
+ env.put(Context.SECURITY_PRINCIPAL, user);
+ env.put(Context.SECURITY_CREDENTIALS, pw);
+ }
+
+ info("\n\nOpen a context for " + uri + "\n\n");
+
+ DirContext ctx = (DirContext)NamingManager.getInitialContext(env);
+ //DirContext ctx = (DirContext)new InitialContext(env);
+
+ explore(ctx, "");
+
+ if (mkCol != null) {
+ info("\n\nAdd a collection " + mkCol + "\n\n");
+
+ Attributes attrs = new BasicAttributes();
+
+ attrs.put(new BasicAttribute("CalDAV:calendar", "true"));
+ ctx.createSubcontext(mkCol, attrs);
+
+ info("\n\nRelist the context after create\n\n");
+
+ explore(ctx, "");
+
+ info("\n\nRemove the collection " + mkCol + "\n\n");
+
+ ctx.destroySubcontext(mkCol);
+
+ info("\n\nRelist the context after destroy\n\n");
+
+ explore(ctx, "");
+ }
+
+ if (searchAttr != null) {
+ Attribute attr = new BasicAttribute(searchAttr, searchAttrVal);
+
+ Attributes attrs = new BasicAttributes();
+ attrs.put(attr);
+
+ NamingEnumeration<SearchResult> srs = ctx.search("", attrs, null);
+
+ info("\n\nSearch results\n\n");
+ while (srs.hasMore()) {
+ SearchResult sr = srs.next();
+
+ info("Name = " + sr.getName());
+ displayAttributes(sr.getAttributes(), " ");
+ }
+ info("\n\nEnd search results\n\n");
+ }
+
+ ctx.close();
+ }
+
+ private void explore(final DirContext ctx,
+ final String indent) throws Throwable {
+ //info("List children of the context");
+
+ NamingEnumeration<NameClassPair> children = ctx.list(name);
+
+ if (children == null) {
+ info(indent + "No children");
+ } else {
+ while (children.hasMore()) {
+ NameClassPair ncp = children.next();
+
+ if (ncp.getName().length() == 0) {
+ // It's the current context
+ continue;
+ }
+
+ info(indent + ncp);
+
+ if (ncp.getClassName().indexOf("Context") > 0) {
+ // That seems bad. Should we always return Context as athe class?
+
+ DirContext childCtx = (DirContext)ctx.lookup(ncp.getName());
+
+ if (childCtx != null) {
+ explore(childCtx, indent + " ");
+ }
+
+ continue;
+ }
+
+ // Try it as some sort of entity
+
+ if (ncp.isRelative()) {
+ displayAttributes((Attributes)ctx.lookup(ncp.getName()),
+ indent + " ");
+ } else {
+ displayAttributes((Attributes)ctx.lookup(ncp.getNameInNamespace()),
+ indent + " ");
+ }
+ }
+ }
+ }
+
+ private void displayAttributes(final Attributes attrs,
+ final String indent) throws Throwable {
+ NamingEnumeration<? extends Attribute> ne = attrs.getAll();
+
+ while (ne.hasMore()) {
+ Attribute attr = ne.next();
+
+ if (attr.getID().equals("OVERRIDES")) {
+ info(indent + " ------- overrides --------");
+
+ NamingEnumeration ovs = attr.getAll();
+
+ while (ovs.hasMore()) {
+ ParameterizedAttributeValue pav = (ParameterizedAttributeValue)ovs.next();
+
+ displayAttributes((Attributes)pav.getValue(), indent + " ");
+ }
+ } else {
+ info(indent + " " + attr);
+ }
+ }
+ }
+
+ void usage() {
+ System.out.println("Usage:");
+ System.out.println("args -debug");
+ System.out.println(" -ndebug");
+ System.out.println(" -ctype type");
+ System.out.println(" set the connection type");
+ System.out.println(" caldav | carddav");
+ System.out.println(" -uri uri");
+ System.out.println(" set the service provider uri");
+ System.out.println(" -user user");
+ System.out.println(" set the login id");
+ System.out.println(" -pw pw");
+ System.out.println(" set the login password");
+ }
+
+ protected Logger getLog() {
+ if (log == null) {
+ log = Logger.getLogger(this.getClass());
+ }
+
+ return log;
+ }
+
+ protected void error(final String msg) {
+ getLog().error(msg);
+ }
+
+ protected void trace(final String msg) {
+ getLog().debug(msg);
+ }
+
+ protected void info(final String msg) {
+ getLog().info(msg);
+ }
+
+ /** Main
+ *
+ * @param args
+ */
+ public static void main(final String[] args) {
+ TestAbstractApi taa = null;
+
+ try {
+ taa = new TestAbstractApi();
+
+ if (!taa.processArgs(new Args(args))) {
+ return;
+ }
+
+ taa.process();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+}
More information about the Bedework-commit
mailing list