001package org.apache.maven.settings; 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 022import junit.framework.TestCase; 023 024import java.util.ArrayList; 025import java.util.List; 026import java.util.Properties; 027import java.util.Random; 028 029public class SettingsUtilsTest 030 extends TestCase 031{ 032 033 public void testShouldAppendRecessivePluginGroupIds() 034 { 035 Settings dominant = new Settings(); 036 dominant.addPluginGroup( "org.apache.maven.plugins" ); 037 dominant.addPluginGroup( "org.codehaus.modello" ); 038 039 Settings recessive = new Settings(); 040 recessive.addPluginGroup( "org.codehaus.plexus" ); 041 042 SettingsUtils.merge( dominant, recessive, Settings.GLOBAL_LEVEL ); 043 044 List<String> pluginGroups = dominant.getPluginGroups(); 045 046 assertNotNull( pluginGroups ); 047 assertEquals( 3, pluginGroups.size() ); 048 assertEquals( "org.apache.maven.plugins", pluginGroups.get( 0 ) ); 049 assertEquals( "org.codehaus.modello", pluginGroups.get( 1 ) ); 050 assertEquals( "org.codehaus.plexus", pluginGroups.get( 2 ) ); 051 } 052 053 public void testRoundTripProfiles() 054 { 055 Random entropy = new Random(); 056 Profile p = new Profile(); 057 p.setId( "id" + Long.toHexString( entropy.nextLong() ) ); 058 Activation a = new Activation(); 059 a.setActiveByDefault( entropy.nextBoolean() ); 060 a.setJdk( "jdk" + Long.toHexString( entropy.nextLong() ) ); 061 ActivationFile af = new ActivationFile(); 062 af.setExists( "exists" + Long.toHexString( entropy.nextLong() ) ); 063 af.setMissing( "missing" + Long.toHexString( entropy.nextLong() ) ); 064 a.setFile( af ); 065 ActivationProperty ap = new ActivationProperty(); 066 ap.setName( "name" + Long.toHexString( entropy.nextLong() ) ); 067 ap.setValue( "value" + Long.toHexString( entropy.nextLong() ) ); 068 a.setProperty( ap ); 069 ActivationOS ao = new ActivationOS(); 070 ao.setArch( "arch" + Long.toHexString( entropy.nextLong() ) ); 071 ao.setFamily( "family" + Long.toHexString( entropy.nextLong() ) ); 072 ao.setName( "name" + Long.toHexString( entropy.nextLong() ) ); 073 ao.setVersion( "version" + Long.toHexString( entropy.nextLong() ) ); 074 a.setOs( ao ); 075 p.setActivation( a ); 076 Properties props = new Properties(); 077 int count = entropy.nextInt( 10 ); 078 for ( int i = 0; i < count; i++ ) 079 { 080 props.setProperty( "name" + Long.toHexString( entropy.nextLong() ), 081 "value" + Long.toHexString( entropy.nextLong() ) ); 082 } 083 p.setProperties( props ); 084 count = entropy.nextInt( 3 ); 085 List<Repository> repos = new ArrayList<Repository>(); 086 for ( int i = 0; i < count; i++ ) 087 { 088 Repository r = new Repository(); 089 r.setId( "id" + Long.toHexString( entropy.nextLong() ) ); 090 r.setName( "name" + Long.toHexString( entropy.nextLong() ) ); 091 r.setUrl( "url" + Long.toHexString( entropy.nextLong() ) ); 092 repos.add( r ); 093 } 094 p.setRepositories( repos ); 095 count = entropy.nextInt( 3 ); 096 repos = new ArrayList<Repository>(); 097 for ( int i = 0; i < count; i++ ) 098 { 099 Repository r = new Repository(); 100 r.setId( "id" + Long.toHexString( entropy.nextLong() ) ); 101 r.setName( "name" + Long.toHexString( entropy.nextLong() ) ); 102 r.setUrl( "url" + Long.toHexString( entropy.nextLong() ) ); 103 repos.add( r ); 104 } 105 p.setPluginRepositories( repos ); 106 107 Profile clone = SettingsUtils.convertToSettingsProfile( SettingsUtils.convertFromSettingsProfile( p ) ); 108 109 assertEquals( p.getId(), clone.getId() ); 110 assertEquals( p.getActivation().getJdk(), clone.getActivation().getJdk() ); 111 assertEquals( p.getActivation().getFile().getExists(), clone.getActivation().getFile().getExists() ); 112 assertEquals( p.getActivation().getFile().getMissing(), clone.getActivation().getFile().getMissing() ); 113 assertEquals( p.getActivation().getProperty().getName(), clone.getActivation().getProperty().getName() ); 114 assertEquals( p.getActivation().getProperty().getValue(), clone.getActivation().getProperty().getValue() ); 115 assertEquals( p.getActivation().getOs().getArch(), clone.getActivation().getOs().getArch() ); 116 assertEquals( p.getActivation().getOs().getFamily(), clone.getActivation().getOs().getFamily() ); 117 assertEquals( p.getActivation().getOs().getName(), clone.getActivation().getOs().getName() ); 118 assertEquals( p.getActivation().getOs().getVersion(), clone.getActivation().getOs().getVersion() ); 119 assertEquals( p.getProperties(), clone.getProperties() ); 120 assertEquals( p.getRepositories().size(), clone.getRepositories().size() ); 121 // TODO deep compare the lists 122 assertEquals( p.getPluginRepositories().size(), clone.getPluginRepositories().size() ); 123 // TODO deep compare the lists 124 } 125 126}