    1   /*
    2    * Copyright 2006 The Apache Software Foundation.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  package org.apache.commons.scxml.model;
    17
    18  import junit.framework.Test;
    19  import junit.framework.TestCase;
    20  import junit.framework.TestSuite;
    21
    22  public class PathTest extends TestCase {
    23
    24      public PathTest(String testName) {
    25          super(testName);
    26      }
    27
    28      public static Test suite() {
    29          return new TestSuite(PathTest.class);
    30      }
    31
    32      public static void main(String args[]) {
    33          String[] testCaseName = { PathTest.class.getName()};
    34          junit.textui.TestRunner.main(testCaseName);
    35      }
    36
    37      public void testConstructorNull() {
    38          Path path = new Path(null, null);
    39
    40          assertNull(path.getScope());
    41      }
    42
    43      public void testConstructorNullState() {
    44          Path path = new Path(new State(), null);
    45
    46          assertTrue(path.getScope() instanceof State);
    47      }
    48
    49      public void testConstructorStates() {
    50          TransitionTarget source = new State();
    51          source.setId("1");
    52
    53          TransitionTarget target = new State();
    54          target.setId("2");
    55
    56          Path path = new Path(source, target);
    57
    58          assertNull(path.getScope());
    59          assertEquals(1, path.getUpwardSegment().size());
    60          assertEquals("1", ((State)path.getUpwardSegment().get(0)).getId());
    61
    62          assertEquals(1, path.getDownwardSegment().size());
    63          assertEquals("2", ((State)path.getDownwardSegment().get(0)).getId());
    64
    65          assertFalse(path.isCrossRegion());
    66      }
    67
    68      public void testConstructorSourceCrossRegion() {
    69          Parallel region = new Parallel();
    70
    71          TransitionTarget source = new State();
    72          source.setId("1");
    73          source.setParent(region);
    74
    75          TransitionTarget target = new State();
    76          target.setId("2");
    77
    78          Path path = new Path(source, target);
    79
    80          assertTrue(path.isCrossRegion());
    81      }
    82
    83      public void testConstructorTargetCrossRegion() {
    84          Parallel region = new Parallel();
    85
    86          TransitionTarget source = new State();
    87          source.setId("1");
    88
    89          TransitionTarget target = new State();
    90          target.setId("2");
    91          target.setParent(region);
    92
    93          Path path = new Path(source, target);
    94
    95          assertTrue(path.isCrossRegion());
    96      }
    97
    98      public void testConstructorParentTarget() {
    99          TransitionTarget source = new State();
    100         source.setId("1");
    101
    102         TransitionTarget target = new State();
    103         target.setId("2");
    104
    105         source.setParent(target);
    106
    107         Path path = new Path(source, target);
    108
    109         assertNull(path.getScope());
    110     }
    111
    112     public void testConstructorParentSource() {
    113         TransitionTarget source = new State();
    114         source.setId("1");
    115
    116         TransitionTarget target = new State();
    117         target.setId("2");
    118
    119         target.setParent(source);
    120
    121         Path path = new Path(source, target);
    122
    123         assertNull(path.getScope());
    124     }
    125
    126     public void testConstructorParent() {
    127         TransitionTarget source = new State();
    128         source.setId("1");
    129
    130         TransitionTarget target = new State();
    131         target.setId("2");
    132
    133         State parent = new State();
    134         parent.setId("parentid");
    135
    136         target.setParent(parent);
    137         source.setParent(parent);
    138
    139         Path path = new Path(source, target);
    140
    141         assertEquals("parentid", path.getScope().getId());
    142     }
    143
    144     public void testConstructorParentParallel() {
    145         TransitionTarget source = new State();
    146         source.setId("1");
    147
    148         TransitionTarget target = new State();
    149         target.setId("2");
    150
    151         Parallel parent = new Parallel();
    152         parent.setId("parentid");
    153
    154         target.setParent(parent);
    155         source.setParent(parent);
    156
    157         Path path = new Path(source, target);
    158
    159         assertNull(path.getScope());
    160     }
    161
    162     public void testConstructorParentParallelParent() {
    163         TransitionTarget source = new State();
    164         source.setId("1");
    165
    166         TransitionTarget target = new State();
    167         target.setId("2");
    168
    169         Parallel parent = new Parallel();
    170         parent.setId("parentid");
    171
    172         State parentOfParent = new State();
    173         parentOfParent.setId("superParent");
    174
    175         parent.setParent(parentOfParent);
    176
    177         target.setParent(parent);
    178         source.setParent(parent);
    179
    180         Path path = new Path(source, target);
    181
    182         assertEquals("superParent", path.getScope().getId());
    183     }
    184
    185     public void testGetRegionsExitedNull() {
    186         Path path = new Path(new State(), null);
    187
    188         assertEquals(0, path.getRegionsExited().size());
    189     }
    190
    191     public void testGetRegionsExitedNotRegion() {
    192         TransitionTarget source = new State();
    193         source.setId("1");
    194
    195         TransitionTarget target = new State();
    196         target.setId("2");
    197
    198         Path path = new Path(source, target);
    199
    200         assertEquals(0, path.getRegionsExited().size());
    201     }
    202
    203     public void testGetRegionsExitedParallel() {
    204         TransitionTarget source = new Parallel();
    205         source.setId("1");
    206
    207         TransitionTarget target = new Parallel();
    208         target.setId("2");
    209
    210         Path path = new Path(source, target);
    211
    212         assertEquals(0, path.getRegionsExited().size());
    213     }
    214
    215     public void testGetRegionsExited() {
    216         Parallel region = new Parallel();
    217
    218         TransitionTarget source = new State();
    219         source.setId("1");
    220         source.setParent(region);
    221
    222         TransitionTarget target = new State();
    223         target.setId("2");
    224
    225         Path path = new Path(source, target);
    226
    227         assertEquals(1, path.getRegionsExited().size());
    228         assertEquals("1", ((State)path.getRegionsExited().get(0)).getId());
    229     }
    230
    231     public void testGetRegionsEnteredNull() {
    232         Path path = new Path(new State(), null);
    233
    234         assertEquals(0, path.getRegionsEntered().size());
    235     }
    236
    237     public void testGetRegionsEnteredNotRegion() {
    238         TransitionTarget source = new State();
    239         source.setId("1");
    240
    241         TransitionTarget target = new State();
    242         target.setId("2");
    243
    244         Path path = new Path(source, target);
    245
    246         assertEquals(0, path.getRegionsEntered().size());
    247     }
    248
    249     public void testGetRegionsEnteredParallel() {
    250         TransitionTarget source = new Parallel();
    251         source.setId("1");
    252
    253         TransitionTarget target = new Parallel();
    254         target.setId("2");
    255
    256         Path path = new Path(source, target);
    257
    258         assertEquals(0, path.getRegionsEntered().size());
    259     }
    260
    261     public void testGetRegionsEntered() {
    262         Parallel region = new Parallel();
    263
    264         TransitionTarget source = new State();
    265         source.setId("1");
    266
    267         TransitionTarget target = new State();
    268         target.setId("2");
    269         target.setParent(region);
    270
    271         Path path = new Path(source, target);
    272
    273         assertEquals(1, path.getRegionsEntered().size());
    274         assertEquals("2", ((State)path.getRegionsEntered().get(0)).getId());
    275     }
    276
    277 }