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) 2023 Jeremy Long. All Rights Reserved.
17 */
18 package org.owasp.dependencycheck.data.update;
19
20 import org.junit.jupiter.api.Test;
21
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23 import static org.junit.jupiter.api.Assertions.assertNull;
24
25 /**
26 *
27 * @author Jeremy Long
28 */
29 class NvdApiDataSourceTest {
30
31 /**
32 * Test of extractUrlData method, of class NvdApiDataSource.
33 */
34 @Test
35 void testExtractUrlData() {
36 String nvdDataFeedUrl = "https://internal.server/nist/nvdcve-{0}.json.gz";
37 NvdApiDataSource instance = new NvdApiDataSource();
38 String expectedUrl = "https://internal.server/nist/";
39 String expectedPattern = "nvdcve-{0}.json.gz";
40 NvdApiDataSource.UrlData result = instance.extractUrlData(nvdDataFeedUrl);
41
42 nvdDataFeedUrl = "https://internal.server/nist/";
43 expectedUrl = "https://internal.server/nist/";
44 result = instance.extractUrlData(nvdDataFeedUrl);
45
46 assertEquals(expectedUrl, result.getUrl());
47 assertNull(result.getPattern());
48
49 nvdDataFeedUrl = "https://internal.server/nist";
50 expectedUrl = "https://internal.server/nist/";
51 result = instance.extractUrlData(nvdDataFeedUrl);
52
53 assertEquals(expectedUrl, result.getUrl());
54 assertNull(result.getPattern());
55 }
56
57 // /**
58 // * Test of getRemoteCacheProperties method, of class NvdApiDataSource.
59 // */
60 // @Test
61 // public void testGetRemoteCacheProperties() throws Exception {
62 // System.out.println("getRemoteCacheProperties");
63 // String url = "";
64 // NvdApiDataSource instance = new NvdApiDataSource();
65 // Properties expResult = null;
66 // Properties result = instance.getRemoteCacheProperties(url);
67 // assertEquals(expResult, result);
68 // // TODO review the generated test code and remove the default call to fail.
69 // fail("The test case is a prototype.");
70 // }
71 }