use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class InputPropertiesStepDefinitions method I_define_the_property_of_the_node_as_of_typeId_as_input_property.
@When("^I define the property \"([^\"]*)\" of the node \"([^\"]*)\" of typeId \"([^\"]*)\" as input property$")
public void I_define_the_property_of_the_node_as_of_typeId_as_input_property(String inputId, String nodeName, String typeId) throws Throwable {
// get the component to use the right property definition
String componentResponse = Context.getRestClientInstance().get("/rest/v1/components/" + typeId);
RestResponse<NodeType> componentResult = JsonUtil.read(componentResponse, NodeType.class, Context.getJsonMapper());
PropertyDefinition propertyDefinition = componentResult.getData().getProperties().get(inputId);
String fullUrl = String.format("/rest/v1/topologies/%s/inputs/%s", Context.getInstance().getTopologyId(), inputId);
String json = JsonUtil.toString(propertyDefinition);
Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon(fullUrl, json));
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class GetComponentDefinitionsSteps method I_should_retrieve_a_component_detail_with_list_of_it_s_properties_and_interfaces.
@Then("^I should retrieve a component detail with list of it's properties and interfaces.$")
public void I_should_retrieve_a_component_detail_with_list_of_it_s_properties_and_interfaces() throws Throwable {
NodeType idnt = JsonUtil.read(Context.getInstance().takeRestResponse(), NodeType.class).getData();
assertNotNull(idnt);
assertNotNull(idnt.getProperties());
assertTrue(!idnt.getProperties().isEmpty());
assertTrue(!idnt.getProperties().values().isEmpty());
assertNotNull(idnt.getInterfaces());
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class SearchDefinitionSteps method createAndIndexComponent.
private void createAndIndexComponent(int count, String type, String baseName, int countHavingProperty, String property, String propertyValue) throws Exception {
testDataList.clear();
Class<?> clazz = QUERY_TYPES.get(type).getIndexedToscaElementClass();
String typeName = MappingBuilder.indexTypeFromClass(clazz);
int remaining = countHavingProperty;
baseName = baseName == null || baseName.isEmpty() ? typeName : baseName;
for (int i = 0; i < count; i++) {
AbstractToscaType componentTemplate = (AbstractToscaType) clazz.newInstance();
String elementId = baseName + "_" + i;
componentTemplate.setElementId(elementId);
componentTemplate.setArchiveVersion(DEFAULT_ARCHIVE_VERSION);
componentTemplate.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
if (property != null && remaining > 0) {
if (type.equalsIgnoreCase("node types")) {
switch(property) {
case "capability":
((NodeType) componentTemplate).setCapabilities(Lists.newArrayList(new CapabilityDefinition(propertyValue, propertyValue, 1)));
break;
case "requirement":
((NodeType) componentTemplate).setRequirements((Lists.newArrayList(new RequirementDefinition(propertyValue, propertyValue))));
break;
case "default capability":
((NodeType) componentTemplate).setDefaultCapabilities((Lists.newArrayList(propertyValue)));
break;
case "elementId":
((NodeType) componentTemplate).setElementId(propertyValue);
break;
default:
break;
}
} else if (type.equalsIgnoreCase("relationship types")) {
((RelationshipType) componentTemplate).setValidSources(new String[] { propertyValue });
}
remaining -= 1;
}
String serializeDatum = JsonUtil.toString(componentTemplate);
log.debug("Saving in ES: " + serializeDatum);
esClient.prepareIndex(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName).setSource(serializeDatum).setRefresh(true).execute().actionGet();
if (componentTemplate instanceof NodeType) {
testDataList.add((NodeType) (componentTemplate));
}
}
indexedComponentTypes.put(type, typeName);
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class UpdateDeleteTagDefinitionsSteps method I_should_have_tag_with_value.
@Then("^I should have tag \"([^\"]*)\" with value \"([^\"]*)\"$")
public void I_should_have_tag_with_value(String tagKey, String tagValue) throws Throwable {
Context.getInstance().registerRestResponse(Context.getRestClientInstance().get("/rest/v1/components/" + Context.getInstance().getComponentId(0)));
NodeType idnt = JsonUtil.read(Context.getInstance().takeRestResponse(), NodeType.class).getData();
assertNotNull(idnt);
int index = idnt.getTags().indexOf(new Tag(tagKey, null));
assertEquals(idnt.getTags().get(index).getValue(), tagValue);
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class UpdateDeleteTagDefinitionsSteps method createOneIndexNodeType.
/**
* Load components IndexedNodeType from a file to use it in tests
*
* @param componentId
* @param refresh
* @throws IOException
* @throws IndexingServiceException
*/
@SuppressWarnings("unchecked")
private void createOneIndexNodeType(String componentId, String archiveVersion, List<Tag> tags, boolean refresh) throws IOException, IndexingServiceException {
String samplePathString = "src/test/resources/data/components/indexed_nodetypes.json";
Path path = Paths.get(samplePathString);
List<Object> tempList = jsonMapper.readValue(path.toFile(), ArrayList.class);
List<NodeType> idntList = new ArrayList<>();
for (Object ob : tempList) {
idntList.add(jsonMapper.readValue(jsonMapper.writeValueAsString(ob), NodeType.class));
}
String typeName = MappingBuilder.indexTypeFromClass(NodeType.class);
NodeType indexedNodeType = null;
// Save on nodeType with
if (componentId != null && archiveVersion != null && !componentId.trim().isEmpty()) {
// Get the first nodetype to update its id and insert it
indexedNodeType = idntList.get(0);
indexedNodeType.setElementId(componentId);
indexedNodeType.setArchiveVersion(archiveVersion);
indexedNodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
if (tags != null) {
indexedNodeType.setTags(tags);
}
String serializeDatum = jsonMapper.writeValueAsString(indexedNodeType);
esClient.prepareIndex(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName).setSource(serializeDatum).setRefresh(refresh).execute().actionGet();
}
}
Aggregations