//	Copyright 2012 John Luetke
//
//	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 WeatherAPI.Tests;
	
import WeatherAPI.IWeather;
import WeatherAPI.WeatherAPI;
import org.junit.Test;

public class WeatherTest {
		
	@Test
	public void testAirportCodes() {
		
		String[] airports = new String[] {
			"SEA",
			"SFO",
			"LAX",
			"ORD",
			"DEN",
			"ATL",
			"JFK",
			"LHR",
			"HND",
			"CDG"
		};
		
		for (int i = 0; i < airports.length; i++) {
			if (i != 0 && i % 10 == 0) {
				try {
                                        System.out.println("Sleeping to avoid rate-limiting...");
					Thread.sleep(60 * 1000);
				}
				catch (Exception e) {
					
				}
			}
			printWeather(WeatherAPI.getWeather(airports[i]));
		}
                
		try {
                        System.out.println("Sleeping to avoid rate-limiting...");
			Thread.sleep(60 * 1000);
		}
		catch (Exception e) {
		}
	}
	
	@Test
	public void testZIPCodes() {
		
		int[] zipCodes = new int[] {
			2045,
			12941,
			27323,
			36033,
			41554,
			55718,
			69022,
			71066,
			88042,
			97436,
		};
		
		for (int i = 0; i < zipCodes.length; i++) {
			if (i != 0 && i % 10 == 0) {
				try {
                                        System.out.println("Sleeping to avoid rate-limiting...");
					Thread.sleep(60 * 1000);
				}
				catch (Exception e) {
					
				}
			}
			printWeather(WeatherAPI.getWeather(zipCodes[i]));
		}
                
		try {
                        System.out.println("Sleeping to avoid rate-limiting...");
			Thread.sleep(60 * 1000);
		}
		catch (Exception e) {
		}
	}
        
        @Test
        public void testCityState() {
		String[][] cities = new String[][] {
			new String[] {"San Francisco", "CA"},
			new String[] {"Los Angeles", "CA"},
			new String[] {"New York City", "NY"}
		};
		
		for (int i = 0; i < cities.length; i++) {
			if (i != 0 && i % 10 == 0) {
				try {
                                        System.out.println("Sleeping to avoid rate-limiting...");
					Thread.sleep(60 * 1000);
				}
				catch (Exception e) {
					
				}
			}
			printWeather(WeatherAPI.getWeather(cities[i][0], cities[i][1]));
		}
        }
	
	private void printWeather(IWeather w) {
		System.out.println(String.format("--- %s ---", w.getLocationName()));
		System.out.println(String.format("Degrees C:          %s", w.getDegreesCelsius()));
		System.out.println(String.format("Degrees F:          %s", w.getDegressFahrenheit()));
		System.out.println(String.format("Wind (MPH):         %s", w.getWindSpeedMPH()));
		System.out.println(String.format("Wind (KPH):         %s", w.getWindSpeedKPH()));
		System.out.println(String.format("Wind Direction:     %s", w.getWindDirection()));
		System.out.println(String.format("Percipitation (mm): %s", w.getPrecipitation()));
		System.out.println(String.format("Clouds:             %s", w.getCloudCover()));
		System.out.println(String.format("Humidity:           %s", w.getHumidity()));
		System.out.println(String.format("Conditions:         %s", w.getConditions()));
		System.out.println();
	}
}


@@ -1146,39 +1146,34 @@
  (Exception e) %7B
-%0A%09%09%09%09
 %09%0A
+
 %09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09pr
@@ -1814,38 +1814,32 @@
 (Exception e) %7B%0A
-%09%09%09%09%09%0A
 %09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09pr
@@ -2533,21 +2533,16 @@
 ion e) %7B
-%0A%09%09%09%09
 %09%0A%09%09%09%09%7D%0A
@@ -2610,32 +2610,164 @@
 es%5Bi%5D%5B1%5D));%0A%09%09%7D%0A
+%09%09%0A%09%09try %7B%0A%09%09%09System.out.println(%22Sleeping to avoid rate-limiting...%22);%0A%09%09%09Thread.sleep(60 * 1000);%0A%09%09%7D%0A%09%09catch (Exception e) %7B%0A%09%09%7D%0A
         %7D%0A%09%0A%09pri
@@ -3663,7 +3663,5 @@
 %0A%09%7D%0A
+
 %7D
-%0A%0A

Test clean-up