瀏覽代碼

All Tests are complete

amizukisato 9 年之前
父節點
當前提交
1ea91a280c

+ 77 - 0
src/test/Start.java

1
+package test;
2
+
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+
6
+import test.resource.ServletTest;
7
+import test.servlet.TestServletConnection;
8
+import test.servlet.event.get.TestGetCategories;
9
+import test.servlet.event.get.TestImportDataFacebook;
10
+import test.servlet.event.get.TestSearch;
11
+import test.servlet.event.post.TestCreateCategory;
12
+import test.servlet.event.post.TestCreateItem;
13
+import test.servlet.event.post.TestDeleteCategory;
14
+import test.servlet.event.post.TestDeleteItem;
15
+import test.servlet.event.post.TestSetCategory;
16
+import test.servlet.event.post.TestUpdateCategory;
17
+import test.servlet.event.post.TestUpdateItem;
18
+import test.servlet.user.get.TestExistsUser;
19
+import test.servlet.user.post.TestCreateUser;
20
+import test.servlet.user.post.TestLogin;
21
+import test.servlet.user.post.TestUpdateUser;
22
+
23
+
24
+/**This is the started from tests*/
25
+public class Start {
26
+	private static List<ServletTest> generateList()
27
+	{
28
+		List<ServletTest> tests = new ArrayList<ServletTest>();
29
+
30
+		tests.add(new TestServletConnection() );
31
+
32
+		tests.add(new TestImportDataFacebook() );
33
+		tests.add(new TestGetCategories());
34
+		tests.add(new TestSearch());
35
+
36
+
37
+		tests.add(new TestCreateCategory());
38
+		tests.add(new TestSetCategory());
39
+		tests.add(new TestDeleteCategory());
40
+		tests.add(new TestDeleteItem());
41
+		tests.add(new TestUpdateCategory());
42
+		tests.add(new TestUpdateItem());
43
+
44
+
45
+		tests.add(new TestExistsUser());
46
+
47
+
48
+		tests.add(new TestCreateUser());
49
+		tests.add(new TestLogin());
50
+		tests.add(new TestUpdateUser());
51
+		tests.add(new TestCreateItem());
52
+
53
+
54
+		return tests;
55
+	}
56
+
57
+
58
+	public static void main (String [] args){
59
+
60
+
61
+		List<ServletTest> tests = generateList();
62
+
63
+
64
+
65
+
66
+		for(ServletTest test : tests)
67
+		{
68
+			test.runTest();
69
+		}
70
+
71
+
72
+	}
73
+
74
+
75
+
76
+
77
+}

+ 2 - 0
src/test/resource/ExecuteGet.java

4
 import java.net.*;
4
 import java.net.*;
5
 import java.io.IOException;
5
 import java.io.IOException;
6
 
6
 
