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.junit.Test;
26  
27  /**
28   * Test for {@link Selector}.
29   */
30  public class SelectorTest
31  {
32      @Test
33      public void testGlobalMatch()
34      {
35          Selector selector = new Selector( "3.2.5", "1.7", null );
36  
37          Properties props = new Properties();
38          props.setProperty( "invoker.maven.version", "3.0+" );
39          InvokerProperties invokerProperties = new InvokerProperties( props );
40          assertEquals( 0, selector.getSelection( invokerProperties ) );
41      }
42  
43      @Test
44      public void testSelectorMatch()
45      {
46          Selector selector = new Selector( "3.2.5", "1.7", null );
47  
48          Properties props = new Properties();
49          props.setProperty( "selector.1.maven.version", "3.0+" );
50          InvokerProperties invokerProperties = new InvokerProperties( props );
51          assertEquals( 0, selector.getSelection( invokerProperties ) );
52  
53          props.setProperty( "selector.1.maven.version", "3.3.1+" );
54          assertEquals( Selector.SELECTOR_MULTI, selector.getSelection( invokerProperties ) );
55      }
56  
57      @Test
58      public void testSelectorWithGlobalMatch()
59      {
60          Selector selector = new Selector( "3.2.5", "1.7", null );
61  
62          Properties props = new Properties();
63          // invoker.maven.version is used by all selectors
64          props.setProperty( "invoker.maven.version", "3.0+" );
65          props.setProperty( "selector.1.java.version", "1.4+" );
66          props.setProperty( "selector.2.os.family", "myos" );
67          InvokerProperties invokerProperties = new InvokerProperties( props );
68          assertEquals( 0, selector.getSelection( invokerProperties ) );
69  
70          props.setProperty( "invoker.maven.version", "3.3.1+" );
71          assertEquals( Selector.SELECTOR_MULTI, selector.getSelection( invokerProperties ) );
72  
73          props.setProperty( "invoker.maven.version", "3.0+" );
74          props.setProperty( "selector.1.maven.version", "3.3.1+" );
75          assertEquals( Selector.SELECTOR_MULTI, selector.getSelection( invokerProperties ) );
76  
77          props.setProperty( "selector.2.os.family", "!myos" );
78          assertEquals( 0, selector.getSelection( invokerProperties ) );
79      }
80  
81  }