Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

/api/resources endpoint was removed in SonarQube 6.3 and later, so … #24

Open
wants to merge 88 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
5cbb73b
Introduced new classes. Refactoring
bradeac Jun 7, 2016
dc725ed
Refactoring. New features. Using the new stuff from common.
bradeac Jun 7, 2016
25677a7
Compiled recent changes
bradeac Jun 7, 2016
4fe17b5
Minor changes
bradeac Jun 7, 2016
a455d68
Using new stuff from common.
bradeac Jun 7, 2016
e78a8fe
Introducing Fetch any artifact plugin
bradeac Jun 15, 2016
3f7e58b
Introducing Fetch any artifact plugin
bradeac Jun 15, 2016
e94cbf7
Compiled recent changes
bradeac Jun 16, 2016
d0651ef
Bug fixing. New stuff for the fetch any artifact plugin
bradeac Jun 17, 2016
b512358
Bug fixing - docker plugin
bradeac Jun 22, 2016
2578752
Compiled recent changes
bradeac Jun 22, 2016
2bddede
Added "fetch even if failed" feature
bradeac Jun 30, 2016
f35bf27
Compiled recent changes
bradeac Jun 30, 2016
3914a55
New features
bradeac Jul 4, 2016
54fa02d
Docker compose plugin
bradeac Jul 4, 2016
d2aebe8
Docker machine plugin
bradeac Jul 4, 2016
1efdc91
Compiled recent changes
bradeac Jul 4, 2016
e99dc41
Compiled recent changes
bradeac Jul 4, 2016
62e5ef0
Added docker compose and docker machine plugin
bradeac Jul 4, 2016
a42d62d
Artifact id change and plugin name change
bradeac Jul 5, 2016
fe46a63
New features - docker plugins
bradeac Jul 22, 2016
4809449
New features
bradeac Jul 22, 2016
bdd0dcb
New features - docker plugin
bradeac Jul 22, 2016
7a8dd98
Circumvent complicated container ID parsing by specifying --name with…
DonMartin76 Jul 26, 2016
6f4f0dc
It's been a while since I last coded in Java.
DonMartin76 Jul 26, 2016
044bdad
Allow non-registry image name for docker build.
DonMartin76 Jul 26, 2016
274d1df
docker starts need an -a, otherwise it exits immediately.
DonMartin76 Jul 26, 2016
6369949
Merge pull request #4 from DonMartin76/master
bradeac Jul 26, 2016
4c76e7c
Fix: Leave out registry if it's docker.io or hub.docker.com.
DonMartin76 Aug 2, 2016
dc16793
Introducing Fortify plugin
bradeac Aug 2, 2016
3b57091
Merge remote-tracking branch 'origin/master'
bradeac Aug 2, 2016
16256c2
Rest of fortify plugins files
bradeac Aug 2, 2016
73ff2cb
Compiled Fortify plugin
bradeac Aug 2, 2016
066f001
Merge remote-tracking branch 'haufe/master'
DonMartin76 Aug 3, 2016
e0945de
Better looking logging :)
bradeac Aug 3, 2016
8af389c
Merge pull request #5 from DonMartin76/master
bradeac Aug 3, 2016
5286fde
Refactored: using enums
bradeac Aug 8, 2016
fa0cf45
Fixed inconsistent handling of "machine-names" when reading from conf…
Aug 8, 2016
08eaa37
Removed hardcoded URL. Used getters
bradeac Aug 11, 2016
896e159
Added getters
bradeac Aug 22, 2016
09c02cd
Merge remote-tracking branch 'origin/master'
bradeac Aug 22, 2016
fd18596
Test for Fortify plugin
bradeac Aug 22, 2016
81a8a56
Remove shell. Using direct execution of commands.
bradeac Aug 22, 2016
14585b6
Login and push to docker hub. Tests
bradeac Aug 22, 2016
5141a77
Reverted to the previous artifactID
bradeac Aug 22, 2016
1fd3fff
Compiled recent changes.
bradeac Aug 22, 2016
c6c01ef
Mod in DockerMachineTaskExecutor: "generic-driver" IP-addresses are e…
Aug 30, 2016
fb2a44b
Fix Removed duplicate dependency in fortify-plugin pom file
Aug 30, 2016
62ae5ae
Merge pull request #8 from thomsch98/master
bradeac Aug 30, 2016
f9a29bb
Add (but not enabled) experimentale "bundle" feature
Sep 2, 2016
26fba4c
Temporary fix. Latest version of go.cd removed trailing / from URL
bradeac Sep 5, 2016
124e4c4
Merge remote-tracking branch 'origin/master'
bradeac Sep 5, 2016
f3488cb
Merge pull request #9 from thomsch98/master
bradeac Sep 6, 2016
d9f5b94
Temporary fix. Latest version of go.cd removed trailing / from URL. F…
bradeac Sep 7, 2016
5b4bb28
Removed unnecessary logging
bradeac Sep 7, 2016
0664b9a
DockerRemoveAllContainers.java: removing all the containers, not just…
bradeac Sep 7, 2016
b7daa85
Fix api url and add parameters update.
Oct 11, 2016
2e6fb11
Checking if PIPELINE_COUNTER from the fileName == actual PIPELINE_COU…
bradeac Oct 19, 2016
0b21aa4
Merge branch 'master' of https://github.com/Haufe-Lexware/gocd-plugins
bradeac Oct 19, 2016
28bad44
Added Edit Host action
Dutzu Dec 5, 2016
33dcef0
Merge pull request #10 from Dutzu/master
Dec 5, 2016
af9d201
Remove Authorization logs
Jan 3, 2017
7795b1c
Fixed bug: ARTIFACT_IS_FILE selection not working
bradeac Jan 16, 2017
468a57c
Added the microlabeling feature
bradeac Feb 3, 2017
1d2e3b6
Fixed removeHost not working. Compiled latest changes.
bradeac Feb 8, 2017
87284d8
html file added - Added microlabeling feature
bradeac Feb 9, 2017
ca22df2
Temporarily commented out failed tests
bradeac Mar 2, 2017
e5c1c99
Skipping common tests for now ...
bradeac Mar 2, 2017
5c9128f
New plugin version.
bradeac Apr 26, 2017
a13be02
-f when doing docker rmi
bradeac Apr 28, 2017
01732bb
Updated Sonar plugin to use the latest stuff from common
bradeac May 30, 2017
db56974
Compiled latest Sonar plugin changes
bradeac May 30, 2017
043349e
Changed "go-target-version" for sonar plugin
bradeac May 30, 2017
b395cf2
Added auth method to obtain project's Quality Gate when Sonarqube ano…
Jun 6, 2017
48dcbab
Merge pull request #15 from droberin/master
bradeac Jun 13, 2017
50239ca
Fixed for the case when the scan has no issues. Compiled latest changes.
bradeac Jun 26, 2017
d4dac02
Fortify plugin for go.cd version 17.3. Compiled recent changes.
bradeac Jun 27, 2017
1342886
Fixed bug when deciding if a scan is successful or not
bradeac Jul 6, 2017
cdfa65c
Sonar plugin: removed unnecessary auth
bradeac Jul 10, 2017
844af08
Fixed microlabeling issue. Compiled recent changes.
bradeac Jul 11, 2017
a4bdf74
go.cd API changed for getting pipeline config
bradeac Jul 11, 2017
9766fb0
Updated test.properties
bradeac Jul 11, 2017
43a3207
Commented out failed tests
bradeac Jul 11, 2017
80e68d5
Fixed sonar plugin bug where pipeline passes even if REST call to son…
bradeac Jul 19, 2017
f8d7b7c
Merge branch 'master' of https://github.com/Haufe-Lexware/gocd-plugins
bradeac Jul 19, 2017
5944b98
Added sonar scan date and sonar scan version to console logs. Compile…
bradeac Jul 19, 2017
1756a54
Fixed fortify. The plugin is now waiting to get the newest scan. Comp…
bradeac Jul 20, 2017
a4b5189
/api/resources endpoint was removed in SonarQube 6.3 and later, so th…
Jan 26, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

