AuthenticationHandlerFactory { public static AuthenticationHandler makeHandler(ClientApi api, ZapInfo zapInfo, AuthenticationInfo authenticationInfo) { if (authenticationInfo == null) { return null; } switch (authenticationInfo.getType()) { case FORM: return new FormAuthenticationHandler(api, zapInfo, authenticationInfo); case CAS: return new CasAuthenticationHandler(api, zapInfo, authenticationInfo); case SELENIUM: return new SeleniumAuthenticationHandler(api, zapInfo, authenticationInfo); case HTTP: return new HttpAuthenticationHandler(api, zapInfo, authenticationInfo); default: return null; } } private  AuthenticationHandlerFactory(); static AuthenticationHandler makeHandler(ClientApi api, ZapInfo zapInfo, AuthenticationInfo authenticationInfo);  }
@Test public void testCasHandlerCreation() { ZapInfo zapInfo = ZapInfo.builder().buildToUseRunningZap("localhost", 8080); AuthenticationInfo authInfo = AuthenticationInfo.builder() .buildCasAuthenticationInfo("loginUrl", "username", "password", "protectedPages"); AuthenticationHandler handler = AuthenticationHandlerFactory.makeHandler(null, zapInfo, authInfo); assertTrue(handler instanceof CasAuthenticationHandler); }
@Test public void testFormHandlerCreation() { ZapInfo zapInfo = ZapInfo.builder().buildToUseRunningZap("localhost", 8080); AuthenticationInfo authInfo = AuthenticationInfo.builder() .buildFormAuthenticationInfo("loginUrl", "username", "password");; AuthenticationHandler handler = AuthenticationHandlerFactory.makeHandler(null, zapInfo, authInfo); assertTrue(handler instanceof FormAuthenticationHandler); }