Exemple #1
0
        public void Constructor_WithIConfigurationRootBinds()
        {
            // Arrange
            var configJson = @"
{
    ""vcap"": {
        ""services"" : {
            ""p-config-server"": [{
                ""credentials"": {
                    ""access_token_uri"": ""https://p-spring-cloud-services.uaa.wise.com/oauth/token"",
                    ""client_id"": ""p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef"",
                    ""client_secret"": ""e8KF1hXvAnGd"",
                    ""uri"": ""http://localhost:8888""
                },
                ""label"": ""p-config-server"",
                ""name"": ""My Config Server"",
                ""plan"": ""standard"",
                ""tags"": [
                    ""configuration"",
                    ""spring-cloud""
                ]
            }]
        }
    }
}";
            var memStream  = CloudFoundryConfigurationProvider.GetMemoryStream(configJson);
            var jsonSource = new JsonStreamConfigurationSource(memStream);
            var builder    = new ConfigurationBuilder().Add(jsonSource);
            var config     = builder.Build();

            var options = new CloudFoundryServicesOptions(config);

            Assert.NotNull(options.Services);
            Assert.Single(options.Services);

            Assert.NotNull(options.Services["p-config-server"]);
            Assert.Single(options.Services["p-config-server"]);

            var firstService = options.GetServicesList().First();

            Assert.Equal("p-config-server", firstService.Label);
            Assert.Equal("My Config Server", firstService.Name);
            Assert.Equal("standard", firstService.Plan);

            Assert.NotNull(firstService.Tags);
            Assert.Equal(2, firstService.Tags.Count());
            Assert.Contains("configuration", firstService.Tags);
            Assert.Contains("spring-cloud", firstService.Tags);

            Assert.NotNull(firstService.Credentials);
            Assert.Equal(4, firstService.Credentials.Count);
            Assert.Equal("https://p-spring-cloud-services.uaa.wise.com/oauth/token", firstService.Credentials["access_token_uri"].Value);
            Assert.Equal("p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef", firstService.Credentials["client_id"].Value);
            Assert.Equal("e8KF1hXvAnGd", firstService.Credentials["client_secret"].Value);
            Assert.Equal("http://localhost:8888", firstService.Credentials["uri"].Value);
        }
Exemple #2
0
        public void Constructor_WithNoVcapServicesConfiguration()
        {
            var builder = new ConfigurationBuilder();
            var config  = builder.Build();

            var options = new CloudFoundryServicesOptions(config);

            Assert.NotNull(options);
            Assert.NotNull(options.Services);
            Assert.Empty(options.Services);
            Assert.Empty(options.GetServicesList());
        }
Exemple #3
0
        public void Constructor_WithMultipleSameServicesConfiguration()
        {
            // Arrange
            var configJson = @"
                {
                    ""vcap"": {
                        ""services"" : {
                            ""p-mysql"": [
                            {
                                ""name"": ""mySql1"",
                                ""label"": ""p-mysql"",
                                ""tags"": [""mysql"",""relational""],
                                ""plan"": ""100mb-dev"",
                                ""credentials"": {
                                    ""hostname"": ""192.168.0.97"",
                                    ""port"": 3306,
                                    ""name"": ""cf_0f5dda44_e678_4727_993f_30e6d455cc31"",
                                    ""username"": ""9vD0Mtk3wFFuaaaY"",
                                    ""password"": ""Cjn4HsAiKV8sImst"",
                                    ""uri"": ""mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true"",
                                    ""jdbcUrl"": ""jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst""
                                }
                            },
                            {
                                ""name"": ""mySql2"",
                                ""label"": ""p-mysql"",
                                ""tags"": [""mysql"",""relational""],
                                ""plan"": ""100mb-dev"",
                                ""credentials"": {
                                    ""hostname"": ""192.168.0.97"",
                                    ""port"": 3306,
                                    ""name"": ""cf_0f5dda44_e678_4727_993f_30e6d455cc31"",
                                    ""username"": ""9vD0Mtk3wFFuaaaY"",
                                    ""password"": ""Cjn4HsAiKV8sImst"",
                                    ""uri"": ""mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true"",
                                    ""jdbcUrl"": ""jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst""
                                }
                            }]
                        }
                    }
                }";
            var memStream  = CloudFoundryConfigurationProvider.GetMemoryStream(configJson);
            var jsonSource = new JsonStreamConfigurationSource(memStream);
            var builder    = new ConfigurationBuilder().Add(jsonSource);
            var config     = builder.Build();

            var options = new CloudFoundryServicesOptions(config);

            Assert.NotNull(options.Services);
            Assert.Single(options.Services);
            Assert.NotNull(options.Services["p-mysql"]);

            Assert.Equal(2, options.GetServicesList().Count());

            var service1 = options.GetServicesList().First(n => n.Name == "mySql1");
            var service2 = options.GetServicesList().First(n => n.Name == "mySql2");

            Assert.NotNull(service1);
            Assert.NotNull(service2);
            Assert.Equal("p-mysql", service1.Label);
            Assert.Equal("192.168.0.97", service1.Credentials["hostname"].Value);
            Assert.Equal("3306", service1.Credentials["port"].Value);
            Assert.Equal("cf_0f5dda44_e678_4727_993f_30e6d455cc31", service1.Credentials["name"].Value);
            Assert.Equal("p-mysql", service2.Label);
            Assert.Equal("192.168.0.97", service2.Credentials["hostname"].Value);
            Assert.Equal("3306", service2.Credentials["port"].Value);
            Assert.Equal("cf_0f5dda44_e678_4727_993f_30e6d455cc31", service2.Credentials["name"].Value);
        }