7
+
8
+/**this class is responsable to connect into a url get*/
7
 public class ExecuteGet {
9
 public class ExecuteGet {
8
 
10
 
9
 	public String get(String urlToRead) throws IOException{
11
 	public String get(String urlToRead) throws IOException{

+ 1 - 1
src/test/resource/ExecutePost.java

19
 
19
 
20
 public class ExecutePost{
20
 public class ExecutePost{
21
 
21
 
22
-
22
+/**This class is responsable to connect into a post message*/
23
 
23
 
24
 	public String execute(String url, Map<String, String> parameters) throws Exception {
24
 	public String execute(String url, Map<String, String> parameters) throws Exception {
25
 
25
 

+ 0 - 39
src/test/resource/Run.java

1
-package test.resource;
2
-
3
-import java.util.ArrayList;
4
-import java.util.List;
5
-
6
-import test.servlet.event.get.TestGetCategories;
7
-import test.servlet.event.get.TestImportDataFacebook;
8
-import test.servlet.event.get.TestSearch;
9
-import test.servlet.event.post.TestCreateCategory;
10
-import test.servlet.event.post.TestSetCategory;
11
-import test.servlet.user.post.TestCreateUser;
12
-import test.servlet.user.post.TestLogin;
13
-
14
-public class Run {
15
-
16
-	public static void main (String [] args){
17
-		
18
-		List<ServletTest> tests = new ArrayList<ServletTest>();
19
-		
20
-		tests.add(new TestImportDataFacebook() );
21
-		tests.add(new TestGetCategories());
22
-		tests.add(new TestSearch());
23
-		
24
-		
25
-		tests.add(new TestCreateCategory());
26
-		tests.add(new TestSetCategory());
27
-		
28
-		
29
-		tests.add(new TestCreateUser());
30
-		tests.add(new TestLogin());
31
-		
32
-		for(ServletTest test : tests)
33
-		{
34
-			test.runTest();
35
-		}
36
-		
37
-	}
38
-
39
-}

+ 42 - 8
src/test/resource/ServletTest.java

1
 package test.resource;
1
 package test.resource;
2
 
2
 
3
 import org.json.JSONArray;
3
 import org.json.JSONArray;
4
-import org.json.JSONObject;
4
+
5
+import javafx.util.Pair;
6
+
7
+
8
+/**Default class for Test*/
5
 
9
 
6
 public abstract class ServletTest {
10
 public abstract class ServletTest {
7
 	
11
 	
12
+	public String domain = "http://localhost:8080/SnailServlet/";
13
+	public String result="";
14
+	
8
 	
15
 	
9
 	public void runTest()
16
 	public void runTest()
10
 	{
17
 	{
18
+		
19
+		String className = this.getClass().getSimpleName();
11
 		try{
20
 		try{
12
 			
21
 			
13
 			if(this.test())
22
 			if(this.test())
14
-				System.out.println("Test "+ this.getClass().getSimpleName() + " ......pass");
23
+			{
24
+				System.out.println(String.format("%s%s%s" , className,new String(new char[30-className.length()]).replace("\0", "."), "pass" ));;
25
+			}
26
+				
15
 			else
27
 			else
16
-				System.err.println("Test "+ this.getClass().getSimpleName() + " ......fail");
28
+			{
29
+				
30
+				System.err.println(String.format("%s%s%s" , className,new String(new char[30-className.length()]).replace("\0", "."), "fail" ));;
31
+				if(className.equals("TestServletConnection"))
32
+				{
33
+					System.err.println("Servlet is not working , please verify your connection");
34
+					System.exit(1);
35
+				}
36
+			}
37
+				
17
 				
38
 				
18
 		}catch(Exception e)
39
 		}catch(Exception e)
19
 		{
40
 		{
41
+			System.err.println(String.format("%s%s%s" , className,new String(new char[30-className.length()]).replace("\0", "."), "fail" ));;
20
 			e.printStackTrace();
42
 			e.printStackTrace();
21
-			System.err.println("Test "+ this.getClass().getSimpleName() + " ......fail");
43
+			if(className.equals("TestServletConnection"))
44
+			{
45
+				System.err.println("Servlet is not working , please verify your connection");
46
+				System.exit(1);
47
+			}
22
 		}
48
 		}
23
 		
49
 		
24
 		
50
 		
25
 	}
51
 	}
26
 	
52
 	
53
+	public abstract Pair<String, String> buildCheckSum();
27
 	protected abstract boolean test() throws Exception;
54
 	protected abstract boolean test() throws Exception;
28
-	
29
-	public String domain = "http://localhost:8080/SnailServlet/";
30
 	public abstract String buildUrl();
55
 	public abstract String buildUrl();
31
 	
56
 	
32
 	protected boolean analyse(String result) throws Exception{
57
 	protected boolean analyse(String result) throws Exception{
33
-		
34
-		
58
+		this.result = result;
35
 		JSONArray json = new JSONArray(result);
59
 		JSONArray json = new JSONArray(result);
36
 		return json.getJSONObject(1).getBoolean("request");
60
 		return json.getJSONObject(1).getBoolean("request");
37
 	}
61
 	}
62
+
63
+	public String toString() {
64
+		String className = this.getClass().getSimpleName();
65
+		StringBuilder sb = new StringBuilder();
66
+		sb.append(className);
67
+		sb.append(": \n");
68
+		sb.append(result+"\n");
69
+		return sb.toString();
70
+		
71
+	}
38
 	
72
 	
39
 }
73
 }

+ 34 - 2
src/test/resource/ServletTestGet.java

1
 package test.resource;
1
 package test.resource;
2
 
2
 
3
+import org.json.JSONArray;
4
+
5
+import javafx.util.Pair;
6
+
7
+/**Class to test the Get 's methods*/
3
 public abstract class ServletTestGet extends ServletTest{
8
 public abstract class ServletTestGet extends ServletTest{
4
 
9
 
5
 	@Override
10
 	@Override
6
 	public boolean test() throws Exception {
11
 	public boolean test() throws Exception {
7
 		
12
 		
8
-		ExecuteGet executor = new ExecuteGet();
9
 		String url = domain +this.buildUrl();
13
 		String url = domain +this.buildUrl();
14
+		ExecuteGet executor = new ExecuteGet();
10
 		String result = executor.get(url);
15
 		String result = executor.get(url);
11
-		return this.analyse(result);
16
+		boolean firstResult =  this.analyse(result);
17
+
18
+		
19
+		boolean secondResult = false;
20
+		Pair<String, String > check = this.buildCheckSum();
21
+		if(check.getKey().equals(""))
22
+		{
23
+			secondResult= true;
24
+		}else
25
+		{
26
+			JSONArray json = new JSONArray(result);
27
+			String value = json.getJSONObject(0).getString(check.getKey());
28
+			 secondResult= value.equals(check.getValue());
29
+			
30
+		}
31
+		
32
+		
12
 		
33
 		
34
+		return firstResult&&secondResult;
13
 	}
35
 	}
14
 	
36
 	
15
 	
37
 	
38
+	public Pair<String , String> buildCheckSum( )
39
+	{
40
+		
41
+		return new Pair<String, String>("", "");
42
+		
43
+	}
44
+	
45
+	
46
+	
47
+	
16
 	
48
 	
17
 
49
 
18
 }
50
 }

+ 4 - 2
src/test/resource/ServletTestPost.java

6
 
6
 
7
 import javafx.util.Pair;
7
 import javafx.util.Pair;
8
 
8
 
9
+
10
+/**responsable to test the post methods*/
9
 public abstract class ServletTestPost extends ServletTest {
11
 public abstract class ServletTestPost extends ServletTest {
10
 
12
 
11
 	@Override
13
 	@Override
21
 
23
 
22
 	public abstract Map<String , String> buildParameters();
24
 	public abstract Map<String , String> buildParameters();
23
 
25
 
24
-	public abstract Pair<String, String> buildCheckSum();
26
+	
25
 
27
 
26
 	@Override
28
 	@Override
27
 	protected boolean analyse(String result ) throws Exception
29
 	protected boolean analyse(String result ) throws Exception
28
 	{
30
 	{
29
-	System.out.println(result);
31
+	
30
 		JSONArray json = new JSONArray(result);
32
 		JSONArray json = new JSONArray(result);
31
 		boolean firstResult = super.analyse(result);
33
 		boolean firstResult = super.analyse(result);
32
 		Pair<String, String > check = this.buildCheckSum();
34
 		Pair<String, String > check = this.buildCheckSum();

+ 4 - 5
src/test/servlet/user/post/TestCreateUser.java

5
 
5
 
6
 import javafx.util.Pair;
6
 import javafx.util.Pair;
7
 import test.resource.ServletTestPost;
7
 import test.resource.ServletTestPost;
8
+import test.resource.StringGenerator;
8
 
9
 
9
 public class TestCreateUser extends ServletTestPost {
10
 public class TestCreateUser extends ServletTestPost {
10
 
11
 
11
 	@Override
12
 	@Override
12
 	public Map<String, String> buildParameters() {
13
 	public Map<String, String> buildParameters() {
14
+		
15
+		StringGenerator stringGen = new StringGenerator();
13
 		Map <String , String> parameters = new HashMap<String , String>();
16
 		Map <String , String> parameters = new HashMap<String , String>();
14
 		parameters.put("name", "Fernanda");
17
 		parameters.put("name", "Fernanda");
15
 		parameters.put("born_date", "1991-04-22");
18
 		parameters.put("born_date", "1991-04-22");
16
 		parameters.put("sex", "m");
19
 		parameters.put("sex", "m");
17
 		parameters.put("password", "99719797");
20
 		parameters.put("password", "99719797");
18
-		parameters.put("email", "ailtonjapaitapeva@idealize.com");
19
-		
20
-		
21
+		parameters.put("email", stringGen.generateEmail());
21
 		
22
 		
22
 		return parameters;
23
 		return parameters;
23
 		
24
 		
35
 		return new Pair<String, String>("name", "Fernanda");
36
 		return new Pair<String, String>("name", "Fernanda");
36
 	}
37
 	}
37
 	
38
 	
38
-	
39
-	
40
 }
39
 }