[New] added a container mock which creates the required directory struct
This commit is contained in:
parent
9de31a136e
commit
a6fe2dce67
4
pom.xml
4
pom.xml
|
@ -34,6 +34,10 @@
|
||||||
<groupId>li.strolch</groupId>
|
<groupId>li.strolch</groupId>
|
||||||
<artifactId>li.strolch.model</artifactId>
|
<artifactId>li.strolch.model</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>li.strolch</groupId>
|
||||||
|
<artifactId>li.strolch.runtime</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package li.strolch.testbase.runtime;
|
||||||
|
|
||||||
|
import li.strolch.runtime.component.StrolchComponent;
|
||||||
|
import li.strolch.runtime.configuration.StrolchConfiguration;
|
||||||
|
|
||||||
|
public interface ComponentMock {
|
||||||
|
|
||||||
|
public StrolchComponent getComponent();
|
||||||
|
|
||||||
|
public void mock(StrolchConfiguration configuration);
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
package li.strolch.testbase.runtime;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
import li.strolch.runtime.configuration.RuntimeConfiguration;
|
||||||
|
import ch.eitchnet.utils.helper.FileHelper;
|
||||||
|
|
||||||
|
public class RuntimeMock {
|
||||||
|
|
||||||
|
private static final String TARGET = "target"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
public static void mockRuntime(File rootPathF, File configSrc) {
|
||||||
|
|
||||||
|
if (!rootPathF.getParentFile().getName().equals(TARGET)) {
|
||||||
|
String msg = "Mocking path must be in a maven target: {0}"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, rootPathF.getAbsolutePath());
|
||||||
|
throw new RuntimeException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!configSrc.isDirectory() || !configSrc.canRead()) {
|
||||||
|
String msg = "Could not find config source in: {0}"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, configSrc.getAbsolutePath());
|
||||||
|
throw new RuntimeException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootPathF.exists()) {
|
||||||
|
if (!FileHelper.deleteFile(rootPathF, true)) {
|
||||||
|
String msg = "Failed to delete {0}"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, rootPathF.getAbsolutePath());
|
||||||
|
throw new RuntimeException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rootPathF.mkdirs()) {
|
||||||
|
String msg = "Failed to create {0}"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, rootPathF.getAbsolutePath());
|
||||||
|
throw new RuntimeException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
File configPathF = new File(rootPathF, RuntimeConfiguration.PATH_CONFIG);
|
||||||
|
configPathF.mkdir();
|
||||||
|
|
||||||
|
if (!FileHelper.copy(configSrc.listFiles(), configPathF, false)) {
|
||||||
|
String msg = "Failed to copy source configs from {0} to {1}"; //$NON-NLS-1$
|
||||||
|
msg = MessageFormat.format(msg, configSrc.getAbsolutePath(), configPathF.getAbsolutePath());
|
||||||
|
throw new RuntimeException(msg);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// // initialize a runtime configuration
|
||||||
|
// Map<String, String> runtimeConfigurationValues = new HashMap<>();
|
||||||
|
// RuntimeConfiguration runtimeConfiguration = new RuntimeConfiguration("RuntimeMock", runtimeConfigurationValues, //$NON-NLS-1$
|
||||||
|
// rootPathF);
|
||||||
|
//
|
||||||
|
// Map<String, ComponentConfiguration> configurationByComponent = new HashMap<>();
|
||||||
|
// StrolchConfiguration configuration = new StrolchConfiguration(runtimeConfiguration, configurationByComponent);
|
||||||
|
//
|
||||||
|
// // initialize the component configuration
|
||||||
|
// for (ComponentMock componentMock : runtimeMocks) {
|
||||||
|
// //configurationByComponent.put(key, value)
|
||||||
|
// componentMock.mock(configuration);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue