001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.scxml2.semantics; 018 019import java.util.HashSet; 020import java.util.Set; 021 022import org.apache.commons.scxml2.env.MockErrorReporter; 023import org.apache.commons.scxml2.env.SimpleErrorReporter; 024import org.apache.commons.scxml2.model.EnterableState; 025import org.apache.commons.scxml2.model.Parallel; 026import org.apache.commons.scxml2.model.State; 027import org.junit.Assert; 028import org.junit.Test; 029 030public class SCXMLSemanticsImplTest { 031 032 @Test 033 public void testIsLegalConfigNoStates() { 034 Set<EnterableState> states = new HashSet<EnterableState>(); 035 036 Assert.assertTrue(new SCXMLSemanticsImpl().isLegalConfiguration(states, new SimpleErrorReporter())); 037 } 038 039 @Test 040 public void testIsLegalConfigInvalidParallel() { 041 Set<EnterableState> states = new HashSet<EnterableState>(); 042 Parallel parallel = new Parallel(); 043 044 Parallel parent = new Parallel(); 045 parent.setId("4"); 046 047 State state1 = new State(); 048 state1.setId("1"); 049 State state2 = new State(); 050 state2.setId("2"); 051 052 parent.addChild(state1); 053 parent.addChild(state2); 054 055 parallel.setParent(parent); 056 057 states.add(parallel); 058 059 MockErrorReporter errorReporter = new MockErrorReporter(); 060 061 Assert.assertFalse(new SCXMLSemanticsImpl().isLegalConfiguration(states, errorReporter)); 062 Assert.assertEquals(ErrorConstants.ILLEGAL_CONFIG, errorReporter.getErrCode()); 063 Assert.assertEquals("Not all AND states active for parallel 4", errorReporter.getErrDetail()); 064 } 065 066 @Test 067 public void testIsLegalConfigMultipleTopLevel() { 068 Set<EnterableState> states = new HashSet<EnterableState>(); 069 070 State state1 = new State(); 071 state1.setId("1"); 072 State state2 = new State(); 073 state2.setId("2"); 074 075 states.add(state1); 076 states.add(state2); 077 078 MockErrorReporter errorReporter = new MockErrorReporter(); 079 080 Assert.assertFalse(new SCXMLSemanticsImpl().isLegalConfiguration(states, errorReporter)); 081 Assert.assertEquals(ErrorConstants.ILLEGAL_CONFIG, errorReporter.getErrCode()); 082 Assert.assertEquals("Multiple top-level OR states active!", errorReporter.getErrDetail()); 083 } 084 085 @Test 086 public void testIsLegalConfigMultipleStatesActive() { 087 Set<EnterableState> states = new HashSet<EnterableState>(); 088 089 State state1 = new State(); 090 state1.setId("1"); 091 092 State state2 = new State(); 093 state2.setId("2"); 094 095 State parent = new State(); 096 parent.setId("parentid"); 097 098 state2.setParent(parent); 099 state1.setParent(parent); 100 101 states.add(state1); 102 states.add(state2); 103 104 MockErrorReporter errorReporter = new MockErrorReporter(); 105 106 Assert.assertFalse(new SCXMLSemanticsImpl().isLegalConfiguration(states, errorReporter)); 107 Assert.assertEquals(ErrorConstants.ILLEGAL_CONFIG, errorReporter.getErrCode()); 108 Assert.assertEquals("Multiple OR states active for state parentid", errorReporter.getErrDetail()); 109 } 110}