Ailton Mizuki Sato 9 年之前
父節點
當前提交
c970ea70ad

+ 7 - 4
config.properties

1
-jdbc= jdbc:mysql://localhost:3306/snail
2
 
1
 
3
 
2
 
4
-username= root
5
-		
6
-password= 99719797
3
+#domain = http://50.30.37.180:38080/snail/
4
+
5
+#domain= http://localhost:8080/snail/
6
+
7
+domain= http://localhost:7000/Servlet/
8
+
9
+

+ 7 - 3
src/test/Start.java

23
 
23
 
24
 /**This is the started from tests*/
24
 /**This is the started from tests*/
25
 public class Start {
25
 public class Start {
26
+	
26
 	private static List<ServletTest> generateList()
27
 	private static List<ServletTest> generateList()
27
 	{
28
 	{
28
 		List<ServletTest> tests = new ArrayList<ServletTest>();
29
 		List<ServletTest> tests = new ArrayList<ServletTest>();
41
 		tests.add(new TestUpdateCategory());
42
 		tests.add(new TestUpdateCategory());
42
 		tests.add(new TestUpdateItem());
43
 		tests.add(new TestUpdateItem());
43
 
44
 
44
-
45
 		tests.add(new TestExistsUser());
45
 		tests.add(new TestExistsUser());
46
-
47
-
48
 		tests.add(new TestCreateUser());
46
 		tests.add(new TestCreateUser());
49
 		tests.add(new TestLogin());
47
 		tests.add(new TestLogin());
50
 		tests.add(new TestUpdateUser());
48
 		tests.add(new TestUpdateUser());
70
 		{
68
 		{
71
 			System.out.println(test);
69
 			System.out.println(test);
72
 		}
70
 		}
71
+		
72
+		
73
+		for(ServletTest test:tests)
74
+		{
75
+			System.out.println(test.getUrl());
76
+		}
73
 
77
 
74
 
78
 
75
 
79
 

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

11
 	public String get(String urlToRead) throws IOException{
11
 	public String get(String urlToRead) throws IOException{
12
 		
12
 		
13
 		URL url;
13
 		URL url;
14
+		
14
 		HttpURLConnection conn;
15
 		HttpURLConnection conn;
15
 		BufferedReader rd;
16
 		BufferedReader rd;
16
 		String line;
17
 		String line;

+ 23 - 1
src/test/resource/ServletTest.java

1
 package test.resource;
1
 package test.resource;
2
 
2
 
3
+import java.io.FileReader;
4
+import java.util.Properties;
5
+
3
 import org.json.JSONArray;
6
 import org.json.JSONArray;
4
 
7
 
5
 import javafx.util.Pair;
8
 import javafx.util.Pair;
9
 
12
 
10
 public abstract class ServletTest {
13
 public abstract class ServletTest {
11
 	
14
 	
12
-	public String domain = "http://localhost:8080/SnailServlet/";
15
+	public ServletTest()
16
+	{
17
+		Properties props = new Properties();
18
+		try{
19
+			props.load(new FileReader("config.properties"));
20
+			domain = props.getProperty("domain");	
21
+		}catch(Exception e)
22
+		{
23
+			
24
+		}
25
+		
26
+	}
27
+	
28
+	public String domain ;
13
 	public String result="";
29
 	public String result="";
30
+	protected String url;
14
 	
31
 	
15
 	
32
 	
16
 	public void runTest()
33
 	public void runTest()
69
 		return sb.toString();
86
 		return sb.toString();
70
 		
87
 		
71
 	}
88
 	}
89
+
90
+	public String getUrl() {
91
+		// TODO Auto-generated method stub
92
+		return url;
93
+	}
72
 	
94
 	
73
 }
95
 }

+ 1 - 0
src/test/resource/ServletTestGet.java

11
 	public boolean test() throws Exception {
11
 	public boolean test() throws Exception {
12
 		
12
 		
13
 		String url = domain +this.buildUrl();
13
 		String url = domain +this.buildUrl();
14
+		this.url = url;
14
 		ExecuteGet executor = new ExecuteGet();
15
 		ExecuteGet executor = new ExecuteGet();
15
 		String result = executor.get(url);
16
 		String result = executor.get(url);
16
 		boolean firstResult =  this.analyse(result);
17
 		boolean firstResult =  this.analyse(result);

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

10
 /**responsable to test the post methods*/
10
 /**responsable to test the post methods*/
11
 public abstract class ServletTestPost extends ServletTest {
11
 public abstract class ServletTestPost extends ServletTest {
12
 
12
 
13
+	public String output;
14
+	
13
 	@Override
15
 	@Override
14
 	public boolean test() throws Exception {
16
 	public boolean test() throws Exception {
15
 		ExecutePost post = new ExecutePost();
17
 		ExecutePost post = new ExecutePost();
16
 
18
 
17
 
19
 
18
 		String url = domain +this.buildUrl();
20
 		String url = domain +this.buildUrl();
21
+		this.url = url;
19
 		Map<String , String > parameters = this.buildParameters();
22
 		Map<String , String > parameters = this.buildParameters();
20
-		String result = post.execute(url, parameters);
21
-		return this.analyse(result);
23
+		output = post.execute(url, parameters);
24
+		return this.analyse(output);
22
 	}
25
 	}
23
 
26
 
24
 	public abstract Map<String , String> buildParameters();
27
 	public abstract Map<String , String> buildParameters();
43
 
46
 
44
 	}
47
 	}
45
 
48
 
49
+	public Integer getId() {
50
+		
51
+		try{
52
+			JSONArray json = new JSONArray(output);
53
+			String value = json.getJSONObject(0).getString("id");
54
+			return new Integer(value);
55
+			
56
+		}catch(Exception e)
57
+		{
58
+			return 0;
59
+		}
60
+		
61
+		
62
+		
63
+	}
64
+	
65
+	
46
 }
66
 }

+ 1 - 1
src/test/servlet/event/get/TestImportDataFacebook.java

11
 	
11
 	
12
 		
12
 		
13
 		return "data?method=import_data&"
13
 		return "data?method=import_data&"
14
-				+ "token=CAACEdEose0cBADZBVpOMdjrAoMWYdXlgvVlBgYe33vJPZAAmnmwBB4IIIiszqSbbbY0tCGy0pp50nstfLMsyoZCxyG53yN3ZBpe0k4kuPsLNZBZB5IfKwD2wSW1d8OfmX2LTZCTsOaLufFRYJLaAfPvjxTS7OERdsfpPNAnrGDoPTwoaWpSip10aZB8cuuSTs5RZA3xZAimYcLUQdHvjYMlWkK"
14
+				+ "token=CAACEdEose0cBAIaFqPHYmsZAQHJnWwCZBJtXAODpUlRKJhvfM5nnRHnZCpdeYvKz2UIvGldXOZAXP3a70mImv69TmlGPOLuxQrUKNNUaf0G8pb2wiNfR6kYCh0SIPZBDV1UJFMIuejoZCvmNbB1LkmviEIArFALrDE9nER1MZAazKYSAgT2ExYmEZAesuTG2lZAagss1HmJiLht8U2Khnzg70"
15
 				+ "&type=Facebook&quantity=14&user_id=1";
15
 				+ "&type=Facebook&quantity=14&user_id=1";
16
 	}
16
 	}
17
 	
17
 	

+ 4 - 0
src/test/servlet/event/post/TestCreateCategory.java

8
 
8
 
9
 public class TestCreateCategory extends ServletTestPost {
9
 public class TestCreateCategory extends ServletTestPost {
10
 
10
 
11
+	
12
+	
11
 	@Override
13
 	@Override
12
 	public Map<String, String> buildParameters() {
14
 	public Map<String, String> buildParameters() {
13
 		// TODO Auto-generated method stub
15
 		// TODO Auto-generated method stub
32
 		return new Pair<String, String>("name", "Radialize");
34
 		return new Pair<String, String>("name", "Radialize");
33
 	}
35
 	}
34
 
36
 
37
+
38
+
35
 	
39
 	
36
 }
40
 }

+ 3 - 2
src/test/servlet/event/post/TestCreateItem.java

11
 	@Override
11
 	@Override
12
 	public Map<String, String> buildParameters() {
12
 	public Map<String, String> buildParameters() {
13
 		Map <String, String> map = new HashMap<String, String>();
13
 		Map <String, String> map = new HashMap<String, String>();
14
-		map.put("user_id", "16");
14
+		map.put("user_id", "3");
15
 		map.put("category_id", "20");
15
 		map.put("category_id", "20");
16
 		map.put("content", "Zueira");
16
 		map.put("content", "Zueira");
17
 		map.put("title", "Doido");
17
 		map.put("title", "Doido");
18
 		map.put("start_date", "2011-04-15");
18
 		map.put("start_date", "2011-04-15");
19
 		map.put("end_date", "2014-12-10");
19
 		map.put("end_date", "2014-12-10");
20
+		map.put("photo", "foto.jpg");
20
 		
21
 		
21
 		
22
 		
22
 		
23
 		
26
 	@Override
27
 	@Override
27
 	public Pair<String, String> buildCheckSum() {
28
 	public Pair<String, String> buildCheckSum() {
28
 		// TODO Auto-generated method stub
29
 		// TODO Auto-generated method stub
29
-		return new Pair<String, String>("categoryId", "9");
30
+		return new Pair<String, String>("categoryId", "20");
30
 	}
31
 	}
31
 
32
 
32
 	@Override
33
 	@Override

+ 5 - 1
src/test/servlet/event/post/TestDeleteCategory.java

11
 	@Override
11
 	@Override
12
 	public Map<String, String> buildParameters() {
12
 	public Map<String, String> buildParameters() {
13
 		
13
 		
14
+		TestCreateCategory createCategory = new  TestCreateCategory();
15
+		createCategory.runTest();
16
+		String id = new Integer(createCategory.getId()).toString();
17
+		
14
 		Map<String, String> map = new HashMap<String, String>();
18
 		Map<String, String> map = new HashMap<String, String>();
15
-		map.put("category_id", "21");
19
+		map.put("category_id", id);
16
 		
20
 		
17
 		return map;
21
 		return map;
18
 	}
22
 	}

+ 33 - 0
src/test/servlet/user/post/TestRecoverPassword.java

1
+package test.servlet.user.post;
2
+
3
+import java.util.Map;
4
+
5
+
6
+import javafx.util.Pair;
7
+import test.resource.ServletTestPost;
8
+
9
+public class TestRecoverPassword extends ServletTestPost{
10
+
11
+	@Override
12
+	public Map<String, String> buildParameters() {
13
+		// TODO Auto-generated method stub
14
+		
15
+		
16
+		return null;
17
+	}
18
+
19
+	@Override
20
+	public Pair<String, String> buildCheckSum() {
21
+		// TODO Auto-generated method stub
22
+		return null;
23
+	}
24
+
25
+	@Override
26
+	public String buildUrl() {
27
+		// TODO Auto-generated method stub
28
+		return null;
29
+	}
30
+
31
+	
32
+	
33
+}