This repository was archived by the owner on Jul 20, 2024. It is now read-only.
forked from splunk/splunk-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigurationTest.java
More file actions
136 lines (116 loc) · 5.08 KB
/
ConfigurationTest.java
File metadata and controls
136 lines (116 loc) · 5.08 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
132
133
134
135
136
/*
* 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.
*/
package com.splunk;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class ConfigurationTest extends SDKTestCase {
private Service appService;
private String applicationName;
@Before
@Override
public void setUp() throws Exception {
super.setUp();
// We cannot straightforwardly delete confs,
// so instead we create a temporary application,
// reconnect using its namespace, then delete it
// when we're done.
applicationName = createTemporaryName();
service.getApplications().create(applicationName);
// We cannot easily change the namespace of service,
// so rather than fight with it, we create a new
// service with the right namespace and work from it
// instead. Then we'll return to service in tearDown
// to clean up.
// NOTE: If you ever have to put a restart into
// the configuration tests, then you will need
// to explicitly re-login appService, since it will
// not be re-logged in by the call to restartSplunk.
Args applicationArgs = new Args(command.opts);
applicationArgs.put("sharing", "app");
applicationArgs.put("owner", "nobody");
applicationArgs.put("app", applicationName);
appService = Service.connect(applicationArgs);
}
@After
@Override
public void tearDown() throws Exception {
appService.logout();
final EntityCollection<Application> apps = service.getApplications();
apps.remove(applicationName);
assertEventuallyTrue(new EventuallyTrueBehavior() {
@Override
public boolean predicate() {
return !apps.refresh().containsKey(applicationName);
}
});
clearRestartMessage();
super.tearDown();
}
@Test
public void testStandardFilesExist() {
ConfCollection confs = appService.getConfs();
Assert.assertTrue(confs.containsKey("eventtypes"));
Assert.assertTrue(confs.containsKey("indexes"));
Assert.assertTrue(confs.containsKey("inputs"));
Assert.assertTrue(confs.containsKey("props"));
Assert.assertTrue(confs.containsKey("transforms"));
Assert.assertTrue(confs.containsKey("savedsearches"));
for (Entity stanza : confs.get("indexes").values()) {
Assert.assertNotNull(stanza);
Assert.assertNotNull(stanza.getName());
Assert.assertNotNull(stanza.getPath());
}
}
@Test
public void testCreateConf() {
ConfCollection confs = appService.getConfs();
String confName = createTemporaryName();
Assert.assertFalse("New configuration name already used.", confs.containsKey(confName));
EntityCollection<Entity> conf = confs.create(confName);
Assert.assertTrue("New configuration doesn't show up after creation.", confs.containsKey(confName));
Assert.assertEquals("New configuration is not empty.", 0, conf.size());
}
@Test
public void testCreateAndDeleteStanza() {
ConfCollection confs = appService.getConfs();
String confName = createTemporaryName();
EntityCollection<Entity> conf = confs.create(confName);
String stanzaName = createTemporaryName();
Assert.assertFalse("Stanza already exists.", conf.containsKey(stanzaName));
Entity stanza = conf.create(stanzaName);
Assert.assertTrue("Stanza doesn't show up after creation.", conf.containsKey(stanzaName));
Assert.assertEquals("Stanza contains something besides eai: and disabled attributes when first created.", 5, stanza.size());
stanza.remove();
conf.refresh();
Assert.assertFalse("Stanza not deleted by remove()", conf.containsKey(stanzaName));
}
@Test
public void testWriteToStanza() {
ConfCollection confs = appService.getConfs();
String confName = createTemporaryName();
EntityCollection<Entity> conf = confs.create(confName);
String stanzaName = createTemporaryName();
Entity stanza = conf.create(stanzaName);
Assert.assertEquals("Stanza begins with only eai:* and disabled in it.", 5, stanza.size());
Args args = new Args();
args.put("test-key", "42");
stanza.update(args);
Assert.assertEquals("Stanza has right size after write.", 6, stanza.size());
Assert.assertEquals("Read from key gives right value.", "42", stanza.get("test-key"));
}
}