001 package org.apache.maven.project;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.io.ByteArrayInputStream;
023 import java.io.InputStream;
024 import java.io.UnsupportedEncodingException;
025 import java.util.Arrays;
026
027 import junit.framework.TestCase;
028
029 /**
030 * Tests {@link ExtensionDescriptorBuilder}.
031 *
032 * @author Benjamin Bentmann
033 */
034 public class ExtensionDescriptorBuilderTest
035 extends TestCase
036 {
037
038 private ExtensionDescriptorBuilder builder;
039
040 @Override
041 protected void setUp()
042 throws Exception
043 {
044 super.setUp();
045
046 builder = new ExtensionDescriptorBuilder();
047 }
048
049 @Override
050 protected void tearDown()
051 throws Exception
052 {
053 builder = null;
054
055 super.tearDown();
056 }
057
058 private InputStream toStream( String xml )
059 {
060 try
061 {
062 return new ByteArrayInputStream( xml.getBytes( "UTF-8" ) );
063 }
064 catch ( UnsupportedEncodingException e )
065 {
066 throw new IllegalStateException( e );
067 }
068 }
069
070 public void testEmptyDescriptor()
071 throws Exception
072 {
073 String xml = "<extension></extension>";
074
075 ExtensionDescriptor ed = builder.build( toStream( xml ) );
076
077 assertNotNull( ed );
078 assertNotNull( ed.getExportedPackages() );
079 assertTrue( ed.getExportedPackages().isEmpty() );
080 assertNotNull( ed.getExportedArtifacts() );
081 assertTrue( ed.getExportedArtifacts().isEmpty() );
082 }
083
084 public void testCompleteDescriptor()
085 throws Exception
086 {
087 String xml =
088 "<?xml version='1.0' encoding='UTF-8'?>" + "<extension>" + "<exportedPackages>"
089 + "<exportedPackage>a</exportedPackage>" + "<exportedPackage>b</exportedPackage>"
090 + "<exportedPackage>c</exportedPackage>" + "</exportedPackages>" + "<exportedArtifacts>"
091 + "<exportedArtifact>x</exportedArtifact>" + "<exportedArtifact>y</exportedArtifact>"
092 + "<exportedArtifact> z </exportedArtifact>" + "</exportedArtifacts>" + "</extension>";
093
094 ExtensionDescriptor ed = builder.build( toStream( xml ) );
095
096 assertNotNull( ed );
097 assertEquals( Arrays.asList( "a", "b", "c" ), ed.getExportedPackages() );
098 assertEquals( Arrays.asList( "x", "y", "z" ), ed.getExportedArtifacts() );
099 }
100
101 }