001: package org.apache.maven.embedder.validation;
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 org.apache.maven.embedder.Configuration;
023: import org.apache.maven.embedder.ConfigurationValidationResult;
024: import org.apache.maven.embedder.DefaultConfiguration;
025: import org.apache.maven.embedder.MavenEmbedder;
026: import org.codehaus.plexus.PlexusTestCase;
027: import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
028:
029: import java.io.File;
030:
031: /** @author Jason van Zyl */
032: public class ValidateConfigurationTest extends PlexusTestCase {
033: public void testConfigurationOnlyUserSettingsAreActiveAndItIsValid() {
034: File user = new File(getBasedir(),
035: "src/test/resources/settings/valid-settings.xml");
036:
037: Configuration configuration = new DefaultConfiguration()
038: .setUserSettingsFile(user);
039:
040: ConfigurationValidationResult result = MavenEmbedder
041: .validateConfiguration(configuration);
042:
043: assertTrue(result.isUserSettingsFilePresent());
044: assertTrue(result.isUserSettingsFileParses());
045: assertNotNull(result.getUserSettings());
046: assertNull(result.getUserSettingsException());
047: assertNull(result.getGlobalSettings());
048: assertNull(result.getGlobalSettingsException());
049: }
050:
051: public void testConfigurationOnlyUserSettingsAreActiveAndItIsInvalid() {
052: File user = new File(getBasedir(),
053: "src/test/resources/settings/invalid-settings.xml");
054:
055: Configuration configuration = new DefaultConfiguration()
056: .setUserSettingsFile(user);
057:
058: ConfigurationValidationResult result = MavenEmbedder
059: .validateConfiguration(configuration);
060:
061: assertTrue(result.isUserSettingsFilePresent());
062: assertFalse(result.isUserSettingsFileParses());
063: assertNull(result.getUserSettings());
064: assertNotNull(result.getUserSettingsException());
065: assertTrue(result.getUserSettingsException() instanceof XmlPullParserException);
066: assertNull(result.getGlobalSettings());
067: assertNull(result.getGlobalSettingsException());
068: }
069:
070: public void testConfigurationOnlyGlobalSettingsAreActiveAndItIsValid() {
071: File global = new File(getBasedir(),
072: "src/test/resources/settings/valid-settings.xml");
073:
074: Configuration configuration = new DefaultConfiguration()
075: .setGlobalSettingsFile(global);
076:
077: ConfigurationValidationResult result = MavenEmbedder
078: .validateConfiguration(configuration);
079:
080: assertTrue(result.isGlobalSettingsFilePresent());
081: assertTrue(result.isGlobalSettingsFileParses());
082: assertNotNull(result.getGlobalSettings());
083: assertNull(result.getGlobalSettingsException());
084: assertNull(result.getUserSettings());
085: assertNull(result.getUserSettingsException());
086: }
087:
088: public void testConfigurationOnlyGlobalSettingsAreActiveAndItIsInvalid() {
089: File global = new File(getBasedir(),
090: "src/test/resources/settings/invalid-settings.xml");
091:
092: Configuration configuration = new DefaultConfiguration()
093: .setGlobalSettingsFile(global);
094:
095: ConfigurationValidationResult result = MavenEmbedder
096: .validateConfiguration(configuration);
097:
098: assertTrue(result.isGlobalSettingsFilePresent());
099: assertFalse(result.isGlobalSettingsFileParses());
100: assertNull(result.getGlobalSettings());
101: assertNotNull(result.getGlobalSettingsException());
102: assertTrue(result.getGlobalSettingsException() instanceof XmlPullParserException);
103: assertNull(result.getUserSettings());
104: assertNull(result.getUserSettingsException());
105: }
106: }
|