<commit_before>package org.apache.maven.continuum;

import java.io.File;

import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
import org.apache.maven.continuum.model.project.BuildDefinition;
import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
import org.apache.maven.continuum.model.project.Project;
import org.apache.maven.continuum.model.project.ProjectGroup;
import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * 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.
 */
/**
 * @author olamy
 * @since 
 * @version $Id$
 */
public class AddMaven2ProjectTest
    extends AbstractContinuumTest
{
    protected Logger log = LoggerFactory.getLogger( getClass() );

    protected BuildDefinitionTemplate bdt;

    protected BuildDefinition bd;
    
    @Override
    protected void setUp()
        throws Exception
    {
        super.setUp();
        bd = new BuildDefinition();
        bd.setGoals( "clean deploy" );
        bd.setBuildFile( "pom.xml" );
        bd.setDescription( "my foo" );
        bd.setTemplate( true );
        BuildDefinitionService bds = (BuildDefinitionService) lookup( BuildDefinitionService.class.getName(), "default" );
        bd = bds.addBuildDefinition( bd );
        
        
        assertEquals( 5, bds.getAllBuildDefinitions().size() );

        bdt = new BuildDefinitionTemplate();
        bdt.setName( "bdt foo" );
        
        bdt = bds.addBuildDefinitionTemplate( bdt );
        
        bdt = bds.addBuildDefinitionInTemplate( bdt, bd, false );        
    }    
    
    
    
    public void testAddProjectWithBuildDefTemplateToExistingGroup()
        throws Exception
    {

        ProjectGroup pg = new ProjectGroup();
        pg.setName( "foo" );
        pg.setDescription( "foo pg" );
        getContinuum().addProjectGroup( pg );
        pg = getContinuum().getAllProjectGroups().get( 1 );
        assertEquals( 2, getContinuum().getAllProjectGroups().size() );

        File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );

        assertTrue( rootPom.exists() );
        //String url = getTestFile( "src/test-projects/project1/pom.xml" ).toURL().toExternalForm();
        ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
                                                                                   rootPom.toURI().toURL()
                                                                                       .toExternalForm(), pg.getId(),
                                                                                   true, false, false, bdt.getId() );
        assertNotNull( result );

        assertEquals( 1, result.getProjects().size() );

        Project project = result.getProjects().get( 0 );
        project = getContinuum().getProjectWithBuildDetails( project.getId() );
        assertNotNull( project );
        pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );
        log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
        assertEquals( 1, project.getBuildDefinitions().size() );
        assertEquals( "clean deploy", ( (BuildDefinition) project.getBuildDefinitions().get( 0 ) ).getGoals() );
    }
    
    public void testAddProjectWithBuildDefTemplateWithGroupCreation()
        throws Exception
    {

        //bdt = bds.addBuildDefinitionInTemplate( bdt, bd, true );
        File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );

        assertTrue( rootPom.exists() );

        ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
                                                                                   rootPom.toURI().toURL()
                                                                                       .toExternalForm(), -1, true,
                                                                                   false, true, bdt.getId() );
        assertNotNull( result );

        assertEquals( 1, result.getProjects().size() );

        Project project = result.getProjects().get( 0 );
        assertNotNull( project );
        log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
        log.info( "all pg size " + getContinuum().getAllProjectGroups().size() );
        ProjectGroup pg = result.getProjectGroups().get( 0 );

        pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );

        log.info( " pg groupId " + pg.getGroupId() );
        //@ group level the db from template must be used
        log.info( " mg builddefs size " + pg.getBuildDefinitions().size() );
        log.info( "pg bd goals " + ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
        assertEquals( "clean deploy", ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
        
    }    
    
    public void testAddProjectWithGroupCreationDefaultBuildDef()
        throws Exception
    {

        //bdt = bds.addBuildDefinitionInTemplate( bdt, bd, true );
        File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );

        assertTrue( rootPom.exists() );

        ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
                                                                                   rootPom.toURI().toURL()
                                                                                       .toExternalForm(), -1, true,
                                                                                   false, true, -1 );
        assertNotNull( result );

        assertEquals( 1, result.getProjects().size() );

        Project project = result.getProjects().get( 0 );
        assertNotNull( project );
        log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
        log.info( "all pg size " + getContinuum().getAllProjectGroups().size() );
        ProjectGroup pg = result.getProjectGroups().get( 0 );

        log.info( getContinuum().getAllProjectGroups().toString() );
        log.info( " pg id " + Integer.toString( pg.getId() ) );

        pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );

        log.info( " pg groupId " + pg.getGroupId() );
        //@ group level the db from template must be used
        log.info( " mg builddefs size " + pg.getBuildDefinitions().size() );
        log.info( "pg bd goals " + ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
        assertEquals( "clean install", ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );

    }       


    public void testAddProjectToExistingGroupDefaultBuildDef()
        throws Exception<commit_msg> merge -r 726461:726462 from 1.2.x branch [CONTINUUM-1953] add comment in the unit test<commit_after>package org.apache.maven.continuum;

import java.io.File;

import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
import org.apache.maven.continuum.model.project.BuildDefinition;
import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
import org.apache.maven.continuum.model.project.Project;
import org.apache.maven.continuum.model.project.ProjectGroup;
import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * 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.
 */
/**
 * @author olamy
 * @since 
 * @version $Id$
 */
