use of com.baidu.disconf.core.common.json.ValueVo in project disconf by knightliao.
the class RestfulMgrMock method getJsonData.
/**
* 获取JSON数据
*
* @param clazz
* @param remoteUrl
*
* @return
*
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Mock
public <T> T getJsonData(Class<T> clazz, RemoteUrl remoteUrl, int retryTimes, int retrySleepSeconds) throws Exception {
ValueVo valueVo = new ValueVo();
valueVo.setMessage("");
valueVo.setStatus(Constants.OK);
valueVo.setValue(defaultValue);
return (T) valueVo;
}
use of com.baidu.disconf.core.common.json.ValueVo in project disconf by knightliao.
the class BaseCoreTestCase method setupRemoteData.
/**
*
*/
private static void setupRemoteData() {
//
// 配置项
//
ValueVo valueVo = new ValueVo();
valueVo.setMessage("");
valueVo.setStatus(Constants.OK);
valueVo.setValue(RemoteMockServer.DEFAULT_ITEM_VALUE);
// System.out.println(GsonUtils.toJson(valueVo));
stubFor(get(urlEqualTo(RemoteMockServer.ITEM_URL)).willReturn(aResponse().withHeader("Content-Type", RemoteMockServer.CONTENT_TYPE).withStatus(200).withBody(GsonUtils.toJson(valueVo))));
//
// 配置文件
//
stubFor(get(urlEqualTo(RemoteMockServer.FILE_URL)).willReturn(aResponse().withHeader("Content-Type", "text/html;charset=UTF-8").withHeader("Content-Disposition", "attachment; filename=" + RemoteMockServer.FILE_NAME).withStatus(200).withBody(RemoteMockServer.FILE_CONTENT.getBytes())));
//
// 空配置文件
//
stubFor(get(urlEqualTo(RemoteMockServer.EMPTY_FILE_URL)).willReturn(aResponse().withHeader("Content-Type", "text/html;charset=UTF-8").withHeader("Content-Disposition", "attachment; filename=" + RemoteMockServer.EMPTY_FILE_URL).withStatus(200).withBody(RemoteMockServer.FILE_CONTENT.getBytes())));
//
// 静态 配置文件
//
stubFor(get(urlEqualTo(RemoteMockServer.STATIC_FILE_URL)).willReturn(aResponse().withHeader("Content-Type", "text/html;charset=UTF-8").withHeader("Content-Disposition", "attachment; filename=" + RemoteMockServer.STATIC_FILE_NAME).withStatus(200).withBody(RemoteMockServer.STATIC_FILE_CONTENT.getBytes())));
//
// 非注解 配置文件
//
stubFor(get(urlEqualTo(RemoteMockServer.NON_ANOTATION_FILE_URL)).willReturn(aResponse().withHeader("Content-Type", "text/html;charset=UTF-8").withHeader("Content-Disposition", "attachment; filename=" + RemoteMockServer.NON_ANOTATION_FILE_NAME).withStatus(200).withBody(RemoteMockServer.NON_ANOTATTION_FILE_CONTENT.getBytes())));
//
// 非注解 配置文件2
//
stubFor(get(urlEqualTo(RemoteMockServer.NON_ANOTATION_FILE_URL2)).willReturn(aResponse().withHeader("Content-Type", "text/html;charset=UTF-8").withHeader("Content-Disposition", "attachment; filename=" + RemoteMockServer.NON_ANOTATION_FILE_NAME2).withStatus(200).withBody(RemoteMockServer.NON_ANOTATTION_FILE_CONTENT2.getBytes())));
//
// ZOO
//
valueVo = new ValueVo();
valueVo.setMessage("");
valueVo.setStatus(Constants.OK);
valueVo.setValue(RemoteMockServer.ZOO_HOSTS);
// System.out.println(GsonUtils.toJson(valueVo));
stubFor(get(urlEqualTo(RemoteMockServer.ZOO_URL)).willReturn(aResponse().withHeader("Content-Type", RemoteMockServer.CONTENT_TYPE).withStatus(200).withBody(GsonUtils.toJson(valueVo))));
valueVo = new ValueVo();
valueVo.setMessage("");
valueVo.setStatus(Constants.OK);
valueVo.setValue(RemoteMockServer.ZOO_PREFIX_VALUE);
// System.out.println(GsonUtils.toJson(valueVo));
stubFor(get(urlEqualTo(RemoteMockServer.ZOO_PREFIX_URL)).willReturn(aResponse().withHeader("Content-Type", RemoteMockServer.CONTENT_TYPE).withStatus(200).withBody(GsonUtils.toJson(valueVo))));
}
use of com.baidu.disconf.core.common.json.ValueVo in project disconf by knightliao.
the class RestfulMgrTestCase method tetGetJsonData.
/**
*
*/
@Test
public void tetGetJsonData() {
try {
RemoteUrl remoteUrl = new RemoteUrl(RemoteMockServer.ITEM_URL, RemoteMockServer.LOCAL_HOST_LIST);
ValueVo valueVo = restfulMgr.getJsonData(ValueVo.class, remoteUrl, 3, 3);
Assert.assertEquals(String.valueOf(RemoteMockServer.DEFAULT_ITEM_VALUE), valueVo.getValue());
} catch (Exception e) {
e.printStackTrace();
Assert.assertTrue(false);
}
}
use of com.baidu.disconf.core.common.json.ValueVo in project disconf by knightliao.
the class FetcherMgrImpl method getValueFromServer.
/**
* 根据 URL 从远程 获取Value值
*/
public String getValueFromServer(String url) throws Exception {
// 远程地址
RemoteUrl remoteUrl = new RemoteUrl(url, hostList);
ValueVo confItemVo = restfulMgr.getJsonData(ValueVo.class, remoteUrl, retryTime, retrySleepSeconds);
LOGGER.debug("remote server return: " + confItemVo.toString());
if (confItemVo.getStatus().equals(Constants.NOTOK)) {
throw new Exception("status is not ok.");
}
return confItemVo.getValue();
}
use of com.baidu.disconf.core.common.json.ValueVo in project disconf by knightliao.
the class ZooController method getPrefixUrl.
/**
* 获取ZK prefix
*
* @return
*/
@NoAuth
@RequestMapping(value = "/prefix", method = RequestMethod.GET)
@ResponseBody
public ValueVo getPrefixUrl() {
ValueVo confItemVo = new ValueVo();
confItemVo.setStatus(Constants.OK);
confItemVo.setValue(zooConfig.getZookeeperUrlPrefix());
return confItemVo;
}
Aggregations