1 /**************************************************************** 2 * Licensed to the Apache Software Foundation (ASF) under one * 3 * or more contributor license agreements. See the NOTICE file * 4 * distributed with this work for additional information * 5 * regarding copyright ownership. The ASF licenses this file * 6 * to you under the Apache License, Version 2.0 (the * 7 * "License"); you may not use this file except in compliance * 8 * with the License. You may obtain a copy of the License at * 9 * * 10 * http://www.apache.org/licenses/LICENSE-2.0 * 11 * * 12 * Unless required by applicable law or agreed to in writing, * 13 * software distributed under the License is distributed on an * 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 15 * KIND, either express or implied. See the License for the * 16 * specific language governing permissions and limitations * 17 * under the License. * 18 ****************************************************************/ 19 20 package org.apache.james.mpt; 21 22 23 /** 24 * <p>Connects to a host system serving on an open port.</p> 25 * <p> 26 * This is typically used for functional integration testing of a complete 27 * server system (including sockets). Apache James MPT AntLib provides an 28 * <a href='http://ant.apache.org' rel='tag'>Ant</a> task suitable for this 29 * use case. 30 * </p> 31 */ 32 public class ExternalHostSystem extends ExternalSessionFactory implements HostSystem { 33 34 private final UserAdder userAdder; 35 36 /** 37 * Constructs a host system suitable for connection to an open port. 38 * @param host host name that will be connected to, not null 39 * @param port port on host that will be connected to, not null 40 * @param monitor monitors the conduct of the connection 41 * @param shabang protocol shabang will be sent to the script test in the place of the 42 * first line received from the server. Many protocols pass server specific information 43 * in the first line. When not null, this line will be replaced. 44 * Or null when the first line should be passed without replacement 45 * @param userAdder null when test system has appropriate users already set 46 */ 47 public ExternalHostSystem(final String host, final int port, 48 final Monitor monitor, final String shabang, final UserAdder userAdder) { 49 super(host, port, monitor, shabang); 50 this.userAdder = userAdder; 51 } 52 53 public void addUser(String user, String password) throws Exception { 54 if (userAdder == null) { 55 monitor.note("Please ensure user '" + user + "' with password '" 56 + password + "' exists."); 57 } else { 58 userAdder.addUser(user, password); 59 } 60 } 61 }