public class AddMaven2ProjectTest
    extends AbstractContinuumTest
{
    protected Logger log = LoggerFactory.getLogger( getClass() );

    protected BuildDefinitionTemplate bdt;

    protected BuildDefinition bd;
    
    @Override
    protected void setUp()
        throws Exception
    {
        super.setUp();
        bd = new BuildDefinition();
        bd.setGoals( "clean deploy" );
        bd.setBuildFile( "pom.xml" );
        bd.setDescription( "my foo" );
        bd.setTemplate( true );
        BuildDefinitionService bds = (BuildDefinitionService) lookup( BuildDefinitionService.class.getName(), "default" );
        bd = bds.addBuildDefinition( bd );
        
        
        assertEquals( 5, bds.getAllBuildDefinitions().size() );

        bdt = new BuildDefinitionTemplate();
        bdt.setName( "bdt foo" );
        
        bdt = bds.addBuildDefinitionTemplate( bdt );
        
        bdt = bds.addBuildDefinitionInTemplate( bdt, bd, false );        
    }    
    
    
    
    public void testAddProjectToExistingGroupWithBuildDefTemplate()
        throws Exception
    {

        ProjectGroup pg = new ProjectGroup();
        pg.setName( "foo" );
        pg.setDescription( "foo pg" );
        getContinuum().addProjectGroup( pg );
        pg = getContinuum().getAllProjectGroups().get( 1 );
        assertEquals( 2, getContinuum().getAllProjectGroups().size() );
        pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );
        // group created with the m2 default build def 
        assertEquals( 1, pg.getBuildDefinitions().size() );
        

        File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );

        assertTrue( rootPom.exists() );
        //String url = getTestFile( "src/test-projects/project1/pom.xml" ).toURL().toExternalForm();
        ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
                                                                                   rootPom.toURI().toURL()
                                                                                       .toExternalForm(), pg.getId(),
                                                                                   true, false, false, bdt.getId() );
        assertNotNull( result );

        assertEquals( 1, result.getProjects().size() );

        Project project = result.getProjects().get( 0 );
        project = getContinuum().getProjectWithBuildDetails( project.getId() );
        assertNotNull( project );
        pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );
        log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
        // project with the build def coming from template
        assertEquals( 1, project.getBuildDefinitions().size() );
        assertEquals( "clean deploy", ( (BuildDefinition) project.getBuildDefinitions().get( 0 ) ).getGoals() );
    }
    
    public void testAddProjectWithGroupCreationWithBuildDefTemplate()
        throws Exception
    {

        //bdt = bds.addBuildDefinitionInTemplate( bdt, bd, true );
        File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );

        assertTrue( rootPom.exists() );

        ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
                                                                                   rootPom.toURI().toURL()
                                                                                       .toExternalForm(), -1, true,
                                                                                   false, true, bdt.getId() );
        assertNotNull( result );

        assertEquals( 1, result.getProjects().size() );
        Project project = result.getProjects().get( 0 );
        assertNotNull( project );
        project = getContinuum().getProjectWithBuildDetails( project.getId() );
        log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
        // build def only at the group level du to group creation 
        assertEquals( 0, project.getBuildDefinitions().size() );
        
        log.info( "all pg size " + getContinuum().getAllProjectGroups().size() );
        ProjectGroup pg = result.getProjectGroups().get( 0 );

        pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );

        log.info( " pg groupId " + pg.getGroupId() );
        //@ group level the db from template must be used
        log.info( " pg builddefs size " + pg.getBuildDefinitions().size() );
        log.info( "pg bd goals " + ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
        assertEquals( "clean deploy", ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
        
    }    
    
    public void testAddProjectWithGroupCreationDefaultBuildDef()
        throws Exception
    {

        //bdt = bds.addBuildDefinitionInTemplate( bdt, bd, true );
        File rootPom = getTestFile( "src/test/resources/projects/continuum/continuum-core/pom.xml" );

        assertTrue( rootPom.exists() );

        ContinuumProjectBuildingResult result = getContinuum().addMavenTwoProject(
                                                                                   rootPom.toURI().toURL()
                                                                                       .toExternalForm(), -1, true,
                                                                                   false, true, -1 );
        assertNotNull( result );

        assertEquals( 1, result.getProjects().size() );

        Project project = result.getProjects().get( 0 );
        assertNotNull( project );
        
        assertNotNull( project );
        project = getContinuum().getProjectWithBuildDetails( project.getId() );
        log.info( "project buildDef list size : " + project.getBuildDefinitions().size() );
        // only build def at group level
        assertEquals( 0, project.getBuildDefinitions().size() );
        
        log.info( "all pg size " + getContinuum().getAllProjectGroups().size() );
        ProjectGroup pg = result.getProjectGroups().get( 0 );

        log.info( getContinuum().getAllProjectGroups().toString() );
        log.info( " pg id " + Integer.toString( pg.getId() ) );

        pg = getContinuum().getProjectGroupWithBuildDetails( pg.getId() );

        log.info( " pg groupId " + pg.getGroupId() );
        //@ group level the db from template must be used
        log.info( " mg builddefs size " + pg.getBuildDefinitions().size() );
        log.info( "pg bd goals " + ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );
        assertEquals( "clean install", ( (BuildDefinition) pg.getBuildDefinitions().get( 0 ) ).getGoals() );

    }       

    public void testAddProjectToExistingGroupDefaultBuildDef()
        throws Exception
{'fraction_non_alphanumeric': 0.10846991117227574, 'fraction_numerical': 0.0048792693606906044, 'mean_word_length': 2.1538765042414676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 60, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4943665', 'n_tokens_mistral': 4116, 'n_tokens_neox': 3977, 'n_words': 991}