kamnani commented on a change in pull request #352:
URL: https://github.com/apache/tomcat/pull/352#discussion_r489609047



##########
File path: test/org/apache/catalina/webresources/TestJarContents.java
##########
@@ -0,0 +1,61 @@
+/*
+ * 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 org.apache.catalina.webresources;
+
+import java.io.File;
+
+import org.junit.Assert;
+import org.junit.Test;
+import java.util.jar.JarFile;
+
+import org.apache.catalina.WebResourceSet;
+
+/**
+ * @author Kamnani, Jatin
+ */
+public class TestJarContents {
+
+    @Test
+    public void testMightContainResource() {
+        try {
+            File empty = new File("test/webresources/dir3");
+            File jar = new File("test/webresources/dir1.jar");
+
+            TesterWebResourceRoot root = new TesterWebResourceRoot();
+
+            // Use empty dir for root of web app.
+            WebResourceSet webResourceSet = new DirResourceSet(root, "/", 
empty.getAbsolutePath(), "/");
+            root.setMainResources(webResourceSet);
+
+            // If this JAR was in a web application, this is equivalent to how 
it
+            // would be added
+            JarResourceSet test =
+                    new JarResourceSet(root, "/", jar.getAbsolutePath(), 
"/META-INF/resources");
+            test.setStaticOnly(true);
+            root.addJarResources(test);
+
+            JarContents testJarContentsObject = new JarContents(new 
JarFile("test/webresources/dir1.jar"));
+            Assert.assertTrue(testJarContentsObject.mightContainResource(
+                    "/d1/d1-f1.txt", jar.getAbsolutePath()));
+
+            Assert.assertFalse(testJarContentsObject.mightContainResource(
+                    "/d7/d1-f1.txt", jar.getAbsolutePath()));
+        } catch (Exception e) {
+            Assert.fail("Error Happened while Testing JarContents, " + e);

Review comment:
       Thanks for the suggestions :) 
   Resolved with the latest commit. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to