Skip to content

Commit

Permalink
[sre] Add test for the multiple event handler and function override.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Mar 2, 2020
1 parent 58df131 commit 75629d7
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 0 deletions.
@@ -0,0 +1,69 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2020 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.sre.tests.runtime.internal.eventguard

import io.sarl.sre.tests.runtime.internal.eventguard.mocks.Agent1
import io.sarl.sre.tests.testutils.^extension.PropertyRestoreExtension
import io.sarl.sre.tests.testutils.^extension.SreRunContext
import io.sarl.sre.tests.testutils.^extension.SreRunExtension
import io.sarl.tests.api.extensions.ContextInitExtension
import io.sarl.tests.api.extensions.JavaVersionCheckExtension
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith

import static io.sarl.sre.tests.testutils.Constants.*

import static extension io.sarl.tests.api.tools.TestAssertions.*
import static extension org.junit.jupiter.api.Assertions.*

/**
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
@ExtendWith(#[
typeof(ContextInitExtension),
typeof(JavaVersionCheckExtension),
typeof(PropertyRestoreExtension),
typeof(SreRunExtension)
])
@DisplayName("run: event and function overriding test")
@Tag("run")
class BehaviorGuardEvaluatorRegistryTest {

@Test
@DisplayName("Override of event handler and action")
def overrideOfEventHanderAndMethod(extension rc : SreRunContext) {
typeof(Agent1).runSre(null, true, STANDARD_TIMEOUT)

var all = allResults
2.assertEquals(all.size)

// These is two data into the results because there is 2 "on Event0".
// The data are the same because of the function overriding.
all.assertContains("myfunction in Agent1", "myfunction in Agent1")
}

}
@@ -0,0 +1,51 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2020 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.sre.tests.runtime.internal.eventguard.mocks

import io.sarl.sre.tests.testutils.agents.TestingAgent
import io.sarl.core.DefaultContextInteractions
import io.sarl.core.Schedules
import io.sarl.core.Lifecycle

abstract agent Agent0 extends TestingAgent {

uses DefaultContextInteractions, Schedules, Lifecycle

def runAgentTest : RunPolicy {
in(1000) [
new Event0().emit
]
in(2000) [
killMe
]
return RunPolicy::STANDARD
}

def myfunction : void {
addResult("myfunction in Agent0")
}

on Event0 {
myfunction
}

}
@@ -0,0 +1,36 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2020 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.sre.tests.runtime.internal.eventguard.mocks

import io.sarl.sre.tests.testutils.agents.TestingAgent.RunPolicy

agent Agent1 extends Agent0 {

override myfunction : void {
addResult("myfunction in Agent1")
}

on Event0 {
myfunction
}

}
@@ -0,0 +1,24 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2020 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.sre.tests.runtime.internal.eventguard.mocks

event Event0

0 comments on commit 75629d7

Please sign in to comment.