Skip to content

Commit

Permalink
SAK-41080 Add tests for HelpManagerImpl (sakaiproject#6389)
Browse files Browse the repository at this point in the history
* SAK-41080 Add tests for HelpManagerImpl

This involved creating testings and removing unused code in the HelpManager API. Also unused files (hibernate) were removed and SizedList was also removed. The Sakai component configuration was split out into multiple files to make it easier to test.
  • Loading branch information
buckett authored Jan 7, 2019
1 parent 7741f00 commit 5c18b18
Show file tree
Hide file tree
Showing 20 changed files with 477 additions and 844 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

package org.sakaiproject.api.app.help;

import org.sakaiproject.component.api.ServerConfigurationService;

import java.util.Comparator;
import java.util.Set;

/**
Expand All @@ -29,6 +32,20 @@
*/
public interface Category
{


/**
* get id
* @return Returns the id.
*/
public Long getId();

/**
* set id
* @param id The id to set.
*/
public void setId(Long id);

/**
* get name
* @return name
Expand Down Expand Up @@ -76,7 +93,22 @@ public interface Category
* @param cat
*/
public void setParent(Category cat);


/**
* Get Comparator for sorting Categories.
* @param serverConfigurationService The server configuration service.
* @return A suitable comparator.
*/
static Comparator<Category> comparator(ServerConfigurationService serverConfigurationService) {
// This is a static method in the API so that you can inject the ServerConfigurationService in a test
// setup rather then have the whole Sakai Component Manager started up. It needs to be here as it's used in
// both the component and the tool
if (!"".equals(serverConfigurationService.getString("help.location"))) {
return Comparator.comparing(Category::getId);
} else {
return Comparator.comparing(Category::getName);
}
}
}


149 changes: 16 additions & 133 deletions help/help-api/src/java/org/sakaiproject/api/app/help/HelpManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,220 +21,103 @@

package org.sakaiproject.api.app.help;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.sakaiproject.component.api.ServerConfigurationService;

/**
* Help Manager for the Sakai Help Tool.
* @version $Id$
*/
public interface HelpManager
{
public static final String TOOLCONFIG_HELP_COLLECTIONS = "help.collections";
String TOOLCONFIG_HELP_COLLECTIONS = "help.collections";

public static final String HELP_DOC_REGEXP = "^[A-Za-z0-9._-]+$";
String HELP_DOC_REGEXP = "^[A-Za-z0-9._-]+$";

/**
* Synchronize initialization of the manager.
*/
public void initialize();
void initialize();

/**
* reInitialization of the help tool.
*/
public void reInitialize();

/**
* Create Category
* @return Category
*/
public Category createCategory();

/**
* Store Category
* @param category
*/
public void storeCategory(Category category);

/**
* find all contexts associated with mappedView
* @param mappedView
* @return - list of contexts (String)
*/
public List<String> getContexts(String mappedView);

/**
* returns a list of all active contexts. Active contexts
* are created when the user navigates around the site.
* @param session
* @return
*/
public List getActiveContexts(Map session);

/**
* adds a context to the active context list
* @param session
* @param mappedView
*/
public void addContexts(Map session, String mappedView);

/**
* get Resources for a context
* @param context
* @return set of resources associated with the supplied context
*/
public Set<Resource> getResources(Long context);
void reInitialize();

/**
* get a resource by id
* @param id
* @return
*/
public Resource getResource(Long id);
Resource getResource(Long id);

/**
* create a resource
* @return Resource
*/
public Resource createResource();
Resource createResource();

/**
* persist a resource
* @param resource
*/
public void storeResource(Resource resource);
void storeResource(Resource resource);

/**
* delete a resource by id
* @param resourceId
*/
public void deleteResource(Long resourceId);

/**
* get source
* @param id
* @return Source
*/
public Source getSource(Long id);

/**
* store source
* @param source
*/
public void storeSource(Source source);

/**
* delete source by id
* @param sourceId
*/
public void deleteSource(Long sourceId);

/**
* get context by id
* @param id
* @return Context
*/
public Context getContext(Long id);

/**
* store context
* @param context
*/
public void storeContext(Context context);

/**
* delete context by id
* @param contextId
*/
public void deleteContext(Long contextId);

/**
*
* @param session
* @return map of resources keyed by active contexts
*/
public Map<String, Set<Resource>> getResourcesForActiveContexts(Map session);
void deleteResource(Long resourceId);

/**
*
* @param query
* @return set of resources found by searching with the supplied query.
* @throws RuntimeException - if query can't be parsed
*/
public Set<Resource> searchResources(String query) throws RuntimeException;
Set<Resource> searchResources(String query) throws RuntimeException;

/**
* get table of contents of manager
* @return TableOfContents
*/
public TableOfContents getTableOfContents();
TableOfContents getTableOfContents();

/**
* set table of contents
* @param toc
*/
public void setTableOfContents(TableOfContents toc);

/**
* searches the glossary for the keyword.
* Returns a GlossaryEntry for this keyword if found,
* return null if no entry is found.
* @param keyword
* @return
*/
public GlossaryEntry searchGlossary(String keyword);

/**
* get glossary
* @return Glossary
*/
public Glossary getGlossary();
void setTableOfContents(TableOfContents toc);

/**
* get resource by doc id
* @param helpDocIdString
* @return Resource
*/
public Resource getResourceByDocId(String helpDocIdString);
Resource getResourceByDocId(String helpDocIdString);

/**
* get support email address
* @return address as string
*/
public String getSupportEmailAddress();
String getSupportEmailAddress();

/**
* get REST configuration
* @return REST configuration
*/
public RestConfiguration getRestConfiguration();
RestConfiguration getRestConfiguration();

/**
* get static EXTERNAL_LOCATION
* @return EXTERNAL_LOCATION
*/
public String getExternalLocation();

/**
* get server config service
* @return
*/
public ServerConfigurationService getServerConfigurationService();

/**
* set server config service
* @param s
*/
public void setServerConfigurationService(ServerConfigurationService s);
String getExternalLocation();

/**
* get Welcome Page
* @return docId of Welcome Page
*/
public String getWelcomePage();
String getWelcomePage();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@

import org.sakaiproject.api.app.help.Category;
import org.sakaiproject.api.app.help.Resource;
import org.sakaiproject.component.cover.ServerConfigurationService;

/**
* category bean
* @version $Id$
*/
public class CategoryBean implements Category, Comparable<CategoryBean>
public class CategoryBean implements Category
{
private Long id;
private String name;
Expand Down Expand Up @@ -136,16 +135,6 @@ public int hashCode()
return name.hashCode();
}

public int compareTo(CategoryBean cb)
{;

if (!"".equals(ServerConfigurationService.getString("help.location"))){
return id.compareTo(cb.id);
}
else{
return name.compareTo(cb.name);
}
}
}


This file was deleted.

Loading

0 comments on commit 5c18b18

Please sign in to comment.