WebHelper { public static UDDIClient getUDDIClient(ServletContext servletContext) throws ConfigurationException { if (servletContext.getAttribute(JUDDI_CLIENT_NAME) != null) { String clientName = String.valueOf(servletContext.getAttribute(JUDDI_CLIENT_NAME)); return UDDIClientContainer.getUDDIClient(clientName); } else { String clientName = servletContext.getInitParameter(UDDI_CLIENT_NAME); if (clientName != null) { try { UDDIClient client = UDDIClientContainer.getUDDIClient(clientName); logger.info("Client " + clientName + " was already started."); servletContext.setAttribute(JUDDI_CLIENT_NAME, clientName); return client; } catch (ConfigurationException ce) { logger.debug("Client " + clientName + " is not yet started."); } } String clientConfigFile = servletContext.getInitParameter(UDDI_CLIENT_CONFIG_FILE); if (clientConfigFile == null) { clientConfigFile = ClientConfig.DEFAULT_UDDI_CONFIG; } logger.info("Reading the clientName from the clientConfig file " + clientConfigFile); UDDIClient client = new UDDIClient(clientConfigFile); if (client.getName() == null) { logger.warn("Deprecated, client name set to 'default', however it should be provided in the uddi.xml"); clientName = "default"; } if (client.getName() != null) { logger.info("Starting Client " + client.getName() + "..."); clientName = client.getName(); } else { throw new ConfigurationException("A client name needs to be specified in the client config file."); } client.start(); servletContext.setAttribute(JUDDI_CLIENT_NAME, clientName); return client; } }  static UDDIClient getUDDIClient(ServletContext servletContext); static final Log logger; static final String UDDI_CLIENT_NAME; static final String UDDI_CLIENT_CONFIG_FILE; static final String JUDDI_CLIENT_NAME; static final String JUDDI_CLIENT_TRANSPORT; }
@Test public void testGetUDDIClient() throws Exception { System.out.println("getUDDIClient"); ServletContext req = createNiceMock(ServletContext.class); req.setAttribute(JUDDI_CLIENT_NAME, null); expect(req.getInitParameter(WebHelper.JUDDI_CLIENT_NAME)).andReturn(null).times(0, 1); replay(req); UDDIClient result = WebHelper.getUDDIClient(req); Assert.assertNotNull(result); }
@Test public void testGetUDDIClientRandom() throws Exception { System.out.println("testGetUDDIClientRandom"); String random = UUID.randomUUID().toString(); ServletContext req = createNiceMock(ServletContext.class); req.setAttribute(UDDI_CLIENT_NAME, random); req.setAttribute(JUDDI_CLIENT_NAME, null); expect(req.getInitParameter(WebHelper.JUDDI_CLIENT_NAME)).andReturn(null).times(0, 1); expect(req.getInitParameter(WebHelper.UDDI_CLIENT_NAME)).andReturn(random).times(0, 1); replay(req); UDDIClient result = WebHelper.getUDDIClient(req); Assert.assertNotNull(result); }
@Test(expected = ConfigurationException.class) public void testGetUDDIClientNoConfig() throws Exception { System.out.println("testGetUDDIClientNoConfig"); String random = UUID.randomUUID().toString(); ServletContext req = createNiceMock(ServletContext.class); req.setAttribute(JUDDI_CLIENT_NAME, null); expect(req.getInitParameter(WebHelper.JUDDI_CLIENT_NAME)).andReturn(null).times(0, 1); req.setAttribute(UDDI_CLIENT_CONFIG_FILE, random); expect(req.getInitParameter(WebHelper.UDDI_CLIENT_CONFIG_FILE)).andReturn(random).times(0, 1); replay(req); UDDIClient result = WebHelper.getUDDIClient(req); Assert.assertNotNull(result); }