View Javadoc
1   package org.apache.maven.project;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.ByteArrayInputStream;
23  import java.io.InputStream;
24  import java.io.UnsupportedEncodingException;
25  import java.util.Arrays;
26  
27  import junit.framework.TestCase;
28  
29  /**
30   * Tests {@link ExtensionDescriptorBuilder}.
31   *
32   * @author Benjamin Bentmann
33   */
34  public class ExtensionDescriptorBuilderTest
35      extends TestCase
36  {
37  
38      private ExtensionDescriptorBuilder builder;
39  
40      @Override
41      protected void setUp()
42          throws Exception
43      {
44          super.setUp();
45  
46          builder = new ExtensionDescriptorBuilder();
47      }
48  
49      @Override
50      protected void tearDown()
51          throws Exception
52      {
53          builder = null;
54  
55          super.tearDown();
56      }
57  
58      private InputStream toStream( String xml )
59      {
60          try
61          {
62              return new ByteArrayInputStream( xml.getBytes( "UTF-8" ) );
63          }
64          catch ( UnsupportedEncodingException e )
65          {
66              throw new IllegalStateException( e );
67          }
68      }
69  
70      public void testEmptyDescriptor()
71          throws Exception
72      {
73          String xml = "<extension></extension>";
74  
75          ExtensionDescriptor ed = builder.build( toStream( xml ) );
76  
77          assertNotNull( ed );
78          assertNotNull( ed.getExportedPackages() );
79          assertTrue( ed.getExportedPackages().isEmpty() );
80          assertNotNull( ed.getExportedArtifacts() );
81          assertTrue( ed.getExportedArtifacts().isEmpty() );
82      }
83  
84      public void testCompleteDescriptor()
85          throws Exception
86      {
87          String xml =
88              "<?xml version='1.0' encoding='UTF-8'?>" + "<extension>" + "<exportedPackages>"
89                  + "<exportedPackage>a</exportedPackage>" + "<exportedPackage>b</exportedPackage>"
90                  + "<exportedPackage>c</exportedPackage>" + "</exportedPackages>" + "<exportedArtifacts>"
91                  + "<exportedArtifact>x</exportedArtifact>" + "<exportedArtifact>y</exportedArtifact>"
92                  + "<exportedArtifact> z </exportedArtifact>" + "</exportedArtifacts>" + "</extension>";
93  
94          ExtensionDescriptor ed = builder.build( toStream( xml ) );
95  
96          assertNotNull( ed );
97          assertEquals( Arrays.asList( "a", "b", "c" ), ed.getExportedPackages() );
98          assertEquals( Arrays.asList( "x", "y", "z" ), ed.getExportedArtifacts() );
99      }
100 
101 }