Screen:此类设计用于使用屏幕。
screen.create: 创建新屏幕
screen.delete: 删除屏幕
screen.exists: 检查屏幕是否存在
screen.get: 检索屏幕
screen.update: 更新屏幕
DummyScreen
package cn.com.yeexun.testzabbix.zabbix4j.example.screen;
import java.util.Date;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestDummyMethodBase;
import com.zabbix4j.ZabbixApi;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.screen.ScreenCreateRequest;
import com.zabbix4j.screen.ScreenCreateResponse;
import com.zabbix4j.screen.ScreenDeleteRequest;
import com.zabbix4j.screen.ScreenDeleteResponse;
/**
* @author Suguru Yajima
*/
public class DummyScreen extends ZabbixApiTestDummyMethodBase {
public DummyScreen(ZabbixApi zabbixApi) {
super(zabbixApi);
}
public Integer create() throws ZabbixApiException {
ScreenCreateRequest request = new ScreenCreateRequest();
ScreenCreateRequest.Params params = request.getParams();
params.setName("test.screen.create." + new Date().getTime());
params.setHsize(3);
params.setVsize(2);
ScreenCreateResponse response = zabbixApi.screen().create(request);
Integer actualId = response.getResult().getScreenids().get(0);
return actualId;
}
public void delete(Integer targetId) throws ZabbixApiException {
ScreenDeleteRequest request = new ScreenDeleteRequest();
request.addScreenId(targetId);
ScreenDeleteResponse response = zabbixApi.screen().delete(request);
}
}
ScreenCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.screen;
import static org.junit.Assert.assertNotNull;
import java.util.Date;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.screen.ScreenCreateRequest;
import com.zabbix4j.screen.ScreenCreateResponse;
/**
* @author Suguru Yajima
*/
public class ScreenCreateTest extends ZabbixApiTestBase {
public ScreenCreateTest() {
super();
}
@Test
public void testCreate() throws Exception {
ScreenCreateRequest request = new ScreenCreateRequest();
ScreenCreateRequest.Params params = request.getParams();
params.setName("test.screen.create." + new Date().getTime());
params.setHsize(3);
params.setVsize(2);
ScreenCreateResponse response = zabbixApi.screen().create(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getScreenids().get(0);
assertNotNull(actualId);
}
}
ScreenDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.screen;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.screen.ScreenDeleteRequest;
import com.zabbix4j.screen.ScreenDeleteResponse;
/**
* @author Suguru Yajima
*/
public class ScreenDeleteTest extends ZabbixApiTestBase {
public ScreenDeleteTest() {
super();
}
@Test
public void testDelete() throws Exception {
DummyScreen dummyScreen = new DummyScreen(zabbixApi);
Integer targetId = dummyScreen.create();
ScreenDeleteRequest request = new ScreenDeleteRequest();
request.addScreenId(targetId);
ScreenDeleteResponse response = zabbixApi.screen().delete(request);
assertNotNull(response);
Integer actualId = response.getResult().getScreenids().get(0);
assertThat(actualId, is(targetId));
}
}
ScreenGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.screen;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiParamter;
import com.zabbix4j.screen.ScreenGetRequest;
import com.zabbix4j.screen.ScreenGetResponse;
/**
* @author Suguru Yajima
*/
public class ScreenGetTest extends ZabbixApiTestBase {
public ScreenGetTest() {
super();
}
@Test
public void testGet() throws Exception {
DummyScreen dummyScreen = new DummyScreen(zabbixApi);
Integer targetId = dummyScreen.create();
try {
ScreenGetRequest request = new ScreenGetRequest();
ScreenGetRequest.Params params = request.getParams();
params.addScreenId(targetId);
params.setSelectScreenItems(ZabbixApiParamter.QUERY.extend.name());
ScreenGetResponse response = zabbixApi.screen().get(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
ScreenGetResponse.Result result = response.getResult().get(0);
assertNotNull(result);
} finally {
dummyScreen.delete(targetId);
}
}
}
ScreenUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.screen;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import java.util.Date;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.screen.ScreenUpdateRequest;
import com.zabbix4j.screen.ScreenUpdateResponse;
/**
* @author Suguru Yajima
*/
public class ScreenUpdateTest extends ZabbixApiTestBase {
public ScreenUpdateTest() {
super();
}
@Test
public void testUpdate() throws Exception {
DummyScreen dummyScreen = new DummyScreen(zabbixApi);
Integer targetId = dummyScreen.create();
try {
ScreenUpdateRequest request = new ScreenUpdateRequest();
ScreenUpdateRequest.Params params = request.getParams();
params.setScreenid(targetId);
params.setName("test.screen.updated." + new Date().getTime());
ScreenUpdateResponse response = zabbixApi.screen().update(request);
assertNotNull(response);
Integer actualId = response.getResult().getScreenids().get(0);
assertThat(actualId, is(targetId));
} finally {
dummyScreen.delete(targetId);
}
}
}