View Javadoc

1   /*
2    * Copyright 2012 Codehaus.
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 org.codehaus.mojo.nbm;
17  
18  import java.io.File;
19  import java.io.PrintWriter;
20  import java.io.StringWriter;
21  import java.util.Collections;
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.factory.ArtifactFactory;
24  import org.apache.maven.artifact.repository.DefaultArtifactRepository;
25  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
26  import org.apache.maven.artifact.resolver.ArtifactResolver;
27  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
28  
29  public class CreateNetBeansFileStructureTest
30          extends AbstractMojoTestCase
31  {
32  
33      public void testWriteExternal()
34              throws Exception
35      {
36          String localRepository = System.getProperty( "localRepository" );
37          ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.class.getName() );
38          ArtifactResolver artifactResolver = (ArtifactResolver) lookup( ArtifactResolver.class.getName() );
39          Artifact a = artifactFactory.createBuildArtifact( "asm", "asm", "3.0", "jar" );
40          artifactResolver.resolve( a, Collections.emptyList(), new DefaultArtifactRepository( "local", new File(localRepository).toURI().toString(), new DefaultRepositoryLayout() ) );
41          StringWriter w = new StringWriter();
42          CreateNetBeansFileStructure.writeExternal( new PrintWriter( w ), a );
43          assertEquals( "CRC:229904029\nSIZE:42710\nURL:m2:/asm:asm:3.0:jar\nURL:http://repo.maven.apache.org/maven2/asm/asm/3.0/asm-3.0.jar\n", w.toString() );
44      }
45  
46  }