View Javadoc
1   /*
2    * This file is part of dependency-check-core.
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    *     http://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   * Copyright (c) 2016 Jeremy Long. All Rights Reserved.
17   */
18  package org.owasp.dependencycheck.xml.hints;
19  
20  import java.io.File;
21  import java.io.InputStream;
22  import org.junit.Test;
23  import static org.junit.Assert.assertEquals;
24  import org.owasp.dependencycheck.BaseTest;
25  
26  /**
27   *
28   * @author Jeremy Long
29   */
30  public class HintParserTest extends BaseTest {
31  
32      /**
33       * Test of parseHints method, of class HintParser.
34       */
35      @Test
36      public void testParseHints_File() throws Exception {
37          File file = BaseTest.getResourceAsFile(this, "hints.xml");
38          HintParser instance = new HintParser();
39          Hints results = instance.parseHints(file);
40          assertEquals("Two duplicating hints should have been read", 2, results.getVendorDuplicatingHintRules().size());
41          assertEquals("Two hint rules should have been read", 2, results.getHintRules().size());
42      }
43  
44      /**
45       * Test of parseHints method, of class HintParser.
46       */
47      @Test
48      public void testParseHints_InputStream() throws Exception {
49          InputStream ins = BaseTest.getResourceAsStream(this, "hints.xml");
50          HintParser instance = new HintParser();
51          Hints results = instance.parseHints(ins);
52          assertEquals("Two duplicating hints should have been read", 2, results.getVendorDuplicatingHintRules().size());
53          assertEquals("Two hint rules should have been read", 2, results.getHintRules().size());
54          assertEquals("One add product should have been read", 1, results.getHintRules().get(0).getAddProduct().size());
55          assertEquals("One add vendor should have been read", 1, results.getHintRules().get(0).getAddVendor().size());
56          assertEquals("Two file name should have been read", 2, results.getHintRules().get(1).getFilenames().size());
57  
58          assertEquals("add product name not found", "add product name", results.getHintRules().get(0).getAddProduct().get(0).getName());
59          assertEquals("add vendor name not found", "add vendor name", results.getHintRules().get(0).getAddVendor().get(0).getName());
60          assertEquals("given product name not found", "given product name", results.getHintRules().get(0).getGivenProduct().get(0).getName());
61          assertEquals("given vendor name not found", "given vendor name", results.getHintRules().get(0).getGivenVendor().get(0).getName());
62  
63          assertEquals("spring file name not found", "spring", results.getHintRules().get(1).getFilenames().get(0).getValue());
64          assertEquals("file name 1 should not be case sensitive", false, results.getHintRules().get(1).getFilenames().get(0).isCaseSensitive());
65          assertEquals("file name 1 should not be a regex", false, results.getHintRules().get(1).getFilenames().get(0).isRegex());
66          assertEquals("file name 2 should be case sensitive", true, results.getHintRules().get(1).getFilenames().get(1).isCaseSensitive());
67          assertEquals("file name 2 should be a regex", true, results.getHintRules().get(1).getFilenames().get(1).isRegex());
68          
69          
70          assertEquals("sun duplicating vendor", "sun", results.getVendorDuplicatingHintRules().get(0).getValue());
71          assertEquals("sun duplicates vendor oracle", "oracle", results.getVendorDuplicatingHintRules().get(0).getDuplicate());
72      }
73  }