forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCase.java
More file actions
138 lines (117 loc) · 4.39 KB
/
Copy pathTestCase.java
File metadata and controls
138 lines (117 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 com.cloud.test.regression;
import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.httpclient.HttpClient;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
public abstract class TestCase {
public static Logger s_logger = Logger.getLogger(TestCase.class.getName());
private Connection conn;
private ArrayList<Document> inputFile = new ArrayList<Document>();
private HttpClient client;
private String testCaseName;
private HashMap<String, String> param = new HashMap<String, String>();
private HashMap<String, String> commands = new HashMap<String, String>();
public HashMap<String, String> getParam() {
return param;
}
public void setParam(HashMap<String, String> param) {
this.param = param;
}
public HashMap<String, String> getCommands() {
return commands;
}
public void setCommands() {
File asyncCommands = null;
if (param.get("apicommands") == null) {
s_logger.info("Unable to get the list of commands, exiting");
System.exit(1);
} else {
asyncCommands = new File(param.get("apicommands"));
}
try {
Properties pro = new Properties();
FileInputStream in = new FileInputStream(asyncCommands);
pro.load(in);
Enumeration<?> en = pro.propertyNames();
while (en.hasMoreElements()) {
String key = (String)en.nextElement();
commands.put(key, pro.getProperty(key));
}
} catch (Exception ex) {
s_logger.info("Unable to find the file " + param.get("apicommands") + " due to following exception " + ex);
}
}
public Connection getConn() {
return conn;
}
public void setConn(String dbPassword) {
this.conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
this.conn = DriverManager.getConnection("jdbc:mysql://" + param.get("db") + "/cloud", "root", dbPassword);
if (!this.conn.isValid(0)) {
s_logger.error("Connection to DB failed to establish");
}
} catch (Exception ex) {
s_logger.error(ex);
}
}
public void setInputFile(ArrayList<String> fileNameInput) {
for (String fileName : fileNameInput) {
File file = new File(fileName);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document doc = null;
try {
DocumentBuilder builder = factory.newDocumentBuilder();
doc = builder.parse(file);
doc.getDocumentElement().normalize();
} catch (Exception ex) {
s_logger.error("Unable to load " + fileName + " due to ", ex);
}
this.inputFile.add(doc);
}
}
public ArrayList<Document> getInputFile() {
return inputFile;
}
public void setTestCaseName(String testCaseName) {
this.testCaseName = testCaseName;
}
public String getTestCaseName() {
return this.testCaseName;
}
public void setClient() {
HttpClient client = new HttpClient();
this.client = client;
}
public HttpClient getClient() {
return this.client;
}
//abstract methods
public abstract boolean executeTest();
}