From acda6a74a5d429e537f411ceaa371f454c991a1f Mon Sep 17 00:00:00 2001
From: Naum Spaseski <naum.spaseski@eglobalmark.com>
Date: Fri, 14 Oct 2016 17:33:58 +0200
Subject: [PATCH] Two REG testcases with correspoding function

---
 LibOneM2M/OneM2M_Functions.ttcn | 68 +++++++++++++++++++++++++
 OneM2M_Testcases.ttcn           | 89 +++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+)

diff --git a/LibOneM2M/OneM2M_Functions.ttcn b/LibOneM2M/OneM2M_Functions.ttcn
index f480e16..14f41e2 100644
--- a/LibOneM2M/OneM2M_Functions.ttcn
+++ b/LibOneM2M/OneM2M_Functions.ttcn
@@ -152,6 +152,74 @@ module OneM2M_Functions {
     		
     		}
     		
+    		/**
+    		 * @desc Creation of auxiliar resources ACP and AE for correct execution of the test case
+    		 * @param p_allowedOperations Allowed operations for the auxiliar AE resource
+    		 * @return Internal AE resource index
+    		 * @verdict 
+    		 */
+    		function f_cse_preamble_registerAeWithId(XSD.ID p_appId, in template (value) AccessControlOperations p_allowedOperations := int63) runs on CseTester return integer {//c_CRUDNDi
+    		
+    			var RequestPrimitive v_request;
+    			var MsgIn v_response;
+    			var integer v_aeAuxIndex := -1;
+    			var integer v_acpAuxIndex := -1;
+    		
+    			if(PX_ACP_SUPPORT){
+    				v_acpAuxIndex := f_cse_createAccessControlPolicyAux(p_allowedOperations := p_allowedOperations);
+    				vc_acpAuxIndex := v_acpAuxIndex;
+    			}
+    			
+    			if(v_acpAuxIndex != -1) {
+    				vc_resourcesIndexToBeDeleted := {v_acpAuxIndex};
+    				v_request := valueof(m_createAe(p_appId, p_accessControlPolicyIDs := {f_getResourceId(vc_resourcesList[v_acpAuxIndex].resource)}));
+    				
+    				//TODO Test, to be removed
+    				v_request.to_ := f_addPrefix(f_getResourceAddress());
+    				
+    				mcaPort.send(m_request(v_request));
+    				//mcaPort.send(m_request(m_createAeAux(p_name, {PX_URI_CSE & PX_CSE_NAME & "/" & PX_ACPAUX_NAME})));
+    			} else {
+    				mcaPort.send(m_request(m_createAe(p_appId)));
+    			}
+    			tc_ac.start;
+    			alt {
+    				[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
+    					tc_ac.stop;
+    					log("Preamble: Application registered successfuly");
+    					if(ischosen(v_response.primitive.responsePrimitive.primitiveContent.any_1[0].AE_optional)) {
+    						vc_aeAux := v_response.primitive.responsePrimitive.primitiveContent.any_1[0].AE_optional;
+    						
+    						v_aeAuxIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent);
+    						vc_resourcesIndexToBeDeleted := vc_resourcesIndexToBeDeleted & {v_aeAuxIndex};
+    						
+    						if(ispresent(vc_aeAux.aE_ID)){
+    							f_sendAcPrimitive("AE-ID_changed", oct2char(unichar2oct(vc_aeAux.aE_ID)));
+    						} else {
+    							f_sendAcPrimitive("AE-ID_changed", "0");
+    						}	
+    					}
+    				}
+    				[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
+    					tc_ac.stop;
+    					setverdict(inconc, "Preamble: Error while registering application");
+    					stop;
+    				}
+    				[] mcaPort.receive {
+    					tc_ac.stop;
+    					setverdict(inconc, "Preamble: Unexpected message received");
+    					stop;
+    				}
+    				[] tc_ac.timeout {
+    					setverdict(inconc, "Preamble: No answer while registering resource");
+    					stop;
+    				}
+    			}	
+    			
+    			return v_aeAuxIndex;
+    		
+    		}
+    		
     		//Added by @Naum
     		function f_cse_preamble_createServiceSubscribedAppRule(in template ListOfM2MID p_allowedAEs, in template (value) AccessControlOperations p_allowedOperations := int63) runs on CseTester return integer {//c_CRUDNDi
     		
diff --git a/OneM2M_Testcases.ttcn b/OneM2M_Testcases.ttcn
index dbdb749..65a6424 100644
--- a/OneM2M_Testcases.ttcn
+++ b/OneM2M_Testcases.ttcn
@@ -319,6 +319,95 @@ module OneM2M_Testcases {
 				f_cf01Down();
 					
 			}
+			
+			testcase TC_CSE_REG_BV_006() runs on CseTester system CseSystem {
+			  
+			   	var MsgIn v_response;
+				var RequestPrimitive v_request;
+				var integer v_aeIndex := -1;
+				var ResourceType v_resourceType := int2;
+				
+				// Test control
+    				
+				// Test component configuration
+				f_cf01Up();
+    			
+				// Test adapter configuration
+    			
+				// Preamble
+				v_aeIndex := f_cse_preamble_registerAeWithId("C-AE-ID-STEM");//c_CRUDNDi);
+				
+				//Test Body	
+				v_request := valueof(m_createAe(PX_APP_ID, omit, "C-AE-ID-STEM"));				
+    									
+				v_request := f_getCreateRequestPrimitive(v_resourceType, v_request, v_aeIndex);
+				
+				mcaPort.send(m_request(v_request));
+				tc_ac.start;
+				alt {
+					[] mcaPort.receive(mw_response(mw_responsePrimitive(int4005))) {
+						tc_ac.stop;
+						setverdict(pass, testcasename() & ": AE creation rejected.");
+					}
+					[] mcaPort.receive(mw_response(mw_responsePrimitiveInverse(int4005))) -> value v_response{
+						tc_ac.stop;
+						setverdict(fail, testcasename() & ": Error while creating AE with status code " & int2str(enum2int(v_response.primitive.responsePrimitive.responseStatusCode)));
+					}
+					[] tc_ac.timeout {
+						setverdict(inconc, testcasename() & ": No answer while creating AE");
+					}
+				}	
+								
+				// Postamble
+				f_cse_postamble_deleteResources();
+					
+				// Tear down
+				f_cf01Down();
+			
+			}
+			
+			testcase TC_CSE_REG_BV_007() runs on CseTester system CseSystem {
+	  	  	
+				var MsgIn v_response;
+				var RequestPrimitive v_request;
+				var integer v_cseBaseIndex := -1;
+				var ResourceType v_resourceType := int2;
+                
+                // Test component configuration
+				f_cf02Up();
+	  	  	
+				//Preambule
+				v_cseBaseIndex := f_cse_preamble_createServiceSubscribedAppRule({"S"});//c_CRUDNDi);
+	
+				//Test Body
+				v_request := valueof(m_createAe(PX_APP_ID, omit, "C-AE-ID-STEM"));				
+    									
+				v_request := f_getUpdateRequestPrimitive(v_resourceType,v_cseBaseIndex, v_request);
+	  	  		
+				mcaPort.send(m_request(v_request));
+				tc_ac.start;
+
+				alt {
+					[] mccPort.receive(mw_request(mw_createAEannc(omit, omit, "APP_ID"))) {
+						tc_ac.stop;
+						setverdict(pass, testcasename() & ": AE creation redirected.");
+					}
+					[] mccPort.receive {
+						tc_ac.stop;
+						setverdict(fail, testcasename() & ": Error while creating AE");
+					}
+					[] tc_ac.timeout {
+						setverdict(inconc, testcasename() & ": No answer while creating AE");
+					}
+				}	
+								
+				// Postamble
+				f_cse_postamble_deleteResources();
+				
+				// Tear down
+				f_cf01Down();
+					
+			}
 	  	  	
 		}//end Registration
 		
-- 
GitLab