You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DependencyTreeBuilderTestMaven3.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package org.apache.archiva.repository.maven.dependency.tree;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import junit.framework.TestCase;
  20. import org.apache.archiva.configuration.ArchivaConfiguration;
  21. import org.apache.archiva.configuration.Configuration;
  22. import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
  23. import org.apache.archiva.maven.model.Artifact;
  24. import org.apache.archiva.maven.model.TreeEntry;
  25. import org.apache.archiva.repository.RepositoryRegistry;
  26. import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
  27. import org.junit.Before;
  28. import org.junit.Test;
  29. import org.junit.runner.RunWith;
  30. import org.springframework.test.context.ContextConfiguration;
  31. import javax.inject.Inject;
  32. import javax.inject.Named;
  33. import java.nio.file.Paths;
  34. import java.util.Collections;
  35. import java.util.List;
  36. import static org.assertj.core.api.Assertions.assertThat;
  37. @RunWith( ArchivaSpringJUnit4ClassRunner.class )
  38. @ContextConfiguration( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
  39. public class DependencyTreeBuilderTestMaven3
  40. extends TestCase
  41. {
  42. @Inject
  43. @Named( "dependencyTreeBuilder#maven3" )
  44. private Maven3DependencyTreeBuilder builder;
  45. private static final String TEST_REPO_ID = "test";
  46. private static final String TEST_VERSION = "1.2.1";
  47. private static final String TEST_ARTIFACT_ID = "archiva-common";
  48. private static final String TEST_GROUP_ID = "org.apache.archiva";
  49. @Inject
  50. @Named( "archivaConfiguration#test" )
  51. ArchivaConfiguration config;
  52. @Inject
  53. RepositoryRegistry repositoryRegistry;
  54. @Before
  55. @Override
  56. public void setUp()
  57. throws Exception
  58. {
  59. super.setUp();
  60. Configuration configuration = new Configuration();
  61. ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
  62. repoConfig.setId( TEST_REPO_ID );
  63. repoConfig.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString() );
  64. configuration.addManagedRepository( repoConfig );
  65. config.getConfiguration().getProxyConnectors().clear();
  66. config.save( configuration );
  67. repositoryRegistry.reload();
  68. //artifactFactory = ((DefaultDependencyTreeBuilder)this.builder).getFactory();
  69. }
  70. private Artifact createArtifact( String groupId, String artifactId, String version )
  71. {
  72. return new Artifact( groupId, artifactId, version );
  73. }
  74. private String getId( Artifact artifact )
  75. {
  76. return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
  77. }
  78. @Test
  79. public void testBuilderDependencies()
  80. throws Exception
  81. {
  82. List<TreeEntry> treeEntries =
  83. builder.buildDependencyTree( Collections.singletonList( TEST_REPO_ID ), TEST_GROUP_ID, TEST_ARTIFACT_ID,
  84. TEST_VERSION );
  85. Artifact artifact = new Artifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "", "" );
  86. artifact.setFileExtension("jar");
  87. assertThat( treeEntries ).isNotNull().isNotEmpty().contains(new TreeEntry(artifact) );
  88. artifact = new Artifact( "commons-lang", "commons-lang", "2.2", "compile", "" );
  89. artifact.setFileExtension("jar");
  90. assertThat( treeEntries.get( 0 ).getChilds() ).isNotNull().isNotEmpty().contains(
  91. new TreeEntry(artifact) );
  92. }
  93. public static class TestTreeEntry
  94. extends TreeEntry
  95. {
  96. Artifact a;
  97. public TestTreeEntry( Artifact a )
  98. {
  99. this.a = a;
  100. }
  101. @Override
  102. public int hashCode()
  103. {
  104. return this.a.hashCode();
  105. }
  106. @Override
  107. public boolean equals( Object o )
  108. {
  109. Artifact artifact = ( (TreeEntry) o ).getArtifact();
  110. return artifact.equals( this.a );
  111. }
  112. }
  113. }