Query模块Test Case,有一系列的异常测试,选取其中之一,进行分析,主要是Assert类的用法,代码如下:
这段代码主要是:使用getQueryData方法时,对参数id进行检查(假如是无效或非法的id,则会抛出异常信息)
@Test
public void queryWithInvalidID() {
log.info("Enter GetQueryDataTest queryWithInvalidID()");
try {
log.info("Try to getQueryData");
dcmAPI.getQueryData(-1, QueryType.AVG_PWR, AggregationLevel.SELF, startTime,
oneCycleEndTime, FREQUENCY);
log.info("getQueryData finished");
Assert.fail("Should get exception here!");
} catch (Exception e) {
Assert.assertFalse("Should not get exception "
+ e.getClass().getSimpleName() + ": " + e.getMessage(),
Utilities.isNotExceptedException(e,
"DcmIllegalIdException", null));
}
log.info("Exit GetQueryDataTest queryWithInvalidID()");
}