-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAY-2833 Unify code related to the Cayenne model paths processing
- performance optimizations
- Loading branch information
Showing
4 changed files
with
158 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
cayenne/src/test/java/org/apache/cayenne/exp/path/PathParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.apache.cayenne.exp.path; | ||
|
||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class PathParserTest { | ||
|
||
@Test | ||
public void testParseSingle() { | ||
assertNull(PathParser.parseAllSegments("")); | ||
assertNull(PathParser.parseAllSegments("bd:test+")); | ||
assertNull(PathParser.parseAllSegments("test")); | ||
} | ||
|
||
@Test | ||
public void testTwoSegmentsSimple() { | ||
CayennePathSegment[] segments = PathParser.parseAllSegments("abc.bed"); | ||
assertNotNull(segments); | ||
assertEquals(4, segments.length); | ||
assertEquals("abc", segments[0].value()); | ||
assertFalse(segments[0].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertEquals("bed", segments[1].value()); | ||
assertFalse(segments[1].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertNull(segments[2]); | ||
assertNull(segments[3]); | ||
} | ||
|
||
@Test | ||
public void testTwoSegmentsOuter() { | ||
CayennePathSegment[] segments = PathParser.parseAllSegments("a+.b+"); | ||
assertNotNull(segments); | ||
assertEquals(4, segments.length); | ||
assertEquals("a", segments[0].value()); | ||
assertTrue(segments[0].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertEquals("b", segments[1].value()); | ||
assertTrue(segments[1].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertNull(segments[2]); | ||
assertNull(segments[3]); | ||
} | ||
|
||
@Test | ||
public void testThreeSegments() { | ||
CayennePathSegment[] segments = PathParser.parseAllSegments("a.b.c"); | ||
assertNotNull(segments); | ||
assertEquals(4, segments.length); | ||
assertEquals("a", segments[0].value()); | ||
assertFalse(segments[0].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertEquals("b", segments[1].value()); | ||
assertFalse(segments[1].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertEquals("c", segments[2].value()); | ||
assertFalse(segments[2].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertNull(segments[3]); | ||
} | ||
|
||
@Test | ||
public void testFourSegments() { | ||
CayennePathSegment[] segments = PathParser.parseAllSegments("a.b+.c+.d"); | ||
assertNotNull(segments); | ||
assertEquals(4, segments.length); | ||
assertEquals("a", segments[0].value()); | ||
assertFalse(segments[0].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertEquals("b", segments[1].value()); | ||
assertTrue(segments[1].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertEquals("c", segments[2].value()); | ||
assertTrue(segments[2].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertEquals("d", segments[3].value()); | ||
assertFalse(segments[3].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
} | ||
|
||
@Test | ||
public void testFiveSegments() { | ||
CayennePathSegment[] segments = PathParser.parseAllSegments("a.b+.c+.d.e"); | ||
assertNotNull(segments); | ||
assertEquals(8, segments.length); | ||
assertEquals("a", segments[0].value()); | ||
assertFalse(segments[0].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertEquals("b", segments[1].value()); | ||
assertTrue(segments[1].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertEquals("c", segments[2].value()); | ||
assertTrue(segments[2].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertEquals("d", segments[3].value()); | ||
assertFalse(segments[3].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertEquals("e", segments[4].value()); | ||
assertFalse(segments[4].hasModifier(CayennePath.OUTER_MODIFIER)); | ||
assertNull(segments[5]); | ||
assertNull(segments[6]); | ||
assertNull(segments[7]); | ||
} | ||
|
||
} |