[jsword-svn] r1236 - in trunk/incubator/org.crosswire.jsword.test: . META-INF src src/org src/org/crosswire src/org/crosswire/jsword src/org/crosswire/jsword/test src/org/crosswire/jsword/test/internal src/org/crosswire/jsword/test/internal/osgi
Apache
apache at www.crosswire.org
Sun Dec 31 15:05:02 MST 2006
Author:
Date: 2006-12-31 15:05:02 -0700 (Sun, 31 Dec 2006)
New Revision: 1236
Added:
trunk/incubator/org.crosswire.jsword.test/.classpath
trunk/incubator/org.crosswire.jsword.test/.project
trunk/incubator/org.crosswire.jsword.test/META-INF/
trunk/incubator/org.crosswire.jsword.test/META-INF/MANIFEST.MF
trunk/incubator/org.crosswire.jsword.test/bin/
trunk/incubator/org.crosswire.jsword.test/build.properties
trunk/incubator/org.crosswire.jsword.test/src/
trunk/incubator/org.crosswire.jsword.test/src/org/
trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/
trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/jsword/
trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/jsword/test/
trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/jsword/test/BundleTrigger.java
trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/jsword/test/internal/
trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/jsword/test/internal/osgi/
trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/jsword/test/internal/osgi/Activator.java
Log:
[PRB] - OSGi test bundle. The activator makes a variety of test calls to ensure the services are registering and working as expected. No JUnit is used.
Added: trunk/incubator/org.crosswire.jsword.test/.classpath
===================================================================
--- trunk/incubator/org.crosswire.jsword.test/.classpath (rev 0)
+++ trunk/incubator/org.crosswire.jsword.test/.classpath 2006-12-31 22:05:02 UTC (rev 1236)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/incubator/org.crosswire.jsword.test/.project
===================================================================
--- trunk/incubator/org.crosswire.jsword.test/.project (rev 0)
+++ trunk/incubator/org.crosswire.jsword.test/.project 2006-12-31 22:05:02 UTC (rev 1236)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.crosswire.jsword.test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: trunk/incubator/org.crosswire.jsword.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/incubator/org.crosswire.jsword.test/META-INF/MANIFEST.MF (rev 0)
+++ trunk/incubator/org.crosswire.jsword.test/META-INF/MANIFEST.MF 2006-12-31 22:05:02 UTC (rev 1236)
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: JSword Test Bundle
+Bundle-SymbolicName: org.crosswire.jsword.test
+Bundle-Version: 1.0.0
+Bundle-Activator: org.crosswire.jsword.test.internal.osgi.Activator
+Bundle-Vendor: crosswire.org
+Bundle-Localization: plugin
+Require-Bundle: org.crosswire.common,
+ org.crosswire.jsword,
+ org.jdom
+Eclipse-AutoStart: true
+Import-Package: org.osgi.framework;version="1.3.0"
+Export-Package: org.crosswire.jsword.test
Added: trunk/incubator/org.crosswire.jsword.test/build.properties
===================================================================
--- trunk/incubator/org.crosswire.jsword.test/build.properties (rev 0)
+++ trunk/incubator/org.crosswire.jsword.test/build.properties 2006-12-31 22:05:02 UTC (rev 1236)
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
Added: trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/jsword/test/BundleTrigger.java
===================================================================
--- trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/jsword/test/BundleTrigger.java (rev 0)
+++ trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/jsword/test/BundleTrigger.java 2006-12-31 22:05:02 UTC (rev 1236)
@@ -0,0 +1,35 @@
+/**
+ * Distribution License:
+ * JSword is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License, version 2.1 as published by
+ * the Free Software Foundation. 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 Lesser General Public License for more details.
+ *
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/lgpl.html
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2006
+ * The copyright to this program is held by it's authors.
+ *
+ */
+package org.crosswire.jsword.test;
+
+/**
+ * This bundle won't start until it's needed, so
+ * create a new instance of this class to force the
+ * bundle to load. This is a hack to allow other
+ * test plugins to trigger the tests in this plugin,
+ * if they haven't been run yet.
+ *
+ * @author Phillip [phillip at paristano dot org]
+ *
+ */
+public class BundleTrigger {
+
+}
Added: trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/jsword/test/internal/osgi/Activator.java
===================================================================
--- trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/jsword/test/internal/osgi/Activator.java (rev 0)
+++ trunk/incubator/org.crosswire.jsword.test/src/org/crosswire/jsword/test/internal/osgi/Activator.java 2006-12-31 22:05:02 UTC (rev 1236)
@@ -0,0 +1,483 @@
+/**
+ * Distribution License:
+ * JSword is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License, version 2.1 as published by
+ * the Free Software Foundation. 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 Lesser General Public License for more details.
+ *
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/lgpl.html
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2006
+ * The copyright to this program is held by it's authors.
+ *
+ */
+package org.crosswire.jsword.test.internal.osgi;
+
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+
+import org.crosswire.common.activate.Lock;
+import org.crosswire.common.util.CommonLogger;
+import org.crosswire.common.util.Logger;
+import org.crosswire.jsword.book.Book;
+import org.crosswire.jsword.book.BookCategory;
+import org.crosswire.jsword.book.BookData;
+import org.crosswire.jsword.book.BookDriver;
+import org.crosswire.jsword.book.BookException;
+import org.crosswire.jsword.book.BookMetaData;
+import org.crosswire.jsword.book.Books;
+import org.crosswire.jsword.book.FeatureType;
+import org.crosswire.jsword.book.filter.Filter;
+import org.crosswire.jsword.book.filter.FilterException;
+import org.crosswire.jsword.book.filter.FilterFactory;
+import org.crosswire.jsword.index.IndexStatus;
+import org.crosswire.jsword.index.IndexStatusListener;
+import org.crosswire.jsword.index.search.SearchRequest;
+import org.crosswire.jsword.passage.Key;
+import org.crosswire.jsword.passage.NoSuchKeyException;
+import org.jdom.Document;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * The main plugin class to be used in the desktop.
+ * @author Phillip [phillip at paristano dot org]
+ */
+public class Activator implements BundleActivator {
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ public void start(BundleContext context) throws Exception {
+ System.out.println("Running Common Tests...");
+ testDefaultFilter(context);
+ testCustomFilter(context);
+ testCustomLogger(context);
+ testCustomBookDriver(context);
+ System.out.println("Done!");
+
+ }
+
+ /**
+ * @param context
+ */
+ private void testCustomBookDriver(BundleContext context) {
+ BookDriver[] drivers = Books.installed().getDrivers();
+ int originalCount = drivers.length;
+
+ BookDriver myDriver = new CustomBookDriver();
+ Hashtable properties = new Hashtable();
+ properties.put("bookdriver.id", "mydriver");
+ ServiceRegistration reg = context.registerService(BookDriver.class.getName(), myDriver, properties);
+
+ drivers = Books.installed().getDrivers();
+
+ if (drivers.length != originalCount + 1) {
+ System.err.println("Error: My book driver wasn't successfully registered: Expected " + (originalCount + 1) + " drivers available, but only found " + originalCount);
+ }
+
+ boolean myDriverFound = false;
+ for (int i = 0; i < drivers.length; i++) {
+ BookDriver driver = drivers[i];
+ if (driver == myDriver) {
+ myDriverFound = true;
+ break;
+ }
+ }
+
+ if (myDriverFound) {
+ System.out.println("Success: My book driver was found.");
+ } else {
+ System.err.println("Error: My book driver was not found");
+ }
+
+ Book myBook = Books.installed().getBook("mybook");
+
+ if (myBook == null) {
+ System.err.println("Error: Could not find my book after registering my driver.");
+ } else {
+ System.out.println("Success: Found my book after registering my driver.");
+ }
+
+ myDriver = null;
+
+ reg.unregister();
+
+ drivers = Books.installed().getDrivers();
+ if (drivers.length != originalCount) {
+ System.err.println("Error: The number of registered book drivers did not decrease after unregistering.");
+ }
+
+ myDriverFound = false;
+ for (int i = 0; i < drivers.length; i++) {
+ BookDriver driver = drivers[i];
+ if (driver == myDriver) {
+ myDriverFound = true;
+ break;
+ }
+ }
+
+ if (myDriverFound) {
+ System.err.println("Error: My book driver was found in the registry after it was unregistered.");
+ } else {
+ System.out.println("Success: My book driver was not found in the registry after unregistering.");
+ }
+
+ myBook = Books.installed().getBook("mybook");
+
+ if (myBook == null) {
+ System.out.println("Success: Could not find my book after unregistering my driver.");
+ } else {
+ System.err.println("Error: Found my book after unregistering my driver.");
+ }
+
+ }
+
+ /**
+ * @param context
+ */
+ private void testCustomLogger(BundleContext context) {
+ final boolean[] logCheck = new boolean[] {false};
+ CommonLogger myLogger = new CommonLogger() {
+ public void log(Level level, String message, Throwable throwable) {
+ logCheck[0] = true;
+ }
+ };
+
+ Hashtable properties = new Hashtable();
+ ServiceRegistration reg = context.registerService(CommonLogger.class.getName(), myLogger, properties);
+
+ Logger logger = Logger.getLogger(Activator.class);
+ logger.info("Testing if my logger gets hit...");
+ if (logCheck[0]) {
+ System.out.println("Success: My logger was successfully triggered.");
+ } else {
+ System.err.println("Error: My logger was not triggered through the Logger class.");
+ }
+
+ reg.unregister();
+
+ logCheck[0] = false;
+
+ logger.info("Testing if my logger gets hit...");
+ if (logCheck[0]) {
+ System.err.println("Error: My logger was triggered after it was unregistered.");
+ } else {
+ System.out.println("Success: My logger was not triggered after it was unregistered.");
+ }
+
+ }
+
+ /**
+ * @param context
+ *
+ */
+ private void testCustomFilter(BundleContext context) {
+ Filter myFilter = new Filter() {
+ public List toOSIS(Book book, Key key, String plain) throws FilterException {
+ return null;
+ }
+ };
+
+ Hashtable properties = new Hashtable();
+ properties.put("filter.id", "myfilter");
+ ServiceRegistration reg = context.registerService(Filter.class.getName(), myFilter, properties);
+ Filter retrievedFilter = FilterFactory.getFilter("myfilter");
+ if (retrievedFilter == myFilter) {
+ System.out.println("Success: Found my own filter in the registry.");
+ } else {
+ System.err.println("Error: Could not find my own filter in the registry.");
+ }
+ retrievedFilter = null;
+
+ reg.unregister();
+
+ retrievedFilter = FilterFactory.getFilter("myfilter");
+ if (retrievedFilter == myFilter) {
+ System.err.println("Error: Found my unregistered filter in the registry.");
+ } else {
+ //the filter is either null or the default filter.
+ System.out.println("Success: My filter unregistered successfully.");
+ }
+ }
+
+ /**
+ * @param context
+ *
+ */
+ private void testDefaultFilter(BundleContext context) {
+ Filter filter = FilterFactory.getDefaultFilter();
+ if (filter == null) {
+ System.err.println("Error: Missing default filter.");
+ } else {
+ System.out.println("Success: Default filter found.");
+ }
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ public void stop(BundleContext context) throws Exception {
+ }
+
+ private static final class CustomBook implements Book {
+ public BookMetaData getBookMetaData() {
+ return new BookMetaData() {
+ public String getName() {
+ return "mybookmetadata";
+ }
+
+ public BookCategory getBookCategory() {
+ return BookCategory.OTHER;
+ }
+
+ public BookDriver getDriver() {
+ return new CustomBookDriver();
+ }
+
+ public String getLanguage() {
+ return "en";
+ }
+
+ public String getInitials() {
+ return "mybook";
+ }
+
+ public String getOsisID() {
+ return null;
+ }
+
+ public String getFullName() {
+ return null;
+ }
+
+ public boolean isSupported() {
+ return false;
+ }
+
+ public boolean isEnciphered() {
+ return false;
+ }
+
+ public boolean isLocked() {
+ return false;
+ }
+
+ public boolean unlock(String unlockKey) {
+ return false;
+ }
+
+ public String getUnlockKey() {
+ return null;
+ }
+
+ public boolean isQuestionable() {
+ return false;
+ }
+
+ public String getDriverName() {
+ return null;
+ }
+
+ public boolean isLeftToRight() {
+ return false;
+ }
+
+ public boolean hasFeature(FeatureType feature) {
+ return false;
+ }
+
+ public URL getLibrary() {
+ return null;
+ }
+
+ public void setLibrary(URL library) {
+ }
+
+ public URL getLocation() {
+ return null;
+ }
+
+ public void setLocation(URL library) {
+ }
+
+ public Map getProperties() {
+ return null;
+ }
+
+ public String getProperty(String key) {
+ return null;
+ }
+
+ public void putProperty(String key, String value) {
+ }
+
+ public IndexStatus getIndexStatus() {
+ return null;
+ }
+
+ public void setIndexStatus(IndexStatus status) {
+ }
+
+ public Document toOSIS() {
+ return null;
+ }
+
+ public int compareTo(Object o) {
+ if (o == null) {
+ return 1;
+ }
+ if (o.getClass().equals(this.getClass())) {
+ return 0;
+ }
+ return -1;
+ }
+ };
+ }
+ public void setBookMetaData(BookMetaData bmd) {
+ }
+
+ public BookData getData(Key key) throws BookException {
+ return null;
+ }
+ public String getRawData(Key key) throws BookException {
+ return "";
+ }
+ public Key find(SearchRequest request) throws BookException {
+ return null;
+ }
+ public Key find(String request) throws BookException {
+ return null;
+ }
+ public String getName() {
+ return "mybook";
+ }
+ public BookCategory getBookCategory() {
+ return BookCategory.OTHER;
+ }
+ public BookDriver getDriver() {
+ return new CustomBookDriver();
+ }
+ public String getLanguage() {
+ return "en";
+ }
+ public String getInitials() {
+ return "mybook";
+ }
+ public String getOsisID() {
+ return null;
+ }
+ public String getFullName() {
+ return "my book";
+ }
+ public boolean isSupported() {
+ return false;
+ }
+ public boolean isEnciphered() {
+ return false;
+ }
+ public boolean isLocked() {
+ return false;
+ }
+ public boolean unlock(String unlockKey) {
+ return false;
+ }
+ public String getUnlockKey() {
+ return null;
+ }
+ public boolean isQuestionable() {
+ return false;
+ }
+ public String getDriverName() {
+ return null;
+ }
+ public boolean isLeftToRight() {
+ return false;
+ }
+ public boolean hasFeature(FeatureType feature) {
+ return false;
+ }
+ public Map getProperties() {
+ return null;
+ }
+ public String getProperty(String key) {
+ return null;
+ }
+ public void putProperty(String key, String value) {
+ }
+ public IndexStatus getIndexStatus() {
+ return null;
+ }
+ public void setIndexStatus(IndexStatus status) {
+ }
+ public void addIndexStatusListener(IndexStatusListener li) {
+ }
+ public void removeIndexStatusListener(IndexStatusListener li) {
+ }
+ public void activate(Lock lock) {
+ }
+ public void deactivate(Lock lock) {
+ }
+ public Key getGlobalKeyList() {
+ return null;
+ }
+ public Key getValidKey(String name) {
+ return null;
+ }
+ public Key getKey(String name) throws NoSuchKeyException {
+ return null;
+ }
+ public Key createEmptyKeyList() {
+ return null;
+ }
+ public int compareTo(Object o) {
+ if (o == null) {
+ return 1;
+ }
+ if (o.getClass().equals(this.getClass())) {
+ return 0;
+ }
+ return -1;
+ }
+ public Document toOSIS() {
+ return null;
+ }
+ }
+
+ private static final class CustomBookDriver implements BookDriver {
+ private static final Book MY_BOOK = new CustomBook();
+ public Book[] getBooks() {
+ return new Book[] {MY_BOOK};
+ }
+
+ public boolean isWritable() {
+ return false;
+ }
+
+ public Book create(Book source) throws BookException {
+ return null;
+ }
+
+ public boolean isDeletable(Book dead) {
+ return false;
+ }
+
+ public void delete(Book dead) throws BookException {
+ }
+
+ public String getDriverName() {
+ return "my driver";
+ }
+ }
+}
More information about the jsword-svn
mailing list