View Javadoc
1   package org.apache.maven.plugins.invoker;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.junit.Assert.assertEquals;
23  import java.util.Properties;
24  
25  import org.apache.maven.plugins.invoker.InvokerProperties;
26  import org.apache.maven.plugins.invoker.Selector;
27  import org.junit.Test;
28  
29  public class SelectorTest
30  {
31      @Test
32      public void testGlobalMatch()
33      {
34          Selector selector = new Selector( "3.2.5", "1.7", null );
35  
36          Properties props = new Properties();
37          props.setProperty( "invoker.maven.version", "3.0+" );
38          InvokerProperties invokerProperties = new InvokerProperties( props );
39          assertEquals( 0, selector.getSelection( invokerProperties ) );
40      }
41  
42      @Test
43      public void testSelectorMatch()
44      {
45          Selector selector = new Selector( "3.2.5", "1.7", null );
46  
47          Properties props = new Properties();
48          props.setProperty( "selector.1.maven.version", "3.0+" );
49          InvokerProperties invokerProperties = new InvokerProperties( props );
50          assertEquals( 0, selector.getSelection( invokerProperties ) );
51  
52          props.setProperty( "selector.1.maven.version", "3.3.1+" );
53          assertEquals( Selector.SELECTOR_MULTI, selector.getSelection( invokerProperties ) );
54      }
55  
56      @Test
57      public void testSelectorWithGlobalMatch()
58      {
59          Selector selector = new Selector( "3.2.5", "1.7", null );
60  
61          Properties props = new Properties();
62          // invoker.maven.version is used by all selectors
63          props.setProperty( "invoker.maven.version", "3.0+" );
64          props.setProperty( "selector.1.java.version", "1.4+" );
65          props.setProperty( "selector.2.os.family", "myos" );
66          InvokerProperties invokerProperties = new InvokerProperties( props );
67          assertEquals( 0, selector.getSelection( invokerProperties ) );
68  
69          props.setProperty( "invoker.maven.version", "3.3.1+" );
70          assertEquals( Selector.SELECTOR_MULTI, selector.getSelection( invokerProperties ) );
71  
72          props.setProperty( "invoker.maven.version", "3.0+" );
73          props.setProperty( "selector.1.maven.version", "3.3.1+" );
74          assertEquals( Selector.SELECTOR_MULTI, selector.getSelection( invokerProperties ) );
75  
76          props.setProperty( "selector.2.os.family", "!myos" );
77          assertEquals( 0, selector.getSelection( invokerProperties ) );
78      }
79  
80  }