This repository was archived by the owner on Sep 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathApplicationTest.cs
168 lines (153 loc) · 6.51 KB
/
ApplicationTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* Copyright 2012 Splunk, Inc.
*
* 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.
*/
namespace UnitTests
{
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Splunk;
/// <summary>
/// Application tests
/// </summary>
[TestClass]
public class ApplicationTest : TestHelper
{
/// <summary>
/// The assert root string
/// </summary>
private static string assertRoot = "Application assert: ";
/// <summary>
/// Cleans an application from Splunk -- requires a restart
/// </summary>
/// <param name="appName">The app name</param>
/// <param name="service">The connected service</param>
/// <returns>The new connection</returns>
private Service CleanApp(string appName, Service service)
{
this.SplunkRestart();
service = this.Connect();
EntityCollection<Application> apps = service.GetApplications();
apps.Remove(appName);
this.SplunkRestart();
return this.Connect();
}
/// <summary>
/// The app tests
/// </summary>
[TestMethod]
public void Application()
{
string dummyString;
bool dummyBool;
int dummyInt;
Service service = Connect();
EntityCollection<Application> apps = service.GetApplications();
foreach (Application app in apps.Values)
{
try
{
ApplicationSetup applicationSetup = app.Setup();
string setupXml = applicationSetup.SetupXml;
}
catch (Exception)
{
// silent exception, if setup doesn't exist, exception occurs
}
ApplicationArchive applicationArchive = app.Archive();
dummyString = app.Author;
dummyBool = app.CheckForUpdates;
dummyString = app.Description;
dummyString = app.Label;
dummyBool = app.Refreshes;
dummyString = app.Version;
dummyBool = app.IsConfigured;
if (service.VersionCompare("5.0") < 0)
{
dummyBool = app.IsManageable;
}
dummyBool = app.IsVisible;
dummyBool = app.StateChangeRequiresRestart;
ApplicationUpdate applicationUpdate = app.AppUpdate();
dummyString = applicationUpdate.Checksum;
dummyString = applicationUpdate.ChecksumType;
dummyString = applicationUpdate.Homepage;
dummyInt = applicationUpdate.UpdateSize;
dummyString = applicationUpdate.UpdateName;
dummyString = applicationUpdate.AppUrl;
dummyString = applicationUpdate.Version;
dummyBool = applicationUpdate.IsImplicitIdRequired;
}
if (apps.ContainsKey("sdk-tests"))
{
service = this.CleanApp("sdk-tests", service);
}
apps = service.GetApplications();
Assert.IsFalse(apps.ContainsKey("sdk-tests"), assertRoot + "#1");
Args createArgs = new Args();
createArgs.Add("author", "me");
if (service.VersionCompare("4.2.4") >= 0)
{
createArgs.Add("configured", false);
}
createArgs.Add("description", "this is a description");
createArgs.Add("label", "SDKTEST");
if (service.VersionCompare("5.0") < 0)
{
createArgs.Add("manageable", false);
}
createArgs.Add("template", "barebones");
createArgs.Add("visible", false);
apps.Create("sdk-tests", createArgs);
Assert.IsTrue(apps.ContainsKey("sdk-tests"), assertRoot + "#2");
Application app2 = apps.Get("sdk-tests");
dummyBool = app2.CheckForUpdates;
Assert.AreEqual("SDKTEST", app2.Label, assertRoot + "#3");
Assert.AreEqual("me", app2.Author, assertRoot + "#4");
Assert.IsFalse(app2.IsConfigured, assertRoot + "#5");
if (service.VersionCompare("5.0") < 0)
{
Assert.IsFalse(app2.IsManageable, assertRoot + "#6");
}
Assert.IsFalse(app2.IsVisible, assertRoot + "#7");
// update the app
app2.Author = "not me";
app2.Description = "new description";
app2.Label = "new label";
app2.IsVisible = false;
if (service.VersionCompare("5.0") < 0)
{
app2.IsManageable = false;
}
app2.Version = "5.0.0";
app2.Update();
// check to see if args took.
Assert.AreEqual("not me", app2.Author, assertRoot + "#8");
Assert.AreEqual("new description", app2.Description, assertRoot + "#9");
Assert.AreEqual("new label", app2.Label, assertRoot + "#10");
Assert.IsFalse(app2.IsVisible, assertRoot + "#11");
Assert.AreEqual("5.0.0", app2.Version, assertRoot + "#12");
// archive (package) the application
ApplicationArchive appArchive = app2.Archive();
Assert.IsTrue(appArchive.AppName.Length > 0, assertRoot + "#13");
Assert.IsTrue(appArchive.FilePath.Length > 0, assertRoot + "#14");
Assert.IsTrue(appArchive.Url.Length > 0, assertRoot + "#15");
ApplicationUpdate appUpdate = app2.AppUpdate();
Assert.IsTrue(appUpdate.ContainsKey("eai:acl"), assertRoot + "#16");
service = this.CleanApp("sdk-tests", service);
apps = service.GetApplications();
Assert.IsFalse(apps.ContainsKey("sdk-tests"), assertRoot + "#17");
}
}
}