001package org.apache.maven.plugins.enforcer; 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 org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; 023import org.apache.maven.plugin.testing.ArtifactStubFactory; 024import org.apache.maven.plugins.enforcer.utils.EnforcerRuleUtilsHelper; 025import org.apache.maven.project.MavenProject; 026import org.junit.Before; 027import org.junit.Test; 028 029import java.io.IOException; 030 031/** 032 * Test class for the RequireSnapshotVersion rule. 033 */ 034public class TestRequireSnapshotVersion 035{ 036 037 private MavenProject project; 038 039 private EnforcerRuleHelper helper; 040 041 private ArtifactStubFactory factory; 042 043 private RequireSnapshotVersion rule; 044 045 @Before 046 public void before() 047 { 048 project = new MockProject(); 049 helper = EnforcerTestUtils.getHelper( project ); 050 factory = new ArtifactStubFactory(); 051 rule = new RequireSnapshotVersion(); 052 } 053 054 @Test 055 public void testRequireSnapshot() 056 throws IOException 057 { 058 project.setArtifact( factory.getReleaseArtifact() ); 059 EnforcerRuleUtilsHelper.execute( rule, helper, true ); 060 061 project.setArtifact( factory.getSnapshotArtifact() ); 062 EnforcerRuleUtilsHelper.execute( rule, helper, false ); 063 } 064 065 @Test 066 public void testWithParentShouldFail() 067 throws IOException 068 { 069 project.setArtifact( factory.getSnapshotArtifact() ); 070 rule.setFailWhenParentIsRelease( true ); 071 072 MockProject parent = new MockProject(); 073 parent.setArtifact( factory.getReleaseArtifact() ); 074 project.setParent( parent ); 075 EnforcerRuleUtilsHelper.execute( rule, helper, true ); 076 077 parent = new MockProject(); 078 parent.setArtifact( factory.getSnapshotArtifact() ); 079 project.setParent( parent ); 080 EnforcerRuleUtilsHelper.execute( rule, helper, false ); 081 } 082 083 @Test 084 public void testWithParentShouldPass() 085 throws IOException 086 { 087 project.setArtifact( factory.getSnapshotArtifact() ); 088 rule.setFailWhenParentIsRelease( false ); 089 090 MockProject parent = new MockProject(); 091 parent.setArtifact( factory.getReleaseArtifact() ); 092 project.setParent( parent ); 093 EnforcerRuleUtilsHelper.execute( rule, helper, false ); 094 095 parent = new MockProject(); 096 parent.setArtifact( factory.getSnapshotArtifact() ); 097 project.setParent( parent ); 098 EnforcerRuleUtilsHelper.execute( rule, helper, false ); 099 } 100 101}