コード例 #1
0
        public void Exception_Thrown_When_Cyclic_Dependency_Between_Capability_Types_Exists()
        {
            string toscaServiceTemplate = @"
tosca_definitions_version: tosca_simple_yaml_1_0

capability_types:
    tosca.types.SoftwareComponent:
        derived_from: tosca.types.BasicComponent
    tosca.types.BasicComponent:
        derived_from: tosca.types.SoftwareComponent
";

            var serviceTemplate = ToscaServiceTemplate.Load(toscaServiceTemplate.ToMemoryStream());

            var toscaMetadata = new ToscaMetadata
            {
                CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yml", ToscaMetaFileVersion = new Version(1, 1), CreatedBy = "anonymous"
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yml", serviceTemplate);

            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results).Should().BeFalse();
            results.Should().ContainSingle(r => r.ErrorMessage.Equals("Circular dependency detected on CapabilityType: 'tosca.types.BasicComponent'"));
            results.Should().ContainSingle(r => r.ErrorMessage.Equals("Circular dependency detected on CapabilityType: 'tosca.types.SoftwareComponent'"));
        }
コード例 #2
0
        public void Validation_Shall_Pass_When_Complex_Data_Type_Consists_Of_Built_In_Type()
        {
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            var toscaAsString = @"
tosca_definitions_version: tosca_simple_yaml_1_0
data_types:
  tosca.datatypes.Complex:
    properties:
      real:
        type: integer";

            using (var memoryStream = toscaAsString.ToMemoryStream())
            {
                // Act
                var serviceTemplate = ToscaServiceTemplate.Load(memoryStream);
                cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

                // Assert
                List <ValidationResult> results;
                cloudServiceArchive.TryValidate(out results).Should().BeTrue(string.Join(Environment.NewLine, results));
            }
        }
コード例 #3
0
        public void It_Should_Be_Possible_To_Save_And_Load_Cloud_Service_Archive()
        {
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml",
                                                        new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            });

            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results)
            .Should()
            .BeTrue(string.Join(Environment.NewLine, results.Select(r => r.ErrorMessage)));

            using (var memoryStream = new MemoryStream())
            {
                cloudServiceArchive.Save(memoryStream);

                var serviceArchive = ToscaCloudServiceArchive.Load(memoryStream);

                // Assert
                serviceArchive.CreatedBy.Should().Be("Anonymous");
            }
        }
コード例 #4
0
        public void Validation_Valid_Values_Of_Custom_Data_Type_Should_Pass_If_Proper_Parser_Registered()
        {
            // Arrange
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1, 2),
                EntryDefinitions     = "definitions.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            var definitions = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };
            var complexDataType = new ToscaDataType();
            var realProperty    = new ToscaProperty {
                Type = "float"
            };

            complexDataType.Properties.Add("real", realProperty);
            complexDataType.Properties.Add("imaginary", new ToscaProperty {
                Type = "float"
            });
            definitions.DataTypes.Add("tosca.standard.Complex", complexDataType);

            var complexProperty = new ToscaProperty {
                Type = "tosca.standard.Complex"
            };

            complexProperty.Constraints.Add(new Dictionary <string, object> {
                { "valid_values", new List <object> {
                      "1 + 1i"
                  } }
            });

            var basicNodetype = new ToscaNodeType();

            basicNodetype.Properties.Add("complex", complexProperty);

            definitions.NodeTypes.Add("basic", basicNodetype);
            DependencyResolver.Current.RegisterDataTypeConverter(new CustomDataTypeConverter());
            cloudServiceArchive.AddToscaServiceTemplate("definitions.yaml", definitions);

            // Act
            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results);

            // Assert
            results.Should().BeEmpty();
        }
