use of com.yahoo.athenz.zms.status.MockStatusCheckerNoException in project athenz by yahoo.
the class ZMSImplTest method testGetStatusWithStatusChecker.
@Test
public void testGetStatusWithStatusChecker() {
// if the MockStatusCheckerNoException is set
// the MockStatusCheckerNoException determines the server is healthy
System.setProperty(ZMSConsts.ZMS_PROP_STATUS_CHECKER_FACTORY_CLASS, MockStatusCheckerNoException.class.getName());
ZMSImpl zmsImpl = zmsTestInitializer.zmsInit();
zmsImpl.statusPort = 0;
Status status = zmsImpl.getStatus(zmsTestInitializer.getMockDomRsrcCtx());
assertEquals(ResourceException.OK, status.getCode());
// if the MockStatusCheckerThrowException is set
// the MockStatusCheckerThrowException determines that there is a problem with the server
System.setProperty(ZMSConsts.ZMS_PROP_STATUS_CHECKER_FACTORY_CLASS, MockStatusCheckerThrowException.NoArguments.class.getName());
zmsImpl = zmsTestInitializer.zmsInit();
zmsImpl.statusPort = 0;
try {
zmsImpl.getStatus(zmsTestInitializer.getMockDomRsrcCtx());
fail();
} catch (ResourceException ex) {
int code = com.yahoo.athenz.common.server.rest.ResourceException.INTERNAL_SERVER_ERROR;
String msg = com.yahoo.athenz.common.server.rest.ResourceException.symbolForCode(ResourceException.INTERNAL_SERVER_ERROR);
assertEquals(new ResourceError().code(code).message(msg).toString(), ex.getData().toString());
}
System.setProperty(ZMSConsts.ZMS_PROP_STATUS_CHECKER_FACTORY_CLASS, MockStatusCheckerThrowException.NotFound.class.getName());
zmsImpl = zmsTestInitializer.zmsInit();
zmsImpl.statusPort = 0;
try {
zmsImpl.getStatus(zmsTestInitializer.getMockDomRsrcCtx());
fail();
} catch (ResourceException ex) {
int code = com.yahoo.athenz.common.server.rest.ResourceException.NOT_FOUND;
String msg = com.yahoo.athenz.common.server.rest.ResourceException.symbolForCode(ResourceException.NOT_FOUND);
assertEquals(new ResourceError().code(code).message(msg).toString(), ex.getData().toString());
}
System.setProperty(ZMSConsts.ZMS_PROP_STATUS_CHECKER_FACTORY_CLASS, MockStatusCheckerThrowException.InternalServerErrorWithMessage.class.getName());
zmsImpl = zmsTestInitializer.zmsInit();
zmsImpl.statusPort = 0;
try {
zmsImpl.getStatus(zmsTestInitializer.getMockDomRsrcCtx());
fail();
} catch (ResourceException ex) {
int code = com.yahoo.athenz.common.server.rest.ResourceException.INTERNAL_SERVER_ERROR;
String msg = "error message";
assertEquals(new ResourceError().code(code).message(msg).toString(), ex.getData().toString());
}
System.setProperty(ZMSConsts.ZMS_PROP_STATUS_CHECKER_FACTORY_CLASS, MockStatusCheckerThrowException.CauseRuntimeException.class.getName());
zmsImpl = zmsTestInitializer.zmsInit();
zmsImpl.statusPort = 0;
try {
zmsImpl.getStatus(zmsTestInitializer.getMockDomRsrcCtx());
fail();
} catch (ResourceException ex) {
int code = com.yahoo.athenz.common.server.rest.ResourceException.INTERNAL_SERVER_ERROR;
String msg = "runtime exception";
assertEquals(new ResourceError().code(code).message(msg).toString(), ex.getData().toString());
}
System.clearProperty(ZMSConsts.ZMS_PROP_STATUS_CHECKER_FACTORY_CLASS);
zmsImpl.objectStore.clearConnections();
}
Aggregations