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.data.update;
    20
    21  import java.io.File;
    22  import org.junit.After;
    23  import org.junit.AfterClass;
    24  import org.junit.Before;
    25  import org.junit.BeforeClass;
    26  import org.junit.Test;
    27  import static org.junit.Assert.*;
    28
    29  /**
    30   *
    31   * @author Jeremy Long (jeremy.long@owasp.org)
    32   */
    33  public class DataStoreMetaInfoTest {
    34
    35      public DataStoreMetaInfoTest() {
    36      }
    37
    38      @BeforeClass
    39      public static void setUpClass() {
    40      }
    41
    42      @AfterClass
    43      public static void tearDownClass() {
    44      }
    45
    46      @Before
    47      public void setUp() {
    48      }
    49
    50      @After
    51      public void tearDown() {
    52      }
    53
    54      /**
    55       * Test of isBatchUpdateMode method, of class DataStoreMetaInfo.
    56       */
    57      @Test
    58      public void testIsBatchUpdateMode() {
    59          DataStoreMetaInfo instance = new DataStoreMetaInfo();
    60          boolean expResult = false;
    61          instance.setBatchUpdateMode(expResult);
    62          boolean result = instance.isBatchUpdateMode();
    63          assertEquals(expResult, result);
    64      }
    65
    66      /**
    67       * Test of isEmpty method, of class DataStoreMetaInfo.
    68       */
    69      @Test
    70      public void testIsEmpty() {
    71          DataStoreMetaInfo instance = new DataStoreMetaInfo();
    72          boolean expResult = false;
    73          boolean result = instance.isEmpty();
    74          assertEquals(expResult, result);
    75      }
    76
    77      /**
    78       * Test of save method, of class DataStoreMetaInfo.
    79       */
    80      @Test
    81      public void testSave() throws Exception {
    82          NvdCveInfo updatedValue = new NvdCveInfo();
    83          String key = "test";
    84          long expected = 1337;
    85          updatedValue.setId(key);
    86          updatedValue.setTimestamp(expected);
    87          DataStoreMetaInfo instance = new DataStoreMetaInfo();
    88          instance.save(updatedValue);
    89          //reload the properties
    90          instance = new DataStoreMetaInfo();
    91          long results = Long.parseLong(instance.getProperty("lastupdated." + key));
    92          assertEquals(expected, results);
    93
    94      }
    95
    96      /**
    97       * Test of getProperty method, of class DataStoreMetaInfo.
    98       */
    99      @Test
    100     public void testGetProperty_String_String() {
    101         String key = "doesn't exist";
    102         String defaultValue = "default";
    103         DataStoreMetaInfo instance = new DataStoreMetaInfo();
    104         String expResult = "default";
    105         String result = instance.getProperty(key, defaultValue);
    106         assertEquals(expResult, result);
    107     }
    108
    109     /**
    110      * Test of getPropertiesFile method, of class DataStoreMetaInfo.
    111      */
    112     @Test
    113     public void testGetPropertiesFile() {
    114         File result = DataStoreMetaInfo.getPropertiesFile();
    115         //wow... rigorous!
    116         assertNotNull(result);
    117     }
    118 }