com.remondis.limbus.system.MockLimbusSystem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of limbus-system Show documentation
Show all versions of limbus-system Show documentation
The Limbus System is a small light-weight CDI framework managing the Limbus Core Components.
The object graph is represented by an XML configuration file or can be build using the Limbus System API.
This module delivers an optional system component that visualizes the object graph and its dependencies after initializing: com.remondis.limbus.system.visualize.LimbusSystemVisualizer
This component can be added to the Limbus System. To keep the dependencies of this module transparent and light-weight, the graph renderer is declared as an optional dependency. Add the following dependencies to your project to use the visualisation component:
<!-- Graph Stream for Visualization feature This is an optional dependency and only required if using the com.remondis.limbus.system.visualize.LimbusSystemVisualizer -->
<dependency>
<groupId>org.graphstream</groupId>
<artifactId>gs-core</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.graphstream</groupId>
<artifactId>gs-ui</artifactId>
<version>1.3</version>
</dependency>
package com.remondis.limbus.system;
import java.io.InputStream;
import java.util.List;
import com.remondis.limbus.IInitializable;
import com.remondis.limbus.utils.Lang;
import com.remondis.limbus.utils.SerializeException;
/**
* This is a facade for {@link LimbusSystem} that should only be used in test environments to specify concrete instances
* for the components managed by the system.
*
* @author schuettec
*
*/
public class MockLimbusSystem implements IInitializable {
private LimbusSystem system;
private MockObjectFactory objectFactory;
public MockLimbusSystem() {
this.system = new LimbusSystem();
setupFields();
}
public MockLimbusSystem(InputStream limbusSystemXML) throws SerializeException {
Lang.denyNull("limbusSystemXML", limbusSystemXML);
this.system = LimbusSystem.deserializeConfiguration(limbusSystemXML);
setupFields();
}
private void setupFields() {
ObjectFactory delegate = system.getObjectFactory();
this.objectFactory = new MockObjectFactory(delegate);
system.setObjectFactory(this.objectFactory);
}
/**
* @return Returns the list of info records.
* @see com.remondis.limbus.system.LimbusSystem#getInfoRecords()
*/
public List getInfoRecords() {
return system.getInfoRecords();
}
/**
* Returns a component instance from this {@link MockLimbusSystem}.
*
* @param requestType
* The request type of the component
* @return Returns the component instance
* @see com.remondis.limbus.system.LimbusSystem#getComponent(java.lang.Class)
*/
public > T getComponent(Class requestType) {
return system.getComponent(requestType);
}
/**
* Checks if a Limbus component is available through this Limbus System.
*
* @param requestType
* The request type of the component.
* @return Returns true
if the component is available, false
otherwise.
*
*/
public > boolean hasComponent(Class requestType) {
return system.hasComponent(requestType);
}
/**
* @see com.remondis.limbus.system.LimbusSystem#logLimbusSystemInformation()
*/
public void logLimbusSystemInformation() {
system.logLimbusSystemInformation();
}
/**
* @return Returns the {@link LimbusSystem} prepared with configuration or mock instances.
*/
public LimbusSystem getLimbusSystem() {
return system;
}
/**
* Adds a private component configuration to this representation of {@link LimbusSystem}.
*
* @param componentType
* The component type of the private component.
* @param failOnError
* If true
this component causes the {@link LimbusSystem} to fail if the component fails to
* initialize. If false
the {@link LimbusSystem} performes a successful startup, even if this
* component fails to start.
* @return Returns this object for method chaining.
*/
public > MockLimbusSystem addComponentConfiguration(Class componentType,
boolean failOnError) {
system.addComponentConfiguration(componentType, failOnError);
return this;
}
/**
* Removes a private component configuration to this representation of {@link LimbusSystem}.
*
* @param componentType
* The component type of the private component.
* @return Returns this object for method chaining.
*/
public > MockLimbusSystem removePrivateComponentConfiguration(Class componentType) {
system.removePrivateComponentConfiguration(componentType);
return this;
}
/**
* Adds configuration for a required public component to this Limbus System.
*
*
* This component causes the {@link LimbusSystem} to fail it's startup if the component fails to initialize.
*
*
* @param requestType
* The component type, used for component requests.
* @param componentType
* The actual component implementation type.
* @return Returns this object for method chaining.
* @see com.remondis.limbus.system.LimbusSystem#addComponentConfiguration(java.lang.Class, java.lang.Class)
*/
public , I extends T> MockLimbusSystem addComponentConfiguration(Class requestType,
Class componentType) {
system.addComponentConfiguration(requestType, componentType);
return this;
}
/**
* Removes configuration for a required public component to this Limbus System.
*
*
* This component causes the {@link LimbusSystem} to fail it's startup if the component fails to initialize.
*
*
* @param requestType
* The component type, used for component requests.
* @return Returns this object for method chaining.
*/
public > MockLimbusSystem removePublicComponentConfiguration(Class requestType) {
system.removePublicComponentConfiguration(requestType);
return this;
}
/**
* Adds a private component with a mock instance.
*
* @param implementationType
* The implementation type of this component.
* @param instance
* The mock instance
* @param failOnError
* If true
this component causes the {@link LimbusSystem} to fail if the component fails to
* initialize. If false
the {@link LimbusSystem} performes a successful startup, even if this
* component fails to start.
* @return Returns this object for method chaining.
*/
public MockLimbusSystem addPrivateComponentMock(Class extends IInitializable>> implementationType,
IInitializable> instance, boolean failOnError) {
objectFactory.putPrivateComponent(implementationType, instance);
system.addComponentConfiguration(implementationType, failOnError);
return this;
}
/**
* Removes a private component with a mock instance.
*
* @param implementationType
* The implementation type of this component.
* @return Returns this object for method chaining.
*/
public MockLimbusSystem removePrivateComponentMock(Class extends IInitializable>> implementationType) {
objectFactory.removePrivateComponent(implementationType);
system.removePrivateComponentConfiguration(implementationType);
return this;
}
/**
* Adds a public required component with the specified mock instance.
*
* @param requestType
* The request type of the public component.
* @param instance
* The mock instance of this component.
* @return Returns this object for method chaining.
*/
@SuppressWarnings("unchecked")
public , I extends T> MockLimbusSystem addPublicComponentMock(Class requestType,
I instance) {
objectFactory.putPublicComponent(requestType, instance);
system.addComponentConfiguration(requestType, (Class) instance.getClass());
return this;
}
/**
* Removes a public required component with the specified mock instance.
*
* @param requestType
* The request type of the public component.
* @return Returns this object for method chaining.
*/
public > MockLimbusSystem removePublicComponentMock(Class requestType) {
objectFactory.removePublicComponent(requestType);
system.removePublicComponentConfiguration(requestType);
return this;
}
@Override
public void initialize() throws Exception {
system.initialize();
}
@Override
public void finish() {
system.finish();
}
}