public abstract class AbstractCRUDTestController extends Object
Testing harness for junit tests that need to stand an in-memory instance of
lightblue. The assumption is made that one LightblueFactory will be
used per test suite.
For initialization code that needs to be executed prior to the
AbstractCRUDTestController(), use the @BeforeClass
annotation.
NOTE: This does not use the rest layer.
Example Usage:
Response response = lightblueFactory.getMediator().insert(
createRequest_FromResource(InsertionRequest.class, "./path/to/insert/metadata.json"));
| Modifier and Type | Field and Description |
|---|---|
static String |
REMOVE_ALL_HOOKS |
| Constructor and Description |
|---|
AbstractCRUDTestController()
Defaults to statically loading lightblue.
|
AbstractCRUDTestController(boolean loadStatically)
Creates an instance of the
LightblueFactory. |
| Modifier and Type | Method and Description |
|---|---|
static void |
cleanup() |
protected static <T extends Request> |
createRequest_FromJsonString(Class<T> type,
String jsonString)
Creates and returns a
Request based on the passed in
jsonString. |
protected static <T extends Request> |
createRequest_FromResource(Class<T> type,
String jsonFile)
Creates and returns a
Request based on the passed in
jsonFile. |
protected static <T extends Request> |
createRequest(Class<T> type,
com.fasterxml.jackson.databind.JsonNode node)
Creates and returns a
Request based on the passed in
JsonNode |
static void |
ensureDatasource(com.fasterxml.jackson.databind.JsonNode node,
String datasource) |
protected String |
getDatasource()
Override to set the datasource values for all metadata to the returned
value of this method.
|
protected abstract com.fasterxml.jackson.databind.JsonNode |
getDatasourcesJson()
Creates and returns an instance of
JsonNode that represents the
relevant lightblue-datasources.json. |
Set<String> |
getHooksToRemove() |
protected com.fasterxml.jackson.databind.JsonNode |
getLightblueCrudJson()
Creates and returns an instance of
JsonNode that represents the
relevant lightblue-crud.json. |
protected static LightblueFactory |
getLightblueFactory() |
protected com.fasterxml.jackson.databind.JsonNode |
getLightblueMetadataJson()
Creates and returns an instance of
JsonNode that represents the
relevant lightblue-metadata.json. |
protected abstract com.fasterxml.jackson.databind.JsonNode[] |
getMetadataJsonNodes()
Create and returns an array of
JsonNodes from which to load the
LightblueFactory with. |
static void |
grantAnyoneAccess(com.fasterxml.jackson.databind.JsonNode node)
Deep dives to set all access levels to 'anyone'.
|
boolean |
isGrantAnyoneAccess() |
static void |
stripHooks(com.fasterxml.jackson.databind.JsonNode node,
Set<String> hooksToRemove)
Strips out the specified hooks.
|
public static final String REMOVE_ALL_HOOKS
public AbstractCRUDTestController()
throws Exception
Exceptionpublic AbstractCRUDTestController(boolean loadStatically)
throws Exception
LightblueFactory.loadStatically - - true loads lightblue statically for the duration of the suite,
otherwise false will load lightblue for each test.IOExceptionClassNotFoundExceptionNoSuchMethodExceptionIllegalAccessExceptionInvocationTargetExceptionInstantiationExceptionExceptionpublic static void cleanup()
protected static LightblueFactory getLightblueFactory()
public static void grantAnyoneAccess(com.fasterxml.jackson.databind.JsonNode node)
node - - root JsonNodeprotected com.fasterxml.jackson.databind.JsonNode getLightblueCrudJson()
throws Exception
JsonNode that represents the
relevant lightblue-crud.json. If not set by a subclass, then the default settings will be used.JsonNode to use when configuring the lightblue crud controllers, or null to use
the default LightblueFactory setting.Exceptionprotected com.fasterxml.jackson.databind.JsonNode getLightblueMetadataJson()
throws Exception
JsonNode that represents the
relevant lightblue-metadata.json. If not set by a subclass, then the default settings will be used.JsonNode to use when configuring the lightblue metadata, or null to use
the default LightblueFactory setting.Exceptionprotected abstract com.fasterxml.jackson.databind.JsonNode getDatasourcesJson()
throws Exception
JsonNode that represents the
relevant lightblue-datasources.json.Exceptionprotected abstract com.fasterxml.jackson.databind.JsonNode[] getMetadataJsonNodes()
throws Exception
JsonNodes from which to load the
LightblueFactory with. These EntityMetadata instances
will be available to all tests in the suite.JsonNodes from which to load the
LightblueFactory with.Exceptionpublic static void ensureDatasource(com.fasterxml.jackson.databind.JsonNode node,
String datasource)
protected String getDatasource()
null will be returned
disabling this feature.public static void stripHooks(com.fasterxml.jackson.databind.JsonNode node,
Set<String> hooksToRemove)
REMOVE_ALL_HOOKS
to remove all the hooks on the node.node - - root JsonNodehooksToRemove - - Set of hook names to remove from entityInfo.public Set<String> getHooksToRemove()
Set of hook names to remove. By default returns
REMOVE_ALL_HOOKS, which will remove all hooks.public boolean isGrantAnyoneAccess()
true if access settings on metadata should be altered to
'anyone', otherwise false. Defaults to true.protected static <T extends Request> T createRequest_FromResource(Class<T> type, String jsonFile) throws IOException
Request based on the passed in
jsonFile.type - - Request class to instantiate.jsonFile - - File containing metadata jsonRequest based on the passed in jsonFile.IOExceptionprotected static <T extends Request> T createRequest_FromJsonString(Class<T> type, String jsonString) throws IOException
Request based on the passed in
jsonString.type - - Request class to instantiate.jsonString - - String of metadata jsonRequest based on the passed in jsonString.IOExceptionprotected static <T extends Request> T createRequest(Class<T> type, com.fasterxml.jackson.databind.JsonNode node)
Request based on the passed in
JsonNodetype - - Request class to instantiate.node - - JsonNode of actions metadataRequest based on the passed in JsonNodeCopyright © 2015. All rights reserved.