package org.apache.maven.embedder;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import org.codehaus.plexus.PlexusTestCase;

import java.io.File;

/** @author Jason van Zyl */
public class ValidateConfigurationTest
    extends PlexusTestCase
{
    public void testConfigurationOnlyUserSettingsAreActiveAndItIsValid()
    {
        File user = new File( getBasedir(), "src/test/resources/settings/valid-settings.xml" );

        Configuration configuration = new DefaultConfiguration()
            .setUserSettingsFile( user );

        ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );

        assertTrue( result.isUserSettingsFilePresent() );

        assertTrue( result.isUserSettingsFileParses() );
    }

    public void testConfigurationOnlyUserSettingsAreActiveAndItIsInvalid()
    {
        File user = new File( getBasedir(), "src/test/resources/settings/invalid-settings.xml" );

        Configuration configuration = new DefaultConfiguration()
            .setUserSettingsFile( user );

        ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );

        assertTrue( result.isUserSettingsFilePresent() );

        assertFalse( result.isUserSettingsFileParses() );
    }

    public void testConfigurationOnlyGlobalSettingsAreActiveAndItIsValid()
    {
        File global = new File( getBasedir(), "src/test/resources/settings/valid-settings.xml" );

        Configuration configuration = new DefaultConfiguration()
            .setGlobalSettingsFile( global );

        ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );

        assertTrue( result.isGlobalSettingsFilePresent() );

        assertTrue( result.isGlobalSettingsFileParses() );
    }

    public void testConfigurationOnlyGlobalSettingsAreActiveAndItIsInvalid()
    {
        File global = new File( getBasedir(), "src/test/resources/settings/invalid-settings.xml" );

        Configuration configuration = new DefaultConfiguration()
            .setGlobalSettingsFile( global );

        ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );

        assertTrue( result.isGlobalSettingsFilePresent() );

        assertFalse( result.isGlobalSettingsFileParses() );
    }
}

@@ -879,16 +879,81 @@
 estCase;
+%0Aimport org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 %0A%0Aimport
@@ -1501,33 +1501,32 @@
 ilePresent() );%0A
-%0A
         assertTr
@@ -1558,32 +1558,249 @@
 FileParses() );%0A
+        assertNotNull( result.getUserSettings() );%0A        assertNull( result.getUserSettingsException() );%0A        assertNull( result.getGlobalSettings() );%0A        assertNull( result.getGlobalSettingsException() );%0A
     %7D%0A%0A    publi
@@ -2230,33 +2230,32 @@
 ilePresent() );%0A
-%0A
         assertFa
@@ -2288,32 +2288,340 @@
 FileParses() );%0A
+        assertNull( result.getUserSettings() );%0A        assertNotNull( result.getUserSettingsException() );%0A        assertTrue( result.getUserSettingsException() instanceof XmlPullParserException );%0A        assertNull( result.getGlobalSettings() );%0A        assertNull( result.getGlobalSettingsException() );%0A
     %7D%0A%0A    publi
@@ -3057,33 +3057,32 @@
 ilePresent() );%0A
-%0A
         assertTr
@@ -3120,24 +3120,241 @@
 Parses() );%0A
+        assertNotNull( result.getGlobalSettings() );%0A        assertNull( result.getGlobalSettingsException() );%0A        assertNull( result.getUserSettings() );%0A        assertNull( result.getUserSettingsException() );%0A
     %7D%0A%0A    p
@@ -3802,25 +3802,24 @@
 resent() );%0A
-%0A
         asse
@@ -3862,20 +3862,330 @@
 Parses() );%0A
+        assertNull( result.getGlobalSettings() );%0A        assertNotNull( result.getGlobalSettingsException() );%0A        assertTrue( result.getGlobalSettingsException() instanceof XmlPullParserException );%0A        assertNull( result.getUserSettings() );%0A        assertNull( result.getUserSettingsException() );%0A
     %7D%0A%7D%0A

Add tests for new methods