org.mmbase.bridge.mock
Class MockCloudContext

java.lang.Object
  extended by org.mmbase.bridge.util.AbstractCloudContext
      extended by org.mmbase.bridge.mock.MockCloudContext
All Implemented Interfaces:
CloudContext

public class MockCloudContext
extends AbstractCloudContext

The 'mock' cloud context is mainly meant for usage in junit test cases. It provides a functional bridge implementation, without the backing of the MMBase core classes. This means on one hand that it takes much less time to initialize, on the other hand that all data created is only availabe in memory and is in no way persistent. Also, at the moment, it is only partially working. You will easily encounter many UnsupportedOperationExceptions and other kind of errors. For several simple tests it is however useful already. The object model must be manually set up using the several addNodeManager methods. The 'core' model is created with addCore(). Current implementation will basicly allow all 'related' and 'posrel' relations, but this part has still to be elaborated on. This may change in future versions of this.

Since:
MMBase-1.9.2
Version:
$Id: MockCloudContext.java 42917 2010-07-15 17:01:52Z michiel $
Author:
Michiel Meeuwissen

Nested Class Summary
static class MockCloudContext.AllowedRelation
           
static class MockCloudContext.MockResolver
           
static class MockCloudContext.NodeDescription
          Simple structure to contain the data of an MMBase node in memory.
static class MockCloudContext.Role
           
 
Field Summary
(package private)  Map<String,MockCloudContext.AllowedRelation> allowed
           
 Map<String,NodeManagerDescription> nodeManagers
           
(package private)  Map<Integer,MockCloudContext.NodeDescription> nodes
           
(package private)  Map<String,MockCloudContext.Role> roles
           
 
Fields inherited from class org.mmbase.bridge.util.AbstractCloudContext
clouds
 
Constructor Summary
MockCloudContext()
           
 
Method Summary
protected  void addAllowedRelation(String r, String source, String dest)
           
 void addCore()
          Adds the 'core' builders to the object model.
 void addCoreModel()
           
(package private)  int addNode(MockCloudContext.NodeDescription nd)
           
 int addNode(String type, Map<String,Object> map)
           
 void addNodeManager(InputSource source)
           
protected  void addNodeManager(MockBuilderReader reader)
           
 void addNodeManager(String name, Map<String,DataType> map)
           
 void addNodeManagers(ResourceLoader directory)
           
protected  void addRole(String r, String builder)
           
 void clear()
           
 Cloud getCloud(String name, UserContext user)
          Returns the cloud with the specified name, based on an existing User object.
static MockCloudContext getInstance()
          Returns 'the' MockCloudContext.
(package private)  String getNodeManagerForRole(String r)
           
 Map<Integer,MockCloudContext.NodeDescription> getNodes()
           
protected  int getRelDefNode(String name, String nodeManager)
           
(package private)  String getRole(int rnumber)
           
 SearchQueryHandler getSearchQueryHandler()
           
protected  int getTypeDefNode(String name)
           
protected  int getTypeRelNode(int snumber, int dnumber, int rnumber)
           
 String getUri()
          The String which was usesd, and could be used again to acquire this cloud context using ContextProvider.getCloudContext(String).
(package private)  void setNodeType(int node, String type)
           
 String toString()
           
 
Methods inherited from class org.mmbase.bridge.util.AbstractCloudContext
assertUp, createFieldList, createModuleList, createNodeList, createNodeManagerList, createRelationList, createRelationManagerList, createStringList, getActionRepository, getAuthentication, getCloud, getCloud, getCloudNames, getDefaultCharacterEncoding, getDefaultCloudName, getDefaultLocale, getDefaultTimeZone, getModule, getModules, hasModule, isUp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nodes

final Map<Integer,MockCloudContext.NodeDescription> nodes

nodeManagers

public final Map<String,NodeManagerDescription> nodeManagers

roles

final Map<String,MockCloudContext.Role> roles

allowed

final Map<String,MockCloudContext.AllowedRelation> allowed
Constructor Detail

MockCloudContext

public MockCloudContext()
Method Detail

getInstance

public static MockCloudContext getInstance()
Returns 'the' MockCloudContext. If you prefer a completely fresh copy, the constructor is public too.


getNodes

public Map<Integer,MockCloudContext.NodeDescription> getNodes()

clear

public void clear()

addCore

public void addCore()
             throws IOException
Adds the 'core' builders to the object model. It may also add a core relation model. Like 'related' and 'posrel' roles.

Throws:
IOException

getTypeDefNode

protected int getTypeDefNode(String name)

getRelDefNode

protected int getRelDefNode(String name,
                            String nodeManager)

getTypeRelNode

protected int getTypeRelNode(int snumber,
                             int dnumber,
                             int rnumber)

getNodeManagerForRole

String getNodeManagerForRole(String r)

getRole

String getRole(int rnumber)

addRole

protected void addRole(String r,
                       String builder)

addAllowedRelation

protected void addAllowedRelation(String r,
                                  String source,
                                  String dest)

addCoreModel

public void addCoreModel()

addNodeManager

public void addNodeManager(String name,
                           Map<String,DataType> map)

addNodeManager

public void addNodeManager(InputSource source)

addNodeManager

protected void addNodeManager(MockBuilderReader reader)

addNodeManagers

public void addNodeManagers(ResourceLoader directory)
                     throws IOException
Throws:
IOException

addNode

public int addNode(String type,
                   Map<String,Object> map)

addNode

int addNode(MockCloudContext.NodeDescription nd)

setNodeType

void setNodeType(int node,
                 String type)

getCloud

public Cloud getCloud(String name,
                      UserContext user)
               throws NotFoundException
Description copied from interface: CloudContext
Returns the cloud with the specified name, based on an existing User object. This user object may originate from a call to Cloud.getUser() or directly from Authentication.login(java.lang.String, java.util.Map, java.lang.Object[])). The security implementation may depend on implementation details of this UserContext.

Parameters:
name - The name of the cloud to be returned. See CloudContext.getCloudNames().
user - The user object for which this cloud object must be created. Many security implementation require this object to be created by themselves.
Returns:
the requested cloud
Throws:
NotFoundException - thrown when cloud not found

getUri

public String getUri()
Description copied from interface: CloudContext
The String which was usesd, and could be used again to acquire this cloud context using ContextProvider.getCloudContext(String).


toString

public String toString()
Overrides:
toString in class Object

getSearchQueryHandler

public SearchQueryHandler getSearchQueryHandler()


MMBase 2.0-SNAPSHOT - null