1 package org.apache.maven.model.converter; 2 3 18 19 import junit.framework.Assert; 20 import org.apache.maven.model.Build; 21 import org.apache.maven.model.Dependency; 22 import org.apache.maven.model.Model; 23 import org.apache.maven.model.Plugin; 24 import org.apache.maven.model.Resource; 25 import org.codehaus.plexus.PlexusTestCase; 26 27 import java.util.Arrays ; 28 29 public class PomV3ToV4TranslatorTest 30 extends PlexusTestCase 31 { 32 33 private ModelConverter translator; 34 35 private org.apache.maven.model.v3_0_0.Dependency v3Dep; 36 37 private org.apache.maven.model.v3_0_0.Model v3Model; 38 39 protected void setUp() 40 throws Exception 41 { 42 super.setUp(); 43 translator = (ModelConverter) lookup( ModelConverter.ROLE ); 44 45 v3Dep = new org.apache.maven.model.v3_0_0.Dependency(); 46 v3Dep.setGroupId( "testGroup" ); 47 v3Dep.setArtifactId( "testArtifact" ); 48 v3Dep.setVersion( "1.0" ); 49 50 v3Model = new org.apache.maven.model.v3_0_0.Model(); 51 v3Model.setBuild( new org.apache.maven.model.v3_0_0.Build() ); 52 } 53 54 public void testConvertedEmptyResourceDirectory() 55 throws PomTranslationException 56 { 57 org.apache.maven.model.v3_0_0.Resource v3Resource = new org.apache.maven.model.v3_0_0.Resource(); 58 v3Resource.setIncludes( Arrays.asList( new String []{"**/*.properties"} ) ); 59 v3Model.getBuild().addResource( v3Resource ); 60 61 Model result = translator.translate( v3Model ); 62 Resource resource = (Resource) result.getBuild().getResources().get( 0 ); 63 Assert.assertEquals( "check directory of v3Resource", ".", resource.getDirectory() ); 64 } 65 66 public void testShouldConvertScopePropertyToDependencyScope() 67 throws Exception 68 { 69 v3Dep.addProperty( "scope", "test" ); 70 71 v3Model.addDependency( v3Dep ); 72 73 Model result = translator.translate( v3Model ); 74 Assert.assertEquals( "test", ( (Dependency) result.getDependencies().get( 0 ) ).getScope() ); 75 76 } 77 78 public void testShouldConvertOptionalPropertyToDependencyOptional() 79 throws Exception 80 { 81 v3Dep.addProperty( "optional", "true" ); 82 83 v3Model.addDependency( v3Dep ); 84 85 Model result = translator.translate( v3Model ); 86 Assert.assertTrue( ( (Dependency) result.getDependencies().get( 0 ) ).isOptional() ); 87 88 v3Dep.addProperty( "optional", "TRUE" ); 89 90 v3Model.addDependency( v3Dep ); 91 92 result = translator.translate( v3Model ); 93 Assert.assertTrue( ( (Dependency) result.getDependencies().get( 0 ) ).isOptional() ); 94 } 95 96 public void testDontBreakWithMalformedOptionalProperty() 97 throws Exception 98 { 99 v3Dep.addProperty( "optional", "xxx" ); 100 101 v3Model.addDependency( v3Dep ); 102 103 Model result = translator.translate( v3Model ); 104 Assert.assertFalse( ( (Dependency) result.getDependencies().get( 0 ) ).isOptional() ); 105 106 v3Dep.addProperty( "optional", "" ); 107 108 v3Model.addDependency( v3Dep ); 109 110 result = translator.translate( v3Model ); 111 Assert.assertFalse( ( (Dependency) result.getDependencies().get( 0 ) ).isOptional() ); 112 } 113 114 public void testShouldConvertDependencyWithTypePluginToBuildPluginEntry() 115 throws Exception 116 { 117 v3Dep.setType( "plugin" ); 118 119 v3Model.addDependency( v3Dep ); 120 121 Model result = translator.translate( v3Model ); 122 123 Build build = result.getBuild(); 124 125 Plugin plugin = (Plugin) build.getPlugins().get( 0 ); 126 127 Assert.assertEquals( "testGroup", plugin.getGroupId() ); 128 Assert.assertEquals( "testArtifact", plugin.getArtifactId() ); 129 Assert.assertEquals( "1.0", plugin.getVersion() ); 130 131 Assert.assertEquals( "check no dependencies", 0, result.getDependencies().size() ); 132 } 133 134 public void testShouldConvertDependencyWithTypePluginAndGroupMavenToBuildPluginEntryWithOAMPluginsGroup() 135 throws Exception 136 { 137 v3Dep.setGroupId( "maven" ); 138 v3Dep.setType( "plugin" ); 139 140 v3Model.addDependency( v3Dep ); 141 142 Model result = translator.translate( v3Model ); 143 144 Build build = result.getBuild(); 145 146 Plugin plugin = (Plugin) build.getPlugins().get( 0 ); 147 148 Assert.assertEquals( "org.apache.maven.plugins", plugin.getGroupId() ); 149 Assert.assertEquals( "testArtifact", plugin.getArtifactId() ); 150 Assert.assertEquals( "1.0", plugin.getVersion() ); 151 152 Assert.assertEquals( "check no dependencies", 0, result.getDependencies().size() ); 153 } 154 155 } 156 | Popular Tags |