hi ,

i wrote a test case for the SourceArtifacts Class.

package org.apache.archiva.stagerepository.merge.repodetails;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import org.apache.log4j.Logger;
import org.junit.Test;

import junit.framework.TestCase;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
import
org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.easymock.MockControl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;


public class SourceArtifactsTest
        extends TestCase
{

    private Logger log = LoggerFactory.getLogger( SourceArtifactsTest.class
);;

    /**
     * @plexus.requirement
     */
    private  SourceAritfacts sourceArtifacts ;

    private MockControl metadataResolverControl;

    private  MetadataResolver metadataResolver ;

    private static final String TEST_REPO_ID = "internal";

    SourceAritfacts sa;


    @Override
    protected void setUp()
            throws Exception
    {
        super.setUp();
        sa = new SourceAritfacts();
        metadataResolverControl =
MockControl.createControl(MetadataResolver.class) ;
        metadataResolver =
(MetadataResolver)metadataResolverControl.getMock();
        sa.setMetadataResolver(metadataResolver);

        ManagedRepositoryConfiguration repository = new
ManagedRepositoryConfiguration();
        repository.setId( TEST_REPO_ID );
        repository.setLocation( " " );
    }


    @Test
    public void test(){

        metadataResolverControl.expectAndReturn(
                sa.getSourceArtifactList(),
(ArrayList<Artifact>)getRootNameSpace()
        );

        metadataResolverControl.replay();
        metadataResolverControl.verify();
    }


    private Collection<Artifact> getRootNameSpace()
    {
        List<Artifact> artifactList = new ArrayList<Artifact>();
        Artifact a = new Artifact();
        Artifact b = new Artifact();
        artifactList.add(a);
        artifactList.add(b);
        return artifactList;
    }
}


but i got a null pointer exception while executing following line.
  metadataResolverControl.expectAndReturn(
                sa.getSourceArtifactList(),
(ArrayList<Artifact>)getRootNameSpace()
        );

and surefire report  pointed following.


test(org.apache.archiva.stagerepository.merge.repodetails.SourceArtifactsTest)
Time elapsed: 0.065 sec  <<< ERROR!
java.lang.NullPointerException
    at
