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) 2014 Jeremy Long. All Rights Reserved.
17   */
18  package org.owasp.dependencycheck.data.nexus;
19  
20  import java.io.FileNotFoundException;
21  import java.net.URL;
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertNotNull;
24  import org.junit.Assume;
25  import org.junit.Before;
26  import org.junit.Ignore;
27  import org.junit.Test;
28  import org.owasp.dependencycheck.BaseTest;
29  import org.owasp.dependencycheck.utils.Settings;
30  import org.slf4j.Logger;
31  import org.slf4j.LoggerFactory;
32  
33  public class NexusSearchTest extends BaseTest {
34  
35      private static final Logger LOGGER = LoggerFactory.getLogger(NexusSearchTest.class);
36      private NexusSearch searcher;
37  
38      @Before
39      public void setUp() throws Exception {
40          String nexusUrl = Settings.getString(Settings.KEYS.ANALYZER_NEXUS_URL);
41          LOGGER.debug(nexusUrl);
42          searcher = new NexusSearch(new URL(nexusUrl));
43          Assume.assumeTrue(searcher.preflightRequest());
44      }
45  
46      @Test(expected = IllegalArgumentException.class)
47      @Ignore
48      public void testNullSha1() throws Exception {
49          searcher.searchSha1(null);
50      }
51  
52      @Test(expected = IllegalArgumentException.class)
53      @Ignore
54      public void testMalformedSha1() throws Exception {
55          searcher.searchSha1("invalid");
56      }
57  
58      // This test does generate network traffic and communicates with a host
59      // you may not be able to reach. Remove the @Ignore annotation if you want to
60      // test it anyway
61      @Test
62      @Ignore
63      public void testValidSha1() throws Exception {
64          MavenArtifact ma = searcher.searchSha1("9977a8d04e75609cf01badc4eb6a9c7198c4c5ea");
65          assertEquals("Incorrect group", "org.apache.maven.plugins", ma.getGroupId());
66          assertEquals("Incorrect artifact", "maven-compiler-plugin", ma.getArtifactId());
67          assertEquals("Incorrect version", "3.1", ma.getVersion());
68          assertNotNull("URL Should not be null", ma.getArtifactUrl());
69      }
70  
71      // This test does generate network traffic and communicates with a host
72      // you may not be able to reach. Remove the @Ignore annotation if you want to
73      // test it anyway
74      @Test(expected = FileNotFoundException.class)
75      @Ignore
76      public void testMissingSha1() throws Exception {
77          searcher.searchSha1("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
78      }
79  }
80  
81  // vim: cc=120:sw=4:ts=4:sts=4