Functional Identity & Storage tests, added playlist for functional tests.

Change-Id: Ica91b9228ba93dc45ae2bcdb5e60d8cc6f9c03dc
This commit is contained in:
Adam Sheldon
2015-05-15 17:18:46 -07:00
parent 244434ba1b
commit 828437b612
7 changed files with 336 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System;
namespace OpenStack.Test.Functional
{
/// <summary>
/// Configuration used for testing.
/// </summary>
public static class Configuration
{
// Identity
// This can be found here: https://horizon.hpcloud.com/project/access_and_security/
public static Uri AuthUri = new Uri("https://XXXXXXXX.identity.hpcloudsvc.com:35357/v2.0/");
public static string UserName = "username";
public static string Password = "password";
public static string TenantId = "the-tenant-id-here";
// Storage tests
// The storage service name can be found in the ServiceCatalog. It is different
// for Public Cloud and private Helion OpenStack deployments.
public static string StorageServiceName = "Object Storage";
public static string ContainerName = "TestContainer";
public static string FolderName = "TestFolder";
public static string ObjectName = "TestObject";
}
}

View File

@@ -0,0 +1 @@
<Playlist Version="1.0"><Add Test="OpenStack.Test.Functional.StorageTests.Containers" /><Add Test="OpenStack.Test.OpenStackClientTests.CanConnect" /></Playlist>

View File

@@ -0,0 +1,44 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Identity;
namespace OpenStack.Test.Functional
{
/// <summary>
/// Tests for the Identity Component
/// </summary>
[TestClass]
public class IdentityTests
{
/// <summary>
/// Verifies that we can connect to the API. A successful connection is determined by whether or not
/// a token was returned. The token is used for future API calls.
/// </summary>
[TestMethod]
public void CanConnect()
{
var credential = new OpenStackCredential(Configuration.AuthUri, Configuration.UserName, Configuration.Password, Configuration.TenantId);
var client = OpenStackClientFactory.CreateClient(credential);
client.Connect().Wait();
Assert.IsNotNull(credential.AccessTokenId, "No AccessTokenId was set, authentication failed.");
Assert.AreNotEqual(0, credential.ServiceCatalog.Count, "ServiceCatalog should not be empty.");
}
}
}

View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F4BF7F04-C96B-4287-882D-B0822930DC4F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenStack.Test.Functional</RootNamespace>
<AssemblyName>OpenStack.Test.Functional</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="Configuration.cs" />
<Compile Include="StorageTests.cs" />
<Compile Include="IdentityTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenStack\OpenStack40.csproj">
<Project>{e9f05cca-2748-4785-9f72-5d3f8893bc28}</Project>
<Name>OpenStack40</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OpenStack.Test.Functional")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OpenStack.Test.Functional")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0db45dae-3483-4be2-b747-e35871ff6824")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,116 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System.IO;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Identity;
using OpenStack.Storage;
namespace OpenStack.Test.Functional
{
/// <summary>
/// Storage based scenario tests
/// </summary>
[TestClass]
public class StorageTests
{
private static IOpenStackCredential _credential;
private static IOpenStackClient _client;
/// <summary>
/// Initializes the specified context.
/// </summary>
/// <param name="context">The test context.</param>
[ClassInitialize]
public static void Initialize(TestContext context)
{
_credential = new OpenStackCredential(Configuration.AuthUri, Configuration.UserName, Configuration.Password, Configuration.TenantId);
_client = OpenStackClientFactory.CreateClient(_credential);
_client.Connect().Wait();
Assert.IsNotNull(_credential.AccessTokenId, "No AccessTokenId was set, authentication failed.");
Assert.AreNotEqual(0, _credential.ServiceCatalog.Count, "ServiceCatalog should not be empty.");
}
/// <summary>
/// This method contains a suite of scenario tests. They are lumped together because they are dependent on each other,
/// and because the setup/cleanup time would be expensive if they were separated out.
/// </summary>
[TestMethod]
public void ScenarioTests()
{
var storageClient =
_client.CreateServiceClientByName<IStorageServiceClient>(Configuration.StorageServiceName);
var getAccountTask = storageClient.GetStorageAccount();
try
{
// Verify that we can get an empty storage account to use.
getAccountTask.Wait();
StorageAccount account = getAccountTask.Result;
Assert.IsNotNull(account.Name, "Unable to get StorageClient and StorageAccount.");
Assert.AreEqual(0, ((List<StorageContainer>) account.Containers).Count,
"Expected storage account to contain no containers.");
// Verify that we can create a container and then get it.
storageClient.CreateStorageContainer(Configuration.ContainerName, new Dictionary<string, string>())
.Wait();
var listContainersTask = storageClient.ListStorageContainers();
listContainersTask.Wait();
List<StorageContainer> containers = (List<StorageContainer>) listContainersTask.Result;
Assert.AreEqual(1, containers.Count, "Expected to find only the container we created.");
Assert.AreEqual(Configuration.ContainerName, containers[0].Name, "Unexpected container name.");
// Verify that we can create a folder, and that it is returned in ListStorageObjects.
storageClient.CreateStorageFolder(Configuration.ContainerName, Configuration.FolderName).Wait();
var listObjectsTask = storageClient.ListStorageObjects(Configuration.ContainerName);
listObjectsTask.Wait();
List<StorageObject> objects = (List<StorageObject>) listObjectsTask.Result;
Assert.AreEqual(1, objects.Count, "Expected to find the folder we just created.");
Assert.AreEqual(Configuration.FolderName, objects[0].Name, "Expected a folder with name TestFolder.");
// Verify that we can create and download an object, and that they match.
storageClient.CreateStorageObject(
Configuration.ContainerName,
Configuration.ObjectName,
new Dictionary<string, string>(),
new MemoryStream(Encoding.ASCII.GetBytes("Test Content"))
).Wait();
var ms = new MemoryStream();
var mr = new StreamReader(ms);
storageClient.DownloadStorageObject(Configuration.ContainerName, Configuration.ObjectName, ms).Wait();
ms.Position = 0;
Assert.AreEqual("Test Content", mr.ReadToEnd(), "The stream we uploaded wasn't what was returned.");
}
finally
{
storageClient.DeleteStorageObject(Configuration.ContainerName, Configuration.ObjectName).Wait();
storageClient.DeleteStorageFolder(Configuration.ContainerName, Configuration.FolderName).Wait();
storageClient.DeleteStorageContainer(Configuration.ContainerName).Wait();
}
}
}
}

View File

@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30110.0
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenStack.Test", "OpenStack.Test\OpenStack.Test.csproj", "{7AF6DEC5-2257-4A29-BB55-66711DE3055D}"
EndProject
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenStack40", "OpenStack\Op
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenStack45-PCL", "OpenStack45-PCL\OpenStack45-PCL.csproj", "{5660F8AA-14D5-4B3B-ADA0-F79A286EF483}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenStack.Test.Functional", "OpenStack.Test.Functional\OpenStack.Test.Functional.csproj", "{F4BF7F04-C96B-4287-882D-B0822930DC4F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +35,10 @@ Global
{5660F8AA-14D5-4B3B-ADA0-F79A286EF483}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5660F8AA-14D5-4B3B-ADA0-F79A286EF483}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5660F8AA-14D5-4B3B-ADA0-F79A286EF483}.Release|Any CPU.Build.0 = Release|Any CPU
{F4BF7F04-C96B-4287-882D-B0822930DC4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4BF7F04-C96B-4287-882D-B0822930DC4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4BF7F04-C96B-4287-882D-B0822930DC4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4BF7F04-C96B-4287-882D-B0822930DC4F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE