forked from splunk/splunk-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationTest.java
More file actions
131 lines (115 loc) · 5.05 KB
/
ApplicationTest.java
File metadata and controls
131 lines (115 loc) · 5.05 KB
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
/*
* Copyright 2011 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.
*/
package com.splunk;
import org.junit.Test;
public class ApplicationTest extends SplunkTestCase {
final static String assertRoot = "Application assert: ";
private Service cleanApp(String appName, Service service) throws Exception {
splunkRestart();
service = connect();
EntityCollection<Application> apps = service.getApplications();
apps.remove(appName);
splunkRestart();
return connect();
}
// Nota Bene: Splunk needs to be restarted whenever an app is deleted
// (more precisely, needs to be restarted after an app is deleted, AND
// you want to manipulate, or create a new one in its place).
// This test assumes the worst case, and will restart splunk
// before and after an application deletion -- to correct for invalid
// splunk application state.
@Test public void testApps() throws Exception {
Service service = connect();
EntityCollection<Application> apps = service.getApplications();
for (Application app: apps.values()) {
try {
ApplicationSetup applicationSetup = app.setup();
applicationSetup.getSetupXml();
} catch (Exception e) {
// silent exception, if setup doesn't exist, exception occurs
}
app.archive();
app.getAuthor();
app.getCheckForUpdates();
app.getDescription();
app.getLabel();
app.getRefresh();
app.getVersion();
app.isConfigured();
app.isManageable();
app.isVisible();
app.stateChangeRequiresRestart();
ApplicationUpdate applicationUpdate = app.getUpdate();
applicationUpdate.getChecksum();
applicationUpdate.getChecksumType();
applicationUpdate.getHomepage();
applicationUpdate.getSize();
applicationUpdate.getUpdateName();
applicationUpdate.getAppUrl();
applicationUpdate.getVersion();
applicationUpdate.isImplicitIdRequired();
}
if (apps.containsKey("sdk-tests")) {
service = cleanApp("sdk-tests", service);
}
apps = service.getApplications();
assertFalse(assertRoot + "#1", apps.containsKey("sdk-tests"));
Args createArgs = new Args();
createArgs.put("author", "me");
if (service.versionCompare("4.2.4") >= 0) {
createArgs.put("configured", false);
}
createArgs.put("description", "this is a description");
createArgs.put("label", "SDKTEST");
createArgs.put("manageable", false);
createArgs.put("template", "barebones");
createArgs.put("visible", false);
apps.create("sdk-tests", createArgs);
assertTrue(assertRoot + "#2", apps.containsKey("sdk-tests"));
Application app = apps.get("sdk-tests");
app.getCheckForUpdates();
assertEquals(assertRoot + "#3", "SDKTEST", app.getLabel());
assertEquals(assertRoot + "#4", "me", app.getAuthor());
assertFalse(assertRoot + "#5", app.isConfigured());
assertFalse(assertRoot + "#6", app.isManageable());
assertFalse(assertRoot + "#7", app.isVisible());
// update the app
app.setAuthor("not me");
app.setDescription("new description");
app.setLabel("new label");
app.setVisible(false);
app.setManageable(false);
app.setVersion("5.0.0");
app.update();
// check to see if args took.
assertEquals(assertRoot + "#8", "not me", app.getAuthor());
assertEquals(
assertRoot + "#9", "new description", app.getDescription());
assertEquals(assertRoot + "#10", "new label", app.getLabel());
assertFalse(assertRoot + "#11", app.isVisible());
assertEquals(assertRoot + "#12", "5.0.0", app.getVersion());
// archive (package) the application
ApplicationArchive appArchive = app.archive();
assertTrue(assertRoot + "#13", appArchive.getAppName().length() > 0);
assertTrue(assertRoot + "#14", appArchive.getFilePath().length() > 0);
assertTrue(assertRoot + "#15", appArchive.getUrl().length() > 0);
ApplicationUpdate appUpdate = app.getUpdate();
assertTrue(assertRoot + "#16", appUpdate.containsKey("eai:acl"));
service = cleanApp("sdk-tests", service);
apps = service.getApplications();
assertFalse(assertRoot + "#17", apps.containsKey("sdk-tests"));
}
}