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

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