]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1283] add test for existing dependencies method
authorBrett Porter <brett@apache.org>
Thu, 26 Nov 2009 05:04:18 +0000 (05:04 +0000)
committerBrett Porter <brett@apache.org>
Thu, 26 Nov 2009 05:04:18 +0000 (05:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884398 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java

index 8764ee7b1de6731b4c4a6a3fc051f515cc0a3bb3..000dd2f5e0b8a03c105cf1ccb8415a6c306316ae 100644 (file)
@@ -41,6 +41,7 @@ import org.apache.maven.archiva.database.constraints.ArtifactsRelatedConstraint;
 import org.apache.maven.archiva.model.ArchivaArtifact;
 import org.apache.maven.archiva.model.ArchivaArtifactModel;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
+import org.apache.maven.archiva.model.Dependency;
 import org.apache.maven.archiva.model.MailingList;
 import org.apache.maven.archiva.model.VersionedReference;
 import org.apache.maven.archiva.security.UserRepositories;
@@ -387,6 +388,78 @@ public class ShowArtifactActionTest
         assertNull( action.getSnapshotVersions() );
     }
 
+    public void testGetDependencies()
+        throws ArchivaDatabaseException
+    {
+        List<ArchivaArtifact> artifacts =
+            Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
+        MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 1 );
+        ArchivaProjectModel legacyModel = createLegacyProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
+        Dependency dependency1 = createDependencyBasic( "artifactId1" );
+        Dependency dependency2 = createDependencyExtended( "artifactId2" );
+        legacyModel.setDependencies( Arrays.asList( dependency1, dependency2 ) );
+        MockControl projectDaoMockControl = createProjectDaoMock( legacyModel );
+
+        setActionParameters();
+
+        String result = action.dependencies();
+
+        artifactDaoMockControl.verify();
+        projectDaoMockControl.verify();
+
+        assertActionSuccess( action, result );
+
+        assertActionParameters( action );
+        ArchivaProjectModel model = action.getModel();
+        assertDefaultModel( model );
+
+        assertNotNull( action.getDependencies() );
+        assertDependencyBasic( action.getDependencies().get( 0 ), "artifactId1" );
+        assertDependencyExtended( action.getDependencies().get( 1 ), "artifactId2" );
+
+        assertNull( action.getRepositoryId() );
+        assertNull( action.getDependees() );
+        assertNull( action.getMailingLists() );
+        assertNull( action.getSnapshotVersions() );
+    }
+
+    private void assertDependencyBasic( Dependency dependency, String artifactId )
+    {
+        assertEquals( artifactId, dependency.getArtifactId() );
+        assertEquals( "groupId", dependency.getGroupId() );
+        assertEquals( "version", dependency.getVersion() );
+    }
+
+    private void assertDependencyExtended( Dependency dependency, String artifactId )
+    {
+        assertDependencyBasic( dependency, artifactId );
+        assertEquals( true, dependency.isOptional() );
+        assertEquals( "classifier", dependency.getClassifier() );
+        assertEquals( "type", dependency.getType() );
+        assertEquals( "scope", dependency.getScope() );
+        assertEquals( "systemPath", dependency.getSystemPath() );
+    }
+
+    private Dependency createDependencyExtended( String artifactId )
+    {
+        Dependency dependency = createDependencyBasic( artifactId );
+        dependency.setClassifier( "classifier" );
+        dependency.setOptional( true );
+        dependency.setScope( "scope" );
+        dependency.setSystemPath( "systemPath" );
+        dependency.setType( "type" );
+        return dependency;
+    }
+
+    private Dependency createDependencyBasic( String artifactId )
+    {
+        Dependency dependency = new Dependency();
+        dependency.setArtifactId( artifactId );
+        dependency.setGroupId( "groupId" );
+        dependency.setVersion( "version" );
+        return dependency;
+    }
+
     private void assertMailingList( MailingList mailingList, String name, String prefix )
     {
         assertEquals( name, mailingList.getName() );