james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1607764 [7/7] - in /james/bond/trunk/src: main/java/org/apache/james/bond/ main/java/org/apache/james/bond/client/ main/java/org/apache/james/bond/client/configure/ main/java/org/apache/james/bond/client/configure/dns/ main/java/org/apache...
Date Thu, 03 Jul 2014 22:58:03 GMT
Added: james/bond/trunk/src/main/java/org/apache/james/bond/server/monitor/MonitoringService.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/main/java/org/apache/james/bond/server/monitor/MonitoringService.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/main/java/org/apache/james/bond/server/monitor/MonitoringService.java (added)
+++ james/bond/trunk/src/main/java/org/apache/james/bond/server/monitor/MonitoringService.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,41 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.bond.server.monitor;
+
+/**
+ * It connects to the server via JMX and defines the services that the
+ * RequestFactory offers to access monitoring information
+ */
+public class MonitoringService {
+
+  private static JMXBondConnector jmxBondConnector;
+
+  /**
+   * It retrieves all the monitoring information from the server
+   * 
+   * @return
+   * @throws Exception
+   */
+  public static Monitoring getMonitoringInformation() throws Exception {
+    if (jmxBondConnector == null) {
+      jmxBondConnector = new JMXBondConnector();
+    }
+    return jmxBondConnector.getMonitoringInformation();
+  }
+}

Added: james/bond/trunk/src/main/java/org/apache/james/bond/server/monitor/MonitoringServiceLocator.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/main/java/org/apache/james/bond/server/monitor/MonitoringServiceLocator.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/main/java/org/apache/james/bond/server/monitor/MonitoringServiceLocator.java (added)
+++ james/bond/trunk/src/main/java/org/apache/james/bond/server/monitor/MonitoringServiceLocator.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,36 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.bond.server.monitor;
+
+import com.google.web.bindery.requestfactory.shared.ServiceLocator;
+
+public class MonitoringServiceLocator implements ServiceLocator {
+  private static MonitoringService serviceInstance;
+
+  @Override
+  public Object getInstance(Class<?> clazz) {
+    return MonitoringServiceLocator.getServiceInstance();
+  }
+
+  private static MonitoringService getServiceInstance() {
+    if (serviceInstance == null)
+      serviceInstance = new MonitoringService();
+    return serviceInstance;
+  }
+}
\ No newline at end of file

Added: james/bond/trunk/src/main/java/org/apache/james/bond/server/servlet/JamesBondFilter.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/main/java/org/apache/james/bond/server/servlet/JamesBondFilter.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/main/java/org/apache/james/bond/server/servlet/JamesBondFilter.java (added)
+++ james/bond/trunk/src/main/java/org/apache/james/bond/server/servlet/JamesBondFilter.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,143 @@
+package org.apache.james.bond.server.servlet;
+
+import static org.apache.james.bond.shared.BondConst.*;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.james.bond.server.JamesConnector;
+
+/**
+ * Filter to authorize certain ip addresses requests.
+ * 
+ * Configure the filter in the web.xml with the parameter 'ip.range'
+ * or using the System property 'ip.range'
+ */
+public class JamesBondFilter implements Filter {
+
+  private String allowed_ips_regex = "127.0.0.1";
+
+  /**
+   * check if IP address match pattern
+   * 
+   * @param pattern *, *.*.*.*, 192.168.1.0-255
+   * @param address n.n.n.n
+   */
+  public boolean checkIPMatching(String pattern, String address) {
+    if (!address.equals("127.0.0.1") && !pattern.equals("*.*.*.*") && !pattern.equals("*")) {
+      String[] mask = pattern.split("\\.");
+      String[] ip_address = address.split("\\.");
+      for (int i = 0; i < mask.length; i++) {
+        if (mask[i].equals("*") || mask[i].equals(ip_address[i])) {
+          continue;
+        } else if (mask[i].contains("-")) {
+          byte min = Byte.parseByte(mask[i].split("-")[0]);
+          byte max = Byte.parseByte(mask[i].split("-")[1]);
+          byte ip = Byte.parseByte(ip_address[i]);
+          if (ip < min || ip > max) {
+            return false;
+          }
+        } else {
+          return false;
+        }
+      }
+    }
+    return true;
+  }
+  
+  public boolean checkJamesJMXConnection() {
+    try {
+      return JamesConnector.getServerProbe() != null;
+    } catch (Exception e) {
+    }
+    return false;
+  }
+  
+  public boolean checkJamesConfFolder() {
+    File conf = new File(JAMES_CONF);
+    return conf.isDirectory() && conf.canWrite();
+  }
+
+  public void doFilter(ServletRequest servletRequest,
+      ServletResponse servletResponse, FilterChain filterChain)
+      throws IOException, ServletException {
+    
+    HttpServletResponse resp = (HttpServletResponse) servletResponse;
+    HttpServletRequest req = (HttpServletRequest) servletRequest;
+    String address = req.getRemoteAddr();
+    
+    if (!checkIPMatching(allowed_ips_regex, address)) {
+      resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, 
+          BOND + "\n\nYour Ip Address (" + address + ") does not match the range of authorized ip addresses." +
+          getConfigurationHint(SYSPROP_AUTHORIZED_IPS, allowed_ips_regex));
+    } else if (!checkJamesConfFolder()) {
+      resp.sendError(HttpServletResponse.SC_EXPECTATION_FAILED, 
+          BOND + "\n\nFolder with James configuration files (" + JAMES_CONF + ") is not writable." +
+          getConfigurationHint(SYSPROP_JAMES_CONF, JAMES_CONF));
+    } else if (!checkJamesJMXConnection()) {
+      resp.sendError(HttpServletResponse.SC_EXPECTATION_FAILED, 
+          BOND + "\n\nUnable to connect with the JMX service (" + JAMES_ADDRESS + ":"  + JAMES_PORT + ")." +
+          "\n\n-- make sure James is running." +
+          getConfigurationHint(SYSPROP_JAMES_JMX, JAMES_ADDRESS + ":" + JAMES_PORT));
+    } else if (filterChain != null) {
+      filterChain.doFilter(req, resp);
+    }
+  }
+  
+
+  @Override
+  public void destroy() {
+  }
+  
+  private String getConfigurationHint(String prop, String value) {
+    return "\n\n-- run Bond with the parameter:\n -D" + prop + "=" + value +
+           "\n\n-- or configure your web.xml file appropriately:" +
+           "\n <env-entry>" + 
+           "\n  <env-entry-name>" + prop + "</env-entry-name>" + 
+           "\n  <env-entry-value>" + value + "</env-entry-value>" +
+           "\n  <env-entry-type>java.lang.String</env-entry-type>" +
+           "\n </evn-entry>";
+  }
+ 
+  @Override
+  public void init(FilterConfig config) throws ServletException {
+    String value = getProperty(config, SYSPROP_AUTHORIZED_IPS);
+    if (!value.isEmpty()) {
+      allowed_ips_regex = value;
+    }
+
+    value = getProperty(config, SYSPROP_JAMES_JMX);
+    if (!value.isEmpty()) {
+      String arr[] = value.split(":");
+      JAMES_ADDRESS = arr[0];
+      if (arr.length > 1) {
+        JAMES_PORT = Integer.parseInt(arr[1]);
+      }
+    }
+
+    value = getProperty(config, SYSPROP_JAMES_CONF);
+    if (!value.isEmpty()) {
+      JAMES_CONF = value;
+    }
+  }
+  
+  private String getProperty(FilterConfig config, String name) {
+    String value = System.getProperty(name);
+    if (value == null || value.isEmpty()) {
+      value = config.getServletContext().getInitParameter(name);
+    }
+    if (value == null || value.isEmpty()) {
+      value = config.getInitParameter(name);
+    }
+    return value == null ? "" : value;
+  }
+}
\ No newline at end of file

