-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from stjarna/feature/splunk
Splunk Custom Steps
- Loading branch information
Showing
25 changed files
with
919 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...upport-core-test-app/src/main/java/org/jbehavesupport/core/test/app/SplunkController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.jbehavesupport.core.test.app; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.util.StreamUtils; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.util.Map; | ||
|
||
import static java.util.Objects.nonNull; | ||
|
||
@RestController | ||
@RequestMapping("/services") | ||
public class SplunkController { | ||
|
||
public static final String CONTENT_KEY_SEARCH = "search"; | ||
public static final String SEARCH_NO_DATA = "no data"; | ||
|
||
@Value("classpath:splunk/server-info-response.xml") | ||
Resource mockedServerInfoResponse; | ||
|
||
@Value("classpath:splunk/login-response.xml") | ||
Resource mockedLoginResponse; | ||
|
||
@Value("classpath:splunk/search-data-response.json") | ||
Resource mockedSearchDataResponse; | ||
|
||
@Value("classpath:splunk/search-no-data-response.json") | ||
Resource mockedSearchNoDataResponse; | ||
|
||
@PostMapping(value = "/auth/login", | ||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, | ||
produces = MediaType.TEXT_XML_VALUE) | ||
public ResponseEntity<String> login(@RequestParam Map<String, String> body) { | ||
return new ResponseEntity<>(resourceToString(mockedLoginResponse), HttpStatus.OK); | ||
} | ||
|
||
@GetMapping(value = "/server/info", | ||
produces = MediaType.TEXT_XML_VALUE) | ||
public ResponseEntity<String> info() { | ||
return new ResponseEntity<>(resourceToString(mockedServerInfoResponse), HttpStatus.OK); | ||
} | ||
|
||
@PostMapping(value = "/search/jobs", | ||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, | ||
produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<String> search(@RequestParam Map<String, String> body) { | ||
ResponseEntity<String> response = new ResponseEntity<>(resourceToString(mockedSearchDataResponse), HttpStatus.OK); | ||
if (nonNull(body) && shouldNotReturnSearchDataMatch(body)) { | ||
response = new ResponseEntity<>(resourceToString(mockedSearchNoDataResponse), HttpStatus.OK); | ||
} | ||
return response; | ||
} | ||
|
||
private boolean shouldNotReturnSearchDataMatch(Map<String, String> body) { | ||
return body.getOrDefault(CONTENT_KEY_SEARCH, "").contains(SEARCH_NO_DATA); | ||
} | ||
|
||
private String resourceToString(Resource resource) { | ||
try { | ||
return StreamUtils.copyToString(resource.getInputStream(), Charset.defaultCharset()); | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Unable to read resource " + resource.getFilename()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...port-core-test/jbehave-support-core-test-app/src/main/resources/splunk/login-response.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<response> | ||
<sessionKey>HRr5SWhzWRAmmzkF10zqr1nAehUya6vnOex5GO^nupzJsxMdlIEvkIwdxlBbg66NmXq30D8VktgwtD1q5zRRVtdCl1uqdiOTL7oLDsX4RwRuqusapFBjs8Y</sessionKey> | ||
<messages> | ||
<msg code=""></msg> | ||
</messages> | ||
</response> |
36 changes: 36 additions & 0 deletions
36
...re-test/jbehave-support-core-test-app/src/main/resources/splunk/search-data-response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"preview": false, | ||
"init_offset": 0, | ||
"messages": [], | ||
"fields": [ | ||
{ | ||
"name": "host" | ||
}, | ||
{ | ||
"name": "namespace" | ||
}, | ||
{ | ||
"name": "index" | ||
}, | ||
{ | ||
"name": "_time" | ||
}, | ||
{ | ||
"name": "message" | ||
}, | ||
{ | ||
"name": "level" | ||
} | ||
], | ||
"results": [ | ||
{ | ||
"host": "a8210fc9865a", | ||
"namespace": "in00a1-hi-am", | ||
"index": "main", | ||
"_time": "2020-07-10T07:40:26.631+00:00", | ||
"message": "response for https://am.in00a1.cz.infra/cabus-am/rest/openapi/v2/account/persons/147814/accountBalance: 200 OK with headers [Date:\"Fri, 10 Jul 2020 07:39:50 GMT\", Content-Type:\"application/json;charset=UTF-8\", Transfer-Encoding:\"chunked\", Connection:\"keep-alive\", Vary:\"Accept-Encoding\", X-B3-TraceId:\"30a3d60bd3d698eae25eaf5afe3e1df5\", X-B3-SpanId:\"48a4bc7562a346eb\", X-B3-ParentSpanId:\"1017258853b1a1d7\", X-B3-Sampled:\"1\", Cache-Control:\"no-cache, no-store, max-age=0, must-revalidate\", Pragma:\"no-cache\", Expires:\"0\", Strict-Transport-Security:\"max-age=15724800; includeSubDomains\", X-XSS-Protection:\"1; mode=block\", X-Frame-Options:\"DENY\", X-Content-Type-Options:\"nosniff\"]", | ||
"level": "DEBUG" | ||
} | ||
], | ||
"highlighted": {} | ||
} |
7 changes: 7 additions & 0 deletions
7
...test/jbehave-support-core-test-app/src/main/resources/splunk/search-no-data-response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"preview": false, | ||
"init_offset": 0, | ||
"post_process_count": 0, | ||
"messages": [], | ||
"results": [] | ||
} |
129 changes: 129 additions & 0 deletions
129
...ore-test/jbehave-support-core-test-app/src/main/resources/splunk/server-info-response.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?xml-stylesheet type="text/xml" href="/static/atom.xsl"?> | ||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:s="http://dev.splunk.com/ns/rest" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"> | ||
<title>server-info</title> | ||
<id>https://localhost:8089/services/server/info</id> | ||
<updated>2020-07-18T09:19:35+00:00</updated> | ||
<generator build="ab7a85abaa98" version="8.0.4.1"/> | ||
<author> | ||
<name>Splunk</name> | ||
</author> | ||
<opensearch:totalResults>1</opensearch:totalResults> | ||
<opensearch:itemsPerPage>30</opensearch:itemsPerPage> | ||
<opensearch:startIndex>0</opensearch:startIndex> | ||
<s:messages/> | ||
<entry> | ||
<title>server-info</title> | ||
<id>https://localhost:8089/services/server/info/server-info</id> | ||
<updated>1970-01-01T00:00:00+00:00</updated> | ||
<link href="/services/server/info/server-info" rel="alternate"/> | ||
<author> | ||
<name>system</name> | ||
</author> | ||
<link href="/services/server/info/server-info" rel="list"/> | ||
<content type="text/xml"> | ||
<s:dict> | ||
<s:key name="activeLicenseGroup">Trial</s:key> | ||
<s:key name="activeLicenseSubgroup">Production</s:key> | ||
<s:key name="addOns"> | ||
<s:dict> | ||
<s:key name="DFS"> | ||
<s:dict> | ||
<s:key name="parameters"> | ||
<s:dict> | ||
<s:key name="vCPU">0</s:key> | ||
</s:dict> | ||
</s:key> | ||
<s:key name="type">add_on</s:key> | ||
</s:dict> | ||
</s:key> | ||
<s:key name="hadoop"> | ||
<s:dict> | ||
<s:key name="parameters"> | ||
<s:dict> | ||
<s:key name="erp_type">report</s:key> | ||
<s:key name="guid">6F416E61-B40E-461C-A782-CBC186E98133</s:key> | ||
<s:key name="maxNodes">200</s:key> | ||
</s:dict> | ||
</s:key> | ||
<s:key name="type">external_results_provider</s:key> | ||
</s:dict> | ||
</s:key> | ||
</s:dict> | ||
</s:key> | ||
<s:key name="build">ab7a85abaa98</s:key> | ||
<s:key name="cpu_arch">x86_64</s:key> | ||
<s:key name="dfs_enabled">0</s:key> | ||
<s:key name="eai:acl"> | ||
<s:dict> | ||
<s:key name="app"></s:key> | ||
<s:key name="can_list">1</s:key> | ||
<s:key name="can_write">1</s:key> | ||
<s:key name="modifiable">0</s:key> | ||
<s:key name="owner">system</s:key> | ||
<s:key name="perms"> | ||
<s:dict> | ||
<s:key name="read"> | ||
<s:list> | ||
<s:item>*</s:item> | ||
</s:list> | ||
</s:key> | ||
<s:key name="write"> | ||
<s:list/> | ||
</s:key> | ||
</s:dict> | ||
</s:key> | ||
<s:key name="removable">0</s:key> | ||
<s:key name="sharing">system</s:key> | ||
</s:dict> | ||
</s:key> | ||
<s:key name="fips_mode">0</s:key> | ||
<s:key name="guid">5634CE98-7B24-43C0-9A97-00B36F905DE4</s:key> | ||
<s:key name="health_info">green</s:key> | ||
<s:key name="health_version">1</s:key> | ||
<s:key name="host">a8210fc9865a</s:key> | ||
<s:key name="host_fqdn">a8210fc9865a</s:key> | ||
<s:key name="host_resolved">a8210fc9865a</s:key> | ||
<s:key name="isForwarding">0</s:key> | ||
<s:key name="isFree">0</s:key> | ||
<s:key name="isTrial">1</s:key> | ||
<s:key name="kvStoreStatus">ready</s:key> | ||
<s:key name="licenseKeys"> | ||
<s:list> | ||
<s:item>5C52DA5145AD67B8188604C49962D12F2C3B2CF1B82A6878E46F68CA2812807B</s:item> | ||
</s:list> | ||
</s:key> | ||
<s:key name="licenseSignature">c31f28d42cbf21ca3563f0244d70d594</s:key> | ||
<s:key name="licenseState">OK</s:key> | ||
<s:key name="license_labels"> | ||
<s:list> | ||
<s:item>Splunk Enterprise Splunk Analytics for Hadoop Download Trial</s:item> | ||
</s:list> | ||
</s:key> | ||
<s:key name="master_guid">5634CE98-7B24-43C0-9A97-00B36F905DE4</s:key> | ||
<s:key name="master_uri">self</s:key> | ||
<s:key name="max_users">4294967295</s:key> | ||
<s:key name="mode">normal</s:key> | ||
<s:key name="numberOfCores">10</s:key> | ||
<s:key name="numberOfVirtualCores">10</s:key> | ||
<s:key name="os_build">#56~18.04.1-Ubuntu SMP Wed Jun 24 16:17:03 UTC 2020</s:key> | ||
<s:key name="os_name">Linux</s:key> | ||
<s:key name="os_name_extended">Linux</s:key> | ||
<s:key name="os_version">5.3.0-62-generic</s:key> | ||
<s:key name="physicalMemoryMB">23003</s:key> | ||
<s:key name="product_type">enterprise</s:key> | ||
<s:key name="rtsearch_enabled">1</s:key> | ||
<s:key name="serverName">a8210fc9865a</s:key> | ||
<s:key name="server_roles"> | ||
<s:list> | ||
<s:item>indexer</s:item> | ||
<s:item>license_master</s:item> | ||
</s:list> | ||
</s:key> | ||
<s:key name="startup_time">1595056837</s:key> | ||
<s:key name="staticAssetId">C79F504C1A3CB7BEE6C5EE03E10BFDF783961A0DE0E4B0AF6F4D75607F96D04C</s:key> | ||
<s:key name="version">8.0.4.1</s:key> | ||
</s:dict> | ||
</content> | ||
</entry> | ||
</feed> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.