package com.example.tests;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;

import com.example.fw.ApplicationManager;



public class BasicClass extends Object{

	static protected ApplicationManager controlManager;
		 
	@BeforeTest
	public void setUp() throws Exception {
		controlManager = new ApplicationManager();
	    }

	@AfterTest
	public void tearDown() throws Exception {
		controlManager.stop();
	  }
	
	@DataProvider
	public Iterator<Object[]> randInitGroup() {
		List<Object[]> list = new ArrayList<Object[]>();
		for (int i =0; i<3; i++){
			InitGroupParameter groupR = new InitGroupParameter();	
			groupR.nameGroup = GenerateString();
			groupR.head = GenerateString();
			groupR.foot = GenerateString();
			list.add(new Object[]{groupR});
		}
		return list.iterator();
	}
	
	@DataProvider
	public Iterator<Object[]> randInitContact() {
		Random rnd = new Random();
		List<Object[]> list = new ArrayList<Object[]>();
		for (int i =0; i<5; i++){
			Integer day = rnd.nextInt(30);
			Integer mon = rnd.nextInt(11);
			Integer year = rnd.nextInt(110)+1904;
			InitContactParameter cont = new InitContactParameter();	
			cont.fname =  GenerateString();
			cont.lname =  GenerateString();
			cont.address= GenerateString();
			cont.home =   GenerateString();
			cont.mobile=  GenerateNumber();
			cont.email =  GenerateString();
			cont.work =   GenerateNumber();
			cont.email2 = GenerateString();
			cont.day =  day.toString();
			cont.mounth = Month(mon);
			cont.year =   year.toString();
			cont.add2 =   GenerateString();
			cont.ph2 =    GenerateNumber();
			list.add(new Object[]{cont});
		}
		return list.iterator();
	}

	public String GenerateString() {
		Random rand = new Random();
		if (rand.nextInt(3)== 0) 
			return "";
		else { 
			String str = new String();
			int z = rand.nextInt(30);
			for (int i = 0; i<z; i++) {
				int c = 'a' + rand.nextInt(26);
				str += (char)c;
			}
			
			return str;
			}
	}
	

	public String GenerateNumber() {
		Random rand = new Random();
		if (rand.nextInt(3)== 0) 
			return "";
		else { 
			String str = new String();
			for (int i = 0; i<8; i++) {
				int c = rand.nextInt(10);
				str += c;
			}
			
			return str;
			}
	}

public static String  Month( int i){
 	String[] month = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
return month[i];
}}
@@ -1469,32 +1469,33 @@
  GenerateNumber(
+8
 );%0A%09%09%09cont.email
@@ -1544,24 +1544,25 @@
 erateNumber(
+7
 );%0A%09%09%09cont.e
@@ -1748,16 +1748,17 @@
 eNumber(
+7
 );%0A%09%09%09li
@@ -1889,91 +1889,139 @@
 ;%0A%09%09
-if (rand.nextInt(3)== 0) %0A%09%09%09return %22%22
+String str = new String();%0A%09%09switch (rand.nextInt(4)) %7B %0A%09%09case 0: str = %22%22; break
 ;%0A%09%09
-else %7B %0A%09%09%09String
+case 1:
  str
- = new String();%0A%09%09%09
++= GenerateNumber(3);  %0A%09%09case 2: 
 int 
@@ -2037,24 +2037,31 @@
 nextInt(
-3
+2
 0);%0A%09%09%09
+       
 for (int
@@ -2074,30 +2074,44 @@
 ; i%3Cz; i++) 
+%0A%09%09%09       
 %7B%0A%09%09%09%09
+   
 int c = 'a' 
@@ -2130,24 +2130,27 @@
 nt(26);%0A%09%09%09%09
+   
 str += (char
@@ -2160,38 +2160,257 @@
 %0A%09%09%09
-%7D%0A%09%09%09%0A%09%09%09return str;%0A%09%09%09%7D%0A%09%7D%0A%09
+%09   %7D str+= %22 %22;%0A%09%09case 3: int x = rand.nextInt(20);%0A%09            %09for (int i = 0; i%3Cx; i++) %0A%09            %09%7B%0A%09%09%09        int c = 'A' + rand.nextInt(26);%0A%09%09%09        str += (char)c;%0A%09%09%09        %7D %0A     %09           %09break;%7D%0A%09%09return str;%0A%09            %09%7D
 %0A%0A%09p
@@ -2437,16 +2437,21 @@
 eNumber(
+int q
 ) %7B%0A%09%09Ra
@@ -2579,17 +2579,17 @@
  = 0; i%3C
-8
+q
 ; i++) %7B
@@ -2642,12 +2642,8 @@
 %09%09%7D%0A
-%09%09%09%0A
 %09%09%09r

add to Homework 7