Added: james/bond/trunk/src/main/java/org/apache/james/bond/shared/BondConst.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/main/java/org/apache/james/bond/shared/BondConst.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/main/java/org/apache/james/bond/shared/BondConst.java (added)
+++ james/bond/trunk/src/main/java/org/apache/james/bond/shared/BondConst.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,42 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ */
+package org.apache.james.bond.shared;
+
+
+/**
+ * abstract class to define static stuff used anywhere in the app
+ */
+public abstract class BondConst {
+  
+  public static final String BOND = "Apache James Bond"; 
+  
+  public static String JAMES_CONF = "/opt/apache-james-3.0-beta4/conf";
+  public static String JAMES_ADDRESS = "127.0.0.1";
+  public static int JAMES_PORT = 9999;
+  
+  public static final String SYSPROP_JAMES_CONF = "james.conf";
+  public static final String SYSPROP_JAMES_JMX = "james.jmx";
+  public static final String SYSPROP_AUTHORIZED_IPS = "ip.range";
+  
+  public static final String NAME_TEMPL_DNS = "dnsservice";
+  public static final String NAME_TEMPL_POP3 = "pop3server";
+  public static final String NAME_TEMPL_SMTP = "smtpserver";
+  public static final String NAME_TEMPL_LMTP = "lmtpserver";
+  public static final String NAME_TEMPL_IMAP = "imapserver";
+}

Added: james/bond/trunk/src/test/java/org/apache/james/bond/TestConst.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/TestConst.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/TestConst.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/TestConst.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,26 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ */
+package org.apache.james.bond;
+
+/**
+ * abstract class to define static stuff used in tests
+ */
+public abstract class TestConst {
+  public static final String TEST_CONF_FOLDER = "target/test.conf";
+}

Added: james/bond/trunk/src/test/java/org/apache/james/bond/client/UtilTest.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/client/UtilTest.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/client/UtilTest.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/client/UtilTest.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,31 @@
+package org.apache.james.bond.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class UtilTest {
+
+  @Test
+  public void convertStringToInt() {
+    assertEquals(0, Util.convertStringToInt("asdf"));
+    assertEquals(5, Util.convertStringToInt("5"));
+    assertEquals(5, Util.convertStringToInt("dfadf", 5));
+  }
+
+  @Test
+  public void isIPAddress() {
+    assertTrue(Util.isIPAddress("0.0.0.0"));
+    assertTrue(Util.isIPAddress("10.0.0.0"));
+    assertTrue(Util.isIPAddress("123.21.12.32"));
+    assertTrue(Util.isIPAddress("255.255.255.255"));
+
+    assertFalse(Util.isIPAddress("255.255.255.255 "));
+    assertFalse(Util.isIPAddress("256.255.255.255"));
+    assertFalse(Util.isIPAddress("0000.0.0.0"));
+    assertFalse(Util.isIPAddress("0.0.0"));
+    assertFalse(Util.isIPAddress("dssgd"));
+  }
+}

