public void AddRequirement_Requirement_Exist() { // Arrange var toscaNodeType = new ToscaNodeType(); var toscaRequirement = new ToscaRequirement() { Node = "port" }; // Act toscaNodeType.AddRequirement("device", toscaRequirement); // Assert toscaNodeType.Requirements.Single()["device"].Node.Should().Be("port"); }
TraverseNodeTypesByRequirements_Traverses_Nodes_From_Specific_Node_Type_By_Requirements_Of_Its_Base_Node_Type () { // Arrange var serviceTemplate = new ToscaServiceTemplate { ToscaDefinitionsVersion = "tosca_simple_yaml_1_0" }; var deviceNodeType = new ToscaNodeType(); deviceNodeType.AddRequirement("power", new ToscaRequirement { Node = "tosca.nodes.port", Capability = "port" }); var switchNodeType = new ToscaNodeType { DerivedFrom = "tosca.nodes.device" }; serviceTemplate.NodeTypes.Add("tosca.nodes.port", new ToscaNodeType()); serviceTemplate.NodeTypes.Add("tosca.nodes.device", deviceNodeType); serviceTemplate.NodeTypes.Add("tosca.nodes.switch", switchNodeType); var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata { CsarVersion = new Version(1, 1), EntryDefinitions = "sample.yaml", ToscaMetaFileVersion = new Version(1, 1), CreatedBy = "Anonymous" }); cloudServiceArchive.AddToscaServiceTemplate("sample.yaml", serviceTemplate); List <ValidationResult> validationResults; cloudServiceArchive.TryValidate(out validationResults) .Should().BeTrue(string.Join(Environment.NewLine, validationResults.Select(a => a.ErrorMessage))); // Act var discoveredNodeTypeNames = new List <string>(); cloudServiceArchive.TraverseNodeTypesByRequirements("tosca.nodes.switch", (nodeTypeName, nodeType) => { discoveredNodeTypeNames.Add(nodeTypeName); }); // Assert discoveredNodeTypeNames.ShouldBeEquivalentTo(new[] { "tosca.nodes.port", "tosca.nodes.switch" }); }
public void Validation_Should_Not_Pass_When_Archive_With_Cyclic_Reference_Between_Requirements_Is_Loaded() { // Arrange var portNodeType = new ToscaNodeType(); portNodeType.AddRequirement("internet", new ToscaRequirement { Capability = "tosca.capabilities.Attachment", Node = "vendor.devices.Switch" }); var switchNodetype = new ToscaNodeType(); switchNodetype.AddRequirement("port", new ToscaRequirement { Capability = "tosca.capabilities.Attachment", Node = "vendor.parts.Port" }); var serviceTemplate = new ToscaServiceTemplate { ToscaDefinitionsVersion = "tosca_simple_yaml_1_0" }; serviceTemplate.NodeTypes.Add("vendor.parts.Port", portNodeType); serviceTemplate.NodeTypes.Add("vendor.devices.Switch", switchNodetype); var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata { CreatedBy = "Anonymous", CsarVersion = new Version(1, 2, 3), EntryDefinitions = "tosca.yaml", ToscaMetaFileVersion = new Version(1, 1) }); cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate); byte[] buffer; using (var memoryStream = new MemoryStream()) { cloudServiceArchive.Save(memoryStream); memoryStream.Flush(); buffer = memoryStream.GetBuffer(); } // Act Action action = () => ToscaCloudServiceArchive.Load(new MemoryStream(buffer)); // Assert action.ShouldThrow <ToscaValidationException>().WithMessage("Circular dependency detected by requirements on node type"); }
public void GetAllRequirements_Shall_Not_Fail_When_Derived_And_Base_Node_Type_Have_Requirements_With_Same_Key() { // Arrange var switchNodeType = new ToscaNodeType(); switchNodeType.AddRequirement("internet", new ToscaRequirement { Capability = "wi-fi" }); var nxosNodeType = new ToscaNodeType { DerivedFrom = "cloudshell.nodes.Switch" }; nxosNodeType.AddRequirement("internet", new ToscaRequirement { Capability = "ssd" }); var serviceTemplate = new ToscaServiceTemplate { ToscaDefinitionsVersion = "tosca_simple_yaml_1_0" }; serviceTemplate.NodeTypes.Add("cloudshell.nodes.Switch", switchNodeType); serviceTemplate.NodeTypes.Add("vendor.switch.NXOS", nxosNodeType); var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata { CreatedBy = "Anonymous", CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yaml", ToscaMetaFileVersion = new Version(1, 1) }); cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate); var validationResults = new List <ValidationResult>(); cloudServiceArchive.TryValidate(out validationResults).Should() .BeTrue(string.Join(Environment.NewLine, validationResults.Select(r => r.ErrorMessage))); // Act var allRequirements = nxosNodeType.GetAllRequirements(); // Assert allRequirements.Should().ContainSingle(r => r.Capability == "ssd"); allRequirements.Should().ContainSingle(r => r.Capability == "wi-fi"); }
public void GetAllRequirements_Shall_Not_Throw_Validation_Exception_When_Circular_Dependency_Exists() { // Arrange var portNodeType = new ToscaNodeType(); portNodeType.AddRequirement("internet", new ToscaRequirement { Capability = "tosca.capabilities.Attachment", Node = "vendor.devices.Switch" }); var switchNodetype = new ToscaNodeType(); switchNodetype.AddRequirement("port", new ToscaRequirement { Capability = "tosca.capabilities.Attachment", Node = "vendor.parts.Port" }); var serviceTemplate = new ToscaServiceTemplate { ToscaDefinitionsVersion = "tosca_simple_yaml_1_0" }; serviceTemplate.NodeTypes.Add("vendor.parts.Port", portNodeType); serviceTemplate.NodeTypes.Add("vendor.devices.Switch", switchNodetype); var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata { CreatedBy = "Anonymous", CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yaml", ToscaMetaFileVersion = new Version(1, 1) }); cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate); // Act List <ValidationResult> validationResults; cloudServiceArchive.TryValidate(out validationResults); // Assert validationResults.Should().ContainSingle(r => r.ErrorMessage.Equals("Circular dependency detected by requirements on node type")); }
public void TraverseNodeTypesByRequirements_Should_Not_Throw_Exception_When_Node_Is_Null() { // Arrange var switchNodeType = new ToscaNodeType(); switchNodeType.AddRequirement("internet", new ToscaRequirement { Capability = "wi-fi" }); var nxosNodeType = new ToscaNodeType { DerivedFrom = "cloudshell.nodes.Switch" }; nxosNodeType.AddRequirement("storage", new ToscaRequirement { Capability = "ssd" }); var serviceTemplate = new ToscaServiceTemplate { ToscaDefinitionsVersion = "tosca_simple_yaml_1_0" }; serviceTemplate.NodeTypes.Add("cloudshell.nodes.Switch", switchNodeType); serviceTemplate.NodeTypes.Add("vendor.switch.NXOS", nxosNodeType); var cloudServiceArchive = new ToscaCloudServiceArchive(new ToscaMetadata { CreatedBy = "Anonymous", CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yaml", ToscaMetaFileVersion = new Version(1, 1) }); cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate); // Act Action action = () => cloudServiceArchive.TraverseNodeTypesByRequirements("vendor.switch.NXOS", (a, b) => {}); // Assert action.ShouldNotThrow <Exception>(); }