When releasing a web system, the project I'm working on does the following:
There are 10 to 20 items to check that the release settings have been made. For example, the following items.
The release frequency is once every three months, so the confirmation itself is not that burdensome. Since there is a risk of leakage by visual confirmation, I made a tool for studying as well. Well, it's possible that the tool is wrong. .. ..
I used JUnit to confirm that it was set correctly.
Load the properties file using the java.util.Properties
class
/**Absolute path of the file to read*/
private static String filePath = Constants.PROJECT_PATH + "sources/system.properties";
/**Property file object*/
private static Properties prop = null;
@Rule
public TestName testname = new TestName();
@BeforeClass
public static void setUpBeforeClass() throws Exception {
prop = new Properties();
prop.load(new FileInputStream(filePath));
}
@Test
public void Confirm connection destination of FTP server() throws Exception{
String key = "ftp.host"; //properties file key
String actual = prop.getProperty(key); //
String expected = "127.0.0.1"; //Expected results
String name = relativeFilePath + ": " + key;
log.info(name + " = " + actual); //Output value to log
assertThat(name, actual, CoreMatchers.is(expected));
}
//Create as many test methods as you want to see
Use org.jsoup.Jsoup to load the JSP / HTML file. Even if there is a custom tag of JSP, it can be read.
index.jsp
<div>
<span id="version">1.2.3</span>
</div>
/**Absolute path of the file to read*/
private static String filePath = Constants.PROJECT_PATH + "webapps/index.jsp";
/**document object*/
private static Document doc = null;
@Rule
public TestName testname = new TestName();
@BeforeClass
public static void setUpBeforeClass() throws Exception {
doc = Jsoup.parse(new File(filePath), "UTF-8");
}
@Test
public void Check version() throws Exception{
String key = "#version";
Element cell = doc.select(key).get(0);
String actual = cell.text();
String expected = "1.2.3";
String name = relativeFilePath + " : " + key;
log.info(name + " = " + actual);
assertThat(name, actual, CoreMatchers.is(expected));
}
Use ʻorg.dom4j.io.SAXReader` in dom4j.jar to read the XML file.
The following process confirms the version described in web.xml.
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<context-param>
<param-name>version</param-name>
<param-value>1.2.3</param-value>
</context-param>
</web-apps>
/**Absolute path of the file to read*/
private static String filePath = Constants.PROJECT_PATH + "webapps/WEB-INF/web.xml";
/**XML file document object*/
private static Document doc = null;
@Rule
public TestName testname = new TestName();
@BeforeClass
public static void setUpBeforeClass() throws Exception {
SAXReader reader = new SAXReader();
//Setting not to read external DTD (web.Although dtd is not referenced in xml, it is set so that it can be read by other XML.)
//http://qiita.com/yoshi389111/items/3d0da72b1f2ccd947052
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
doc = reader.read(filePath);
}
@Test
Confirmation of public void version() throws Exception {
//<param-value>XPath to get the value of the tag
String key = "//p:context-param/p:param-name[text()='version']/following-sibling::p:param-value";
//Namespace["p"]Set the default namespace to
BaseXPath xpath = new Dom4jXPath(key);
xpath.addNamespace("p", ""http://java.sun.com/xml/ns/j2ee");
String actual = xpath.stringValueOf(doc);
String expected = "1.2.3";
String name = relativeFilePath + " : " + key;
log.info(name + " = " + actual);
assertThat(name, actual, CoreMatchers.is(expected));
}
Use javax.script.ScriptEngine
.
You cannot get the property value of an object with the get
method.
Once assigned to another js variable of the ʻeval method, get the value of that variable with the
get` method.
sample.js
var C = {version: "1.2.3"};
engine.eval(new FileReader("sample.js"));
Object a = engine.get("C.version"); //→null
engine.eval("tmp = C.version");
Object b = engine.get("tmp"); //→"1.2.3"
If you use an external library such as jQuery, a ReferenceError will occur as shown below. For the JavaScript file to be released check, it may be better not to use an external library. (I didn't know how to resolve the ReferenceError)
javax.script.ScriptException: ReferenceError: "$" is not defined in <eval> ...(abridgement)
Recommended Posts