Added: james/bond/trunk/src/test/java/org/apache/james/bond/client/ioc/ClientFactoryTestImpl.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/client/ioc/ClientFactoryTestImpl.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/client/ioc/ClientFactoryTestImpl.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/client/ioc/ClientFactoryTestImpl.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,187 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.bond.client.ioc;
+
+import org.apache.james.bond.client.configure.ConfigureView;
+import org.apache.james.bond.client.configure.ConfigureViewImpl;
+import org.apache.james.bond.client.configure.dns.ConfigureDNSView;
+import org.apache.james.bond.client.configure.dns.ConfigureDNSViewImpl;
+import org.apache.james.bond.client.configure.imap.ConfigureImapView;
+import org.apache.james.bond.client.configure.lmtp.ConfigureLmtpView;
+import org.apache.james.bond.client.configure.pop3.ConfigurePop3View;
+import org.apache.james.bond.client.configure.pop3.ConfigurePop3ViewImpl;
+import org.apache.james.bond.client.configure.smtp.ConfigureSmtpView;
+import org.apache.james.bond.client.configure.smtp.ConfigureSmtpViewImpl;
+import org.apache.james.bond.client.manage.ManageView;
+import org.apache.james.bond.client.manage.ManageViewImpl;
+import org.apache.james.bond.client.manage.domain.DomainsAsyncDataProvider;
+import org.apache.james.bond.client.manage.domain.ManageDomainsTabView;
+import org.apache.james.bond.client.manage.domain.ManageDomainsTabViewImpl;
+import org.apache.james.bond.client.manage.mappings.ManageMappingsView;
+import org.apache.james.bond.client.manage.user.ManageUsersTabView;
+import org.apache.james.bond.client.manage.user.ManageUsersTabViewImpl;
+import org.apache.james.bond.client.manage.user.UsersAsyncDataProvider;
+import org.apache.james.bond.client.monitor.MonitorSummaryView;
+import org.apache.james.bond.client.monitor.MonitorView;
+import org.apache.james.bond.client.serverconnection.AppRequestFactory;
+
+import com.google.gwt.place.shared.PlaceController;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.SimpleEventBus;
+import com.google.web.bindery.requestfactory.server.ExceptionHandler;
+import com.google.web.bindery.requestfactory.server.ServiceLayer;
+import com.google.web.bindery.requestfactory.server.SimpleRequestProcessor;
+import com.google.web.bindery.requestfactory.server.testing.InProcessRequestTransport;
+import com.google.web.bindery.requestfactory.shared.ServerFailure;
+import com.google.web.bindery.requestfactory.vm.RequestFactorySource;
+
+/**
+ * Test implementation of ClientFactory.
+ * 
+ * @author manolo
+ * 
+ */
+public class ClientFactoryTestImpl implements ClientFactory {
+
+  private static final EventBus eventBus = new SimpleEventBus();
+
+  private final AppRequestFactory requestFactory;
+  private static PlaceController placeController;
+  private static ManageUsersTabView manageUsersTabView;
+  private static ManageDomainsTabView manageDomainsTabView;
+  private static ManageView manageView;
+  private static ConfigureView configureView;
+  private static ConfigureDNSView configureDNSView;
+  private static ConfigurePop3View configurePop3View;
+  private static ConfigureSmtpView configureSmtpView;
+
+  public ClientFactoryTestImpl() {
+    // Create a requstFactory which works in JVM
+    requestFactory = RequestFactorySource.create(AppRequestFactory.class);
+    SimpleRequestProcessor processor = new SimpleRequestProcessor(
+        ServiceLayer.create());
+
+    processor.setExceptionHandler(new ExceptionHandler() {
+      public ServerFailure createServerFailure(Throwable e) {
+        e.printStackTrace();
+        return new ServerFailure(e.getMessage());
+      }
+    });
+    requestFactory.initialize(new SimpleEventBus(),
+        new InProcessRequestTransport(processor));
+  }
+
+  @Override
+  public AppRequestFactory getRequestFactory() {
+    return requestFactory;
+  }
+
+  @Override
+  public EventBus getEventBus() {
+    return eventBus;
+  }
+
+  @Override
+  public PlaceController getPlaceController() {
+    if (placeController == null)
+      placeController = new PlaceController(getEventBus());
+    return placeController;
+  }
+
+  @Override
+  public ManageView getManageView(String place) {
+    if (manageView == null)
+      manageView = new ManageViewImpl(place);
+    return manageView;
+  }
+
+  @Override
+  public ConfigureView getConfigureView(String place) {
+    if (configureView == null)
+      configureView = new ConfigureViewImpl(place);
+    return configureView;
+  }
+
+  @Override
+  public ManageUsersTabView getManageUsersTabView() {
+    if (manageUsersTabView == null)
+      manageUsersTabView = new ManageUsersTabViewImpl(
+          new UsersAsyncDataProvider(getRequestFactory()));
+    return manageUsersTabView;
+  }
+
+  @Override
+  public ManageDomainsTabView getManageDomainsTabView() {
+    if (manageDomainsTabView == null)
+      manageDomainsTabView = new ManageDomainsTabViewImpl(
+          new DomainsAsyncDataProvider(getRequestFactory()));
+    return manageDomainsTabView;
+  }
+
+  @Override
+  public ConfigureDNSView getConfigureDNSView() {
+    if (configureDNSView == null)
+      configureDNSView = new ConfigureDNSViewImpl();
+    return configureDNSView;
+  }
+
+  @Override
+  public ConfigurePop3View getConfigurePop3View() {
+    if (configurePop3View == null)
+      configurePop3View = new ConfigurePop3ViewImpl();
+    return configurePop3View;
+  }
+
+  @Override
+  public ConfigureSmtpView getConfigureSmtpView() {
+    if (configureSmtpView == null)
+      configureSmtpView = new ConfigureSmtpViewImpl();
+    return configureSmtpView;
+  }
+
+  @Override
+  public ConfigureLmtpView getConfigureLmtpView() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public ConfigureImapView getConfigureImapView() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public MonitorView getMonitorView(String place) {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public MonitorSummaryView getMonitorSummaryView() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public ManageMappingsView getManageMappingsView() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+}

Added: james/bond/trunk/src/test/java/org/apache/james/bond/client/manage/ManageActivityTest.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/client/manage/ManageActivityTest.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/client/manage/ManageActivityTest.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/client/manage/ManageActivityTest.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,158 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.bond.client.manage;
+
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.james.bond.client.ioc.ClientFactory;
+import org.apache.james.bond.client.ioc.ClientFactoryTestImpl;
+import org.apache.james.bond.client.manage.domain.ManageDomainsTabView;
+import org.apache.james.bond.client.manage.mappings.ManageMappingsView;
+import org.apache.james.bond.client.manage.user.ManageUsersTabView;
+import org.apache.james.bond.client.mvp.AppActivityMapper;
+import org.apache.james.bond.client.serverconnection.UserProxy;
+import org.junit.Test;
+
+import com.google.gwt.event.logical.shared.SelectionEvent;
+import com.google.gwt.user.client.ui.IsWidget;
+import com.google.gwt.user.client.ui.Widget;
+import com.google.web.bindery.requestfactory.shared.Receiver;
+
+/**
+ * Just an example of how to test activities in JVM
+ * 
+ * @author manolo
+ */
+public class ManageActivityTest {
+
+  boolean userRfSucceed = false;
+
+  @Test
+  public void testRequestFactory() throws Exception {
+    try {
+      ClientFactory clientFactory = new ClientFactoryTestImpl();
+      clientFactory.getRequestFactory().createUserRequest().listUsers()
+          .fire(new Receiver<List<UserProxy>>() {
+            @Override
+            public void onSuccess(List<UserProxy> response) {
+              userRfSucceed = true;
+            }
+          });
+
+      Assert.assertTrue(userRfSucceed);
+    } catch (Exception e) {
+      System.err.println("James not reachable");
+    }
+  }
+
+  int selectedTab = -1;
+
+  @Test
+  public void testManageActivity() throws Exception {
+    try {
+      // We create our test version of clientFactory
+      ClientFactory clientFactory = new ClientFactoryTestImpl() {
+
+        // For this test we only need an implementation of ManageView
+        @Override
+        public ManageView getManageView(String place) {
+          return new ManageView() {
+            @Override
+            public Widget asWidget() {
+              return null;
+            }
+
+            @Override
+            public void selectTab(int index) {
+              selectedTab = index;
+            }
+
+            @Override
+            public void setPlaceString(String place) {
+              // TODO Auto-generated method stub
+
+            }
+
+            @Override
+            public String getPlaceString() {
+              // TODO Auto-generated method stub
+              return null;
+            }
+
+            @Override
+            public void addTab(IsWidget widget, String text) {
+              // TODO Auto-generated method stub
+
+            }
+
+            @Override
+            public int getTabsCount() {
+              // TODO Auto-generated method stub
+              return 0;
+            }
+
+            @Override
+            public void onSelection(SelectionEvent<Integer> event) {
+              // TODO Auto-generated method stub
+
+            }
+
+            @Override
+            public void setUsersView(ManageUsersTabView manageUsersTabView) {
+              // TODO Auto-generated method stub
+
+            }
+
+            @Override
+            public void setDomainsView(ManageDomainsTabView manageDomainsTabView) {
+              // TODO Auto-generated method stub
+
+            }
+
+            @Override
+            public void addTab(IsWidget widget, String text, String title) {
+              // TODO Auto-generated method stub
+
+            }
+
+            @Override
+            public void setMappingsView(ManageMappingsView manageMappingsView) {
+              // TODO Auto-generated method stub
+
+            }
+          };
+        }
+      };
+
+      // We use the mapper to get the activity
+      AppActivityMapper mapper = new AppActivityMapper(clientFactory);
+      //
+      // // when the activity is created it selects the appropriate tab
+      // // and does a RF call to the server
+      // ManageActivity manageActivity = (ManageActivity) mapper
+      // .getActivity(new ManagePlace(""));
+      //
+      // Assert.assertEquals(1, selectedTab);
+    } catch (Exception e) {
+      System.err.println("James not reachable");
+    }
+  }
+}
\ No newline at end of file

Added: james/bond/trunk/src/test/java/org/apache/james/bond/client/serverconnection/AppRequestFactoryTest.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/client/serverconnection/AppRequestFactoryTest.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/client/serverconnection/AppRequestFactoryTest.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/client/serverconnection/AppRequestFactoryTest.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,273 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.bond.client.serverconnection;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.james.bond.TestConst;
+import org.apache.james.bond.client.ioc.ClientFactory;
+import org.apache.james.bond.client.ioc.ClientFactoryTestImpl;
+import org.apache.james.bond.client.serverconnection.AppRequestFactory.DnsRequest;
+import org.apache.james.bond.client.serverconnection.AppRequestFactory.Pop3Request;
+import org.apache.james.bond.client.serverconnection.AppRequestFactory.SmtpRequest;
+import org.apache.james.bond.client.serverconnection.AppRequestFactory.UserRequest;
+import org.apache.james.bond.shared.BondConst;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.web.bindery.requestfactory.shared.Receiver;
+import com.google.web.bindery.requestfactory.shared.ServerFailure;
+
+public class AppRequestFactoryTest {
+  ClientFactory clientFactory = new ClientFactoryTestImpl();
+  AppRequestFactory requestFactory = clientFactory.getRequestFactory();
+
+  @Before
+  public void setup() {
+    new File(TestConst.TEST_CONF_FOLDER).mkdirs();
+    BondConst.JAMES_CONF = TestConst.TEST_CONF_FOLDER;
+  }
+
+  @Test
+  public void userFunctionalityTest() {
+    clearUser();
+    addUser();
+    removeUser();
+  }
+
+  private void clearUser() {
+    Receiver<List<UserProxy>> rec = new Receiver<List<UserProxy>>() {
+      public void onSuccess(List<UserProxy> users) {
+        UserRequest context = requestFactory.createUserRequest();
+        UserProxy user1234 = context.create(UserProxy.class);
+        String username = "user1234@yo.es";
+        user1234.setUsername(username);
+        user1234.setPassword("1234");
+
+        boolean contains = false;
+
+        for (UserProxy user : users) {
+          if (user.getId().equals(username)) {
+            contains = true;
+          }
+        }
+
+        if (contains) {
+          context.remove(user1234).fire();
+        }
+      }
+
+      public void onFailure(ServerFailure error) {
+        String msg = "Server error: " + error.getMessage();
+        System.err.println(msg);
+      }
+    };
+    requestFactory.createUserRequest().listUsers().fire(rec);
+  }
+
+  private void addUser() {
+    Receiver<List<UserProxy>> rec = new Receiver<List<UserProxy>>() {
+      public void onSuccess(List<UserProxy> users) {
+        UserRequest context = requestFactory.createUserRequest();
+        UserProxy user1234 = context.create(UserProxy.class);
+        String username = "user1234@yo.es";
+        user1234.setUsername(username);
+        user1234.setPassword("1234");
+
+        boolean contains = false;
+
+        for (UserProxy user : users) {
+
+          if (user.getId().equals(username)) {
+            contains = true;
+          }
+        }
+        assertFalse(contains);
+
+        context.persist(user1234).fire();
+      }
+
+      public void onFailure(ServerFailure error) {
+        String msg = "Server error: " + error.getMessage();
+        System.err.println(msg);
+      }
+    };
+    requestFactory.createUserRequest().listUsers().fire(rec);
+  }
+
+  private void removeUser() {
+    Receiver<List<UserProxy>> rec = new Receiver<List<UserProxy>>() {
+      public void onSuccess(List<UserProxy> users) {
+        UserRequest context = requestFactory.createUserRequest();
+        UserProxy user1234 = context.create(UserProxy.class);
+        String username = "user1234@yo.es";
+        user1234.setUsername(username);
+        user1234.setPassword("1234");
+
+        boolean contains = false;
+
+        for (UserProxy user : users) {
+
+          if (user.getId().equals(username)) {
+            contains = true;
+          }
+        }
+        assertFalse(!contains);
+
+        context.remove(user1234).fire();
+      }
+
+      public void onFailure(ServerFailure error) {
+        String msg = "Server error: " + error.getMessage();
+        System.err.println(msg);
+      }
+    };
+    requestFactory.createUserRequest().listUsers().fire(rec);
+  }
+
+  DnsRequest editableDnsRequest;
+  DNSProxy editableDnsProxy;
+
+  @Test
+  public void readDnsTest() {
+    File conf = new File(TestConst.TEST_CONF_FOLDER + "/"
+        + BondConst.NAME_TEMPL_DNS + ".conf");
+    conf.delete();
+
+    Receiver<DNSProxy> rec = new Receiver<DNSProxy>() {
+      public void onSuccess(DNSProxy dns) {
+        editableDnsRequest = requestFactory.createDnsRequest();
+        editableDnsProxy = editableDnsRequest.edit(dns);
+
+        List<String> dnsServerList = dns.getServersIp();
+        for (String server : dnsServerList) {
+          System.err.println(server);
+        }
+        assertTrue(dnsServerList.isEmpty());
+
+        assertTrue(dns.isAutodiscover());
+        assertFalse(dns.isAuthoritative());
+        assertFalse(dns.isSingleIPperMX());
+        assertEquals("50000", dns.getMaxCacheSize());
+        assertEquals(0, dns.getServersIp().size());
+      }
+
+      public void onFailure(ServerFailure error) {
+        String msg = "Server error: " + error.getMessage();
+        fail(msg);
+      }
+    };
+
+    this.requestFactory.createDnsRequest().getAllDNSData().fire(rec);
+  }
+
+  Pop3Request editablePop3Request;
+  Pop3Proxy editablePop3Proxy;
+
+  @Test
+  public void readPop3Test() {
+    File conf = new File(TestConst.TEST_CONF_FOLDER + "/"
+        + BondConst.NAME_TEMPL_POP3 + ".conf");
+    conf.delete();
+
+    Receiver<Pop3Proxy> rec = new Receiver<Pop3Proxy>() {
+      public void onSuccess(Pop3Proxy pop3) {
+        editablePop3Request = requestFactory.createPop3Request();
+        editablePop3Proxy = editablePop3Request.edit(pop3);
+
+        assertTrue(pop3.isEnabled());
+        assertEquals("0.0.0.0:110", pop3.getBind());
+        assertEquals("200", pop3.getConnectionBacklog());
+        assertEquals("1200", pop3.getConnectionTimeout());
+        assertEquals("0", pop3.getConnectionLimit());
+        assertEquals("0", pop3.getConnectionLimitPerIp());
+        assertTrue(pop3.isHelloNameAutodetect());
+        assertNull(pop3.getHelloNameValue());
+        assertFalse(pop3.isTlsSocket());
+        assertFalse(pop3.isTlsStart());
+        assertEquals("file://conf/keystore", pop3.getTlsKeystore());
+        assertEquals("yoursecret", pop3.getTlsSecret());
+        assertEquals("org.bouncycastle.jce.provider.BouncyCastleProvider",
+            pop3.getTlsProvider());
+      }
+
+      public void onFailure(ServerFailure error) {
+        String msg = "Server error: " + error.getMessage();
+        fail(msg);
+      }
+    };
+
+    this.requestFactory.createPop3Request().getAllPop3Data().fire(rec);
+  }
+
+  SmtpRequest editableSmtpRequest;
+  SmtpProxy editableSmtpProxy;
+
+  @Test
+  public void readSmtpTest() {
+    File conf = new File(TestConst.TEST_CONF_FOLDER + "/"
+        + BondConst.NAME_TEMPL_SMTP + ".conf");
+    conf.delete();
+
+    Receiver<SmtpProxy> rec = new Receiver<SmtpProxy>() {
+      public void onSuccess(SmtpProxy smtp) {
+        editableSmtpRequest = requestFactory.createSmtpRequest();
+        editableSmtpProxy = editableSmtpRequest.edit(smtp);
+
+        assertTrue(smtp.isEnabled());
+        assertEquals("0.0.0.0:25", smtp.getBind());
+        assertEquals("200", smtp.getConnectionBacklog());
+        assertEquals("360", smtp.getConnectionTimeout());
+        assertEquals("0", smtp.getConnectionLimit());
+        assertEquals("0", smtp.getConnectionLimitPerIp());
+        assertTrue(smtp.isHelloNameAutodetect());
+        assertNull(smtp.getHelloNameValue());
+        assertFalse(smtp.isTlsSocket());
+        assertFalse(smtp.isTlsStart());
+        assertEquals("file://conf/keystore", smtp.getTlsKeystore());
+        assertEquals("yoursecret", smtp.getTlsSecret());
+        assertEquals("org.bouncycastle.jce.provider.BouncyCastleProvider",
+            smtp.getTlsProvider());
+        assertEquals("SunX509", smtp.getTlsAlgorithm());
+
+        assertEquals("false", smtp.getAuthRequired());
+        assertTrue(smtp.isVerifyIdentity());
+        assertEquals("0", smtp.getMaximumMessageSize());
+        assertTrue(smtp.isHeloEhloEnforcement());
+        assertTrue(smtp.isAddrBracketsEnforcement());
+        assertNull(smtp.getGreeting());
+        assertEquals("127.0.0.0/8", smtp.getAuthorizedAddresses());
+      }
+
+      public void onFailure(ServerFailure error) {
+        String msg = "Server error: " + error.getMessage();
+        fail(msg);
+      }
+    };
+
+    this.requestFactory.createSmtpRequest().getAllSmtpData().fire(rec);
+  }
+}

Added: james/bond/trunk/src/test/java/org/apache/james/bond/server/JamesConnectorTest.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/server/JamesConnectorTest.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/server/JamesConnectorTest.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/server/JamesConnectorTest.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,73 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.bond.server;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.james.bond.server.manage.domain.Domain;
+import org.apache.james.bond.server.manage.user.User;
+import org.junit.Test;
+
+public class JamesConnectorTest {
+
+  @Test
+  public void testAddDeleteUser() {
+    try {
+      List<User> users = JamesConnector.listUsers();
+      User user1234 = new User("user1234@yo.es", "1234");
+
+      if (users.contains(user1234))
+        JamesConnector.removeUser(user1234);
+
+      JamesConnector.addUser(user1234);
+      users = JamesConnector.listUsers();
+      assertTrue(users.contains(user1234));
+
+      JamesConnector.removeUser(user1234);
+      users = JamesConnector.listUsers();
+      assertFalse(users.contains(user1234));
+    } catch (Exception e) {
+      System.err.println("James server not reachable");
+    }
+  }
+
+  @Test
+  public void testAddDeleteDomain() {
+    try {
+      List<Domain> domains = JamesConnector.listDomains();
+      Domain domain = new Domain("domain.es");
+
+      if (domains.contains(domain))
+        JamesConnector.removeDomain(domain);
+
+      JamesConnector.addDomain(domain);
+      domains = JamesConnector.listDomains();
+      assertTrue(domains.contains(domain));
+
+      JamesConnector.removeDomain(domain);
+      domains = JamesConnector.listDomains();
+      assertFalse(domains.contains(domain));
+    } catch (Exception e) {
+      System.err.println("James server not reachable");
+    }
+  }
+}

Added: james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/dns/DNSEditorTest.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/dns/DNSEditorTest.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/dns/DNSEditorTest.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/dns/DNSEditorTest.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,96 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.bond.server.configure.dns;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.james.bond.TestConst;
+import org.apache.james.bond.server.configure.dns.DNS;
+import org.apache.james.bond.server.configure.dns.DNSEditor;
+import org.apache.james.bond.shared.BondConst;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DNSEditorTest {
+
+  @Before
+  public void setup() {
+    new File(TestConst.TEST_CONF_FOLDER).mkdirs();
+    BondConst.JAMES_CONF = TestConst.TEST_CONF_FOLDER;
+  }
+
+  @Test
+  public void testReadXml() throws Exception {
+    File conf = new File(TestConst.TEST_CONF_FOLDER + "/"
+        + BondConst.NAME_TEMPL_DNS + ".conf");
+    conf.delete();
+
+    DNS dns = DNSEditor.readProtocol();
+
+    assertTrue(conf.exists());
+
+    List<String> dnsServerList = dns.getServersIp();
+    assertTrue(dnsServerList.isEmpty());
+
+    assertTrue(dns.isAutodiscover());
+    assertFalse(dns.isAuthoritative());
+    assertFalse(dns.isSingleIPperMX());
+    assertEquals("50000", dns.getMaxCacheSize());
+    assertEquals(0, dns.getServersIp().size());
+
+    dns.setAutodiscover(false);
+    dns.setAuthoritative(true);
+    dns.setSingleIPperMX(true);
+    dns.setMaxCacheSize("10000");
+    dns.setServersIp(Arrays.asList("127.0.0.1", "192.168.1.1"));
+
+    DNSEditor.writeProtocol(dns);
+
+    dns = DNSEditor.readProtocol();
+    assertFalse(dns.isAutodiscover());
+    assertTrue(dns.isAuthoritative());
+    assertTrue(dns.isSingleIPperMX());
+    assertEquals("10000", dns.getMaxCacheSize());
+    assertEquals(2, dns.getServersIp().size());
+    assertTrue(dns.getServersIp().contains("127.0.0.1"));
+    assertTrue(dns.getServersIp().contains("192.168.1.1"));
+
+    dns.setServersIp(Arrays.asList("127.0.0.1", "192.168.1.1", "10.0.0.1"));
+    assertEquals(3, dns.getServersIp().size());
+    assertTrue(dns.getServersIp().contains("127.0.0.1"));
+    assertTrue(dns.getServersIp().contains("192.168.1.1"));
+    assertTrue(dns.getServersIp().contains("10.0.0.1"));
+
+    DNSEditor.writeProtocol(dns);
+    dns = DNSEditor.readProtocol();
+    assertFalse(dns.isAutodiscover());
+    assertTrue(dns.isAuthoritative());
+    assertTrue(dns.isSingleIPperMX());
+    assertEquals("10000", dns.getMaxCacheSize());
+    assertEquals(3, dns.getServersIp().size());
+
+    conf.delete();
+  }
+}
\ No newline at end of file

Added: james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/imap/ImapEditorTest.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/imap/ImapEditorTest.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/imap/ImapEditorTest.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/imap/ImapEditorTest.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,83 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.bond.server.configure.imap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.apache.james.bond.TestConst;
+import org.apache.james.bond.shared.BondConst;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ImapEditorTest {
+  private ImapEditor imapEditor;
+
+  @Before
+  public void setup() {
+    new File(TestConst.TEST_CONF_FOLDER).mkdirs();
+    BondConst.JAMES_CONF = TestConst.TEST_CONF_FOLDER;
+    imapEditor = new ImapEditor();
+  }
+
+  @Test
+  public void testReadXml() throws Exception {
+    File conf = new File(TestConst.TEST_CONF_FOLDER + "/"
+        + BondConst.NAME_TEMPL_IMAP + ".conf");
+    conf.delete();
+
+    Imap imap;
+    imap = imapEditor.readProtocol();
+
+    assertTrue(conf.exists());
+
+    assertTrue(imap.isEnabled());
+    assertEquals("0.0.0.0:143", imap.getBind());
+    assertEquals("200", imap.getConnectionBacklog());
+    assertEquals("1800", imap.getConnectionTimeout());
+    assertEquals("0", imap.getConnectionLimit());
+    assertEquals("0", imap.getConnectionLimitPerIp());
+    assertTrue(imap.isHelloNameAutodetect());
+    assertNull(imap.getHelloNameValue());
+    assertFalse(imap.isTlsSocket());
+    assertFalse(imap.isTlsStart());
+    assertEquals("file://conf/keystore", imap.getTlsKeystore());
+    assertEquals("yoursecret", imap.getTlsSecret());
+    assertEquals("org.bouncycastle.jce.provider.BouncyCastleProvider",
+        imap.getTlsProvider());
+
+    // imap.setConnectionBacklog(300);
+    // imap.setConnectionTimeout(1400);
+    // imap.setHelloNameAutodetect(false);
+    // imap.setHelloNameValue("Hello");
+    //
+    // imapEditor.writeProtocol(imap);
+    //
+    // imap = imapEditor.readProtocol();
+    //
+    // assertEquals(300, imap.getConnectionBacklog());
+    // assertEquals(1400, imap.getConnectionTimeout());
+    // assertFalse(imap.isHelloNameAutodetect());
+    // assertEquals("Hello", imap.getHelloNameValue());
+  }
+}

Added: james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/lmtp/LmtpEditorTest.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/lmtp/LmtpEditorTest.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/lmtp/LmtpEditorTest.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/lmtp/LmtpEditorTest.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,91 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.bond.server.configure.lmtp;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.apache.james.bond.TestConst;
+import org.apache.james.bond.shared.BondConst;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LmtpEditorTest {
+  private LmtpEditor lmtpEditor;
+
+  @Before
+  public void setup() {
+    new File(TestConst.TEST_CONF_FOLDER).mkdirs();
+    BondConst.JAMES_CONF = TestConst.TEST_CONF_FOLDER;
+    lmtpEditor = new LmtpEditor();
+  }
+
+  @Test
+  public void testReadXml() throws Exception {
+    File conf = new File(TestConst.TEST_CONF_FOLDER + "/"
+        + BondConst.NAME_TEMPL_LMTP + ".conf");
+    conf.delete();
+
+    Lmtp lmtp;
+    lmtp = lmtpEditor.readProtocol();
+
+    assertTrue(conf.exists());
+
+    assertFalse(lmtp.isEnabled());
+    assertEquals("127.0.0.1:24", lmtp.getBind());
+    assertEquals("200", lmtp.getConnectionBacklog());
+    assertEquals("1200", lmtp.getConnectionTimeout());
+    assertEquals("0", lmtp.getConnectionLimit());
+    assertEquals("0", lmtp.getConnectionLimitPerIp());
+    assertTrue(lmtp.isHelloNameAutodetect());
+    assertNull(lmtp.getHelloNameValue());
+    assertFalse(lmtp.isTlsSocket());
+    assertFalse(lmtp.isTlsStart());
+    assertNull(lmtp.getTlsKeystore());
+    assertNull(lmtp.getTlsSecret());
+    assertNull(lmtp.getTlsProvider());
+
+    assertEquals("0", lmtp.getMaximumMessageSize());
+    assertNull(lmtp.getGreeting());
+
+    lmtp.setConnectionBacklog("300");
+    lmtp.setConnectionTimeout("1400");
+    lmtp.setHelloNameAutodetect(false);
+    lmtp.setHelloNameValue("Hello");
+
+    lmtp.setMaximumMessageSize("30");
+    lmtp.setGreeting("James Lmtp Hello");
+
+    lmtpEditor.writeProtocol(lmtp);
+
+    lmtp = lmtpEditor.readProtocol();
+
+    assertEquals("300", lmtp.getConnectionBacklog());
+    assertEquals("1400", lmtp.getConnectionTimeout());
+    assertFalse(lmtp.isHelloNameAutodetect());
+    assertEquals("Hello", lmtp.getHelloNameValue());
+
+    assertEquals("30", lmtp.getMaximumMessageSize());
+    assertEquals("James Lmtp Hello", lmtp.getGreeting());
+  }
+}

Added: james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/pop3/Pop3EditorTest.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/pop3/Pop3EditorTest.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/pop3/Pop3EditorTest.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/pop3/Pop3EditorTest.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,85 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.bond.server.configure.pop3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.apache.james.bond.TestConst;
+import org.apache.james.bond.shared.BondConst;
+import org.junit.Before;
+import org.junit.Test;
+
+public class Pop3EditorTest {
+  private Pop3Editor pop3Editor;
+  
+  @Before
+  public void setup() {
+    new File(TestConst.TEST_CONF_FOLDER).mkdirs();
+    BondConst.JAMES_CONF = TestConst.TEST_CONF_FOLDER;
+    pop3Editor = new Pop3Editor();
+  }
+
+  @Test
+  public void testReadXml() throws Exception {
+    File conf = new File(TestConst.TEST_CONF_FOLDER + "/"
+        + BondConst.NAME_TEMPL_POP3 + ".conf");
+    conf.delete();
+
+    Pop3 pop3;
+    pop3 = pop3Editor.readProtocol();
+    
+    assertTrue(conf.exists());
+
+    assertTrue(pop3.isEnabled());
+    assertEquals("0.0.0.0:110", pop3.getBind());
+    assertEquals("200", pop3.getConnectionBacklog());
+    assertEquals("1200", pop3.getConnectionTimeout());
+    assertEquals("0", pop3.getConnectionLimit());
+    assertEquals("0", pop3.getConnectionLimitPerIp());
+    assertTrue(pop3.isHelloNameAutodetect());
+    assertNull(pop3.getHelloNameValue());
+    assertFalse(pop3.isTlsSocket());
+    assertFalse(pop3.isTlsStart());
+    assertEquals("file://conf/keystore", pop3.getTlsKeystore());
+    assertEquals("yoursecret", pop3.getTlsSecret());
+    assertEquals("org.bouncycastle.jce.provider.BouncyCastleProvider",
+        pop3.getTlsProvider());
+
+    // pop3.setEnabled(false);
+    pop3.setConnectionBacklog("300");
+    pop3.setConnectionTimeout("1400");
+    pop3.setHelloNameAutodetect(false);
+    pop3.setHelloNameValue("Hello");
+
+    pop3Editor.writeProtocol(pop3);
+
+    pop3 = pop3Editor.readProtocol();
+
+    // assertFalse(pop3.isEnabled());
+    assertEquals("300", pop3.getConnectionBacklog());
+    assertEquals("1400", pop3.getConnectionTimeout());
+    assertFalse(pop3.isHelloNameAutodetect());
+    assertEquals("Hello", pop3.getHelloNameValue());
+  }
+}
\ No newline at end of file

Added: james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/smtp/SmtpEditorTest.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/smtp/SmtpEditorTest.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/smtp/SmtpEditorTest.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/server/configure/smtp/SmtpEditorTest.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,108 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.bond.server.configure.smtp;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.apache.james.bond.TestConst;
+import org.apache.james.bond.shared.BondConst;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SmtpEditorTest {
+  private SmtpEditor smtpEditor;
+
+  @Before
+  public void setup() {
+    new File(TestConst.TEST_CONF_FOLDER).mkdirs();
+    BondConst.JAMES_CONF = TestConst.TEST_CONF_FOLDER;
+    smtpEditor = new SmtpEditor();
+  }
+
+  @Test
+  public void testReadXml() throws Exception {
+    File conf = new File(TestConst.TEST_CONF_FOLDER + "/"
+        + BondConst.NAME_TEMPL_SMTP + ".conf");
+    conf.delete();
+
+    Smtp smtp;
+    smtp = smtpEditor.readProtocol();
+
+    assertTrue(conf.exists());
+
+    assertTrue(smtp.isEnabled());
+    assertEquals("0.0.0.0:25", smtp.getBind());
+    assertEquals("200", smtp.getConnectionBacklog());
+    assertEquals("360", smtp.getConnectionTimeout());
+    assertEquals("0", smtp.getConnectionLimit());
+    assertEquals("0", smtp.getConnectionLimitPerIp());
+    assertTrue(smtp.isHelloNameAutodetect());
+    assertNull(smtp.getHelloNameValue());
+    assertFalse(smtp.isTlsSocket());
+    assertFalse(smtp.isTlsStart());
+    assertEquals("file://conf/keystore", smtp.getTlsKeystore());
+    assertEquals("yoursecret", smtp.getTlsSecret());
+    assertEquals("org.bouncycastle.jce.provider.BouncyCastleProvider",
+        smtp.getTlsProvider());
+    assertEquals("SunX509", smtp.getTlsAlgorithm());
+
+    assertEquals("false", smtp.getAuthRequired());
+    assertTrue(smtp.isVerifyIdentity());
+    assertEquals("0", smtp.getMaximumMessageSize());
+    assertTrue(smtp.isHeloEhloEnforcement());
+    assertTrue(smtp.isAddrBracketsEnforcement());
+    assertNull(smtp.getGreeting());
+    assertEquals("127.0.0.0/8", smtp.getAuthorizedAddresses());
+
+    smtp.setConnectionBacklog("300");
+    smtp.setConnectionTimeout("1400");
+    smtp.setHelloNameAutodetect(false);
+    smtp.setHelloNameValue("Hello");
+
+    smtp.setAuthRequired("announce");
+    smtp.setVerifyIdentity(false);
+    smtp.setMaximumMessageSize("30");
+    smtp.setHeloEhloEnforcement(false);
+    smtp.setAddrBracketsEnforcement(false);
+    smtp.setGreeting("James Smtp Hello");
+    smtp.setAuthorizedAddresses("127.0.0.0/255.0.0.0");
+
+    smtpEditor.writeProtocol(smtp);
+
+    smtp = smtpEditor.readProtocol();
+
+    assertEquals("300", smtp.getConnectionBacklog());
+    assertEquals("1400", smtp.getConnectionTimeout());
+    assertFalse(smtp.isHelloNameAutodetect());
+    assertEquals("Hello", smtp.getHelloNameValue());
+
+    assertEquals("announce", smtp.getAuthRequired());
+    assertFalse(smtp.isVerifyIdentity());
+    assertEquals("30", smtp.getMaximumMessageSize());
+    assertFalse(smtp.isHeloEhloEnforcement());
+    assertFalse(smtp.isAddrBracketsEnforcement());
+    assertEquals("James Smtp Hello", smtp.getGreeting());
+    assertEquals("127.0.0.0/255.0.0.0", smtp.getAuthorizedAddresses());
+  }
+}

Added: james/bond/trunk/src/test/java/org/apache/james/bond/server/manage/domain/DomainCacheTest.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/server/manage/domain/DomainCacheTest.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/server/manage/domain/DomainCacheTest.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/server/manage/domain/DomainCacheTest.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,52 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.bond.server.manage.domain;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.Test;
+
+public class DomainCacheTest {
+
+  @Test
+  public void testAddDeleteDomain() {
+    try {
+      DomainCache domainsCache = new DomainCache();
+
+      List<Domain> domains = domainsCache.listDomains();
+      Domain domain = new Domain("domain.es");
+
+      if (domains.contains(domain)) {
+        domainsCache.removeDomain(domain);
+      }
+      domainsCache.addDomain(domain);
+      domains = domainsCache.listDomains();
+      assertTrue(domains.contains(domain));
+
+      domainsCache.removeDomain(domain);
+      domains = domainsCache.listDomains();
+      assertFalse(domains.contains(domain));
+    } catch (Exception e) {
+      System.err.println("James server not reachable");
+    }
+  }
+}

Added: james/bond/trunk/src/test/java/org/apache/james/bond/server/monitor/JMXBondConnectorTest.java
URL: http://svn.apache.org/viewvc/james/bond/trunk/src/test/java/org/apache/james/bond/server/monitor/JMXBondConnectorTest.java?rev=1607764&view=auto
==============================================================================
--- james/bond/trunk/src/test/java/org/apache/james/bond/server/monitor/JMXBondConnectorTest.java (added)
+++ james/bond/trunk/src/test/java/org/apache/james/bond/server/monitor/JMXBondConnectorTest.java Thu Jul  3 22:57:59 2014
@@ -0,0 +1,22 @@
+package org.apache.james.bond.server.monitor;
+
+import java.io.IOException;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+public class JMXBondConnectorTest {
+  @Test
+  public void testConnection() {
+    try {
+      JMXBondConnector jmxConnector = new JMXBondConnector();
+      
+      Monitoring m = jmxConnector.getMonitoringInformation();
+      
+      Assert.assertTrue(m.getDaemonThreadCount() > 0);
+    } catch (IOException e) {
+      System.err.println("James server not reachable");
+    }
+  }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message