コード例 #5
0
        public void Exception_Should_Be_Thrown_When_Parser_For_Custom_Data_Type_Not_Defined()
        {
            // Arrange
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1, 2),
                EntryDefinitions     = "definitions.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            var definitions = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };
            var complexDataType = new ToscaDataType();
            var realProperty    = new ToscaProperty {
                Type = "float"
            };

            complexDataType.Properties.Add("real", realProperty);
            complexDataType.Properties.Add("imaginary", new ToscaProperty {
                Type = "float"
            });
            definitions.DataTypes.Add("tosca.standard.Complex", complexDataType);

            var complexProperty = new ToscaProperty {
                Type = "tosca.standard.Complex"
            };

            complexProperty.Constraints.Add(new Dictionary <string, object> {
                { "valid_values", new List <object> {
                      "1 + 1i"
                  } }
            });

            var basicNodetype = new ToscaNodeType();

            basicNodetype.Properties.Add("complex", complexProperty);

            definitions.NodeTypes.Add("basic", basicNodetype);
            cloudServiceArchive.AddToscaServiceTemplate("definitions.yaml", definitions);

            // Act
            List <ValidationResult> results;
            Action action = () => cloudServiceArchive.TryValidate(out results);

            // Assert
            action.ShouldThrow <ToscaDataTypeParserNotFoundException>()
            .WithMessage("Parser for data type 'tosca.standard.Complex' nod found.");
        }
コード例 #6
0
        public void ToscaServiceTemplateAlreadyExistsException_Should_Be_Thrown_When_Same_Service_Template_Added_Twice()
        {
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            cloudServiceArchive.AddToscaServiceTemplate("reference1.yml", new ToscaServiceTemplate());
            Action action =
                () => cloudServiceArchive.AddToscaServiceTemplate("reference1.yml", new ToscaServiceTemplate());

            action.ShouldThrow <ToscaServiceTemplateAlreadyExistsException>()
            .WithMessage("Service Template 'reference1.yml' already exists");
        }
コード例 #7
0
        public void Validation_Shall_Fail_When_Circular_Dependency_Detected_Between_Imports()
        {
            // Arrange
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1, 2),
                EntryDefinitions     = "definitions.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            var definitions = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            definitions.Imports.Add(new Dictionary <string, ToscaImport> {
                { "import", new ToscaImport {
                      File = "import.yaml"
                  } }
            });

            var import = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };

            import.Imports.Add(new Dictionary <string, ToscaImport> {
                { "import", new ToscaImport {
                      File = "definitions.yaml"
                  } }
            });

            cloudServiceArchive.AddToscaServiceTemplate("import.yaml", import);
            cloudServiceArchive.AddToscaServiceTemplate("definitions.yaml", definitions);

            // Act
            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results);

            // Assert
            results.Should().ContainSingle(r => r.ErrorMessage.Equals("Circular dependency detected on import \'import.yaml\'"));
        }
コード例 #8
0
        public void It_Should_Be_Possible_To_Save_And_Load_Cloud_Service_Archive_With_Artifacts()
        {
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            cloudServiceArchive.AddArtifact("readme.txt", "readme content".ToByteArray(Encoding.ASCII));
            var serviceTemplate = new ToscaServiceTemplate {
                ToscaDefinitionsVersion = "tosca_simple_yaml_1_0"
            };
            var nodeType = new ToscaNodeType();

            nodeType.Artifacts.Add("readme", new ToscaArtifact {
                Type = "tosca.artifacts.File", File = "readme.txt"
            });
            serviceTemplate.NodeTypes.Add("some_node", nodeType);
            cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results)
            .Should()
            .BeTrue(string.Join(Environment.NewLine, results.Select(r => r.ErrorMessage)));

            using (var memoryStream = new MemoryStream())
            {
                cloudServiceArchive.Save(memoryStream);

                var serviceArchive = ToscaCloudServiceArchive.Load(memoryStream);

                // Assert
                serviceArchive.CreatedBy.Should().Be("Anonymous");
                serviceArchive.GetArtifactBytes("readme.txt")
                .Should()
                .BeEquivalentTo("readme content".ToByteArray(Encoding.ASCII));
            }
        }
