Media type: 这个类被设计为与媒体类型一起工作。
mediatype.create: 创建新媒体类型
mediatype.delete: 删除媒体类型
mediatype.get: 检索媒体类型
mediatype.update: 更新媒体类型
DummyMediaType
package cn.com.yeexun.testzabbix.zabbix4j.example.mediatype;
import java.util.Date;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestDummyMethodBase;
import com.zabbix4j.ZabbixApi;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.mediatype.MediaTypeCreateRequest;
import com.zabbix4j.mediatype.MediaTypeCreateResponse;
import com.zabbix4j.mediatype.MediaTypeDeleteRequest;
import com.zabbix4j.mediatype.MediaTypeDeleteResponse;
import com.zabbix4j.mediatype.MediaTypeObject;
/**
* @author Suguru Yajima
*/
public class DummyMediaType extends ZabbixApiTestDummyMethodBase {
public DummyMediaType(ZabbixApi zabbixApi) {
super(zabbixApi);
}
public Integer create() throws ZabbixApiException {
MediaTypeCreateRequest request = new MediaTypeCreateRequest();
MediaTypeObject obj = new MediaTypeObject();
obj.setDescription("test.mediatype." + new Date());
obj.setType(MediaTypeObject.MEDIA_TYPE.EMAIL.value);
obj.setSmtp_server("rootmail@company.com");
obj.setSmtp_helo("company.com");
obj.setSmtp_email("zabbix@company.com");
request.addMediaType(obj);
MediaTypeCreateResponse response = zabbixApi.mediaType().create(request);
Integer actualId = response.getResult().getMediatypeids().get(0);
return actualId;
}
public void delete(Integer targetId) throws ZabbixApiException {
MediaTypeDeleteRequest request = new MediaTypeDeleteRequest();
request.addMediaTypeId(targetId);
MediaTypeDeleteResponse response = zabbixApi.mediaType().delete(request);
}
}
MediaTypeCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.mediatype;
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.mediatype.MediaTypeCreateRequest;
import com.zabbix4j.mediatype.MediaTypeCreateResponse;
import com.zabbix4j.mediatype.MediaTypeObject;
/**
* @author Suguru Yajima
*/
public class MediaTypeCreateTest extends ZabbixApiTestBase {
public MediaTypeCreateTest() {
super();
}
@Test
public void testCreate() throws Exception {
MediaTypeCreateRequest request = new MediaTypeCreateRequest();
MediaTypeObject obj = new MediaTypeObject();
obj.setDescription("test.mediatype." + new Date());
obj.setType(MediaTypeObject.MEDIA_TYPE.EMAIL.value);
obj.setSmtp_server("rootmail@company.com");
obj.setSmtp_helo("company.com");
obj.setSmtp_email("zabbix@company.com");
request.addMediaType(obj);
MediaTypeCreateResponse response = zabbixApi.mediaType().create(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getMediatypeids().get(0);
assertNotNull(actualId);
}
}
MediaTypeDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.mediatype;
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.mediatype.MediaTypeDeleteRequest;
import com.zabbix4j.mediatype.MediaTypeDeleteResponse;
/**
* @author Suguru Yajima
*/
public class MediaTypeDeleteTest extends ZabbixApiTestBase {
public MediaTypeDeleteTest() {
super();
}
@Test
public void testDelete() throws Exception {
DummyMediaType dummyMediaType = new DummyMediaType(zabbixApi);
Integer targetId = dummyMediaType.create();
MediaTypeDeleteRequest request = new MediaTypeDeleteRequest();
request.addMediaTypeId(targetId);
MediaTypeDeleteResponse response = zabbixApi.mediaType().delete(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getMediatypeids().get(0);
assertThat(actualId, is(targetId));
}
}
MediaTypeGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.mediatype;
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.ZabbixApiParamter;
import com.zabbix4j.mediatype.MediaTypeGetRequest;
import com.zabbix4j.mediatype.MediaTypeGetResponse;
/**
* @author Suguru Yajima
*/
public class MediaTypeGetTest extends ZabbixApiTestBase {
public MediaTypeGetTest() {
super();
}
@Test
public void testGet() throws Exception {
MediaTypeGetRequest request = new MediaTypeGetRequest();
MediaTypeGetRequest.Params params = request.getParams();
params.addMediaTypeId(1);
params.addMediaTypeId(2);
params.addMediaTypeId(3);
params.setSelectUsers(ZabbixApiParamter.QUERY.extend.name());
MediaTypeGetResponse response = zabbixApi.mediaType().get(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
int actualCount = response.getResult().size();
assertThat(actualCount, is(3));
}
}
MediaTypeUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.mediatype;
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.mediatype.MediaTypeObject;
import com.zabbix4j.mediatype.MediaTypeUpdateRequest;
import com.zabbix4j.mediatype.MediaTypeUpdateResponse;
/**
* @author Suguru Yajima
*/
public class MediaTypeUpdateTest extends ZabbixApiTestBase {
public MediaTypeUpdateTest() {
super();
}
@Test
public void testUpdate() throws Exception {
DummyMediaType dummyMediaType = new DummyMediaType(zabbixApi);
Integer targetId = dummyMediaType.create();
try {
MediaTypeUpdateRequest request = new MediaTypeUpdateRequest();
MediaTypeObject obj = new MediaTypeObject();
obj.setMediatypeid(targetId);
obj.setDescription("update" + new Date());
obj.setSmtp_email("hoge@hoge.com");
request.addMediaTypeObject(obj);
MediaTypeUpdateResponse response = zabbixApi.mediaType().update(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getMediatypeids().get(0);
assertThat(actualId, is(targetId));
} finally {
dummyMediaType.delete(targetId);
}
}
}