View Javadoc

1   package org.apache.tomcat.maven.it;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  
23  import org.apache.maven.it.VerificationException;
24  import org.junit.Test;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  import java.io.File;
29  import java.net.URI;
30  import java.net.URISyntaxException;
31  
32  import static junitx.framework.StringAssert.assertContains;
33  import static org.junit.Assert.assertNotNull;
34  import static org.junit.Assert.assertTrue;
35  
36  /**
37   * Tests a bunch of configuration options for the tomcat-run Mojo.
38   *
39   * @author Mark Michaelis
40   */
41  public abstract class AbstractTomcatRunMultiConfigIT
42      extends AbstractWarProjectIT
43  {
44  
45      private static final String URL_QUERY = "\u3053\u3093\u306b\u3061\u306f";
46  
47      /**
48       * ArtifactId of the sample WAR project.
49       */
50      private static final String WAR_ARTIFACT_ID = "tomcat-run-multi-config";
51  
52      @Override
53      protected String getWebappUrl()
54      {
55          try
56          {
57              return new URI(
58                  "http://localhost:" + getHttpItPort() + "/multi-config/index.jsp?string=" + URL_QUERY ).toASCIIString();
59          }
60          catch ( URISyntaxException e )
61          {
62              logger.error( "An exception occurred.", e );
63              return "http://localhost:" + getHttpItPort() + "/multi-config";
64          }
65      }
66  
67      @Override
68      protected String getWarArtifactId()
69      {
70          return WAR_ARTIFACT_ID;
71      }
72  
73      @Test
74      public void testIt()
75          throws Exception
76      {
77          final String responseBody = executeVerifyWithGet();
78          assertNotNull( "Received message body from " + getWebappUrl() + " must not be null.", responseBody );
79          assertContains( "Response from " + getWebappUrl() + " must match expected content.", URL_QUERY, responseBody );
80  
81          final File tomcatFolder = new File( webappHome, "target/tc" );
82          final File emptyLocation = new File( tomcatFolder, "conf/empty.txt" );
83  
84          assertTrue(
85              "Tomcat folder \"" + tomcatFolder.getAbsolutePath() + "\" should exist in target folder of project at "
86                  + webappHome, tomcatFolder.exists() );
87          assertTrue(
88              "File \"" + emptyLocation.getAbsolutePath() + "\" should have been copied from tcconf to tomcat/conf",
89              emptyLocation.exists() );
90  
91          logger.info( "Error Free Log check" );
92          verifier.verifyErrorFreeLog();
93          verifyConnectorsStarted();
94  
95      }
96  
97      /**
98       * impls check the logs if http/https/apr has been started
99       */
100     protected abstract void verifyConnectorsStarted()
101         throws VerificationException;
102 
103 }