Site Service CRUD API's (Java, JavaScript and REST), unit test methods added to JS API to help unit test JS API's

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8986 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2008-05-01 16:48:30 +00:00
parent c5733ca5ae
commit 5194966123
8 changed files with 440 additions and 72 deletions

View File

@@ -67,7 +67,7 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
public Site createSite(String sitePreset, String shortName, String title, String descripion, boolean isPublic)
{
SiteInfo siteInfo = this.siteService.createSite(sitePreset, shortName, title, descripion, isPublic);
return new Site(siteInfo);
return new Site(this.siteService, siteInfo);
}
/**
@@ -86,8 +86,27 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
List<Site> sites = new ArrayList<Site>(siteInfos.size());
for (SiteInfo siteInfo : siteInfos)
{
sites.add(new Site(siteInfo));
sites.add(new Site(this.siteService, siteInfo));
}
return sites;
}
/**
* Get a site for a provided site short name.
* <p>
* Returns null if the site does not exist.
*
* @param shortName short name of the site
* @return Site the site, null if does not exist
*/
public Site getSite(String shortName)
{
Site site = null;
SiteInfo siteInfo = this.siteService.getSite(shortName);
if (siteInfo != null)
{
site = new Site(this.siteService, siteInfo);
}
return site;
}
}

View File

@@ -27,6 +27,7 @@ package org.alfresco.repo.site.script;
import java.io.Serializable;
import org.alfresco.repo.site.SiteInfo;
import org.alfresco.repo.site.SiteService;
/**
* @author Roy Wetherall
@@ -34,42 +35,133 @@ import org.alfresco.repo.site.SiteInfo;
public class Site implements Serializable
{
private static final long serialVersionUID = 8013569574120957923L;
/** Site information */
private SiteInfo siteInfo;
public Site(SiteInfo siteInfo)
/** Site service */
private SiteService siteService;
/** Indicates whether there are any outstanding changes that need to be saved */
private boolean isDirty = false;
/**
* Constructor
*
* @param siteInfo site information
*/
/*package*/ Site(SiteService siteService, SiteInfo siteInfo)
{
this.siteService = siteService;
this.siteInfo = siteInfo;
}
/**
* Get the site preset
*
* @return String the site preset
*/
public String getSitePreset()
{
return this.siteInfo.getSitePreset();
}
/**
* Set the short name
*
* @return String the short name
*/
public String getShortName()
{
return this.siteInfo.getShortName();
}
/**
* Get the title
*
* @return String the site title
*/
public String getTitle()
{
return this.siteInfo.getTitle();
}
// TODO set title
/**
* Set the title
*
* @param title the title
*/
public void setTitle(String title)
{
this.isDirty = true;
this.siteInfo.setTitle(title);
}
/**
* Get the description
*
* @return String the description
*/
public String getDescription()
{
return this.siteInfo.getDescription();
}
// TODO set description
/**
* Set the description
*
* @param description the description
*/
public void setDescription(String description)
{
this.isDirty = true;
this.siteInfo.setDescription(description);
}
/**
* Gets whether the site is public or not
*
* @return true is public false otherwise
*/
public boolean getIsPublic()
{
return this.siteInfo.getIsPublic();
}
// TODO set isPublic
/**
* Set whether the site is public or not
*
* @param isPublic true the site is public false otherwise
*/
public void setIsPublic(boolean isPublic)
{
this.isDirty = true;
this.siteInfo.setIsPublic(isPublic);
}
/**
* Saves any outstanding updates to the site details.
* <p>
* If properties of the site are changed and save is not called, those changes will be lost.
*/
public void save()
{
if (this.isDirty == true)
{
// Update the site details
this.siteService.updateSite(this.siteInfo);
// Reset the dirty flag
this.isDirty = false;
}
}
/**
* Deletes the site
*/
public void deleteSite()
{
// Delete the site
this.siteService.deleteSite(this.siteInfo.getShortName());
}
}

View File

@@ -1,29 +1,47 @@
var failure = "";
// Try and create a site
var site = siteService.createSite("sitePreset", "siteShortName", "siteTitle", "siteDescription", true);
// Check that the site details are correct
if (site.sitePreset != "sitePreset")
function checkSite(site, sitePreset, shortName, title, description, isPublic)
{
failure += "\nSite preset is not set on created site";
}
if (site.shortName != "siteShortName")
{
failure += "\nSite short name is not set on created site";
}
if (site.title != "siteTitle")
{
failure += "\nSite title is not set on created site";
}
if (site.description != "siteDescription")
{
failure += "\nSite description is not set on created site";
}
if (site.isPublic != true)
{
failure += "\nCreated site should be marked public";
test.assertNotNull(site, "Site should not be null");
test.assertEquals(sitePreset, site.sitePreset, "Site preset incorrect for site " + shortName);
test.assertEquals(shortName, site.shortName, "Site shortname incorrect");
test.assertEquals(title, site.title, "Site title incorrect for site " + shortName);
test.assertEquals(description, site.description, "Site description incorrect for site " + shortName);
test.assertEquals(isPublic, site.isPublic, "Site ispublic incorrect for site " + shortName);
}
// Return the failure message
failure;
function testCRUD()
{
// Try and get a site that doesn't exist
var site = siteService.getSite("siteShortName");
test.assertNull(site, "Site should not have been found.");
// Try and create a site
site = siteService.createSite("sitePreset", "siteShortName", "siteTitle", "siteDescription", true);
checkSite(site, "sitePreset", "siteShortName", "siteTitle", "siteDescription", true);
// Try and get the created site
site = siteService.getSite("siteShortName");
checkSite(site, "sitePreset", "siteShortName", "siteTitle", "siteDescription", true);
// Try and update the values of the site
site.title = "abc123abc";
site.description = "abc123abc";
site.isPublic = false;
checkSite(site, "sitePreset", "siteShortName", "abc123abc", "abc123abc", false);
site.save();
site = siteService.getSite("siteShortName");
checkSite(site, "sitePreset", "siteShortName", "abc123abc", "abc123abc", false);
// Delete the site
site.deleteSite();
site = siteService.getSite("siteShortName");
test.assertNull(site, "");
}
function testListSites()
{
// TODO
}
// Execute test's
testCRUD();
testListSites();