コード例 #9
0
        public void GetArtifactBytes_Should_Return_Empty_Array_When_File_Is_Empty()
        {
            // Arrange
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Devil",
                CsarVersion          = new Version(1, 1),
                ToscaMetaFileVersion = new Version(1, 0),
                EntryDefinitions     = "tosca.yaml"
            };

            var toscaCloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            // Act
            toscaCloudServiceArchive.AddArtifact("some_icon.png", "IMAGE".ToByteArray(Encoding.ASCII));

            // Assert
            toscaCloudServiceArchive.GetArtifactBytes("some_icon.png")
            .Should()
            .BeEquivalentTo(new byte[] { 73, 77, 65, 71, 69 });
        }
コード例 #10
0
        public void Exception_Thrown_When_Cyclic_Dependency_Between_Node_Types_Exists()
        {
            string toscaServiceTemplate = @"
tosca_definitions_version: tosca_simple_yaml_1_0

node_types:
    tosca.nodes.SoftwareComponent:
        derived_from: tosca.nodes.BasicComponent
        properties:
            # domain-specific software component version
            component_version:
                type: version
                required: false
            admin_credential:
                type: tosca.datatypes.Credential
                required: false
    tosca.nodes.BasicComponent:
        derived_from: tosca.nodes.SoftwareComponent
";

            var serviceTemplate = ToscaServiceTemplate.Load(toscaServiceTemplate.ToMemoryStream());

            var toscaMetadata = new ToscaMetadata
            {
                CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yml", ToscaMetaFileVersion = new Version(1, 1), CreatedBy = "anonymous"
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yml", serviceTemplate);

            // Act
            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results);

            // Assert
            results.Should().ContainSingle(r => r.ErrorMessage.Equals("Circular dependency detected on NodeType: 'tosca.nodes.BasicComponent'"));
        }
コード例 #11
0
        public void Service_Template_With_Complex_Data_Type_Can_Be_Parsed()
        {
            string toscaServiceTemplate = @"
tosca_definitions_version: tosca_simple_yaml_1_0

node_types:
    tosca.nodes.SoftwareComponent:
        derived_from: tosca.nodes.Root
        properties:
            # domain-specific software component version
            component_version:
                type: version
                required: false
            admin_credential:
                type: tosca.datatypes.Credential
                required: false
        requirements:
        - host:
            capability: tosca.capabilities.Container
            node: tosca.nodes.Compute
            relationship: tosca.relationships.HostedOn";

            var serviceTemplate = ToscaServiceTemplate.Load(toscaServiceTemplate.ToMemoryStream());

            var toscaMetadata = new ToscaMetadata
            {
                CsarVersion = new Version(1, 1), EntryDefinitions = "tosca.yml", ToscaMetaFileVersion = new Version(1, 1), CreatedBy = "anonymous"
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            cloudServiceArchive.AddToscaServiceTemplate("tosca.yml", serviceTemplate);

            List <ValidationResult> results;

            cloudServiceArchive.TryValidate(out results)
            .Should()
            .BeTrue(string.Join(Environment.NewLine, results.Select(r => r.ErrorMessage)));
        }
コード例 #12
0
        public void Exception_Should_Be_Thrown_When_Complex_Data_Type_Consists_Of_Not_Existing_Type()
        {
            var toscaMetadata = new ToscaMetadata
            {
                CreatedBy            = "Anonymous",
                CsarVersion          = new Version(1, 1),
                EntryDefinitions     = "tosca.yaml",
                ToscaMetaFileVersion = new Version(1, 0)
            };
            var cloudServiceArchive = new ToscaCloudServiceArchive(toscaMetadata);

            var toscaAsString = @"
tosca_definitions_version: tosca_simple_yaml_1_0
data_types:
  tosca.datatypes.Complex:
    properties:
      real:
        type: weight";

            using (var memoryStream = toscaAsString.ToMemoryStream())
            {
                // Act
                var serviceTemplate = ToscaServiceTemplate.Load(memoryStream);
                cloudServiceArchive.AddToscaServiceTemplate("tosca.yaml", serviceTemplate);

                List <ValidationResult> results;
                cloudServiceArchive.TryValidate(out results);

                results.Should().HaveCount(1);
                results.Should()
                .Contain(
                    a =>
                    a.ErrorMessage.Contains(
                        "Data type 'weight' specified as part of data type 'tosca.datatypes.Complex' not found."));
            }
        }