Revision: 2001
Author: [email protected]
Date: Fri Aug 13 02:11:14 2010
Log: Save submitted DOAP specifications to a file on disk. Also fixed some
findbugs warnings. (fixes Issue 337)
http://code.google.com/p/simal/source/detail?r=2001
Modified:
/trunk/uk.ac.osswatch.simal.web/pom.xml
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/BasePage.java
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/DoapFormInputModel.java
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/DoapFormPage.html
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/DoapFormPage.java
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/style/default.css
/trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/TestBase.java
/trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/doap/TestDoapFormPage.java
/trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/foaf/TestPersonDetailsPage.java
=======================================
--- /trunk/uk.ac.osswatch.simal.web/pom.xml Wed Jul 21 07:20:51 2010
+++ /trunk/uk.ac.osswatch.simal.web/pom.xml Fri Aug 13 02:11:14 2010
@@ -294,9 +294,11 @@
<configuration>
<excludes>
<exclude>.pmd</exclude>
+ <exclude>.pydevproject</exclude>
<exclude>derby.log</exclude>
<exclude>simal*/**.*</exclude>
<exclude>build/**/*</exclude>
+ <exclude>backup/**.*</exclude>
<exclude>simalDOAPFilestore/**/*</exclude>
<exclude>simalRepository/**/*</exclude>
<exclude>local.simal.properties</exclude>
@@ -363,6 +365,19 @@
<excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
</configuration>
</plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <version>2.0</version>
+ <configuration>
+ <formats>
+ <format>xml</format>
+ <format>html</format>
+ </formats>
+ </configuration>
+ </plugin>
+
</plugins>
</reporting>
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/BasePage.java
Thu Jun 10 08:06:49 2010
+++
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/BasePage.java
Fri Aug 13 02:11:14 2010
@@ -109,12 +109,8 @@
String defaultWidgetName = "doapcreator";
String doapProjectWidgetName;
- try {
- doapProjectWidgetName = SimalProperties.getProperty(
- SimalProperties.PROPERTY_ADD_PROJECT_WIDGET_TITLE,
defaultWidgetName);
- } catch (SimalRepositoryException e) {
- doapProjectWidgetName = defaultWidgetName;
- }
+ doapProjectWidgetName = SimalProperties.getProperty(
+ SimalProperties.PROPERTY_ADD_PROJECT_WIDGET_TITLE,
defaultWidgetName);
return doapProjectWidgetName;
}
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/DoapFormInputModel.java
Thu Sep 18 15:05:34 2008
+++
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/DoapFormInputModel.java
Fri Aug 13 02:11:14 2010
@@ -28,10 +28,11 @@
public class DoapFormInputModel implements IClusterable {
private static final long serialVersionUID = -9089647575258232806L;
private URL sourceURL;
- private String name;
- private String shortDesc;
- private String description;
private String rawRDF;
+ private String sourceForgeId;
+
+ public DoapFormInputModel() {
+ }
/**
* If the form contains raw RDF get that RDF content.
@@ -50,43 +51,6 @@
public void setRawRDF(String rawRDF) {
this.rawRDF = rawRDF;
}
-
- /**
- * Get the full description for this project.
- *
- * @return
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * Set the full description for this project.
- *
- * @param description
- */
- public void setDescription(String description) {
- this.description = description;
- }
-
- public DoapFormInputModel() {
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getShortDesc() {
- return shortDesc;
- }
-
- public void setShortDesc(String shortDesc) {
- this.shortDesc = shortDesc;
- }
/**
* Get the source URL for the data in this DOAP form.
@@ -101,5 +65,13 @@
public void setSourceURL(URL sourceURL) {
this.sourceURL = sourceURL;
}
+
+ public void setSourceForgeId(String sourceForgeId) {
+ this.sourceForgeId = sourceForgeId;
+ }
+
+ public String getSourceForgeId() {
+ return sourceForgeId;
+ }
}
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/DoapFormPage.html
Mon Sep 15 15:28:15 2008
+++
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/DoapFormPage.html
Fri Aug 13 02:11:14 2010
@@ -1,6 +1,6 @@
<!--
-Copyright 2008 University of Oxford
+Copyright 2008, 2010 University of Oxford
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
@@ -31,16 +31,29 @@
your own copy of your DOAP file.
</div>
- <form wicket:id="addByURLForm">
- <fieldset>
+ <div id="feedbackPanel">
+ <span class="warning" wicket:id="feedback">Feedback</span>
+ </div>
+ <fieldset>
<legend>Load hosted DOAP</legend>
+ <form wicket:id="addByURLForm">
<p>
<label>Source URL:</label>
<input type="text" wicket:id="sourceURL" value="" size="50" />
+ <input type="submit" value="Add to repository" /><br />
+ <span class="instruction">Enter the full URL to the project's
DOAP file.</span>
</p>
- <input type="submit" value="Add to repository" />
- </fieldset>
- </form>
+ </form>
+ <form wicket:id="addBySourceForgeIdForm">
+ <p>
+ <label>SourceForge project:</label>
+ <input type="text" wicket:id="sourceForgeId" value="" size="50"
/>
+ <input type="submit" value="Add to repository" /><br />
+ <span class="instruction">Enter the short name of a project that
is hosted on SourceForge.<br />
+ For example: enter 'foo' if the project is hosted at
http://sourceforge.net/projects/foo</span>
+ </p>
+ </form>
+ </fieldset>
<form wicket:id="uploadForm">
<fieldset>
@@ -65,34 +78,6 @@
</fieldset>
</form>
- <hr/>
-
- <form wicket:id="doapForm">
- <fieldset>
- <legend>DOAP Generator</legend>
- <table>
- <tr>
- <td><label for="name">Name</label></td>
- <td><input type="text" id="name" wicket:id="name" value=""
size="80" /></td>
- </tr>
- <tr>
- <td><label for="shortDesc">Short Description</label></td>
- <td><input type="text" id="shortDesc" wicket:id="shortDesc"
value="" size="80" /></td>
- </tr>
- <tr>
- <td><label for="description">Description</label></td>
- <td><textarea id="description" wicket:id="description"
cols="80" rows="10"></textarea></td>
- </tr>
- <tr>
- <td colspan="2"><input type="submit" value="Add to repository"
/></td>
- </tr>
- </table>
- </fieldset>
- </form>
- </div>
-
- <div id="feedbackPanel">
- <span wicket:id="feedback">Feedback</span>
</div>
</wicket:extend>
</body>
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/DoapFormPage.java
Tue Feb 16 05:15:45 2010
+++
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/doap/DoapFormPage.java
Fri Aug 13 02:11:14 2010
@@ -1,7 +1,7 @@
package uk.ac.osswatch.simal.wicket.doap;
/*
- * Copyright 2008 University of Oxford
+ * Copyright 2008,2010 University of Oxford
*
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
@@ -18,11 +18,21 @@
*/
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
-
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.Session;
import
org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RequiredTextField;
@@ -32,40 +42,51 @@
import org.apache.wicket.markup.html.form.upload.FileUploadField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
-import org.apache.wicket.util.file.Files;
-import org.apache.wicket.util.file.Folder;
import org.apache.wicket.util.lang.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
+import org.xml.sax.SAXParseException;
+
+import uk.ac.osswatch.simal.SimalProperties;
import uk.ac.osswatch.simal.SimalRepositoryFactory;
import uk.ac.osswatch.simal.model.IProject;
-import uk.ac.osswatch.simal.rdf.DuplicateURIException;
-import uk.ac.osswatch.simal.rdf.ISimalRepository;
-import uk.ac.osswatch.simal.rdf.SimalRepositoryException;
-import uk.ac.osswatch.simal.rdf.io.RDFUtils;
+import uk.ac.osswatch.simal.rdf.SimalException;
+import uk.ac.osswatch.simal.rdf.io.RDFXMLUtils;
import uk.ac.osswatch.simal.wicket.BasePage;
import uk.ac.osswatch.simal.wicket.ErrorReportPage;
-import uk.ac.osswatch.simal.wicket.UserApplication;
-import uk.ac.osswatch.simal.wicket.UserHomePage;
import uk.ac.osswatch.simal.wicket.UserReportableException;
/**
- * A form for manipulating and creating DOAP files.
+ * A form for importing and creating DOAP files.
*/
public class DoapFormPage extends BasePage {
private static final long serialVersionUID = -7082891387390604176L;
private static final Logger logger = LoggerFactory
.getLogger(DoapFormPage.class);
+
+ private static final String FILE_NAME_FORMAT = "%s_%s.xml";
+
private static DoapFormInputModel inputModel = new DoapFormInputModel();
- private Folder uploadFolder;
+ private FeedbackPanel feedback;
public DoapFormPage() {
- final FeedbackPanel feedback = new FeedbackPanel("feedback");
+ feedback = new FeedbackPanel("feedback");
add(feedback);
- add(new AddByURLForm("addByURLForm"));
+ AddByURLForm<DoapFormInputModel> addByURLForm = new
AddByURLForm<DoapFormInputModel>(
+ "addByURLForm", new CompoundPropertyModel<DoapFormInputModel>(
+ inputModel));
+ TextField<URL> urlField = new TextField<URL>("sourceURL", URL.class);
+ addByURLForm.add(urlField);
+ String[] defaultValue = { "" };
+ urlField.setModelValue(defaultValue);
+ add(addByURLForm);
+
+ add(new AddBySourceForgeURLForm<DoapFormInputModel>(
+ "addBySourceForgeIdForm",
+ new CompoundPropertyModel<DoapFormInputModel>(inputModel)));
final FileUploadForm ajaxSimpleUploadForm = new
FileUploadForm("uploadForm");
ajaxSimpleUploadForm.add(new UploadProgressBar("uploadProgress",
@@ -73,11 +94,13 @@
add(ajaxSimpleUploadForm);
add(new AddByRawRDFForm("rawRDFForm"));
-
- add(new DoapForm("doapForm"));
}
- private static class AddByRawRDFForm extends Form<DoapFormInputModel> {
+ /**
+ * Form for a project's DOAP description that can been entered in a text
area
+ * and is processed as a project if it's valid RDF/XML containing DOAP.
+ */
+ private class AddByRawRDFForm extends Form<DoapFormInputModel> {
private static final long serialVersionUID = 5436861979864365527L;
private TextArea<String> rdfField;
@@ -92,29 +115,18 @@
protected void onSubmit() {
super.onSubmit();
String rdf = StringEscapeUtils.unescapeXml(rdfField.getValue());
- try {
- ISimalRepository repo = UserApplication.getRepository();
- repo.add(rdf);
- setResponsePage(new UserHomePage());
- } catch (SimalRepositoryException e) {
- setResponsePage(new ErrorReportPage(new UserReportableException(
- "Unable to add doap using RDF supplied", DoapFormPage.class,
e)));
- }
-
+ processSubmittedDoap(rdf);
}
}
+ /**
+ * Form for uploading a DOAP description as a file.
+ */
private class FileUploadForm extends Form<FileUploadField> {
private static final long serialVersionUID = -6275625011225339551L;
private FileUploadField fileUploadField;
- /**
- * Simple constructor.
- *
- * @param name
- * Component name
- */
public FileUploadForm(String name) {
super(name);
setMultiPart(true);
@@ -131,119 +143,199 @@
if (!this.hasError()) {
final FileUpload upload = fileUploadField.getFileUpload();
if (upload != null) {
- File newFile = new File(getUploadFolder(),
upload.getClientFileName());
-
- if (newFile.exists() && !Files.remove(newFile)) {
- throw new IllegalStateException("Unable to overwrite "
- + newFile.getAbsolutePath());
- }
-
try {
- boolean success = newFile.createNewFile();
- if (!success) {
- logger.warn("Trying ot create a file that already exists: "
- + newFile);
- }
- upload.writeTo(newFile);
- DoapFormPage.this.info("saved file: " +
upload.getClientFileName());
+ StringWriter xmlSourceWriter = new StringWriter();
+ IOUtils.copy(upload.getInputStream(), xmlSourceWriter);
+ processSubmittedDoap(xmlSourceWriter.toString());
} catch (IOException e) {
- throw new IllegalStateException("Unable to write file");
- }
-
- try {
-
UserApplication.getRepository().addProject(newFile.toURI().toURL(),
- null);
- setResponsePage(new UserHomePage());
- } catch (SimalRepositoryException e) {
setResponsePage(new ErrorReportPage(new
UserReportableException(
- "Unable to add doap from url", DoapFormPage.class, e)));
- } catch (MalformedURLException e) {
- // should never be thrown as file is created locally
- setResponsePage(new ErrorReportPage(new
UserReportableException(
- "Unable to add uploaded file", DoapFormPage.class, e)));
+ "Unable to add doap using RDF supplied",
DoapFormPage.class, e)));
}
}
}
}
}
- private static class DoapForm extends Form<DoapFormInputModel> {
+ /**
+ * For for submitting a project to Simal by specifying a URL to
+ * a DOAP specification.
+ * @param <T>
+ */
+ private class AddByURLForm<T extends DoapFormInputModel> extends
+ Form<DoapFormInputModel> {
private static final long serialVersionUID = 4350446873545711199L;
- public DoapForm(String name) {
- super(name, new
CompoundPropertyModel<DoapFormInputModel>(inputModel));
-
- RequiredTextField<String> stringTextField = new
RequiredTextField<String>(
- "name");
- stringTextField.setLabel(new Model<String>());
- add(stringTextField);
-
- stringTextField = new RequiredTextField<String>("shortDesc");
- stringTextField.setLabel(new Model<String>());
- add(stringTextField);
-
- TextArea<String> descriptionField = new
TextArea<String>("description");
- add(descriptionField);
- String[] defaultValue = { "" };
- descriptionField.setModelValue(defaultValue);
+ public AddByURLForm(String name, IModel<DoapFormInputModel> model) {
+ super(name, model);
}
- @Override
- protected void onSubmit() {
- super.onSubmit();
-
+ protected void processAddByURLSubmit(URL url, String invalidUrlMsg) {
if (!this.hasError()) {
- String uri = RDFUtils.PROJECT_NAMESPACE_URI + inputModel.getName();
try {
- IProject project =
SimalRepositoryFactory.getProjectService().createProject(uri);
- project.addName(inputModel.getName());
- project.setShortDesc(inputModel.getShortDesc());
- project.setDescription(inputModel.getDescription());
- setResponsePage(new UserHomePage());
- } catch (DuplicateURIException e) {
- error("Name must be unique within the registry");
- } catch (SimalRepositoryException e) {
+ StringWriter xmlSourceWriter = new StringWriter();
+ IOUtils.copy(url.openStream(), xmlSourceWriter);
+ processSubmittedDoap(xmlSourceWriter.toString());
+ } catch (FileNotFoundException e) {
+ // Invalid URL
+ Session.get().error(invalidUrlMsg);
+ logger.warn("Error processing URL: " + invalidUrlMsg);
+ } catch (IOException e) {
setResponsePage(new ErrorReportPage(new UserReportableException(
- "Unable to add doap from form", DoapFormPage.class, e)));
+ "Unable to add doap using RDF supplied", DoapFormPage.class,
e)));
+ logger.warn("Error processing URL: " + url + "; " +
e.getMessage(), e);
}
}
}
+
+ @Override
+ protected void onSubmit() {
+ String invalidUrlMsg = "Invalid URL : " + inputModel.getSourceURL();
+ processAddByURLSubmit(inputModel.getSourceURL(), invalidUrlMsg);
+ }
}
- private static class AddByURLForm extends Form<DoapFormInputModel> {
- private static final long serialVersionUID = 4350446873545711199L;
-
- public AddByURLForm(String name) {
- super(name, new
CompoundPropertyModel<DoapFormInputModel>(inputModel));
- TextField<URL> urlField = new TextField<URL>("sourceURL", URL.class);
- add(urlField);
- String[] defaultValue = { "" };
- urlField.setModelValue(defaultValue);
+ /**
+ * Add a project to Simal based on the Unix name of the project. The form
+ * will fetch the DOAP from SourceForge based on the name entered by the
user.
+ * @param <T>
+ */
+ private class AddBySourceForgeURLForm<T extends DoapFormInputModel>
extends
+ AddByURLForm<DoapFormInputModel> {
+
+ private static final long serialVersionUID = 5717813288953568375L;
+ private static final String SF_URL_FORMAT
= "http://sourceforge.net/api/project/name/%s/doap";
+
+ /**
+ * @param name
+ */
+ public AddBySourceForgeURLForm(String name, IModel<DoapFormInputModel>
model) {
+ super(name, model);
+ RequiredTextField<String> stringTextField = new
RequiredTextField<String>(
+ "sourceForgeId");
+ stringTextField.setLabel(new Model<String>());
+ add(stringTextField);
}
@Override
protected void onSubmit() {
- super.onSubmit();
-
- if (!this.hasError()) {
- try {
-
UserApplication.getRepository().addProject(inputModel.getSourceURL(),
- inputModel.getSourceURL().getHost());
- setResponsePage(new UserHomePage());
- } catch (SimalRepositoryException e) {
- setResponsePage(new ErrorReportPage(new UserReportableException(
- "Unable to add doap from url", DoapFormPage.class, e)));
- }
+ try {
+ URL url = new URL(String.format(SF_URL_FORMAT, inputModel
+ .getSourceForgeId()));
+ String invalidUrlMsg = "Could not get DOAP from SourceForge for
the project named "
+ + inputModel.getSourceForgeId();
+ processAddByURLSubmit(url, invalidUrlMsg);
+ } catch (MalformedURLException e) {
+ // This should be unreachable since we're constructing this URL.
+ logger.error("Unexpected malformed URL: " + e.getMessage(), e);
+ setResponsePage(new ErrorReportPage(new UserReportableException(
+ "Unable to add doap using RDF supplied", DoapFormPage.class,
e)));
+ }
+ }
+ }
+
+ /**
+ * Generic method of processing a DOAP specification as a String. This
+ * will store a backup of the submitted DOAP and create a new project.
+ *
+ * @param doap
+ * @throws SimalException
+ */
+ private void processSubmittedDoap(String doap) {
+ try {
+ backupDoapFile(doap);
+ IProject newProject = SimalRepositoryFactory.getProjectService()
+ .createProject(RDFXMLUtils.convertXmlStringToDom(doap));
+ if (newProject != null) {
+ PageParameters newProjectPageParams = new PageParameters();
+ newProjectPageParams.add("simalID", newProject.getSimalID());
+ setResponsePage(ProjectDetailPage.class, newProjectPageParams);
+ } else {
+ throw new SimalException(
+ "Failed to created new project based on submitted DOAP.");
+ }
+ } catch (SimalException e) {
+ if (e.getCause().getClass() == IOException.class ||
+ e.getCause().getClass() == SAXParseException.class) {
+ logger.warn("No valid doap found, msg: " + e.getMessage() + ";
doap: " + doap, e);
+ Session.get().error("No valid DOAP file found at the provided
URL.");
+ } else {
+ logger.warn("Unable to create a project from the following doap: "
+ doap);
+ setResponsePage(new ErrorReportPage(new UserReportableException(
+ "Unable to add doap using RDF supplied", DoapFormPage.class,
e)));
}
}
}
- private Folder getUploadFolder() {
- if (uploadFolder == null) {
- uploadFolder = new Folder(System.getProperty("java.io.tmpdir"),
- "wicket-uploads");
- uploadFolder.mkdirs();
- }
- return uploadFolder;
- }
-}
+ /**
+ * Backup the doap string on the local file system.
+ * @param doap
+ * @throws SimalException If the backup failed.
+ */
+ private void backupDoapFile(String doap) throws SimalException {
+ String backupPath = SimalProperties
+ .getProperty(SimalProperties.PROPERTY_RDF_BACKUP_DIR);
+ String backupFileName = generateFileName(doap);
+ File backupFile = new File(backupPath, backupFileName);
+
+ try {
+ FileUtils.writeStringToFile(backupFile, doap, "UTF-8");
+ logger.debug("Written file to " + backupFile.getAbsolutePath());
+ } catch (IOException e) {
+ String msg = "Could not write file to " + backupFileName + "; "
+ + e.getMessage();
+ logger.warn(msg);
+ throw new SimalException(msg, e);
+ }
+ }
+
+ /**
+ * Generate a unique file name based on timestamp information and
+ * information in the xml.
+ * @param doapXml
+ * @return
+ */
+ private String generateFileName(String doapXml) {
+ String timestamp = new SimpleDateFormat("yyyyMMddHHmmss")
+ .format(new Date());
+
+ List<String> projectTags = new ArrayList<String>();
+ projectTags.add("shortname");
+ projectTags.add("doap:shortname");
+ projectTags.add("name");
+ projectTags.add("doap:name");
+
+ String projectName = findXmlContentByTagName(doapXml, projectTags);
+
+ return String.format(FILE_NAME_FORMAT, timestamp, projectName);
+ }
+
+ /**
+ * Iterates of the list tagNames for a tag that is present in the xml.
+ * If a match is found the content of this tag will be returned,
+ * otherwise null will be returned.
+ * @param xml
+ * @param tagNames
+ * @return
+ */
+ private static String findXmlContentByTagName(String xml, List<String>
tagNames) {
+ String xmlContent = null;
+
+ for(String tagName : tagNames) {
+ String startName = "<" + tagName + ">";
+ String endName = "</" + tagName + ">";
+ if (xml != null) {
+ int startNameIndex = xml.indexOf(startName);
+ int endNameIndex = xml.indexOf(endName);
+ if (startNameIndex != -1 && endNameIndex != -1) {
+ xmlContent = xml.substring(startNameIndex + startName.length(),
+ endNameIndex);
+ xmlContent = xmlContent.replaceAll(" ", "");
+ break;
+ }
+ }
+ }
+
+ return xmlContent;
+ }
+
+}
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/style/default.css
Sun Jun 21 01:21:46 2009
+++
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/style/default.css
Fri Aug 13 02:11:14 2010
@@ -91,6 +91,11 @@
font-size: 120%;
}
+.feedbackPanelERROR {
+ color: #F00;
+ list-style-type: none;
+}
+
h2 {
background: #8BBBFD;
color: black;
@@ -143,6 +148,13 @@
border-top: 1px solid #2C4AA0;
}
+label {
+ width: 200px;
+}
+
+.instruction {
+ font-style: italic;
+}
/****************
Header
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/TestBase.java
Sun Nov 22 17:22:33 2009
+++
/trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/TestBase.java
Fri Aug 13 02:11:14 2010
@@ -21,6 +21,7 @@
import java.util.Set;
import org.apache.wicket.util.tester.WicketTester;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,10 +36,11 @@
protected static final int NUMBER_OF_TEST_CATEGORIES = 55;
protected static final int NUMBER_OF_TEST_PROJECTS = 9;
protected static final int NUMBER_OF_TEST_PEOPLE = 22;
- protected static WicketTester tester;
protected static String projectURI;
protected static String developerURI;
+ protected WicketTester tester;
+
private static final Logger logger =
LoggerFactory.getLogger(TestBase.class);
@BeforeClass
@@ -52,9 +54,13 @@
IPerson developer =
SimalRepositoryFactory.getPersonService().findBySeeAlso("http://foo.org/~developer/#me");
developerURI = developer.getURI();
- tester = new WicketTester();
logProjectData("before");
}
+
+ @Before
+ public void setUp() {
+ tester = new WicketTester();
+ }
public static void logProjectData(String beforeOrAfter)
throws SimalRepositoryException {
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/doap/TestDoapFormPage.java
Sat Jan 9 14:00:05 2010
+++
/trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/doap/TestDoapFormPage.java
Fri Aug 13 02:11:14 2010
@@ -17,9 +17,7 @@
* under the License. *
*/
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.*;
import java.net.URISyntaxException;
import java.net.URL;
@@ -39,14 +37,17 @@
import uk.ac.osswatch.simal.rdf.io.RDFUtils;
import uk.ac.osswatch.simal.wicket.TestBase;
import uk.ac.osswatch.simal.wicket.UserApplication;
-import uk.ac.osswatch.simal.wicket.UserHomePage;
public class TestDoapFormPage extends TestBase {
+ private final static String INVALID_SF_PROJECT = "qqqq111qqqqq";
+ private final static String VALID_SF_PROJECT = "jena";
+ private final static String SF_FORM_ID = "addBySourceForgeIdForm";
+ private final static String SF_FIELD_ID = "sourceForgeId";
+
+
private final static String INVALID_URL = "this is not a valid URL";
private static final String DOAP_FORM_FILE = "doapFormFile.xml";
private static final String TEST_NAME = "Form Project";
- private static final String TEST_SHORT_DESC = "A project added by
filling in the DOAP form";
- private static final String TEST_DESCRIPTION = "The long description og
a project added by filling in the DOAP form";
private static final String TEST_RAW_RDF_URI = "simal:99999";
private static final String TEST_RAW_RDF_PROJECT_NAME = "Load From RAW
RDF Test";
private static final String TEST_RAW_RDF = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>"
@@ -156,12 +157,38 @@
// FIXME: since adding the URLConverter the onSubmit method does not
work. I
// (RG) think that this is because the URLConverter is not being
loaded.
- //int numProjectsBefore =
UserApplication.getRepository().getAllProjects().size();
+ // int numProjectsBefore =
UserApplication.getRepository().getAllProjects().size();
formTester.submit();
- //int numProjectsAfter =
UserApplication.getRepository().getAllProjects().size();
-
- // assertTrue("Loading data by URL does not appear to have added any
- // projects", numProjectsAfter > numProjectsBefore);
+ // int numProjectsAfter =
UserApplication.getRepository().getAllProjects().size();
+
+ // assertTrue("Loading data by URL does not appear to have added any
projects", numProjectsAfter > numProjectsBefore);
+ }
+
+ /**
+ * Test adding a project by a both a valid and invalid URL.
+ *
+ * @throws SimalRepositoryException
+ */
+ @Test
+ public void testAddProjectBySourceForgeURLForm() throws
SimalRepositoryException {
+ tester.assertVisible(SF_FORM_ID + ":" + SF_FIELD_ID);
+
+ FormTester formTester = tester.newFormTester(SF_FORM_ID);
+ formTester.setValue(SF_FIELD_ID, INVALID_SF_PROJECT);
+ formTester.submit();
+ tester.assertRenderedPage(DoapFormPage.class);
+ String[] errors = { "Could not get DOAP from SourceForge for the
project named " + INVALID_SF_PROJECT };
+ tester.assertErrorMessages(errors);
+
+ initTester();
+ formTester = tester.newFormTester(SF_FORM_ID);
+ formTester.setValue(SF_FIELD_ID, VALID_SF_PROJECT);
+
+ int numProjectsBefore =
UserApplication.getRepository().getAllProjects().size();
+ formTester.submit();
+ int numProjectsAfter =
UserApplication.getRepository().getAllProjects().size();
+
+ assertTrue("Loading data by URL does not appear to have added any
projects", numProjectsAfter > numProjectsBefore);
}
/**
@@ -177,29 +204,7 @@
tester.assertVisible("uploadForm:fileInput");
uploadFile();
- tester.assertRenderedPage(UserHomePage.class);
- }
-
- @Test
- public void testProjectForm() throws SimalRepositoryException {
- tester.assertVisible("doapForm");
- tester.assertVisible("doapForm:name");
- tester.assertVisible("doapForm:shortDesc");
- tester.assertVisible("doapForm:description");
- }
-
- @Test
- public void testProjectFormRequiredFields() throws
SimalRepositoryException {
- FormTester formTester = tester.newFormTester("doapForm");
-
- formTester.setValue("name", "");
- formTester.setValue("shortDesc", "");
- formTester.submit();
-
- tester.assertRenderedPage(DoapFormPage.class);
- String[] errors = { "Field 'name' is required.",
- "Field 'shortDesc' is required." };
- tester.assertErrorMessages(errors);
+ tester.assertRenderedPage(ProjectDetailPage.class);
}
@Test
@@ -208,7 +213,7 @@
formTester.setValue("rawRDF", TEST_RAW_RDF);
formTester.submit();
- tester.assertRenderedPage(UserHomePage.class);
+ tester.assertRenderedPage(ProjectDetailPage.class);
tester.assertNoErrorMessage();
Set<IProject> projects =
SimalRepositoryFactory.getProjectService().filterByName(TEST_RAW_RDF_PROJECT_NAME);
@@ -221,28 +226,6 @@
TEST_RAW_RDF_URI);
assertNull(project);
}
-
- @Test
- public void testAddProjectByForm() throws SimalRepositoryException {
- FormTester formTester = tester.newFormTester("doapForm");
-
- formTester = tester.newFormTester("doapForm");
- formTester.setValue("name", TEST_NAME);
- formTester.setValue("shortDesc", TEST_SHORT_DESC);
- formTester.setValue("description", TEST_DESCRIPTION);
- formTester.submit();
-
- tester.assertRenderedPage(UserHomePage.class);
- tester.assertNoErrorMessage();
-
- IProject project =
SimalRepositoryFactory.getProjectService().getProject(formInputURI);
- assertNotNull(project);
- assertEquals("Name is not correct", TEST_NAME, project.getName());
- assertEquals("Short descritpion is not correct", TEST_SHORT_DESC,
project
- .getShortDesc());
- assertEquals("Description is not correct", TEST_DESCRIPTION, project
- .getDescription());
- }
private void uploadFile() throws SimalRepositoryException,
URISyntaxException {
FormTester formTester = tester.newFormTester("uploadForm");
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/foaf/TestPersonDetailsPage.java
Sat Jul 4 17:30:16 2009
+++
/trunk/uk.ac.osswatch.simal.web/src/test/java/uk/ac/osswatch/simal/wicket/foaf/TestPersonDetailsPage.java
Fri Aug 13 02:11:14 2010
@@ -38,7 +38,6 @@
return new
PersonDetailPage(SimalRepositoryFactory.getPersonService().get(developerURI));
} catch (SimalRepositoryException e) {
System.err.println("Can't find the test project");
- System.exit(1);
return null;
}
}
--
You received this message because you are subscribed to the Google Groups "Simal
Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/simal-commits?hl=en.