View Javadoc

    1   /*
    2    * This file is part of dependency-check-core.
    3    *
    4    * Dependency-check-core is free software: you can redistribute it and/or modify it
    5    * under the terms of the GNU General Public License as published by the Free
    6    * Software Foundation, either version 3 of the License, or (at your option) any
    7    * later version.
    8    *
    9    * Dependency-check-core is distributed in the hope that it will be useful, but
    10   * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    12   * details.
    13   *
    14   * You should have received a copy of the GNU General Public License along with
    15   * dependency-check-core. If not, see http://www.gnu.org/licenses/.
    16   *
    17   * Copyright (c) 2013 Jeremy Long. All Rights Reserved.
    18   */
    19  package org.owasp.dependencycheck.dependency;
    20
    21  import java.util.Set;
    22  import org.owasp.dependencycheck.dependency.EvidenceCollection;
    23  import org.owasp.dependencycheck.dependency.Identifier;
    24  import org.owasp.dependencycheck.dependency.Dependency;
    25  import org.owasp.dependencycheck.dependency.Evidence;
    26  import java.io.File;
    27  import java.util.List;
    28  import org.junit.After;
    29  import org.junit.AfterClass;
    30  import org.junit.Before;
    31  import org.junit.BeforeClass;
    32  import org.junit.Test;
    33  import static org.junit.Assert.*;
    34
    35  /**
    36   *
    37   * @author Jeremy Long (jeremy.long@owasp.org)
    38   */
    39  public class DependencyTest {
    40
    41      public DependencyTest() {
    42      }
    43
    44      @BeforeClass
    45      public static void setUpClass() throws Exception {
    46      }
    47
    48      @AfterClass
    49      public static void tearDownClass() throws Exception {
    50      }
    51
    52      @Before
    53      public void setUp() {
    54      }
    55
    56      @After
    57      public void tearDown() {
    58      }
    59
    60      /**
    61       * Test of getFileName method, of class Dependency.
    62       */
    63      @Test
    64      public void testGetFileName() {
    65          Dependency instance = new Dependency();
    66          String expResult = "filename";
    67          instance.setFileName(expResult);
    68          String result = instance.getFileName();
    69          assertEquals(expResult, result);
    70      }
    71
    72      /**
    73       * Test of setFileName method, of class Dependency.
    74       */
    75      @Test
    76      public void testSetFileName() {
    77          String fileName = "test.file";
    78          Dependency instance = new Dependency();
    79          instance.setFileName(fileName);
    80          assertEquals(fileName, instance.getFileName());
    81      }
    82
    83      /**
    84       * Test of setActualFilePath method, of class Dependency.
    85       */
    86      @Test
    87      public void testSetActualFilePath() {
    88          String actualFilePath = "test.file";
    89          Dependency instance = new Dependency();
    90          instance.setActualFilePath(actualFilePath);
    91          assertEquals(actualFilePath, instance.getActualFilePath());
    92      }
    93
    94      /**
    95       * Test of getActualFilePath method, of class Dependency.
    96       */
    97      @Test
    98      public void testGetActualFilePath() {
    99          Dependency instance = new Dependency();
    100         String expResult = "test.file";
    101         instance.setActualFilePath(expResult);
    102         String result = instance.getActualFilePath();
    103         assertEquals(expResult, result);
    104     }
    105
    106     /**
    107      * Test of setFilePath method, of class Dependency.
    108      */
    109     @Test
    110     public void testSetFilePath() {
    111         String filePath = "test.file";
    112         Dependency instance = new Dependency();
    113         instance.setFilePath(filePath);
    114         assertEquals(filePath, instance.getFilePath());
    115     }
    116
    117     /**
    118      * Test of getFilePath method, of class Dependency.
    119      */
    120     @Test
    121     public void testGetFilePath() {
    122         Dependency instance = new Dependency();
    123         String expResult = "path/test.file";
    124         instance.setFilePath(expResult);
    125         String result = instance.getFilePath();
    126         assertEquals(expResult, result);
    127     }
    128
    129     /**
    130      * Test of setFileExtension method, of class Dependency.
    131      */
    132     @Test
    133     public void testSetFileExtension() {
    134         String fileExtension = "jar";
    135         Dependency instance = new Dependency();
    136         instance.setFileExtension(fileExtension);
    137         assertEquals(fileExtension, instance.getFileExtension());
    138     }
    139
    140     /**
    141      * Test of getFileExtension method, of class Dependency.
    142      */
    143     @Test
    144     public void testGetFileExtension() {
    145         Dependency instance = new Dependency();
    146         String expResult = "jar";
    147         instance.setFileExtension(expResult);
    148         String result = instance.getFileExtension();
    149         assertEquals(expResult, result);
    150     }
    151
    152     /**
    153      * Test of getMd5sum method, of class Dependency.
    154      */
    155     @Test
    156     public void testGetMd5sum() {
    157         File file = new File(this.getClass().getClassLoader().getResource("struts2-core-2.1.2.jar").getPath());
    158         Dependency instance = new Dependency(file);
    159 //        assertEquals("89CE9E36AA9A9E03F1450936D2F4F8DD0F961F8B", result.getSha1sum());
    160         String expResult = "C30B57142E1CCBC1EFD5CD15F307358F";
    161         String result = instance.getMd5sum();
    162         assertEquals(expResult, result);
    163     }
    164
    165     /**
    166      * Test of setMd5sum method, of class Dependency.
    167      */
    168     @Test
    169     public void testSetMd5sum() {
    170         String md5sum = "test";
    171         Dependency instance = new Dependency();
    172         instance.setMd5sum(md5sum);
    173         assertEquals(md5sum, instance.getMd5sum());
    174     }
    175
    176     /**
    177      * Test of getSha1sum method, of class Dependency.
    178      */
    179     @Test
    180     public void testGetSha1sum() {
    181         File file = new File(this.getClass().getClassLoader().getResource("struts2-core-2.1.2.jar").getPath());
    182         Dependency instance = new Dependency(file);
    183         String expResult = "89CE9E36AA9A9E03F1450936D2F4F8DD0F961F8B";
    184         String result = instance.getSha1sum();
    185         assertEquals(expResult, result);
    186     }
    187
    188     /**
    189      * Test of setSha1sum method, of class Dependency.
    190      */
    191     @Test
    192     public void testSetSha1sum() {
    193         String sha1sum = "test";
    194         Dependency instance = new Dependency();
    195         instance.setSha1sum(sha1sum);
    196         assertEquals(sha1sum, instance.getSha1sum());
    197     }
    198
    199     /**
    200      * Test of getIdentifiers method, of class Dependency.
    201      */
    202     @Test
    203     public void testGetIdentifiers() {
    204         Dependency instance = new Dependency();
    205         List expResult = null;
    206         Set<Identifier> result = instance.getIdentifiers();
    207
    208         assertTrue(true); //this is just a getter setter pair.
    209     }
    210
    211     /**
    212      * Test of setIdentifiers method, of class Dependency.
    213      */
    214     @Test
    215     public void testSetIdentifiers() {
    216         Set<Identifier> identifiers = null;
    217         Dependency instance = new Dependency();
    218         instance.setIdentifiers(identifiers);
    219         assertTrue(true); //this is just a getter setter pair.
    220     }
    221
    222     /**
    223      * Test of addIdentifier method, of class Dependency.
    224      */
    225     @Test
    226     public void testAddIdentifier() {
    227         String type = "cpe";
    228         String value = "cpe:/a:apache:struts:2.1.2";
    229         String url = "http://somewhere";
    230         Identifier expResult = new Identifier(type, value, url);
    231
    232         Dependency instance = new Dependency();
    233         instance.addIdentifier(type, value, url);
    234         assertEquals(1, instance.getIdentifiers().size());
    235         assertTrue("Identifier doesn't contain expected result.", instance.getIdentifiers().contains(expResult));
    236     }
    237
    238     /**
    239      * Test of getEvidence method, of class Dependency.
    240      */
    241     @Test
    242     public void testGetEvidence() {
    243         Dependency instance = new Dependency();
    244         EvidenceCollection expResult = null;
    245         EvidenceCollection result = instance.getEvidence();
    246         assertTrue(true); //this is just a getter setter pair.
    247     }
    248
    249     /**
    250      * Test of getEvidenceUsed method, of class Dependency.
    251      */
    252     @Test
    253     public void testGetEvidenceUsed() {
    254         Dependency instance = new Dependency();
    255         String expResult = "used";
    256
    257         instance.getProductEvidence().addEvidence("used", "used", "used", Evidence.Confidence.HIGH);
    258         instance.getProductEvidence().addEvidence("not", "not", "not", Evidence.Confidence.MEDIUM);
    259         for (Evidence e : instance.getProductEvidence().iterator(Evidence.Confidence.HIGH)) {
    260             String use = e.getValue();
    261         }
    262
    263         EvidenceCollection result = instance.getEvidenceUsed();
    264
    265         assertEquals(1, result.size());
    266         assertTrue(result.containsUsedString(expResult));
    267     }
    268
    269     /**
    270      * Test of getVendorEvidence method, of class Dependency.
    271      */
    272     @Test
    273     public void testGetVendorEvidence() {
    274         Dependency instance = new Dependency();
    275         EvidenceCollection expResult = null;
    276         EvidenceCollection result = instance.getVendorEvidence();
    277         assertTrue(true); //this is just a getter setter pair.
    278     }
    279
    280     /**
    281      * Test of getProductEvidence method, of class Dependency.
    282      */
    283     @Test
    284     public void testGetProductEvidence() {
    285         Dependency instance = new Dependency();
    286         EvidenceCollection expResult = null;
    287         EvidenceCollection result = instance.getProductEvidence();
    288         assertTrue(true); //this is just a getter setter pair.
    289     }
    290
    291     /**
    292      * Test of getVersionEvidence method, of class Dependency.
    293      */
    294     @Test
    295     public void testGetVersionEvidence() {
    296         Dependency instance = new Dependency();
    297         EvidenceCollection expResult = null;
    298         EvidenceCollection result = instance.getVersionEvidence();
    299         assertTrue(true); //this is just a getter setter pair.
    300     }
    301 }