Author: glen
Date: Tue Dec 18 17:27:14 2007
New Revision: 11434
Log:
Reformat, spelling.
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAtomProvider.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/InMemoryJDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/realm/RegistryRealm.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAtomProvider.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAtomProvider.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAtomProvider.java
Tue Dec 18 17:27:14 2007
@@ -56,7 +56,7 @@
public RegistryAtomProvider() {
super(10);
- registry = (Registry)
System.getProperties().get(RegistryConstants.REGISTRY);
+ registry =
(Registry)System.getProperties().get(RegistryConstants.REGISTRY);
}
private Document<Service> init_service_doc(Abdera abdera) {
@@ -105,8 +105,8 @@
}
/**
- * This method will check whether there are any request paramters , like
?version
- * if so need to act differently
+ * This method will check whether there are any request paramters , like
?version if so need to
+ * act differently
*
* @param request : RequestContext
* @return return true if there are any request parameters else false
@@ -115,11 +115,11 @@
String parameters[] = request.getParameterNames();
if (parameters.length > 0) {
if (RegistryConstants.PARAMETER_VERSION.equals(parameters[0]) ||
- RegistryConstants.PARAMETER_TAGS.equals(parameters[0]) ||
-
RegistryConstants.PARAMETER_AVARAGE_REATINGS.equals(parameters[0]) ||
- RegistryConstants.PARAMETER_REATINGS.equals(parameters[0])
||
- RegistryConstants.PARAMETER_COMMENTS.equals(parameters[0])
||
-
RegistryConstants.PARAMETER_TAG_PATHS.equals(parameters[0])) {
+ RegistryConstants.PARAMETER_TAGS.equals(parameters[0]) ||
+
RegistryConstants.PARAMETER_AVARAGE_REATINGS.equals(parameters[0]) ||
+ RegistryConstants.PARAMETER_REATINGS.equals(parameters[0]) ||
+ RegistryConstants.PARAMETER_COMMENTS.equals(parameters[0]) ||
+ RegistryConstants.PARAMETER_TAG_PATHS.equals(parameters[0])) {
return true;
}
}
@@ -168,7 +168,7 @@
Factory factory = abdera.getFactory();
Feed feed = factory.newFeed();
feed.setId("http://wso2.org/registry,2007:feed");
- feed.setText(Messages.getMessage("resource.version",path));
+ feed.setText(Messages.getMessage("resource.version",
path));
feed.setTitle("versions for " + path);
feed.setUpdated(new Date());
feed.addLink(request.getBaseUri() + "atom" + path);
@@ -254,8 +254,7 @@
feed.setTitle(tag + " [Tag Paths]");
feed.setUpdated(new Date());
feed.addLink("", "self");
- for (int i = 0; i < tagpaths.length; i++) {
- TaggedResourcePath tagPath = tagpaths[i];
+ for (TaggedResourcePath tagPath : tagpaths) {
Entry entry = abdera.getFactory().newEntry();
entry.setId("http://wso2.org/registry" + "atom" + tag);
entry.setTitle(tagPath.getResourcePath());
@@ -277,8 +276,7 @@
feed.setTitle(path + " [Comments]");
feed.setUpdated(new Date());
feed.addLink("", "self");
- for (int i = 0; i < comments.length; i++) {
- Comment comment = comments[i];
+ for (Comment comment : comments) {
Entry entry = abdera.getFactory().newEntry();
entry.setId("http://wso2.org/registry" + "atom" + "comment");
entry.setTitle("Resource Comment");
@@ -322,8 +320,8 @@
if (properties != null) {
Iterator keys = properties.keySet().iterator();
while (keys.hasNext()) {
- String key = (String) keys.next();
- feed.setAttributeValue(key, (String) properties.get(key));
+ String key = (String)keys.next();
+ feed.setAttributeValue(key, (String)properties.get(key));
}
}
if (resource.getState() == RegistryConstants.DELETED_STATE) {
@@ -338,13 +336,12 @@
feed.addLink("", "self");
if (resource.isDirectory() ||
- "comments".equals(resource.getMediaType())) {
+ "comments".equals(resource.getMediaType())) {
feed.setAttributeValue("directory", "true");
Object o = resource.getContent();
if (o instanceof String[]) {
- String values[] = (String[]) o;
- for (int i = 0; i < values.length; i++) {
- String value = values[i];
+ String values[] = (String[])o;
+ for (String value : values) {
Entry entry = abdera.getFactory().newEntry();
if (executeQuery) {
entry.setTitle(value);
@@ -382,7 +379,7 @@
entry.setUpdated(resource.getLastModified());
entry.setPublished(resource.getCreatedTime());
if (content != null && content instanceof byte[]) {
- ByteArrayInputStream in = new
ByteArrayInputStream((byte[]) content);
+ ByteArrayInputStream in = new
ByteArrayInputStream((byte[])content);
entry.setContent(in);
} else {
if (content != null) {
@@ -401,7 +398,7 @@
entry.setUpdated(resource.getLastModified());
entry.setPublished(resource.getCreatedTime());
if (content != null && content instanceof byte[]) {
- ByteArrayInputStream in = new ByteArrayInputStream((byte[])
content);
+ ByteArrayInputStream in = new
ByteArrayInputStream((byte[])content);
entry.setContent(in);
} else {
if (content != null) {
@@ -424,8 +421,7 @@
feed.setUpdated(new Date());
feed.addLink("", "self");
- for (int i = 0; i < tags.length; i++) {
- Tag tag = tags[i];
+ for (Tag tag : tags) {
Entry entry = abdera.getFactory().newEntry();
entry.setId("http://wso2.org/registry" + "atom" + tag);
entry.setTitle(tag.getTagName());
@@ -468,8 +464,7 @@
}
}
- public ResponseContext createEntry(
- RequestContext request) {
+ public ResponseContext createEntry(RequestContext request) {
Abdera abdera = request.getAbdera();
Parser parser = abdera.getParser();
try {
@@ -478,15 +473,14 @@
if (ctype != null && !MimeTypeHelper.isAtom(ctype) &&
!MimeTypeHelper.isXml(ctype))
return new EmptyResponseContext(415);
- Document<Entry> entry_doc =
- (Document<Entry>) request.getDocument(parser).clone();
+ Document<Entry> entry_doc =
(Document<Entry>)request.getDocument(parser).clone();
if (entry_doc != null) {
Entry entry = entry_doc.getRoot();
Resource resource = new Resource();
String attValue = entry.getAttributeValue("directory");
List attributes = entry.getAttributes();
- for (int i = 0; i < attributes.size(); i++) {
- QName attName = (QName) attributes.get(i);
+ for (Object attribute : attributes) {
+ QName attName = (QName)attribute;
String key = attName.getLocalPart();
if (!("directory".equals(key) || "mediaType".equals(key)))
{
resource.setProperty(key,
entry.getAttributeValue(key));
@@ -574,7 +568,7 @@
if (contentType != null &&
!MimeTypeHelper.isAtom(contentType.toString()))
return new EmptyResponseContext(415);
Document<Entry> entry_doc =
- (Document<Entry>) request.getDocument(parser).clone();
+ (Document<Entry>)request.getDocument(parser).clone();
if (entry_doc != null) {
Entry entry = entry_doc.getRoot();
String title = entry.getSummary();
@@ -616,16 +610,17 @@
return rc;
} else if (RegistryConstants.PARAMETER_QUERY.equals(title)) {
String path = entry.getTitle();
- String[] parameters =
RemoteRegistry.decodeParametesAsString(entry.getContent());
+ String[] parameters =
+
RemoteRegistry.decodeParametesAsString(entry.getContent());
Resource resource = registry.executeQuery(path,
parameters);
Factory factory = abdera.getFactory();
Feed feed = factory.newFeed();
feed = createFeedFromResource(resource,
- feed,
- path,
- request.getBaseUri().toString(),
- abdera, true);
+ feed,
+ path,
+
request.getBaseUri().toString(),
+ abdera, true);
Document<Feed> docfeed = feed.getDocument();
AbstractResponseContext rc;
rc = new BaseResponseContext<Document<Feed>>(docfeed);
@@ -654,8 +649,7 @@
feed.setTitle(path + " [Logs]");
feed.setUpdated(new Date());
feed.addLink("", "self");
- for (int i = 0; i < entries.length; i++) {
- LogEntry logentry = entries[i];
+ for (LogEntry logentry : entries) {
Entry entry = abdera.getFactory().newEntry();
entry.setEdited(logentry.getDate());
entry.setContent(logentry.getActionData());
@@ -671,11 +665,11 @@
String id = null;
String modified = null;
if (base instanceof Entry) {
- id = ((Entry) base).getId().toString();
- modified = ((Entry) base).getUpdatedElement().getText();
+ id = ((Entry)base).getId().toString();
+ modified = ((Entry)base).getUpdatedElement().getText();
} else if (base instanceof Feed) {
- id = ((Feed) base).getId().toString();
- modified = ((Feed) base).getUpdatedElement().getText();
+ id = ((Feed)base).getId().toString();
+ modified = ((Feed)base).getUpdatedElement().getText();
}
return EntityTag.generate(id, modified);
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
Tue Dec 18 17:27:14 2007
@@ -45,10 +45,9 @@
private Log log = LogFactory.getLog(RemoteRegistry.class);
/**
- * To create a remote registry need to provide a URL of a remote registry
and the URL
- * should be something like
- * http://localhost:8080/wso2registry
- * NOTE : Should not have "/" after the wso2registry part
+ * To create a remote registry need to provide a URL of a remote registry
and the URL should be
+ * something like http://localhost:8080/wso2registry NOTE : Should not
have "/" after the
+ * wso2registry part
*
* @param registryURL : URL to the registry
* @throws RegistryException : If something went wrong
@@ -68,7 +67,7 @@
}
Document introspection =
clientResponse.getDocument();
- Feed feed = (Feed) introspection.getRoot();
+ Feed feed = (Feed)introspection.getRoot();
if (feed.getSubtitle() != null &&
feed.getSubtitle().equals("Deleted")) {
throw new
RegistryException(Messages.getMessage("resource.not.found"));
@@ -82,8 +81,8 @@
Resource resource = new Resource();
List attributes = feed.getAttributes();
- for (int i = 0; i < attributes.size(); i++) {
- QName attName = (QName) attributes.get(i);
+ for (Object attribute : attributes) {
+ QName attName = (QName)attribute;
String key = attName.getLocalPart();
if (!"directory".equals(key)) {
resource.setProperty(key, feed.getAttributeValue(key));
@@ -106,17 +105,17 @@
if (entries != null) {
String[] childNodes = new String[entries.size()];
for (int i = 0; i < entries.size(); i++) {
- Entry entery = (Entry) entries.get(i);
- childNodes[i] = entery.getTitle();
+ Entry entry = (Entry)entries.get(i);
+ childNodes[i] = entry.getTitle();
}
resource.setContent(childNodes);
}
} else {
List entries = feed.getEntries();
- Entry entery = (Entry) entries.get(0);
- String content1 = entery.getContent();
+ Entry entry = (Entry)entries.get(0);
+ String content1 = entry.getContent();
- if (content1 != null &&
!Content.Type.TEXT.equals(entery.getContentType())) {
+ if (content1 != null &&
!Content.Type.TEXT.equals(entry.getContentType())) {
byte[] content = Base64.decode(content1);
resource.setContent(content);
} else {
@@ -144,8 +143,8 @@
if (properties != null) {
Iterator keys = properties.keySet().iterator();
while (keys.hasNext()) {
- String key = (String) keys.next();
- entry.setAttributeValue(key, (String) properties.get(key));
+ String key = (String)keys.next();
+ entry.setAttributeValue(key, (String)properties.get(key));
}
}
if (resource.isDirectory()) {
@@ -157,12 +156,12 @@
if (!resource.isDirectory()) {
Object content = resource.getContent();
if (content != null && content instanceof byte[]) {
- ByteArrayInputStream in = new ByteArrayInputStream((byte[])
content);
+ ByteArrayInputStream in = new
ByteArrayInputStream((byte[])content);
entry.setContent(in);
} else if (content instanceof InputStream) {
- entry.setContent((InputStream) content);
+ entry.setContent((InputStream)content);
} else {
- entry.setContent((String) content);
+ entry.setContent((String)content);
}
}
ClientResponse resp = abderaClient.post(collectionRoot + path, entry);
@@ -190,10 +189,10 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(collectionRoot + path
+ "?" +
- RegistryConstants.PARAMETER_VERSION);
+
RegistryConstants.PARAMETER_VERSION);
Document introspection =
clientResponse.getDocument();
- Feed feed = (Feed) introspection.getRoot();
+ Feed feed = (Feed)introspection.getRoot();
String versionString = feed.getText();
if (versionString != null) {
return versionString.split(",");
@@ -239,19 +238,20 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(collectionRoot + "?" +
- RegistryConstants.PARAMETER_TAG_PATHS + "=" + tag);
+
RegistryConstants.PARAMETER_TAG_PATHS +
+ "=" + tag);
Document introspection =
clientResponse.getDocument();
- Feed feed = (Feed) introspection.getRoot();
+ Feed feed = (Feed)introspection.getRoot();
List entries = feed.getEntries();
TaggedResourcePath taggedResourcePaths[] = null;
if (entries != null) {
taggedResourcePaths = new TaggedResourcePath[entries.size()];
for (int i = 0; i < entries.size(); i++) {
- Entry entery = (Entry) entries.get(i);
+ Entry entry = (Entry)entries.get(i);
TaggedResourcePath tagpath = new TaggedResourcePath();
- tagpath.setResourcePath(entery.getTitle());
- tagpath.setTagCount(Long.parseLong(entery.getContent()));
+ tagpath.setResourcePath(entry.getTitle());
+ tagpath.setTagCount(Long.parseLong(entry.getContent()));
taggedResourcePaths[i] = tagpath;
}
}
@@ -262,19 +262,19 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(collectionRoot +
resourcePath + "?" +
- RegistryConstants.PARAMETER_TAGS);
+
RegistryConstants.PARAMETER_TAGS);
Document introspection =
clientResponse.getDocument();
- Feed feed = (Feed) introspection.getRoot();
+ Feed feed = (Feed)introspection.getRoot();
List entries = feed.getEntries();
Tag tags[] = null;
if (entries != null) {
tags = new Tag[entries.size()];
for (int i = 0; i < entries.size(); i++) {
- Entry entery = (Entry) entries.get(i);
+ Entry entry = (Entry)entries.get(i);
Tag tag = new Tag();
- tag.setTagCount(Integer.parseInt(entery.getSummary()));
- tag.setTagName(entery.getTitle());
+ tag.setTagCount(Integer.parseInt(entry.getSummary()));
+ tag.setTagName(entry.getTitle());
tags[i] = tag;
}
}
@@ -319,21 +319,21 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(collectionRoot +
resourcePath + "?" +
- RegistryConstants.PARAMETER_COMMENTS);
+
RegistryConstants.PARAMETER_COMMENTS);
Document introspection =
clientResponse.getDocument();
Element element = introspection.getRoot();
- Feed feed = (Feed) element;
+ Feed feed = (Feed)element;
List entries = feed.getEntries();
Comment comments[] = null;
if (entries != null) {
comments = new Comment[entries.size()];
for (int i = 0; i < entries.size(); i++) {
- Entry entery = (Entry) entries.get(i);
+ Entry entry = (Entry)entries.get(i);
Comment comment = new Comment();
- comment.setCommentedTime(entery.getUpdated());
- comment.setCommentText(entery.getContent());
- comment.setCommentedUser(entery.getAuthor().getName());
+ comment.setCommentedTime(entry.getUpdated());
+ comment.setCommentText(entry.getContent());
+ comment.setCommentedUser(entry.getAuthor().getName());
comments[i] = comment;
}
}
@@ -360,10 +360,11 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(collectionRoot +
resourcePath + "?" +
- RegistryConstants.PARAMETER_AVARAGE_REATINGS);
+ RegistryConstants
+
.PARAMETER_AVARAGE_REATINGS);
Document introspection =
clientResponse.getDocument();
- Feed feed = (Feed) introspection.getRoot();
+ Feed feed = (Feed)introspection.getRoot();
String floatvalue = feed.getSubtitle();
return Float.parseFloat(floatvalue);
}
@@ -371,11 +372,12 @@
public int getRating(String path, String userName) throws
RegistryException {
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
- ClientResponse clientResponse = abderaClient.get(collectionRoot + path
+ "/" + userName + "?" +
- RegistryConstants.PARAMETER_REATINGS);
+ ClientResponse clientResponse =
+ abderaClient.get(collectionRoot + path + "/" + userName + "?" +
+ RegistryConstants.PARAMETER_REATINGS);
Document introspection =
clientResponse.getDocument();
- Feed feed = (Feed) introspection.getRoot();
+ Feed feed = (Feed)introspection.getRoot();
String intvalue = feed.getSubtitle();
return Integer.parseInt(intvalue);
}
@@ -391,7 +393,7 @@
ClientResponse resp = abderaClient.put(entryRoot, entry);
Document introspection =
resp.getDocument();
- Feed feed = (Feed) introspection.getRoot();
+ Feed feed = (Feed)introspection.getRoot();
return createResourceFromFeed(feed);
}
@@ -431,19 +433,19 @@
ClientResponse resp = abderaClient.put(entryRoot, entry);
Document introspection =
resp.getDocument();
- Feed feed = (Feed) introspection.getRoot();
+ Feed feed = (Feed)introspection.getRoot();
List entries = feed.getEntries();
LogEntry logs[] = null;
if (entries != null) {
logs = new LogEntry[entries.size()];
for (int i = 0; i < entries.size(); i++) {
- Entry entery = (Entry) entries.get(i);
+ Entry thisEntry = (Entry)entries.get(i);
LogEntry logEntry = new LogEntry();
- logEntry.setDate(entery.getEdited());
- logEntry.setActionData(entery.getContent());
- logEntry.setUserName(entery.getAuthor().getName());
- logEntry.setAction(Integer.parseInt(entery.getSummary()));
- logEntry.setResourcePath(entery.getTitle());
+ logEntry.setDate(thisEntry.getEdited());
+ logEntry.setActionData(thisEntry.getContent());
+ logEntry.setUserName(thisEntry.getAuthor().getName());
+ logEntry.setAction(Integer.parseInt(thisEntry.getSummary()));
+ logEntry.setResourcePath(thisEntry.getTitle());
logs[i] = logEntry;
}
}
@@ -454,6 +456,7 @@
* This method can be used to export a local file system into a runing
instanse of a registry.
* Need to create a file object representing the local file and the need
to tell where to add
* the resource in the registry.
+ *
* @param file : File representing local file system
* @param path : Where to put the file
* @throws RegistryException : if something went wrong
@@ -473,8 +476,9 @@
* This method can be used to export registry instance or node in a
regsitry to a local file
* system. When we call this method a file srcuture will be created to
match the structure to
* map the strcuture in the registry
+ *
* @param toFile : File in the local file system
- * @param path : To which node export
+ * @param path : To which node export
* @throws RegistryException : If something went wrong
*/
public void exportFromRegistry(File toFile, String path) throws
RegistryException {
@@ -492,8 +496,7 @@
if (file.isDirectory()) {
File files[] = file.listFiles();
if (files.length > 0) {
- for (int i = 0; i < files.length; i++) {
- File childFile = files[i];
+ for (File childFile : files) {
processImport(childFile, resourcePath);
}
} else {
@@ -518,9 +521,8 @@
if (resource.isDirectory()) {
File file = new File(toFile, resource.getPath());
file.mkdirs();
- String childNodes[] = (String[]) resource.getContent();
- for (int i = 0; i < childNodes.length; i++) {
- String childNode = childNodes[i];
+ String childNodes[] = (String[])resource.getContent();
+ for (String childNode : childNodes) {
processExport(childNode, toFile);
}
} else {
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/InMemoryJDBCRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/InMemoryJDBCRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/InMemoryJDBCRegistry.java
Tue Dec 18 17:27:14 2007
@@ -36,15 +36,15 @@
/**
* Creates an in-memory HSQL database based registry without the support
for authentication and
* authorization.
- *
+ *
* @throws RegistryException
*/
public InMemoryJDBCRegistry() throws RegistryException {
RegistryDataSource dataSource = new RegistryDataSource(INMEMORY_DB_URL,
- INMEMORY_DB_DRIVER_NAME,
- INMEMORY_DB_USER_NAME,
- INMEMORY_DB_PASSWORD);
+
INMEMORY_DB_DRIVER_NAME,
+
INMEMORY_DB_USER_NAME,
+
INMEMORY_DB_PASSWORD);
startInProcessDatabase(dataSource);
@@ -55,17 +55,18 @@
* Creates the in-memory HSQL database and creates all tables necessary
for the registry. Then
* contructs the registry with a datasource pointing to the HSQL database.
*
- * @param registryRealm User manager registryRealm to use with the
registry. It is strongly recommended to use
- * a registryRealm configured with a in-memory (transient) database with
the in-memory registry.
+ * @param registryRealm User manager registryRealm to use with the
registry. It is strongly
+ * recommended to use a registryRealm configured with
a in-memory
+ * (transient) database with the in-memory registry.
*/
public InMemoryJDBCRegistry(RegistryRealm registryRealm) throws
RegistryException {
// create a datasource using the HSQL database. jdbc registry should
use this datasource.
RegistryDataSource dataSource = new RegistryDataSource(INMEMORY_DB_URL,
- INMEMORY_DB_DRIVER_NAME,
- INMEMORY_DB_USER_NAME,
- INMEMORY_DB_PASSWORD);
+
INMEMORY_DB_DRIVER_NAME,
+
INMEMORY_DB_USER_NAME,
+
INMEMORY_DB_PASSWORD);
startInProcessDatabase(dataSource);
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/realm/RegistryRealm.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/realm/RegistryRealm.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/realm/RegistryRealm.java
Tue Dec 18 17:27:14 2007
@@ -17,11 +17,9 @@
package org.wso2.registry.jdbc.realm;
import org.wso2.registry.RegistryException;
-import org.wso2.registry.secure.HSQLDBInitializer;
import org.wso2.registry.utils.AuthorizationUtil;
import org.wso2.usermanager.UserManagerException;
import org.wso2.usermanager.UserStoreAdmin;
-import org.wso2.usermanager.Realm;
import org.wso2.usermanager.readwrite.DefaultRealm;
import org.wso2.usermanager.readwrite.DefaultRealmConfig;
@@ -36,7 +34,8 @@
init(dataSource);
}
- protected RegistryRealm() throws RegistryException {}
+ protected RegistryRealm() throws RegistryException {
+ }
protected void configure(DataSource dataSource) throws RegistryException {
init(dataSource);
@@ -59,7 +58,7 @@
} catch (UserManagerException e) {
String msg = "Could not initiate a user manager realm using the
given data source. " +
- "Cause by: " + e.getMessage();
+ "Caused by: " + e.getMessage();
throw new RegistryException(msg);
}
}
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
Tue Dec 18 17:27:14 2007
@@ -18,22 +18,20 @@
*/
package org.wso2.registry.app;
-import org.apache.abdera.protocol.server.impl.DefaultServiceContext;
+import org.apache.abdera.protocol.server.ServiceContext;
import org.apache.abdera.protocol.server.impl.AbstractSingletonProviderManager;
+import org.apache.abdera.protocol.server.impl.DefaultServiceContext;
import org.apache.abdera.protocol.server.servlet.AbderaServlet;
-import org.apache.abdera.protocol.server.ServiceContext;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
-import org.wso2.registry.jdbc.JDBCRegistryTest;
-import org.wso2.registry.jdbc.JDBCRegistry;
+import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.RegistryException;
import org.wso2.registry.jdbc.InMemoryJDBCRegistry;
-import org.wso2.registry.jdbc.realm.RegistryRealm;
+import org.wso2.registry.jdbc.JDBCRegistry;
+import org.wso2.registry.jdbc.JDBCRegistryTest;
import org.wso2.registry.jdbc.realm.InMemoryRegistryRealm;
-import org.wso2.registry.RegistryException;
-import org.wso2.registry.RegistryConstants;
-import org.wso2.registry.servlet.RegistryRealmFactory;
-import org.wso2.usermanager.Realm;
+import org.wso2.registry.jdbc.realm.RegistryRealm;
import javax.servlet.ServletException;
import java.net.URL;
@@ -41,10 +39,8 @@
//This test case run all the test cases that there in JDBCRegistry using
RemoteRegistry
public class JettyBasedServerTest extends JDBCRegistryTest {
- private Server server;
private DefaultServiceContext abderaServiceContext;
-
public void setUp() {
try {
if (registry == null) {
@@ -59,7 +55,8 @@
// protected void tearDown() throws Exception {
// if (server != null) server.stop();
// }
-//
+
+ //
private void initJetty() throws Exception {
abderaServiceContext = new RegistryAPPServiceContext();
RegistryAPPTargetResolver resolver = new RegistryAPPTargetResolver();
@@ -67,14 +64,16 @@
AbstractSingletonProviderManager pm = new
RegistryAtomProviderManager();
abderaServiceContext.setProviderManager(pm);
- server = new Server(8081);
+ Server server = new Server(8081);
Context root = new Context(server, "/wso2registry",
Context.NO_SESSIONS);
root.addServlet(new ServletHolder(new AbderaServlet() {
@Override
protected ServiceContext createServiceContext() {
-
abderaServiceContext.setDefaultProviderManager(RegistryAtomProviderManager.class.getName());
-
abderaServiceContext.setDefaultTargetResolver(RegistryAPPTargetResolver.class.getName());
+ abderaServiceContext
+
.setDefaultProviderManager(RegistryAtomProviderManager.class.getName());
+ abderaServiceContext
+
.setDefaultTargetResolver(RegistryAPPTargetResolver.class.getName());
abderaServiceContext.init(getAbdera(),
getProperties(getServletConfig()));
JDBCRegistry jdbcRegistry = null;
try {
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
Tue Dec 18 17:27:14 2007
@@ -25,12 +25,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
+import java.util.Arrays;
public class JDBCRegistryTest extends TestCase {
/**
- * Registry instance for use in tests. Note that there should be only one
Registry instance
- * in a JVM.
+ * Registry instance for use in tests. Note that there should be only one
Registry instance in a
+ * JVM.
*/
protected static Registry registry = null;
@@ -68,7 +69,7 @@
}
assertEquals("Content is not equal.",
- new String((byte[]) r1.getContent()), new String((byte[])
r1f.getContent()));
+ new String((byte[])r1.getContent()), new
String((byte[])r1f.getContent()));
assertEquals("Author is not equal.", r1.getAuthorUserName(),
r1f.getAuthorUserName());
@@ -118,10 +119,10 @@
assertTrue("Content of /d1 should be a String[]", d1.getContent()
instanceof String[]);
- String[] children = (String[]) d1.getContent();
+ String[] children = (String[])d1.getContent();
boolean found = false;
- for (int i = 0; i < children.length; i++) {
- if (children[i].startsWith("/d1/r1")) {
+ for (String aChildren : children) {
+ if (aChildren.startsWith("/d1/r1")) {
found = true;
break;
}
@@ -136,7 +137,7 @@
}
assertEquals("Resource content is not stored correctly.",
- new String((byte[]) r1.getContent()), new String((byte[])
r1f.getContent()));
+ new String((byte[])r1.getContent()), new
String((byte[])r1f.getContent()));
try {
registry.delete("/d1");
@@ -154,7 +155,7 @@
boolean f2 = false;
try {
- registry.get("/d1/r1");
+ registry.get("/d1/r1");
} catch (RegistryException e) {
f2 = true;
}
@@ -226,9 +227,9 @@
fail("Failed to get versioned resource.");
}
- String content1 = new String((byte[]) v1.getContent());
- String content2 = new String((byte[]) v2.getContent());
- String content3 = new String((byte[]) v3.getContent());
+ String content1 = new String((byte[])v1.getContent());
+ String content2 = new String((byte[])v2.getContent());
+ String content3 = new String((byte[])v3.getContent());
assertEquals("Content is not versioned properly.", content1, "R1
content");
assertEquals("Content is not versioned properly.", content2, "New
content");
@@ -247,7 +248,7 @@
fail("Valid get failed.");
}
- String restoredContent = new String((byte[]) r5restored.getContent());
+ String restoredContent = new String((byte[])r5restored.getContent());
assertEquals("Content is not restored properly.", "R1 content",
restoredContent);
}
@@ -343,12 +344,15 @@
fail("Valid get failed.");
}
- String[] chidrenOfv1 = (String[]) c10v1.getContent();
- assertTrue("collection content is not versioned properly.",
containsString(chidrenOfv1, "/c10/r1"));
-
- String[] chidrenOfv2 = (String[]) c10v2.getContent();
- assertTrue("collection content is not versioned properly.",
containsString(chidrenOfv2, "/c10/r1"));
- assertTrue("collection content is not versioned properly.",
containsString(chidrenOfv2, "/c10/r2"));
+ String[] chidrenOfv1 = (String[])c10v1.getContent();
+ assertTrue("collection content is not versioned properly.",
+ containsString(chidrenOfv1, "/c10/r1"));
+
+ String[] chidrenOfv2 = (String[])c10v2.getContent();
+ assertTrue("collection content is not versioned properly.",
+ containsString(chidrenOfv2, "/c10/r1"));
+ assertTrue("collection content is not versioned properly.",
+ containsString(chidrenOfv2, "/c10/r2"));
try {
registry.restoreVersion(versionPaths[0]);
@@ -363,13 +367,14 @@
fail("Valid get failed.");
}
- String[] restoredC10Children = (String[]) restoredC10.getContent();
- assertTrue("Collection children are not restored properly.",
containsString(restoredC10Children, "/c10/r1"));
- assertTrue("Collection children are not restored properly.",
!containsString(restoredC10Children, "/c10/r2"));
+ String[] restoredC10Children = (String[])restoredC10.getContent();
+ assertTrue("Collection children are not restored properly.",
+ containsString(restoredC10Children, "/c10/r1"));
+ assertTrue("Collection children are not restored properly.",
+ !containsString(restoredC10Children, "/c10/r2"));
}
-
public void testComments() {
// add a resource
@@ -401,29 +406,31 @@
}
boolean commentFound = false;
- for (int i = 0; i < comments.length; i++) {
- if (comments[i].getCommentText().equals(comment1)) {
+ for (Comment comment : comments) {
+ if (comment.getCommentText().equals(comment1)) {
commentFound = true;
break;
}
}
assertTrue("comment '" + comment1 +
- "' is not associated with the artifact /d12/r1", commentFound);
+ "' is not associated with the artifact /d12/r1",
commentFound);
try {
Resource commentsResource = registry.get("/d12/r1?comments");
assertTrue("Comment collection resource should be a directory.",
- commentsResource.isDirectory());
- String[] commentPaths = (String[]) commentsResource.getContent();
+ commentsResource.isDirectory());
+ String[] commentPaths = (String[])commentsResource.getContent();
List commentTexts = new ArrayList();
- for (int i = 0; i < commentPaths.length; i++) {
- Resource commentResource = registry.get(commentPaths[i]);
+ for (String commentPath : commentPaths) {
+ Resource commentResource = registry.get(commentPath);
commentTexts.add(commentResource.getContent());
}
- assertTrue(comment1 + " is not associated for resource /d12/r1.",
commentTexts.contains(comment1));
- assertTrue(comment2 + " is not associated for resource /d12/r1.",
commentTexts.contains(comment2));
+ assertTrue(comment1 + " is not associated for resource /d12/r1.",
+ commentTexts.contains(comment1));
+ assertTrue(comment2 + " is not associated for resource /d12/r1.",
+ commentTexts.contains(comment2));
} catch (RegistryException e) {
e.printStackTrace();
@@ -464,7 +471,8 @@
fail("Couldn't get the rating of the resource /d13/r1");
}
- assertEquals("Rating of the resource /d13/r1 should be 4.", rating,
(float) 4.0, (float) 0.01);
+ assertEquals("Rating of the resource /d13/r1 should be 4.", rating,
(float)4.0,
+ (float)0.01);
try {
registry.delete("/d13");
@@ -502,7 +510,7 @@
q1.setContent(sql1);
q1.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
q1.setProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME,
- RegistryConstants.RESOURCES_RESULT_TYPE);
+ RegistryConstants.RESOURCES_RESULT_TYPE);
registry.put("/qs/q1", q1);
} catch (RegistryException e) {
@@ -510,16 +518,14 @@
}
try {
- Resource result1 = registry.executeQuery("/qs/q1", new String[]
{"%production%"});
+ Resource result1 = registry.executeQuery("/qs/q1", new
String[]{"%production%"});
assertTrue("Search with result type Resource should return a
directory.",
- result1.isDirectory());
+ result1.isDirectory());
List matchingPaths = new ArrayList();
- String[] paths = (String[]) result1.getContent();
- for (int i = 0; i < paths.length; i++) {
- matchingPaths.add(paths[i]);
- }
+ String[] paths = (String[])result1.getContent();
+ matchingPaths.addAll(Arrays.asList(paths));
assertTrue("Path /c1/r1 should be in the results.",
matchingPaths.contains("/c1/r1"));
assertTrue("Path /c2/r2 should be in the results.",
matchingPaths.contains("/c2/r2"));
@@ -557,12 +563,13 @@
registry.rateResource("/c3/r2", 4);
registry.rateResource("/c3/r3", 5);
- String sql1 = "SELECT R.R_ID FROM RATINGS R, ARTIFACTS A WHERE
A.AID=R.AID AND A.DESCRIPTION LIKE ?";
+ String sql1 =
+ "SELECT R.R_ID FROM RATINGS R, ARTIFACTS A WHERE
A.AID=R.AID AND A.DESCRIPTION LIKE ?";
Resource q1 = new Resource();
q1.setContent(sql1);
q1.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
q1.setProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME,
- RegistryConstants.RATINGS_RESULT_TYPE);
+ RegistryConstants.RATINGS_RESULT_TYPE);
registry.put("/qs/q2", q1);
} catch (RegistryException e) {
@@ -570,21 +577,21 @@
}
try {
- Resource result1 = registry.executeQuery("/qs/q2", new String[]
{"%production%"});
+ Resource result1 = registry.executeQuery("/qs/q2", new
String[]{"%production%"});
assertTrue("Search with result type Resource should return a
directory.",
- result1.isDirectory());
+ result1.isDirectory());
- String[] ratingPaths = (String[]) result1.getContent();
+ String[] ratingPaths = (String[])result1.getContent();
assertEquals("There should be two match ratings.",
ratingPaths.length, 2);
Resource rating1 = registry.get(ratingPaths[0]);
assertEquals("First matching rating should be 3",
- rating1.getContent().toString(), "3");
+ rating1.getContent().toString(), "3");
Resource rating2 = registry.get(ratingPaths[1]);
assertEquals("First matching rating should be 3",
- rating2.getContent().toString(), "4");
+ rating2.getContent().toString(), "4");
} catch (RegistryException e) {
fail("Failed to execute query.");
@@ -619,12 +626,13 @@
registry.applyTag("/c3/r2", "jsp");
registry.applyTag("/c3/r3", "ajax");
- String sql1 = "SELECT T.TN_ID FROM TAGS T, ARTIFACTS A WHERE
A.AID=T.AID AND A.DESCRIPTION LIKE ?";
+ String sql1 =
+ "SELECT T.TN_ID FROM TAGS T, ARTIFACTS A WHERE A.AID=T.AID
AND A.DESCRIPTION LIKE ?";
Resource q1 = new Resource();
q1.setContent(sql1);
q1.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
q1.setProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME,
- RegistryConstants.TAGS_RESULT_TYPE);
+ RegistryConstants.TAGS_RESULT_TYPE);
registry.put("/qs/q3", q1);
} catch (RegistryException e) {
@@ -632,21 +640,21 @@
}
try {
- Resource result1 = registry.executeQuery("/qs/q3", new String[]
{"%production%"});
+ Resource result1 = registry.executeQuery("/qs/q3", new
String[]{"%production%"});
assertTrue("Search with result type tags should return a
directory.",
- result1.isDirectory());
+ result1.isDirectory());
- String[] tagPaths = (String[]) result1.getContent();
+ String[] tagPaths = (String[])result1.getContent();
assertEquals("There should be two matching tags.",
tagPaths.length, 2);
Resource tag1 = registry.get(tagPaths[0]);
assertEquals("First matching tag should be 'java'",
- (String)tag1.getContent(), "java");
+ (String)tag1.getContent(), "java");
Resource tag2 = registry.get(tagPaths[1]);
assertEquals("First matching tag should be 'jsp'",
- (String)tag2.getContent(), "jsp");
+ (String)tag2.getContent(), "jsp");
} catch (RegistryException e) {
fail("Failed to execute query.");
@@ -681,12 +689,13 @@
registry.addComment("/c5/r2", new Comment("replace this with a
better one"));
registry.addComment("/c5/r3", new Comment("import all dependencies
for this resource"));
- String sql1 = "SELECT C.CM_ID FROM COMMENTS C, ARTIFACTS A WHERE
A.AID=C.AID AND A.DESCRIPTION LIKE ?";
+ String sql1 =
+ "SELECT C.CM_ID FROM COMMENTS C, ARTIFACTS A WHERE
A.AID=C.AID AND A.DESCRIPTION LIKE ?";
Resource q1 = new Resource();
q1.setContent(sql1);
q1.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
q1.setProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME,
- RegistryConstants.COMMENTS_RESULT_TYPE);
+ RegistryConstants.COMMENTS_RESULT_TYPE);
registry.put("/qs/q4", q1);
} catch (RegistryException e) {
@@ -694,21 +703,21 @@
}
try {
- Resource result1 = registry.executeQuery("/qs/q4", new String[]
{"%production%"});
+ Resource result1 = registry.executeQuery("/qs/q4", new
String[]{"%production%"});
assertTrue("Search with result type Comment should return a
collection.",
- result1.isDirectory());
+ result1.isDirectory());
- String[] commentPaths = (String[]) result1.getContent();
+ String[] commentPaths = (String[])result1.getContent();
assertEquals("There should be two match comments.",
commentPaths.length, 2);
Resource c1 = registry.get(commentPaths[0]);
assertEquals("First matching comment is incorrect",
- (String) c1.getContent(), "we have to change this file.");
+ (String)c1.getContent(), "we have to change this
file.");
Resource c2 = registry.get(commentPaths[1]);
assertEquals("Second matching comment is incorrect",
- (String) c2.getContent(), "replace this with a better
one");
+ (String)c2.getContent(), "replace this with a better
one");
} catch (RegistryException e) {
fail("Failed to execute query.");
@@ -796,13 +805,13 @@
fail("Failed to get comments using URL.");
}
- String[] commentPaths = (String[]) comments.getContent();
+ String[] commentPaths = (String[])comments.getContent();
List commentStrings = new ArrayList();
- for (int i = 0; i < commentPaths.length; i++) {
+ for (String commentPath : commentPaths) {
try {
- Resource c1 = registry.get(commentPaths[i]);
- String commentString = (String) c1.getContent();
+ Resource c1 = registry.get(commentPath);
+ String commentString = (String)c1.getContent();
commentStrings.add(commentString);
} catch (RegistryException e) {
fail("Failed to get comment using a path.");
@@ -810,13 +819,13 @@
}
assertTrue("Comments are not retrieved properly as resources.",
- commentStrings.contains("this is used to test comments."));
+ commentStrings.contains("this is used to test comments."));
assertTrue("Comments are not retrieved properly as resources.",
- commentStrings.contains("dummy resource."));
+ commentStrings.contains("dummy resource."));
assertTrue("Comments are not retrieved properly as resources.",
- commentStrings.contains("simple test resource."));
+ commentStrings.contains("simple test resource."));
}
public void testRatingsAsResources() {
@@ -845,15 +854,15 @@
fail("Failed to get ratings using URL.");
}
- String[] ratingPaths = (String[]) ratings.getContent();
+ String[] ratingPaths = (String[])ratings.getContent();
int rating = 0;
try {
Resource c1 = registry.get(ratingPaths[0]);
Object o = c1.getContent();
- if(o instanceof Integer) {
- rating = ((Integer) o).intValue();
+ if (o instanceof Integer) {
+ rating = (Integer)o;
} else {
rating = Integer.parseInt(o.toString());
}
@@ -878,7 +887,6 @@
registry.rateResource("/r200", 5);
-
// assertEquals("Log for adding /r200 is not added properly.",
LogEntry.UPDATE, l1.getAction());
// assertEquals("Log for adding /r200 is not added properly.", "/r200",
l1.getResourcePath());
@@ -886,7 +894,7 @@
// assertEquals("Log for rating /r200 is not added properly.", "5",
l2.getActionData());
}
- public void testResourceDelete() throws RegistryException{
+ public void testResourceDelete() throws RegistryException {
String content1 = "Content1";
Resource r1 = new Resource();
r1.setContent(content1);
@@ -903,35 +911,35 @@
registry.put("/wso2/wsas/v2", v2);
//getting the resource
- Resource r2= registry.get("/wso2/wsas/v1");
+ Resource r2 = registry.get("/wso2/wsas/v1");
//chcek whether the content is corrcet
- assertEquals("/wso2/wsas/v1/r1",((String[])r2.getContent())[0]);
+ assertEquals("/wso2/wsas/v1/r1", ((String[])r2.getContent())[0]);
Resource wsas = registry.get("/wso2/wsas");
- String wasaContent [] = (String[]) wsas.getContent();
+ String wasaContent[] = (String[])wsas.getContent();
assertNotNull(wasaContent);
- assertEquals(2,wasaContent.length);
+ assertEquals(2, wasaContent.length);
registry.delete("/wso2/wsas/v1");
- String content2 ="Content2";
+ String content2 = "Content2";
Resource resourceContent2 = new Resource();
resourceContent2.setContent(content2);
- registry.put("/wso2/wsas/v1/r2",resourceContent2);
+ registry.put("/wso2/wsas/v1/r2", resourceContent2);
wsas = registry.get("/wso2/wsas");
- wasaContent = (String[]) wsas.getContent();
+ wasaContent = (String[])wsas.getContent();
assertNotNull(wasaContent);
- assertEquals(2,wasaContent.length);
+ assertEquals(2, wasaContent.length);
- r2= registry.get("/wso2/wsas/v1");
+ r2 = registry.get("/wso2/wsas/v1");
//chcek whether the content is corrcet
- assertEquals("/wso2/wsas/v1/r2",((String[])r2.getContent())[0]);
+ assertEquals("/wso2/wsas/v1/r2", ((String[])r2.getContent())[0]);
registry.restoreVersion("/wso2/wsas?v=2");
- r2= registry.get("/wso2/wsas/v1");
+ r2 = registry.get("/wso2/wsas/v1");
//chcek whether the content is corrcet
- assertEquals("/wso2/wsas/v1/r1",((String[])r2.getContent())[0]);
+ assertEquals("/wso2/wsas/v1/r1", ((String[])r2.getContent())[0]);
}
@@ -992,7 +1000,6 @@
registry.put("/c2/r4", r4);
-
// do some taggings
try {
@@ -1017,7 +1024,8 @@
registry.addComment("/r1", new Comment("this is a test
artifact."));
registry.addComment("/c1", new Comment("I don't agree with having
this collection."));
registry.addComment("/c1/r2", new Comment("Is this a collection
;)"));
- registry.addComment("/c2", new Comment("I can understand the
purpose of this. Thanks."));
+ registry.addComment("/c2",
+ new Comment("I can understand the purpose of
this. Thanks."));
} catch (RegistryException e) {
fail("Valid commenting scenario failed.");
}
@@ -1045,8 +1053,8 @@
private boolean containsString(String[] array, String value) {
boolean found = false;
- for (int i = 0; i < array.length; i++) {
- if (array[i].startsWith(value)) {
+ for (String anArray : array) {
+ if (anArray.startsWith(value)) {
found = true;
break;
}
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev