Sfoglia il codice sorgente

OCB interfaces should be checked for null in init() method (#1717)

* added exception for unimplemented OCBs

* added exception for unimplemented internal OCBs

* formatting

* added java test for unimplemented OCBs

* Changed throwing exceptions for unimpl ocbs to init function instead of
enter function

* updated tests

* updated oxygen target

* fixed tests
rherrmannr 7 anni fa
parent
commit
d1612425c9

+ 15 - 13
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/Statemachine.xtend

@@ -202,6 +202,20 @@ class Statemachine {
 				throw new IllegalStateException("timer not set.");
 			}
 			«ENDIF»
+			«IF flow.internalScope !== null && flow.internalScope.hasOperations»
+				if (this.operationCallback == null) {
+					throw new IllegalStateException("Operation callback for internal must be set.");	
+				}
+			«ENDIF»
+			
+			«FOR scope : flow.interfaceScopes»
+				«IF scope.hasOperations»
+					if (this.«scope.interfaceName.asEscapedIdentifier».operationCallback == null) {
+						throw new IllegalStateException("Operation callback for interface «scope.interfaceName.asEscapedIdentifier» must be set.");
+					}
+					
+				«ENDIF»
+			«ENDFOR»
 			for (int i = 0; i < «flow.stateVector.size»; i++) {
 				stateVector[i] = State.$NullState$;
 			}
@@ -634,19 +648,7 @@ class Statemachine {
 				throw new IllegalStateException("timer not set.");
 			}
 			«ENDIF»
-			«IF flow.internalScope !== null && flow.internalScope.hasOperations»
-				if (this.operationCallback == null) {
-					throw new IllegalStateException("Operation callback for internal must be set.");	
-				}
-			«ENDIF»
-			«FOR scope : flow.interfaceScopes»
-				«IF scope.hasOperations»
-					if (this.«scope.interfaceName.asEscapedIdentifier».operationCallback == null) {
-						throw new IllegalStateException("Operation callback for interface «scope.interfaceName.asEscapedIdentifier» must be set.");
-					}
-					
-				«ENDIF»
-			«ENDFOR»
+
 			«enterSequences.defaultSequence.code»
 		}
 

+ 13 - 11
test-plugins/org.yakindu.sct.generator.java.test/src-gen/org/yakindu/src/operationcallbackimpl/OperationCallbackImplStatemachine.java

@@ -49,6 +49,18 @@ public class OperationCallbackImplStatemachine implements IOperationCallbackImpl
 	
 	public void init() {
 		this.initialized = true;
+		if (this.operationCallback == null) {
+			throw new IllegalStateException("Operation callback for internal must be set.");	
+		}
+		
+		if (this.sCInterface.operationCallback == null) {
+			throw new IllegalStateException("Operation callback for interface sCInterface must be set.");
+		}
+		
+		if (this.sCINamed.operationCallback == null) {
+			throw new IllegalStateException("Operation callback for interface sCINamed must be set.");
+		}
+
 		for (int i = 0; i < 1; i++) {
 			stateVector[i] = State.$NullState$;
 		}
@@ -61,17 +73,7 @@ public class OperationCallbackImplStatemachine implements IOperationCallbackImpl
 			throw new IllegalStateException(
 					"The state machine needs to be initialized first by calling the init() function.");
 		}
-		if (this.operationCallback == null) {
-			throw new IllegalStateException("Operation callback for internal must be set.");	
-		}
-		if (this.sCInterface.operationCallback == null) {
-			throw new IllegalStateException("Operation callback for interface sCInterface must be set.");
-		}
-		
-		if (this.sCINamed.operationCallback == null) {
-			throw new IllegalStateException("Operation callback for interface sCINamed must be set.");
-		}
-		
+
 		enterSequence_main_region_default();
 	}
 	

+ 14 - 16
test-plugins/org.yakindu.sct.generator.java.test/src/org/yakindu/sct/generator/java/test/UnimplementedOCBTest.java

@@ -13,52 +13,50 @@ import org.yakindu.src.operationcallbackimpl.OperationCallbackImplStatemachine;
 import org.yakindu.src.operationcallbackimpl.OperationCallbackImplStatemachine.State;
 
 public class UnimplementedOCBTest {
-	
+
 	private OperationCallbackImplStatemachine statemachine;
-	
+
 	@Rule
 	public ExpectedException exceptions = ExpectedException.none();
-	
+
 	@Before
 	public void setUp() {
 		statemachine = new OperationCallbackImplStatemachine();
-		statemachine.init();
 	}
-	
+
 	@Test
-	public void testUnimplementedInternal() throws IllegalStateException{		
+	public void testUnimplementedInternal() throws IllegalStateException {
 		exceptions.expect(IllegalStateException.class);
 		exceptions.expectMessage("Operation callback for internal must be set.");
-		statemachine.enter();
+		statemachine.init();
+
 	}
-	
+
 	@Test
 	public void testUnimplementedInterfacce() {
-		statemachine.setInternalOperationCallback(new InternalOCBImpl()); 
-		
+		statemachine.setInternalOperationCallback(new InternalOCBImpl());
 		exceptions.expect(IllegalStateException.class);
 		exceptions.expectMessage("Operation callback for interface sCInterface must be set.");
-		
-		statemachine.enter();
+		statemachine.init();
 	}
 	
 	@Test
 	public void testUnimplementedNamedInterface() {
 		statemachine.setInternalOperationCallback(new InternalOCBImpl());
 		statemachine.getSCInterface().setSCInterfaceOperationCallback(new InterfaceOCBImpl());
-
 		exceptions.expect(IllegalStateException.class);
 		exceptions.expectMessage("Operation callback for interface sCINamed must be set.");
-		
-		statemachine.enter();
+		statemachine.init();
 	}
-	
+
 	@Test
 	public void testImplementedOCBs(){
 		statemachine.setInternalOperationCallback(new InternalOCBImpl());
 		statemachine.getSCInterface().setSCInterfaceOperationCallback(new InterfaceOCBImpl());
 		statemachine.getSCINamed().setSCINamedOperationCallback(new NamedInterfaceOCBImpl());
+		statemachine.init();
 		statemachine.enter();
+
 		assertTrue(statemachine.isStateActive(State.main_region_StateA));
 	}
 }