View Javadoc
1   /*
2    * Copyright (c) 2011-2023 Alex Tunyk <alex at tunyk.com>.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * See the NOTICE file distributed with this work for additional information
17   * regarding copyright ownership.
18   */
19  package com.tunyk.mvn.plugins.htmlcompressor;
20  
21  import org.junit.jupiter.api.AfterAll;
22  import org.junit.jupiter.api.BeforeAll;
23  import org.junit.jupiter.api.BeforeEach;
24  import org.junit.jupiter.api.Test;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  /**
29   * The Class HtmlCompressorTest.
30   */
31  class HtmlCompressorTest {
32  
33      /** The Constant LOG. */
34      private static final Logger LOG = LoggerFactory.getLogger(HtmlCompressorTest.class);
35  
36      /**
37       * Sets the up class.
38       */
39      @BeforeAll
40      static void setUpClass() {
41          LOG.info("Setting up class...");
42      }
43  
44      /**
45       * Tear down class.
46       */
47      @AfterAll
48      static void tearDownClass() {
49          LOG.info("Test finished.");
50      }
51  
52      /**
53       * Sets the up.
54       */
55      @BeforeEach
56      void setUp() {
57          LOG.info("Setting up data for testing...");
58      }
59  
60      /**
61       * Test compress.
62       *
63       * @throws Exception
64       *             the exception
65       */
66      @Test
67      void testCompress() throws Exception {
68          LOG.info("Testing compress method...");
69  
70          HtmlCompressor htmlCompressor = new HtmlCompressor("src/test/resources/html", "target/test/htmlcompressor/0");
71          htmlCompressor.compress();
72          // TODO: test files where created and every one has the right contents
73  
74          htmlCompressor = new HtmlCompressor("src/test/resources/html", "target/test/htmlcompressor/1", true,
75                  "target/test/htmlcompressor/1/integration.js", "src/test/resources/html/integration.js");
76          htmlCompressor.compress();
77          // TODO: test json file was created and it has right contents
78  
79          htmlCompressor = new HtmlCompressor("src/test/resources/html", "target/test/htmlcompressor/2");
80          com.googlecode.htmlcompressor.compressor.HtmlCompressor htmlCompressorHandler = new com.googlecode.htmlcompressor.compressor.HtmlCompressor();
81          htmlCompressorHandler.setEnabled(false);
82          htmlCompressor.setHtmlCompressor(htmlCompressorHandler);
83          htmlCompressor.compress();
84          // TODO: verify if provided compression params are picked up
85  
86          LOG.info("Passed");
87      }
88  }