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 static org.hamcrest.Matchers.empty;
23  import static org.hamcrest.Matchers.is;
24  import static org.junit.Assert.assertThat;
25  
26  import java.io.ByteArrayInputStream;
27  import java.io.InputStream;
28  import java.nio.charset.StandardCharsets;
29  import java.util.Arrays;
30  
31  import junit.framework.TestCase;
32  
33  /**
34   * Tests {@link ExtensionDescriptorBuilder}.
35   *
36   * @author Benjamin Bentmann
37   */
38  public class ExtensionDescriptorBuilderTest
39      extends TestCase
40  {
41  
42      private ExtensionDescriptorBuilder builder;
43  
44      @Override
45      protected void setUp()
46          throws Exception
47      {
48          super.setUp();
49  
50          builder = new ExtensionDescriptorBuilder();
51      }
52  
53      @Override
54      protected void tearDown()
55          throws Exception
56      {
57          builder = null;
58  
59          super.tearDown();
60      }
61  
62      private InputStream toStream( String xml )
63      {
64          return new ByteArrayInputStream( xml.getBytes( StandardCharsets.UTF_8 ) );
65      }
66  
67      public void testEmptyDescriptor()
68          throws Exception
69      {
70          String xml = "<extension></extension>";
71  
72          ExtensionDescriptor ed = builder.build( toStream( xml ) );
73  
74          assertNotNull( ed );
75          assertNotNull( ed.getExportedPackages() );
76          assertThat( ed.getExportedPackages(), is( empty() ) );
77          assertNotNull( ed.getExportedArtifacts() );
78          assertThat( ed.getExportedArtifacts(), is( empty() ) );
79      }
80  
81      public void testCompleteDescriptor()
82          throws Exception
83      {
84          String xml =
85              "<?xml version='1.0' encoding='UTF-8'?>" + "<extension>" + "<exportedPackages>"
86                  + "<exportedPackage>a</exportedPackage>" + "<exportedPackage>b</exportedPackage>"
87                  + "<exportedPackage>c</exportedPackage>" + "</exportedPackages>" + "<exportedArtifacts>"
88                  + "<exportedArtifact>x</exportedArtifact>" + "<exportedArtifact>y</exportedArtifact>"
89                  + "<exportedArtifact> z </exportedArtifact>" + "</exportedArtifacts>" + "</extension>";
90  
91          ExtensionDescriptor ed = builder.build( toStream( xml ) );
92  
93          assertNotNull( ed );
94          assertEquals( Arrays.asList( "a", "b", "c" ), ed.getExportedPackages() );
95          assertEquals( Arrays.asList( "x", "y", "z" ), ed.getExportedArtifacts() );
96      }
97  
98  }