use of cucumber.api.java.en.When in project alien4cloud by alien4cloud.
the class RuntimeStepDefinitions method iTriggerOnTheNodeTemplateTheCustomCommandOfTheInterfaceForApplicationUsingTheSecretProviderAndTheSecretCredentialsWithParameters.
/**
* Attention: Should use the json format if the property value is a function when filling the parameters.
*
* @param nodeTemplateName
* @param commandName
* @param interfaceName
* @param appName
* @param secretProviderPluginName
* @param secretCredentials
* @param operationParameters
* @throws Throwable
*/
@When("^I trigger on the node template \"([^\"]*)\" the custom command \"([^\"]*)\" of the interface \"([^\"]*)\" for application \"([^\"]*)\" using the secret provider \"([^\"]*)\" and the secret credentials \"([^\"]*)\" with parameters:$")
public void iTriggerOnTheNodeTemplateTheCustomCommandOfTheInterfaceForApplicationUsingTheSecretProviderAndTheSecretCredentialsWithParameters(String nodeTemplateName, String commandName, String interfaceName, String appName, String secretProviderPluginName, String secretCredentials, DataTable operationParameters) throws Throwable {
OperationExecRequest commandRequest = new OperationExecRequest();
commandRequest.setNodeTemplateName(nodeTemplateName);
commandRequest.setInterfaceName(interfaceName);
commandRequest.setOperationName(commandName);
commandRequest.setApplicationEnvironmentId(Context.getInstance().getDefaultApplicationEnvironmentId(appName));
if (StringUtils.isNotBlank(secretProviderPluginName) && StringUtils.isNotBlank(secretCredentials)) {
commandRequest.setSecretProviderPluginName(secretProviderPluginName);
Map<String, String> credentials = Splitter.on(",").withKeyValueSeparator(":").split(secretCredentials.replaceAll("\\s+", ""));
commandRequest.setSecretProviderCredentials(credentials);
}
if (operationParameters != null) {
Map<String, Object> parameters = Maps.newHashMap();
for (List<String> operationParameter : operationParameters.raw()) {
// check if the property is a function
if (PropertyUtils.isFunction(ToscaFunctionConstants.GET_SECRET, operationParameter.get(1))) {
parameters.put(operationParameter.get(0), PropertyUtils.toFunctionValue(operationParameter.get(1)));
} else {
parameters.put(operationParameter.get(0), operationParameter.get(1));
}
}
commandRequest.setParameters(parameters);
}
String jSon = JsonUtil.toString(commandRequest);
String restResponse = Context.getRestClientInstance().postJSon("/rest/v1/runtime/" + Context.getInstance().getApplication().getId() + "/operations/", jSon);
Context.getInstance().registerRestResponse(restResponse);
}
use of cucumber.api.java.en.When in project alien4cloud by alien4cloud.
the class AuthenticationStepDefinitions method I_update_user_s_fields.
@When("^I update \"([^\"]*)\" user's fields:$")
public void I_update_user_s_fields(String username, List<Entry> fields) throws Throwable {
Map<String, String> fieldsMap = Maps.newHashMap();
for (Entry field : fields) {
fieldsMap.put(field.getName(), field.getValue());
}
String resp = Context.getRestClientInstance().putJSon("/rest/v1/users/" + username, JsonUtil.toString(fieldsMap));
System.out.println(resp);
Context.getInstance().registerRestResponse(resp);
}
use of cucumber.api.java.en.When in project alien4cloud by alien4cloud.
the class AuthenticationStepDefinitions method I_create_a_new_user_with_name_and_password_in_the_system.
@When("^I create a new user with username \"([^\"]*)\" and password \"([^\"]*)\" in the system$")
public void I_create_a_new_user_with_name_and_password_in_the_system(String username, String password) throws Throwable {
CreateUserRequest request = new CreateUserRequest();
request.setUsername(username);
request.setPassword(password);
request.setEmail(username + "@alien4cloud.org");
Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon("/rest/v1/users/", JsonUtil.toString(request)));
}
use of cucumber.api.java.en.When in project alien4cloud by alien4cloud.
the class ManagedServiceStepDefinitions method iDeleteTheServiceRelatedToTheApplicationEnvironment.
@When("^I (successfully\\s)?delete the service related to the application \"([^\"]*)\", environment \"([^\"]*)\"$")
public void iDeleteTheServiceRelatedToTheApplicationEnvironment(String successfully, String applicationName, String environmentName) throws Throwable {
String applicationId = Context.getInstance().getApplicationId(applicationName);
String environmentId = Context.getInstance().getApplicationEnvironmentId(applicationName, environmentName);
Context.getInstance().registerRestResponse(getRestClientInstance().delete(String.format("/rest/applications/%s/environments/%s/services", applicationId, nullAsString(environmentId))));
CommonStepDefinitions.validateIfNeeded(StringUtils.isNotBlank(successfully));
}
use of cucumber.api.java.en.When in project alien4cloud by alien4cloud.
the class ServiceStepDefinitions method createService.
@When("^I (successfully\\s)?create a service with name \"(.*?)\", version \"(.*?)\", type \"(.*?)\", archive version \"(.*?)\"$")
public void createService(String successfully, String serviceName, String serviceVersion, String type, String archiveVersion) throws Throwable {
CreateServiceResourceRequest request = new CreateServiceResourceRequest(nullable(serviceName), nullable(serviceVersion), nullable(type), nullable(archiveVersion));
Context.getInstance().registerRestResponse(getRestClientInstance().postJSon("/rest/v1/services/", JsonUtil.toString(request)));
CommonStepDefinitions.validateIfNeeded(StringUtils.isNotBlank(successfully));
try {
LAST_CREATED_ID = JsonUtil.read(Context.getInstance().getRestResponse(), String.class).getData();
Context.getInstance().registerService(LAST_CREATED_ID, serviceName);
} catch (Throwable t) {
}
}
Aggregations