View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
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  package de.smartics.properties.resource.maven.repository;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.containsString;
20  import static org.hamcrest.Matchers.equalTo;
21  import static org.hamcrest.Matchers.is;
22  
23  import java.io.File;
24  import java.util.List;
25  
26  import org.junit.Before;
27  import org.junit.Test;
28  import org.sonatype.aether.RepositorySystemSession;
29  import org.sonatype.aether.artifact.Artifact;
30  import org.sonatype.aether.resolution.DependencyResolutionException;
31  import org.sonatype.aether.util.artifact.DefaultArtifact;
32  
33  import de.smartics.properties.resource.domain.ArtifactRef;
34  import de.smartics.properties.resource.domain.ClassPathEnvironment;
35  import de.smartics.testdoc.annotations.Uut;
36  import de.smartics.util.test.io.FileTestUtils;
37  
38  /**
39   * Tests {@link MavenRepository}.
40   */
41  public class ResourceRepositoryTest
42  {
43    // ********************************* Fields *********************************
44  
45    // --- constants ------------------------------------------------------------
46  
47    // --- members --------------------------------------------------------------
48  
49    @Uut
50    private MavenRepository uut;
51  
52    private RepositorySystemSession session;
53  
54    // ****************************** Inner Classes *****************************
55  
56    // ********************************* Methods ********************************
57  
58    // --- prepare --------------------------------------------------------------
59  
60    @Before
61    public void setUp()
62    {
63      final File repoDir = FileTestUtils.getFileFromResource("repository");
64      uut = new MavenRepository(null,
65      // "http://www.smartics.eu/nexus/content/repositories/public/",
66          repoDir.getAbsolutePath());
67      session = uut.createSession();
68    }
69  
70    // --- helper ---------------------------------------------------------------
71  
72    // --- tests ----------------------------------------------------------------
73  
74    @Test
75    public void resolvesLocalFiles() throws DependencyResolutionException
76    {
77      final Artifact artifact =
78          new DefaultArtifact("de.smartics.test", "single-project", "jar",
79              "1.2.3");
80      final ClassPathEnvironment resources = uut.resolve(session, artifact);
81  
82      final List<ArtifactRef> refs = resources.getArtifactRefs();
83      assertThat(refs.size(), is(equalTo(1)));
84      assertThat(
85          refs.get(0).getUrl().toExternalForm(),
86          containsString("repository/de/smartics/test/single-project/1.2.3/single-project-1.2.3.jar"));
87    }
88  }