12 |
|
|
13 |
public class TestServlet extends HttpServlet { |
public class TestServlet extends HttpServlet { |
14 |
private static final long serialVersionUID = 1L; |
private static final long serialVersionUID = 1L; |
15 |
|
|
16 |
|
Random r = new Random(); |
17 |
|
|
18 |
//South-West corner= 54.0, 7.0 |
//South-West corner= 54.5, 8.0 |
19 |
//North-East corner= 58.0, 13.0 |
//North-East corner= 58.0, 13.0 |
20 |
//Latitude span=4.0 |
//Latitude span=3.5 |
21 |
//Longitude span=6.0 |
//Longitude span=5.0 |
22 |
void testFindNearest(int count) throws SQLException { |
void testFindNearest(int count) throws SQLException { |
|
Random r = new Random(); |
|
23 |
|
|
24 |
StationDAO db = new StationDAO(); |
StationDAO db = new StationDAO(); |
25 |
|
|
26 |
|
|
27 |
for (int i=0; i<count; i++) { |
for (int i=0; i<count; i++) { |
28 |
float lat = (r.nextFloat()*4.0F) + 54.0F; |
float lat = (r.nextFloat()*3.5F) + 54.5F; |
29 |
float lng = (r.nextFloat()*6.0F) + 7.0F; |
float lng = (r.nextFloat()*5.0F) + 8.0F; |
30 |
db.getByLocation(lat, lng); |
db.getByLocation(lat, lng); |
31 |
} |
} |
32 |
|
|
35 |
} |
} |
36 |
|
|
37 |
void testFindName(int count) throws SQLException { |
void testFindName(int count) throws SQLException { |
|
Random r = new Random(); |
|
38 |
|
|
39 |
StationDAO db = new StationDAO(); |
StationDAO db = new StationDAO(); |
40 |
|
|
49 |
|
|
50 |
db.getByName(search); |
db.getByName(search); |
51 |
} |
} |
52 |
|
} |
53 |
|
|
54 |
|
void testFindFavorites(int count) throws SQLException { |
55 |
|
|
56 |
|
StationDAO db = new StationDAO(); |
57 |
|
|
58 |
|
for (int i=0; i<count; i++) { |
59 |
|
final int MAX = 8; |
60 |
|
|
61 |
|
StringBuilder sb = new StringBuilder(); |
62 |
|
sb.append('('); |
63 |
|
for (int j=0; j<MAX;j++) { |
64 |
|
if (j>0) |
65 |
|
sb.append(','); |
66 |
|
sb.append(r.nextInt(400)); |
67 |
|
} |
68 |
|
sb.append(')'); |
69 |
|
|
70 |
|
|
71 |
|
db.getByList(sb.toString()); |
72 |
|
} |
73 |
} |
} |
74 |
|
|
75 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
87 |
testFindName(count); |
testFindName(count); |
88 |
} else if ( test.equals("nearest") ) { |
} else if ( test.equals("nearest") ) { |
89 |
testFindNearest(count); |
testFindNearest(count); |
90 |
|
} else if ( test.equals("favorites") ) { |
91 |
|
testFindFavorites(count); |
92 |
} else { |
} else { |
93 |
throw new ServletException("No parameter test"); |
throw new ServletException("No parameter test"); |
94 |
} |
} |