[JAVA] I made a check tool for the release module

background

When releasing a web system, the project I'm working on does the following:

  1. Merge the contents of the develop branch into the release branch in Git
  2. Check out to the release branch
  3. Confirm that the settings for release have been made.
  4. Create a war file

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. .. ..

Contents of the tool

Constitution

I used JUnit to confirm that it was set correctly.

properties file

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
 

JSP / HTML file

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));
    }

XML file

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));
	}

JavaScript file

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

I made a check tool for the release module
I made a Diff tool for Java files
I made a package.xml generation tool.
I made a reply function for the Rails Tutorial extension (Part 1)
I made a plugin for IntelliJ IDEA
I made a reply function for the Rails Tutorial extension (Part 5):
I made a new Java deployment tool
I made a tool to output the difference of CSV file
I made a method to ask for Premium Friday
I made a library for displaying tutorials on Android.
I made a chat app.
I tried JAX-RS and made a note of the procedure
I made a reply function for the Rails Tutorial extension (Part 4): A function that makes the user unique
Ruby: I made a FizzBuzz program!
I want to create a chat screen for the Swift chat app!
I made a Ruby container image and moved the Lambda function
I made a shopify app @java
When I made a bar graph with MPAndroidChart, the x-axis label was misaligned for some reason
I made a GUI with Swing
I recently made a js app in the rumored Dart language
I made a gem to post the text of org-mode to qiita
I made a question that can be used for a technical interview
I made a method to ask for Premium Friday (Java 8 version)
I made a simple recommendation function.
How to check for the contents of a java fixed-length string
I made a matching app (Android app)
[Android] I made a pedometer app.
I was in trouble at work, so I made a plugin for IntelliJ
I made a reply function for Rails Tutorial extension (Part 2): Change model
A review note for the class java.util.Scanner
[Ruby] I made a simple Ping client
Prepare the security check environment for Rails 6
Made a one-liner method for Premium Friday
A review note for the class java.util.Optional
I made a risky die with Ruby
I made a rock-paper-scissors app with kotlin
I made a calculator app on Android
A review note for the class java.util.Objects
I made a rock-paper-scissors app with android
A review note for the package java.time.temporal
I made a bulletin board using Docker 1
I made a THETA API client that can be used for plug-in development
The training for newcomers was "Make an app!", So I made an app for the time being.
I was a little addicted to the S3 Checksum comparison, so I made a note.
[Question] I cannot obtain a license for a business package application from the license server.
I made a simple graph library for smartphone apps [MP Android Chart Kai]
I searched for a lightweight framework that answers the sudden "make it quickly"
[Must-see for fledgling engineers] A story that the world expanded when I actually operated a web service that I made by myself
left4dead2 I made a Docker image for the server and tried running it on GCE # 3 (I had a hard time building the server)
I made a primality test program in Java
I tried using Docker for the first time
Check the options set for the running Java process
04. I made a front end with SpringBoot + Thymeleaf
I made a mosaic art with Pokemon images
I tried to develop a man-hour management tool
I made an app for myself! (Reading management app)
I made a gender selection column with enum
I made an Android app for MiRm service
A tool for hitting arbitrary SQL using JDBC
I made a rock-paper-scissors game in Java (CLI)
I made a viewer app that displays a PDF