Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Make Repository Manager manageble by IoC #198

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public static void tearDownClass() {

@Before
public void setUp() {
MockMvcBuilders.webAppContextSetup(this.wac).build();
WPSConfig.getInstance().setConfigurationManager(this.wac.getBean(ConfigurationManager.class));
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ public class ServiceLoaderAlgorithmRepository implements IAlgorithmRepository {
public ServiceLoaderAlgorithmRepository() {
this.currentAlgorithms = loadAlgorithms();
}

private Map<String, Class<? extends IAlgorithm>> loadAlgorithms() {
Map<String, Class<? extends IAlgorithm>> result = new HashMap<String, Class<? extends IAlgorithm>>();
ServiceLoader<IAlgorithm> loader = ServiceLoader.load(IAlgorithm.class);

for (IAlgorithm ia : loader) {
logger.debug("Adding algorithm with identifier {} and class {}",
ia.getWellKnownName(), ia.getClass().getCanonicalName());
result.put(ia.getWellKnownName(), ia.getClass());
}

return result;
}

@Override
public Collection<String> getAlgorithmNames() {
return this.currentAlgorithms.keySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@
* @author tkunicki
*/
public class AbstractSelfDescribingAlgorithmTest extends AbstractITClass {

public AbstractSelfDescribingAlgorithmTest() {
}

@Before
public void setUp() throws Exception {
MockMvcBuilders.webAppContextSetup(this.wac).build();
WPSConfig.getInstance().setConfigurationManager(this.wac.getBean(ConfigurationManager.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,26 @@

public class ExecuteRequestBuilderTest extends AbstractITClass{

private ProcessDescription processDescription;
private ProcessDescriptionType processDescriptionType;
private ProcessDescription processDescription;
private ProcessDescriptionType processDescriptionType;
private String inputID;
private String outputID;
private String url = "http://xyz.test.data";
private String complexDataString = "testString";

@Before
public void setUp(){
MockMvcBuilders.webAppContextSetup(this.wac).build();
WPSConfig.getInstance().setConfigurationManager(this.wac.getBean(ConfigurationManager.class));
processDescription = new MultiReferenceBinaryInputAlgorithm().getDescription();
processDescriptionType = ((ProcessDescriptionType)processDescription.getProcessDescriptionType(WPSConfig.VERSION_100));
processDescriptionType = ((ProcessDescriptionType)processDescription.getProcessDescriptionType(WPSConfig.VERSION_100));
inputID = processDescriptionType.getDataInputs().getInputArray(0).getIdentifier().getStringValue();
outputID = processDescriptionType.getProcessOutputs().getOutputArray(0).getIdentifier().getStringValue();
}

@Test
public void addComplexDataInputByReference() {

ExecuteRequestBuilder executeRequestBuilder = new ExecuteRequestBuilder(processDescriptionType);

addTestDataByReference(executeRequestBuilder);

ExecuteDocument request = executeRequestBuilder.getExecute();
Expand All @@ -90,151 +88,151 @@ public void addComplexDataInputByReference() {
Assert.assertThat("generated doc contains input url", request.toString(), containsString(url));
Assert.assertThat("document is valid", request.validate(), is(true));
}

@Test
public void addComplexDataInputString() {

ExecuteRequestBuilder executeRequestBuilder = new ExecuteRequestBuilder(processDescriptionType);

addTestDataString(executeRequestBuilder);

ExecuteDocument request = executeRequestBuilder.getExecute();

Assert.assertThat("generated doc contains input id", request.toString(), containsString(inputID));
Assert.assertThat("generated doc contains input string", request.toString(), containsString(complexDataString));
Assert.assertThat("document is valid", request.validate(), is(true));
}

@Test
public void setSupportedMimeTypeForOutput(){
ExecuteRequestBuilder executeRequestBuilder = new ExecuteRequestBuilder(processDescriptionType);

addTestDataByReference(executeRequestBuilder);

String mimeType = getMimeType(processDescriptionType, false);

executeRequestBuilder.setMimeTypeForOutput(mimeType, outputID);

ExecuteDocument request = executeRequestBuilder.getExecute();

checkOutputIdentifier(request.getExecute(), outputID);
checkOutputMimeType(request.getExecute(), mimeType);
Assert.assertThat("document is valid", request.validate(), is(true));

}

@Test
public void setDefaultMimeTypeForOutput(){
ExecuteRequestBuilder executeRequestBuilder = new ExecuteRequestBuilder(processDescriptionType);

addTestDataByReference(executeRequestBuilder);

String mimeType = getMimeType(processDescriptionType, true);

ExecuteDocument request = executeRequestBuilder.getExecute();

executeRequestBuilder.setMimeTypeForOutput(mimeType, outputID);

checkOutputIdentifier(request.getExecute(), outputID);
checkOutputMimeType(request.getExecute(), mimeType);
Assert.assertThat("document is valid", request.validate(), is(true));

}

private void addTestDataByReference(ExecuteRequestBuilder executeRequestBuilder){

InputType inputType = InputType.Factory.newInstance();

inputType.addNewIdentifier().setStringValue(inputID);
inputType.addNewReference().setHref(url);

executeRequestBuilder.addComplexData(inputType);

}

private void addTestDataString(ExecuteRequestBuilder executeRequestBuilder){

try {
executeRequestBuilder.addComplexData(inputID, complexDataString, "", "", "text/plain");
} catch (WPSClientException e) {
e.printStackTrace();
}

}

private String getMimeType(ProcessDescriptionType processDescriptionType, boolean isGetDefaultMimeType){

String result = "";

ProcessOutputs processOutputs = processDescriptionType.getProcessOutputs();

assertNotNull(processOutputs);

OutputDescriptionType outputDescriptionType = processOutputs.getOutputArray(0);

assertNotNull(outputDescriptionType);

SupportedComplexDataType complexDataType = outputDescriptionType.getComplexOutput();

assertNotNull(complexDataType);

if(isGetDefaultMimeType){
ComplexDataCombinationType defaultFormat = complexDataType.getDefault();

assertNotNull(defaultFormat);

ComplexDataDescriptionType format = defaultFormat.getFormat();

assertNotNull(format);
result = format.getMimeType();

result = format.getMimeType();
}else{
ComplexDataCombinationsType supportedFormats = complexDataType.getSupported();

assertNotNull(supportedFormats);

ComplexDataDescriptionType format = supportedFormats.getFormatArray(0);

assertNotNull(format);
result = format.getMimeType();

result = format.getMimeType();
}

return result;
}

private void checkOutputMimeType(Execute execute, String mimeType){

DocumentOutputDefinitionType outputDefinitionType = getOutputDefinitionType(execute);
assertTrue(outputDefinitionType.getMimeType() != null && outputDefinitionType.getMimeType().equals(mimeType));

assertTrue(outputDefinitionType.getMimeType() != null && outputDefinitionType.getMimeType().equals(mimeType));

}

private void checkOutputIdentifier(Execute execute, String identifier){

DocumentOutputDefinitionType outputDefinitionType = getOutputDefinitionType(execute);
assertTrue(outputDefinitionType.getIdentifier() != null && outputDefinitionType.getIdentifier().getStringValue().equals(identifier));

assertTrue(outputDefinitionType.getIdentifier() != null && outputDefinitionType.getIdentifier().getStringValue().equals(identifier));

}

private DocumentOutputDefinitionType getOutputDefinitionType(Execute execute){

ResponseFormType responseFormType = execute.getResponseForm();

assertNotNull(responseFormType);

ResponseDocumentType responseDocumentType = responseFormType.getResponseDocument();

assertNotNull(responseDocumentType);

DocumentOutputDefinitionType outputDefinitionType = responseDocumentType.getOutputArray(0);
assertNotNull(outputDefinitionType);

assertNotNull(outputDefinitionType);

return outputDefinitionType;

}

}
41 changes: 21 additions & 20 deletions 52n-wps-commons/src/main/java/org/n52/wps/commons/WPSConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.slf4j.LoggerFactory;

/**
*
*
* @author Benjamin Pross, Daniel Nüst
*
*/
Expand All @@ -66,19 +66,20 @@ public class WPSConfig implements Serializable {
public static final String VERSION_100 = "1.0.0";
public static final String VERSION_200 = "2.0.0";
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(new String[]{VERSION_100, VERSION_200});

public static final String JOB_CONTROL_OPTION_SYNC_EXECUTE = "sync-execute";
public static final String JOB_CONTROL_OPTION_ASYNC_EXECUTE = "async-execute";

public static final String JOB_CONTROL_OPTIONS_SEPARATOR = " ";

public static final String OUTPUT_TRANSMISSION_VALUE = "value";
public static final String OUTPUT_TRANSMISSION_REFERENCE = "reference";

public static final String OUTPUT_TRANSMISSIONS_SEPARATOR = " ";

private ConfigurationManager configurationManager;
private Server serverConfigurationModule;

private Server serverConfigurationModule;

public Server getServerConfigurationModule() {

Expand Down Expand Up @@ -176,46 +177,46 @@ public String getServiceEndpoint() {
}

public List<? extends ConfigurationEntry<?>> getConfigurationEntriesForGeneratorClass(
String name) {
String name) {
ConfigurationModule module = getConfigurationModuleForClass(name, ConfigurationCategory.GENERATOR);
return (module == null) ? new ArrayList<ConfigurationEntry<?>>() : module.getConfigurationEntries();
}

public List<FormatEntry> getFormatEntriesForGeneratorClass(String name) {
public List<FormatEntry> getFormatEntriesForGeneratorClass(String name) {
ConfigurationModule module = getConfigurationModuleForClass(name, ConfigurationCategory.GENERATOR);
return (module == null) ? new ArrayList<FormatEntry>() : module.getFormatEntries();
}

public List<? extends ConfigurationEntry<?>> getConfigurationEntriesForParserClass(
String name) {
String name) {
ConfigurationModule module = getConfigurationModuleForClass(name, ConfigurationCategory.PARSER);
return (module == null) ? new ArrayList<ConfigurationEntry<?>>() : module.getConfigurationEntries();
}

public List<FormatEntry> getFormatEntriesForParserClass(String name) {
public List<FormatEntry> getFormatEntriesForParserClass(String name) {
ConfigurationModule module = getConfigurationModuleForClass(name, ConfigurationCategory.PARSER);
return (module == null) ? new ArrayList<FormatEntry>() : module.getFormatEntries();
}

public ConfigurationModule getConfigurationModuleForClass(String name, ConfigurationCategory moduleCategorie){

Map<String, ConfigurationModule> activeModules = getActiveConfigurationModules(moduleCategorie);

for (String moduleName : activeModules.keySet()) {

ConfigurationModule tmpModule = activeModules.get(moduleName);

if(!(tmpModule instanceof ClassKnowingModule)){
continue;
}

if(((ClassKnowingModule)tmpModule).getClassName().equals(name)){
return tmpModule;
}
return tmpModule;
}
}
return null;
}

private Map<String, ConfigurationModule> getActiveConfigurationModules(ConfigurationCategory moduleCategorie){
return configurationManager.getConfigurationServices().getActiveConfigurationModulesByCategory(moduleCategorie);
}
Expand Down
Loading