/*
 * Copyright 2010 netling project <http://netling.org>
 *
 * Licensed 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.
 *
 * This file may incorporate work covered by the following copyright and
 * permission notice:
 *
 *     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.netling.ftp;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;

import org.junit.Test;
<<<<<<< HEAD
import org.netling.MalformedServerReplyException;
import org.netling.ftp.FTP.FileType;
=======
>>>>>>> 059609572b530ecd0a3de6d5d5ed5da7ab8c88e3


public class FTPClientTest {
	
	/**
	 * Dummy client class that saves calling methods on an unconnected socket
	 */
	class DummyFTPClient extends FTPClient {
		private ArrayList<String> commandBuf = new ArrayList<String>();
		
		@Override
		public InetAddress getRemoteAddress()  {
			InetAddress addr = null;
			try {
				// this form of getByAddress() shouldnt make any DNS calls
				addr = InetAddress.getByAddress("localhost", new byte[]{127,0,0,1});
			} catch (UnknownHostException e) {
				fail("Error creating dummy IP address:" + e.getMessage());
			}
			return addr;
		}
		
		
		@Override
		public int sendCommand(FTPCommand command, String args)
				throws IOException {
			commandBuf.add(command.command() + " " + args);
			return FTPReply.COMMAND_OK.code();
		}
		
		public ArrayList<String> getCommandBuf() { return commandBuf; }
	}
	
	FTPClient client = new DummyFTPClient();
	
	@Test
	public void testParsePassiveModeReply() {
		String reply = "227 Entering Passive Mode (64,4,30,33,59,205)";
		try {
			client.parsePassiveModeReply(reply);
		} catch (MalformedServerReplyException e) {
			fail("PASV reply [" + reply + "] should parse correctly");
		}
		assertEquals("64.4.30.33", client.getPassiveHost());
		assertEquals(59<<8|205, client.getPassivePort());
	}
	
	@Test
	public void testExtendedPassiveModeReply() {
		String reply = "229 Entering Extended Passive Mode (|||13747|)";
		try {
			client.parseExtendedPassiveModeReply(reply);
		} catch (MalformedServerReplyException e) {
			fail("EPSV reply [" + reply + "] should parse correctly");
		}
	}

	@Test
	public void testFileType() throws IOException {
		client.setFileType(FileType.BINARY);
		assertEquals(client.fileType ,FileType.BINARY);
		
		client.setFileType(FileType.ASCII);
		assertEquals(client.fileType ,FileType.ASCII);
		
		System.out.println((((DummyFTPClient)client).getCommandBuf()));
		
	}

}

@@ -1839,164 +1839,45 @@
 st;%0A
-%3C%3C%3C%3C%3C%3C%3C HEAD%0Aimport org.netling.MalformedServerReplyException;%0Aimport org.netling.ftp.FTP.FileType;%0A=======%0A%3E%3E%3E%3E%3E%3E%3E 059609572b530ecd0a3de6d5d5ed5da7ab8c88e3
+import org.netling.ftp.FTP.FileType;%0A
 %0A%0A%0Ap

Remove import