Package org.springframework.issues

Source Code of org.springframework.issues.ReproTests

package org.springframework.issues;

import static org.junit.Assert.assertTrue;

import java.util.Comparator;

import org.junit.Test;
import org.springframework.util.AntPathMatcher;

// Negative means we prefer the first argument when both patterns match
public class ReproTests {

  @Test
  public void patternComparatorWithHierarchicalMatchAccidentalPass() {
    Comparator<String> comparator = new AntPathMatcher().getPatternComparator("/hotels/new");
    // This passes accidentally: the order is correct but for the wrong reason
    assertTrue(comparator.compare("/hotels/{hotel}", "/hotels/**") < 0);
  }

  @Test
  public void patternComparatorWithHierarchicalMatchBracketsPreferred() {
    Comparator<String> comparator = new AntPathMatcher().getPatternComparator("/hotels/new/123");
    // This passes accidentally: the order is correct but for the wrong reason
    assertTrue(comparator.compare("/hotels/{hotel}/{booking}", "/hotels/**") < 0);
  }

  @Test
  public void patternComparatorWithHierarchicalMatch() {
    Comparator<String> comparator = new AntPathMatcher().getPatternComparator("/hotels/new/123");
    // This fails, even though the first path is clearly more specific
    assertTrue(comparator.compare("/hotels/{hotel}/**", "/**") < 0);
  }

  @Test
  public void patternComparatorWithHierarchicalMatchWithWorkaround() {
    Comparator<String> comparator = new AntPathMatcher().getPatternComparator("/hotels/new/123");
    // This is a workaround
    assertTrue(comparator.compare("/hotels/{hotel}/**", "/**/**") < 0);
  }

}
TOP

Related Classes of org.springframework.issues.ReproTests

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.