/*
 * 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.
 */

package org.netling.ftp;

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

import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class FTPClientConfigTest {

	/*
	 * Class under test for void FTPClientConfig(String)
	 */
	public void testFTPClientConfigString() {
		FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_VMS);
		assertEquals(FTPClientConfig.SYST_VMS, config.getServerSystemKey());
		assertEquals(config.getDefaultDateFormatStr(), null);
		assertEquals(config.getRecentDateFormatStr(), null);
		assertEquals(config.getShortMonthNames(), null);
		assertEquals(config.getServerTimeZoneId(), null);
		assertEquals(config.getServerLanguageCode(), null);
	}

	String A = "A";
	String B = "B";
	String C = "C";
	String D = "D";
	String E = "E";
	String F = "F";

	/*
	 * Class under test for void FTPClientConfig(String, String, String, String, String, String)
	 */
	public void testFTPClientConfigStringStringStringStringStringString() {
		FTPClientConfig conf = new FTPClientConfig(A,B,C,D,E,F);

		assertEquals("A", conf.getServerSystemKey());
		assertEquals("B", conf.getDefaultDateFormatStr());
		assertEquals("C", conf.getRecentDateFormatStr());
		assertEquals("E", conf.getShortMonthNames());
		assertEquals("F", conf.getServerTimeZoneId());
		assertEquals("D", conf.getServerLanguageCode());
	}


	String badDelim = "jan,feb,mar,apr,may,jun,jul,aug.sep,oct,nov,dec";
	String tooLong =  "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|jan";
	String tooShort = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov";
	String fakeLang = "abc|def|ghi|jkl|mno|pqr|stu|vwx|yza|bcd|efg|hij";

	public void testSetShortMonthNames() {
	}

	public void testGetServerLanguageCode() {
	}

	public void testLookupDateFormatSymbols() {
		DateFormatSymbols dfs1 = null;
		DateFormatSymbols dfs2 = null;
		DateFormatSymbols dfs3 = null;
		DateFormatSymbols dfs4 = null;


		try {
			dfs1 = FTPClientConfig.lookupDateFormatSymbols("fr");
		} catch (IllegalArgumentException e){
			fail("french");
		}

		try {
			dfs2 = FTPClientConfig.lookupDateFormatSymbols("sq");
		} catch (IllegalArgumentException e){
			fail("albanian");
		}

		try {
			dfs3 = FTPClientConfig.lookupDateFormatSymbols("ru");
		} catch (IllegalArgumentException e){
			fail("unusupported.default.to.en");
		}
		try {
			dfs4 = FTPClientConfig.lookupDateFormatSymbols(fakeLang);
		} catch (IllegalArgumentException e){
			fail("not.language.code.but.defaults");
		}

		assertEquals(dfs3,dfs4);

		SimpleDateFormat sdf1 = new SimpleDateFormat("d MMM yyyy", dfs1);
		SimpleDateFormat sdf2 = new SimpleDateFormat("MMM dd, yyyy", dfs2);
		SimpleDateFormat sdf3 = new SimpleDateFormat("MMM dd, yyyy", dfs3);
		Date d1 = null;
		Date d2 = null;
		Date d3 = null;
		try {
			d1 = sdf1.parse("31 d\u00e9c 2004");
		} catch (ParseException px) {
			fail("failed.to.parse.french");
		}
		try {
			d2 = sdf2.parse("dhj 31, 2004");
		} catch (ParseException px) {
			fail("failed.to.parse.albanian");
		}
		try {
			d3 = sdf3.parse("DEC 31, 2004");
		} catch (ParseException px) {
			fail("failed.to.parse.'russian'");
		}
		assertEquals("different.parser.same.date", d1, d2);
		assertEquals("different.parser.same.date", d1, d3);

	}

	public void testGetDateFormatSymbols() {

		try {
			FTPClientConfig.getDateFormatSymbols(badDelim);
			fail("bad delimiter");
		} catch (IllegalArgumentException e){
			// should have failed
		}
		try {
			FTPClientConfig.getDateFormatSymbols(tooLong);
			fail("more than 12 months");
		} catch (IllegalArgumentException e){
			// should have failed
		}
		try {
			FTPClientConfig.getDateFormatSymbols(tooShort);
			fail("fewer than 12 months");
		} catch (IllegalArgumentException e){
			// should have failed
		}
		DateFormatSymbols dfs2 = null;
		try {
			dfs2 = FTPClientConfig.getDateFormatSymbols(fakeLang);
		} catch (Exception e){
			fail("rejected valid short month string");
		}
		SimpleDateFormat sdf1 = 
			new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH);
		SimpleDateFormat sdf2 = new SimpleDateFormat("MMM dd, yyyy", dfs2);

		Date d1 = null;
		Date d2 = null;
		try {
			d1 = sdf1.parse("dec 31, 2004");
		} catch (ParseException px) {
			fail("failed.to.parse.std");
		}
		try {
			d2 = sdf2.parse("hij 31, 2004");
		} catch (ParseException px) {
			fail("failed.to.parse.weird");
		}

		assertEquals("different.parser.same.date",d1, d2);

		try {
			d2 = sdf1.parse("hij 31, 2004");
			fail("should.have.failed.to.parse.weird");
		} catch (ParseException px) {
		}
		try {
			d2 = sdf2.parse("dec 31, 2004");
			fail("should.have.failed.to.parse.standard");
		} catch (ParseException px) {
		}


	}

}

@@ -872,16 +872,40 @@
 ocale;%0A%0A
+import org.junit.Test;%0A%0A
 public c
@@ -987,32 +987,39 @@
 ig(String)%0A%09 */%0A
+%09@Test%0A
 %09public void tes
@@ -1668,16 +1668,23 @@
 g)%0A%09 */%0A
+%09@Test%0A
 %09public 
@@ -2400,97 +2400,13 @@
 ;%0A%0A%09
-public void testSetShortMonthNames() %7B%0A%09%7D%0A%0A%09public void testGetServerLanguageCode() %7B%0A%09%7D%0A
+@Test
 %0A%09pu
@@ -3903,16 +3903,23 @@
 );%0A%0A%09%7D%0A%0A
+%09@Test%0A
 %09public 

Add test annotations