*/target/*
out/*.jar
target/lib/*.jar
Empty file modified bin/go-plugin-api-15.1.0.jar
100644 → 100755
Empty file.
Binary file modified bin/gocd-check_mk-plugin-1.0.0.jar
Binary file not shown.
Binary file added bin/gocd-docker-compose-plugin-1.0.0.jar
Binary file not shown.
Binary file added bin/gocd-docker-machine-plugin-1.0.0.jar
Binary file not shown.
Binary file modified bin/gocd-docker-pipeline-plugin-1.0.0.jar
Binary file not shown.
Binary file added bin/gocd-docker-plugin-2.0.0.jar
Binary file not shown.
Binary file added bin/gocd-fetch-any-artifact-plugin-1.0.0.jar
Binary file not shown.
Binary file added bin/gocd-fortify-plugin-1.0.0.jar
Binary file not shown.
Empty file modified bin/gocd-nessus-scan-plugin-1.0.0.jar
100644 → 100755
Empty file.
Empty file modified bin/gocd-plugin-common-1.0.0.jar
100644 → 100755
Empty file.
Binary file modified bin/gocd-sonar-qualitygates-plugin-1.0.0.jar
100644 → 100755
Binary file not shown.
14 changes: 14 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

mvn install:install-file \
-Dfile=bin/go-plugin-api-15.1.0.jar \
-DgroupId=com.thoughtworks.go \
-DartifactId=go-plugin-api \
-Dversion=15.1.0 \
-Dpackaging=jar && \
\
mvn clean \
package \
-DskipTests && \
\
mvn cobertura:cobertura
4 changes: 2 additions & 2 deletions check_mk-plugin/pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<go.target.version>15.1.0</go.target.version>
<go.version>15.1.0</go.version>
<go.target.version>16.4.0</go.target.version>
<go.version>16.4.0</go.version>
<plugin.version>${project.version}</plugin.version>

<sonar.java.coveragePlugin>cobertura</sonar.java.coveragePlugin>
Expand Down
Empty file modified check_mk-plugin/resources/plugin.xml
100644 → 100755
Empty file.
Empty file modified check_mk-plugin/resources/test.properties
100644 → 100755
Empty file.
30 changes: 30 additions & 0 deletions check_mk-plugin/resources/views/checkMk.template.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<select ng-init="SelectedAction='default'" ng-model="SelectedAction" >
<option selected disabled value="default">Select action</option>
<option value="add">Add Host</option>
<option value="edit">Edit Host</option>
<option value="remove">Remove Host</option>
</select>
</br>
Expand Down Expand Up @@ -59,6 +60,35 @@
</div>
</div>
</div>
<div ng-switch-when="edit">
<div class="form_item_block">
<label>Hostname:<span class="asterisk">*</span>
</label>
<input type="text" ng-model="Hostname" ng-required="true">
</input>
<div role="alert">
<span class="error" color="red" ng-show="GOINPUTNAME[Hostname].$error.required" >Required!</span>
</div>
</div>
<div class="form_item_block">
<label>New Host ip:<span class="asterisk">*</span>
</label>
<input type="text" ng-model="HostIp" ng-required="true">
</input>
<div role="alert">
<span class="error" color="red" ng-show="GOINPUTNAME[HostIp].$error.required" >Required!</span>
</div>
</div>
<div class="form_item_block">
<label>New Folder path:<span class="asterisk">*</span>
</label>
<input type="text" ng-model="FolderPath" ng-required="true">
</input>
<div role="alert">
<span class="error" color="red" ng-show="GOINPUTNAME[FolderPath].$error.required" >Required!</span>
</div>
</div>
</div>
<div ng-switch-when="remove">
<div class="form_item_block">
<label>Hostname:<span class="asterisk">*</span>
Expand Down
Empty file.
Empty file.
Empty file.
Empty file modified check_mk-plugin/src/com/tw/go/task/check_mk/AddHostJob.java
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion check_mk-plugin/src/com/tw/go/task/check_mk/AddHostTaskExecutor.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public AddHostTaskExecutor(JobConsoleLogger console, Context context, Map config
super(console, context, config);
}

public Result execute() {
public Result execute() throws Exception {
try {
String hostname = (String) ((Map) this.config.get(CheckMkTask.HOSTNAME)).get("value");
String serverIp = (String) ((Map) this.config.get(CheckMkTask.HOST_IP)).get("value");
Expand Down
Empty file modified check_mk-plugin/src/com/tw/go/task/check_mk/CheckMkClient.java
100644 → 100755
Empty file.
Empty file modified check_mk-plugin/src/com/tw/go/task/check_mk/CheckMkJob.java
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions check_mk-plugin/src/com/tw/go/task/check_mk/CheckMkRequestObjectFactory.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ public static JSONObject CreateAddHostObject(String folderName, String hostname,
return objAddHost;
}

public static JSONObject CreateEditHostObject(String folderName, String hostname, String serverIp)throws Exception
{
JSONObject objCreateAttributes = new JSONObject();
objCreateAttributes.put("ipaddress", serverIp);
JSONObject objAddHost= new JSONObject();
objAddHost.put("folder", folderName);
objAddHost.put("hostname", hostname);
objAddHost.put("attributes", objCreateAttributes);
return objAddHost;
}

public static JSONObject CreateRemoveHostObject(String hostname)throws Exception
{
JSONObject objRemoveHost= new JSONObject();
Expand Down
65 changes: 21 additions & 44 deletions check_mk-plugin/src/com/tw/go/task/check_mk/CheckMkTask.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@
package com.tw.go.task.check_mk;

import com.google.gson.GsonBuilder;
import com.thoughtworks.go.plugin.api.GoApplicationAccessor;
import com.thoughtworks.go.plugin.api.GoPlugin;
import com.thoughtworks.go.plugin.api.GoPluginIdentifier;
import com.thoughtworks.go.plugin.api.annotation.Extension;
import com.thoughtworks.go.plugin.api.exceptions.UnhandledRequestTypeException;
import com.thoughtworks.go.plugin.api.logging.Logger;
import com.thoughtworks.go.plugin.api.request.GoPluginApiRequest;
import com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse;
import com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse;
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
import com.thoughtworks.go.plugin.api.task.JobConsoleLogger;
import com.tw.go.plugin.common.Context;
import com.tw.go.plugin.common.Result;
import com.tw.go.plugin.common.*;
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@Extension
public class CheckMkTask implements GoPlugin {
public class CheckMkTask extends BaseGoPlugin {

public static final String CHECK_MK_SERVER="Server";
public static final String CHECK_MK_SERVER = "Server";
public static final String HOSTNAME = "Hostname";
public static final String HOST_IP = "HostIp";
public static final String FOLDER_PATH = "FolderPath";
Expand All @@ -34,29 +30,12 @@ public class CheckMkTask implements GoPlugin {
private Logger logger = Logger.getLoggerFor(CheckMkTask.class);

@Override
public void initializeGoApplicationAccessor(GoApplicationAccessor goApplicationAccessor) {
}

@Override
public GoPluginApiResponse handle(GoPluginApiRequest request) throws UnhandledRequestTypeException {
if ("configuration".equals(request.requestName())) {
return handleGetConfigRequest();
} else if ("validate".equals(request.requestName())) {
return handleValidation(request);
} else if ("execute".equals(request.requestName())) {
return handleTaskExecution(request);
} else if ("view".equals(request.requestName())) {
return handleTaskView();
}
throw new UnhandledRequestTypeException(request.requestName());
}

private GoPluginApiResponse handleTaskView() {
protected GoPluginApiResponse handleTaskView(GoPluginApiRequest request) {
int responseCode = DefaultGoApiResponse.SUCCESS_RESPONSE_CODE;
HashMap view = new HashMap();
view.put("displayValue", "Monitoring - Check MK");
try {
String checkMkTemplate=IOUtils.toString(getClass().getResourceAsStream("/views/checkMk.template.html"), "UTF-8");
String checkMkTemplate = IOUtils.toString(getClass().getResourceAsStream("/views/checkMk.template.html"), "UTF-8");
view.put("template", checkMkTemplate);
} catch (Exception e) {
responseCode = DefaultGoApiResponse.INTERNAL_ERROR;
Expand All @@ -67,29 +46,26 @@ private GoPluginApiResponse handleTaskView() {
return createResponse(responseCode, view);
}

private GoPluginApiResponse handleTaskExecution(GoPluginApiRequest request) {
@Override
protected GoPluginApiResponse handleTaskExecution(GoPluginApiRequest request) throws Exception {
Map executionRequest = (Map) new GsonBuilder().create().fromJson(request.requestBody(), Object.class);
Map config = (Map) executionRequest.get("config");
Map contextMap = (Map) executionRequest.get("context");
JobConsoleLogger consoleLogger=JobConsoleLogger.getConsoleLogger();

Map<String, Map> config = (Map) executionRequest.get("config");

Context context = new Context((Map) executionRequest.get("context"));

try {
CheckMkTaskExecutor checkMkTaskExecutor=TaskExecutorFactory.Create(consoleLogger, new Context(contextMap), config);
CheckMkTaskExecutor checkMkTaskExecutor = TaskExecutorFactory.Create(MaskingJobConsoleLogger.getConsoleLogger(),
context, config);
Result result = checkMkTaskExecutor.execute();
return createResponse(result.responseCode(), result.toMap());
}
catch (JobNotSupportedException e)
{
consoleLogger.printLine(e.getMessage());
return createResponse( DefaultGoApiResponse.INTERNAL_ERROR,null);
}
catch(Exception e)
{
consoleLogger.printLine(e.getMessage());
return createResponse( DefaultGoApiResponse.INTERNAL_ERROR,null);
} catch (JobNotSupportedException | IOException e) {
return success(new Result(false, e.getMessage()));
}
}

private GoPluginApiResponse handleValidation(GoPluginApiRequest request) {
@Override
protected GoPluginApiResponse handleValidation(GoPluginApiRequest request) {
HashMap validationResult = new HashMap();
int responseCode = DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE;
Map configMap = (Map) new GsonBuilder().create().fromJson(request.requestBody(), Object.class);
Expand All @@ -104,7 +80,8 @@ private GoPluginApiResponse handleValidation(GoPluginApiRequest request) {

// return json description to tell go.cd which config properties need to be stored
// sample and schema can be found at http://www.go.cd/documentation/developer/writing_go_plugins/task/version_1_0/configuration.html
private GoPluginApiResponse handleGetConfigRequest() {
@Override
protected GoPluginApiResponse handleGetConfigRequest(GoPluginApiRequest request) {

HashMap config = new HashMap();

Expand Down
3 changes: 0 additions & 3 deletions check_mk-plugin/src/com/tw/go/task/check_mk/CheckMkTaskExecutor.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.thoughtworks.go.plugin.api.task.JobConsoleLogger;
import com.tw.go.plugin.common.Context;
import com.tw.go.plugin.common.Result;
import com.tw.go.plugin.common.TaskExecutor;
import org.json.JSONObject;

Expand All @@ -15,8 +14,6 @@ public CheckMkTaskExecutor(JobConsoleLogger console, Context context, Map config
super(console, context, config);
}

public abstract Result execute() ;

protected String getPluginLogPrefix() {
return "[Check_Mk Task] ";
}
Expand Down
12 changes: 12 additions & 0 deletions check_mk-plugin/src/com/tw/go/task/check_mk/EditHostException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.tw.go.task.check_mk;

import org.json.JSONObject;

public class EditHostException extends Exception
{
public EditHostException(JSONObject requestObject, JSONObject resultObject)
{
super("Failed to edit host "+requestObject.get("hostname")+". " +resultObject.get("result"));
}
}

24 changes: 24 additions & 0 deletions check_mk-plugin/src/com/tw/go/task/check_mk/EditHostJob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.tw.go.task.check_mk;

import org.json.JSONObject;

public class EditHostJob extends CheckMkJob
{
public EditHostJob(ICheckMkClient checkMkClient) {
super(checkMkClient);
Action="edit_host";
Parameters="";
}

@Override
public String Execute(JSONObject requestObject) throws Exception {
JSONObject jsonResult = ExecuteWebRequest(requestObject);
if(!jsonResult.get("result_code").toString().equals("0"))
{
throw new EditHostException(requestObject,jsonResult);
}
return "Host "+requestObject.get("hostname")+" updated.";
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

package com.tw.go.task.check_mk;


import com.thoughtworks.go.plugin.api.task.JobConsoleLogger;
import com.tw.go.plugin.common.Context;
import com.tw.go.plugin.common.Result;
import org.json.JSONObject;

import java.util.Map;

public class EditHostTaskExecutor extends CheckMkTaskExecutor {

public EditHostTaskExecutor(JobConsoleLogger console, Context context, Map config) {
super(console, context, config);
}

public Result execute() throws Exception {
try {
String hostname = (String) ((Map) this.config.get(CheckMkTask.HOSTNAME)).get("value");
String serverIp = (String) ((Map) this.config.get(CheckMkTask.HOST_IP)).get("value");
String folderPath = (String) ((Map) this.config.get(CheckMkTask.FOLDER_PATH)).get("value");
ServerCredentials credentials = CreateCredentials();
TryInitClient(credentials);
CheckMkJob checkMkJob = new EditHostJob(checkMkClient);
JSONObject requestObject = CheckMkRequestObjectFactory.CreateEditHostObject(folderPath, hostname, serverIp);
ExecuteJob(requestObject, checkMkJob);
return new Result(true, "Edit host was successful.");
} catch (Exception e) {
log("Exception. " + e.getMessage());
return new Result(false, "Edit host failed", e);
}
}

protected String getPluginLogPrefix() {
return "[Edit Host Task] ";
}

public void setCheckMkClient(ICheckMkClient checkMkClient) {
this.checkMkClient = checkMkClient;
}
}

Empty file modified check_mk-plugin/src/com/tw/go/task/check_mk/ICheckMkClient.java
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file modified check_mk-plugin/src/com/tw/go/task/check_mk/RemoveHostJob.java
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion check_mk-plugin/src/com/tw/go/task/check_mk/RemoveHostTaskExecutor.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public RemoveHostTaskExecutor(JobConsoleLogger console, Context context, Map con
super(console, context, config);
}

public Result execute() {
public Result execute() throws Exception {
try {
String hostname = (String) ((Map) this.config.get(CheckMkTask.HOSTNAME)).get("value");
ServerCredentials credentials = CreateCredentials();
Expand Down
Empty file.
18 changes: 11 additions & 7 deletions check_mk-plugin/src/com/tw/go/task/check_mk/TaskExecutorFactory.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@

import java.util.Map;

public class TaskExecutorFactory
{
public class TaskExecutorFactory {
public static CheckMkTaskExecutor Create(JobConsoleLogger console, Context context, Map config) throws JobNotSupportedException {
String action = (String) ((Map) config.get(CheckMkTask.ACTION)).get("value");
switch (action)
{
case "add":return new AddHostTaskExecutor(console,context,config);
case "remove":return new RemoveHostTaskExecutor(console,context,config);
switch (action) {
case "add":
return new AddHostTaskExecutor(console, context, config);
case "edit":
return new EditHostTaskExecutor(console, context, config);
case "remove":
((Map) config.get(CheckMkTask.FOLDER_PATH)).put("value", "");
((Map) config.get(CheckMkTask.HOST_IP)).put("value", "");
return new RemoveHostTaskExecutor(console, context, config);
}
throw new JobNotSupportedException("Action "+action+" not supported!");
throw new JobNotSupportedException("Action " + action + " not supported!");
}
}
Empty file.
Empty file.
Empty file.
Empty file modified check_mk-plugin/test/com/tw/go/task/check_mk/CheckMkStub.java
100644 → 100755
Empty file.
33 changes: 33 additions & 0 deletions check_mk-plugin/test/com/tw/go/task/check_mk/EditHostJobTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.tw.go.task.check_mk;

import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
public class EditHostJobTests {

@BeforeClass
public static void Init() throws Exception {
CheckMkStub.init();

}

@Test(expected = EditHostException.class)
public void Execute_RequestFailed_ThrowException() throws Exception {
CheckMkStub.SetupRequestError();
CheckMkJob job = new EditHostJob(CheckMkStub.checkMkClient);

job.Execute(CheckMkRequestObjectFactory.CreateEditHostObject(CheckMkStub.folderPath, CheckMkStub.hostName, CheckMkStub.hostIp));
}

@Test
public void Execute_RequestSuccess_ReturnsOkMessage() throws Exception {
CheckMkStub.SetupRequestOk();
CheckMkJob job = new EditHostJob(CheckMkStub.checkMkClient);

String result = job.Execute(CheckMkRequestObjectFactory.CreateEditHostObject(CheckMkStub.folderPath, CheckMkStub.hostName, CheckMkStub.hostIp));

assertEquals(result, "Host test updated.");
}
}

Loading