org.apache.archiva.stagerepository.merge.repodetails.SourceAritfacts.process(SourceAritfacts.java:88)



    private void process()
    {
        //this will get the root name spaces eg : org, com
        rootNameSpacesList = ( ArrayList<String> )
metadataResolver.getRootNamespaces( repoId );
        gruopIdList = new ArrayList<String>() ;
        artifactsList = new ArrayList<String>() ;

87        //following iterates through the  root name spaces list and get
the gruo id of relavet root name spaces.
88        for( String namespace : rootNameSpacesList )
        {

i think here exception throws since rootNameSpaceList is null..
is
is it possible to inject that list or is there any other alternative to
solve this ?

thanks.


On Mon, Jun 14, 2010 at 10:25 PM, Eshan Sudharaka <[email protected]>wrote:

> yes. i got your point. previously i was confusing how to return that
> ArtifactMetaData list since we have a Artifact list .
> now i added a method which is returning ArtifactMetadata list for a
> particular artifact.
>
> so the caller first need to get the Artifact list and then pass those
> artifacts one by one to get the Artifactmetadata.
>
> http://jira.codehaus.org/secure/ManageAttachments.jspa?id=75406
>
> thanks.
>
> On Mon, Jun 14, 2010 at 6:21 PM, Deng Ching <[email protected]> wrote:
>
>> We're using ArtifactMetadata to abstract what type of artifact it is
>> (whether it is a maven artifact or simply a file in the repository)..
>>  Also,
>> if you'll returning a list of Artifact objects from the SourceArtifact
>>
>> class then from those Artifact objects, you'll be querying for the
>> artifact
>> metadata again in the repository merge, won't it be redundant since in the
>> first place you already have ArtifactMetadata objects in the
>> SourceArtifact
>> class but you returned a list of Artifact objects instead?
>>
>> Thanks,
>> Deng
>>
>> On Sun, Jun 13, 2010 at 12:21 PM, Eshan Sudharaka <[email protected]
>> >wrote:
>>
>> > as i understood the purpose of the SourceArtifacts class is the return a
>> > list of available artifacts to the caller. Once the caller receives the
>> list
>> > i guess it is his responsibility to get the ArtifactMetaData using
>> >
>> >      **  metadataRepository.getArtifacts( repoId, namespace, projectId,
>> > projectVersion );
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Fri, Jun 11, 2010 at 9:28 PM, Eshan Sudharaka <[email protected]
>> >wrote:
>> >
>> >> i have a problem regarding
>> >>   Collection<ArtifactMetadata> getArtifacts( String repoId, String
>> >> namespace, String projectId,  String projectVersion );
>> >>  method.
>> >>
>> >> here parameters are unique to a particular artifact. so what are  the
>> >> things  that  returning list  contains ?
>> >>
>> >> as i understood class ArtifactMetadata contains the details for a
>> >> particular artifact. So i am wondering how this method returns a list
>> for
>> >> the parameters of a particular artifact ..
>> >>
>> >>
>> >> also the purpose of sourceArtifact class is to retrieve the list of
>> >> Artifacts in the target repo. i guess once we have Artifacts details
>> >> (gruopId, artifact id , version) we can check that artifact is
>> available or
>> >> not using available archiva methods.(as deng menstioned for that task
>> we
>> >> need only artifacts coordinates) So i am still confusing why we need a
>> list
>> >> of  ArtifactMetadata instead of a list of Artifacts.
>> >>
>> >> may be inorder to update archiva meta data model this  ArtifactMetadata
>> >> list will be usefull.
>> >>
>> >>
>> >> On Fri, Jun 11, 2010 at 8:33 PM, Eshan Sudharaka <[email protected]
>> >wrote:
>> >>
>> >>> package org.apache.archiva.stagerepository.merge.repodetails;
>> >>>
>> >>> /*
>> >>>  * Licensed to the Apache Software Foundation (ASF) under one
>> >>>  * or more contributor license agreements.  See the NOTICE file
>> >>>  * distributed with this work for additional information
>> >>>  * regarding copyright ownership.  The ASF licenses this file
>> >>>  * to you under the Apache License, Version 2.0 (the
>> >>>  * "License"); you may not use this file except in compliance
>> >>>  * with the License.  You may obtain a copy of the License at
>> >>>  *
>> >>>  *  http://www.apache.org/licenses/LICENSE-2.0
>> >>>  *
>> >>>  * Unless required by applicable law or agreed to in writing,
>> >>>  * software distributed under the License is distributed on an
>> >>>  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> >>>  * KIND, either express or implied.  See the License for the
>> >>>  * specific language governing permissions and limitations
>> >>>  * under the License.
>> >>>  */
>> >>> import org.apache.archiva.metadata.repository.DefaultMetadataResolver;
>> >>> import org.apache.archiva.metadata.repository.MetadataRepository;
>> >>> import org.apache.archiva.metadata.repository.MetadataResolver;
>> >>> import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
>> >>> import java.util.List;
>> >>> import java.util.Collection;
>> >>> import java.util.ArrayList;
>> >>> import java.util.Iterator;
>> >>> import org.slf4j.Logger;
>> >>> import org.slf4j.LoggerFactory;
>> >>>
>> >>> /**
>> >>>  * @plexus.component
>> >>> role="org.apache.archiva.repodetails.SourceAritfacts"
>> >>>  */
>> >>>
>> >>> public class SourceAritfacts
>> >>> {
>> >>>
>> >>>     /**
>> >>>      * @plexus.requirement
>> >>>      */
>> >>>     private MetadataResolver metadataResolver;
>> >>>
>> >>>     private ArrayList<String> rootNameSpacesList;
>> >>>
>> >>>     private ArrayList<String> gruopIdList;
>> >>>
>> >>>     private ArrayList<String> artifactsList;
>> >>>
>> >>>     private ArrayList<String> artifactsVersionsList;
>> >>>
>> >>>     private List<Artifact>  artifactsListWithDetails;
>> >>>
>> >>>     private String repoId;
>> >>>
>> >>>     private static final Logger log = LoggerFactory.getLogger(
>> >>> SourceAritfacts.class );
>> >>>
>> >>>     public List<Artifact> getSourceArtifactList(String repoId)
>> >>>     {
>> >>>         this.repoId = repoId;
>> >>>         artifactsListWithDetails = new ArrayList<Artifact>();
>> >>>         process();
>> >>>         return artifactsListWithDetails;
>> >>>     }
>> >>>
>> >>>
>> >>>     private void process()
>> >>>     {
>> >>>         //this will get the root name spaces eg : org, com
>> >>>         rootNameSpacesList = ( ArrayList<String> )
>> >>> metadataResolver.getRootNamespaces( repoId );
>> >>>         gruopIdList = new ArrayList<String>() ;
>> >>>         artifactsList = new ArrayList<String>() ;
>> >>>
>> >>>         //following iterates through the  root name spaces list and
>> get
>> >>> the gruo id of relavet root name spaces.
>> >>>         for( String namespace : rootNameSpacesList )
>> >>>         {
>> >>>             //this will get the gruop id list of relavant name space .
>> eg
>> >>> : org > archiva(gruop id)
>> >>>             gruopIdList =
>> >>> (ArrayList<String>)metadataResolver.getNamespaces( repoId , namespace
>> );
>> >>>
>> >>>             // following will iterates through the particular gruop id
>> 's
>> >>>             for (String gruopId : gruopIdList )
>> >>>             {
>> >>>                 // parse the parameters "repoId" and "namespace +
>> gruop
>> >>> id "to  artifacts list. eg : params = ("internal" , "org.archiva")
>> >>>                 artifactsList =
>> >>> (ArrayList<String>)metadataResolver.getNamespaces( repoId,namespace +
>> "." +
>> >>> gruopId );
>> >>>
>> >>>                 for (String artifact : artifactsList)
>> >>>                 {
>> >>>                     //iterates through the artifacts and get the
>> >>> available versions of a particular artifact
>> >>>                     artifactsVersionsList = ( ArrayList <String>
>> >>> )metadataResolver.getProjectVersions( repoId , namespace + "." +
>> gruopId ,
>> >>> artifact );
>> >>>                     Artifact artifactWithDetails = new Artifact();
>> >>>
>> >>>                     for (String version : artifactsVersionsList)
>> >>>                     {
>> >>>                         //assign gathered attributes Artifact object
>> and
>> >>> add it in to the list
>> >>>                         artifactWithDetails.setVersion(version);
>> >>>                         artifactWithDetails.setArtifactId(artifact);
>> >>>                         artifactWithDetails.setGroupId(gruopId);
>> >>>                         artifactWithDetails.setRepositoryId(repoId);
>> >>>
>> >>> artifactsListWithDetails.add(artifactWithDetails);
>> >>>
>> >>>                     }
>> >>>                 }
>> >>>             }
>> >>>         }
>> >>>
>> >>>
>> >>>     }
>> >>> }
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> P.A.Eshan Sudharaka
>> >>> Dept of Computer Science and Engineering
>> >>> University of Moratuwa
>> >>> Sri Lanka
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> P.A.Eshan Sudharaka
>> >> Dept of Computer Science and Engineering
>> >> University of Moratuwa
>> >> Sri Lanka
>> >>
>> >
>> >
>> >
>> > --
>> > P.A.Eshan Sudharaka
>> > Dept of Computer Science and Engineering
>> > University of Moratuwa
>> > Sri Lanka
>> >
>>
>
>
>
> --
> P.A.Eshan Sudharaka
> Dept of Computer Science and Engineering
> University of Moratuwa
> Sri Lanka
>



-- 
P.A.Eshan Sudharaka
Dept of Computer Science and Engineering
University of Moratuwa
Sri Lanka

Reply via email to