Application:
此类设计用于处理应用程序。
application.create: 创建新应用程序
application.delete: 删除应用程序
application.exists: 检查应用程序是否存在
application.get: 检索应用
application.massadd: 更新中的应用
application.update: 将项目添加到应用程序



ApplicationCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.application;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.application.ApplicationCreateRequest;
import com.zabbix4j.application.ApplicationCreateResponse;
import com.zabbix4j.application.ApplicationDeleteRequest;
import com.zabbix4j.application.ApplicationDeleteResponse;
/**
* Created by Suguru Yajima on 2014/05/22.
*/
public class ApplicationCreateTest extends ZabbixApiTestBase {
public ApplicationCreateTest() {
super();
}
@Test
public void testCreate1() throws Exception {
ApplicationCreateRequest request = new ApplicationCreateRequest();
ApplicationCreateRequest.Params params = request.getParams();
params.setName("Application crated");
params.setHostid(10084);
ApplicationCreateResponse response = zabbixApi.application().create(request);
assertNotNull(response);
Integer id = response.getResult().getApplicationids().get(0);
assertNotNull(id);
delete(id);
}
private void delete(Integer id) throws ZabbixApiException {
ApplicationDeleteRequest request = new ApplicationDeleteRequest();
request.addParams(id);
ApplicationDeleteResponse response = zabbixApi.application().delete(request);
}
}
ApplicationDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.application;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.application.ApplicationCreateRequest;
import com.zabbix4j.application.ApplicationCreateResponse;
import com.zabbix4j.application.ApplicationDeleteRequest;
import com.zabbix4j.application.ApplicationDeleteResponse;
/**
* Created by Suguru Yajima on 2014/05/23.
*/
public class ApplicationDeleteTest extends ZabbixApiTestBase {
public ApplicationDeleteTest() {
super();
}
@Test
public void testDelete() throws Exception {
Integer expect = createDummy();
ApplicationDeleteRequest request = new ApplicationDeleteRequest();
request.addParams(expect);
ApplicationDeleteResponse response = zabbixApi.application().delete(request);
assertNotNull(response);
Integer actual = response.getResult().getApplicationids().get(0);
assertEquals(expect, actual);
}
private Integer createDummy() throws ZabbixApiException {
ApplicationCreateRequest request = new ApplicationCreateRequest();
ApplicationCreateRequest.Params params = request.getParams();
params.setName("Application before delete");
params.setHostid(10084);
ApplicationCreateResponse response = zabbixApi.application().create(request);
assertNotNull(response);
Integer id = response.getResult().getApplicationids().get(0);
return id;
}
}
ApplicationGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.application;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.application.ApplicationCreateRequest;
import com.zabbix4j.application.ApplicationCreateResponse;
import com.zabbix4j.application.ApplicationDeleteRequest;
import com.zabbix4j.application.ApplicationDeleteResponse;
import com.zabbix4j.application.ApplicationGetRequest;
import com.zabbix4j.application.ApplicationGetResponse;
/**
* Created by Suguru Yajima on 2014/05/24.
*/
public class ApplicationGetTest extends ZabbixApiTestBase {
public ApplicationGetTest() {
super();
}
@Test
public void testGet() throws Exception {
ArrayList<Integer> ids = new ArrayList<Integer>();
ids.add(createDummy());
ids.add(createDummy2());
Integer hostId = 10084;
ApplicationGetRequest request = new ApplicationGetRequest();
ApplicationGetRequest.Params params = request.getParams();
params.addHostId(hostId);
ApplicationGetResponse response = zabbixApi.application().get(request);
assertNotNull(response);
deleteDummy(ids.get(0));
deleteDummy(ids.get(1));
List<ApplicationGetResponse.Result> resultList = response.getResult();
for (int i = 0; i < resultList.size(); i++) {
ApplicationGetResponse.Result result = resultList.get(i);
assertNotNull(result);
assertEquals(hostId, result.getHostid());
}
}
private Integer createDummy() throws ZabbixApiException {
ApplicationCreateRequest request = new ApplicationCreateRequest();
ApplicationCreateRequest.Params params = request.getParams();
params.setName("Application get test");
params.setHostid(10084);
ApplicationCreateResponse response = zabbixApi.application().create(request);
Integer id = response.getResult().getApplicationids().get(0);
return id;
}
private Integer createDummy2() throws ZabbixApiException {
ApplicationCreateRequest request = new ApplicationCreateRequest();
ApplicationCreateRequest.Params params = request.getParams();
params.setName("Application get test2");
params.setHostid(10084);
ApplicationCreateResponse response = zabbixApi.application().create(request);
Integer id = response.getResult().getApplicationids().get(0);
return id;
}
private void deleteDummy(Integer id) throws ZabbixApiException {
ApplicationDeleteRequest request = new ApplicationDeleteRequest();
request.addParams(id);
ApplicationDeleteResponse response = zabbixApi.application().delete(request);
}
}
ApplicationUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.application;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.application.ApplicationCreateRequest;
import com.zabbix4j.application.ApplicationCreateResponse;
import com.zabbix4j.application.ApplicationDeleteRequest;
import com.zabbix4j.application.ApplicationDeleteResponse;
import com.zabbix4j.application.ApplicationUpdateRequest;
import com.zabbix4j.application.ApplicationUpdateResponse;
/**
* Created by Suguru Yajima on 2014/05/23.
*/
public class ApplicationUpdateTest extends ZabbixApiTestBase {
public ApplicationUpdateTest() {
super();
}
@Test
public void testUpdte() throws Exception {
Integer expected = createDummy();
ApplicationUpdateRequest request = new ApplicationUpdateRequest();
ApplicationUpdateRequest.Params params = request.getParams();
params.setApplicationid(expected);
params.setName("Applicaton updated");
ApplicationUpdateResponse response = zabbixApi.application().update(request);
assertNotNull(response);
Integer actual = response.getResult().getApplicationids().get(0);
delete(actual);
assertEquals(expected, actual);
}
private Integer createDummy() throws ZabbixApiException {
ApplicationCreateRequest request = new ApplicationCreateRequest();
ApplicationCreateRequest.Params params = request.getParams();
params.setName("Application before update");
params.setHostid(10113);
ApplicationCreateResponse response = zabbixApi.application().create(request);
assertNotNull(response);
Integer id = response.getResult().getApplicationids().get(0);
return id;
}
private void delete(Integer id) throws ZabbixApiException {
ApplicationDeleteRequest request = new ApplicationDeleteRequest();
request.addParams(id);
ApplicationDeleteResponse response = zabbixApi.application().delete(request);
}
}
网友评论