Skip to content

Commit

Permalink
Reapply "Add id test and util"
Browse files Browse the repository at this point in the history
This reverts commit 288aeb6.
  • Loading branch information
TomWerm committed Sep 19, 2024
1 parent 288aeb6 commit 595300d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ class AutoSARtoSimuLinkSwComponentTest extends AbstractAutoSARToSimuLinkTest {
assertNoElementWithNameInRootModel(DEFAULT_Component_NAME)

}

@Test
def void testChangeId() {
createCompositeSWComponentInModel(DEFAULT_COMPOSITE_COMPONENT_NAME)
changeAutoSARView [
val component = claimAutoSARElement(CompositeSwComponent, DEFAULT_COMPOSITE_COMPONENT_NAME) as CompositeSwComponent
component.id = "newId"
]
assertCompositeSwComponentWithIdInRootModel("newId")
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,15 @@ class SimuLinkToAutoSARBlockTest extends AbstractSimuLinkToAutoSARTest {

}

@Test
def void testChangeId() {
createSubsystemInModel(DEFAUL_SUBSYSTEM_NAME)
changeSimuLinkView [
val subSystem = claimSimuLinkBlock(DEFAUL_SUBSYSTEM_NAME)
subSystem.id = "newId"
]
assertCompositeSwComponentWithIdInRootModel("newId")
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class AutoSARQueryUtil {
].claimOne
}

static def <T extends AutoSARElement> SwComponent claimAutoSARElementById(View view, Class<T> element,
String elementId) {
view.getRootObjects(AutoSARModel).map[swcomponent].flatten.filter[
it.id == elementId
].claimOne
}

static def <T extends AutoSARElement> CompositeSwComponent claimAutoSARCompositeSwComponent(View view, Class<T> element,
String elementName) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class SimuLinkAutoSARClassifierEqualityValidation {
assertElementWithName(SubSystem, CompositeSwComponent, compositeComponentName)
}

def assertCompositeSwComponentWithIdInRootModel(String compositeComponentId){
assertElementWithId(SubSystem, CompositeSwComponent, compositeComponentId)
}



/*
Expand Down Expand Up @@ -114,6 +118,18 @@ class SimuLinkAutoSARClassifierEqualityValidation {
]
}

private def void assertElementWithId(
Class <? extends SimulinkElement> simulinkElement,
Class <? extends AutoSARElement> autoSARElement,
String id) {
viewExecutor.apply [
val SimulinkElement = claimSimuLinkElementById(simulinkElement, id)

val AutoSARElement = claimAutoSARElementById(autoSARElement, id)
assertElementEquals(SimulinkElement , AutoSARElement )
]
}


def static dispatch void assertElementEquals(Block block, AtomicSwComponent component){
assertSimuLinkBlockEqualsAutoSARSwComponent(block,component)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ class SimuLinkQueryUtil {
].claimOne
}

static def <T extends SimulinkElement> Block claimSimuLinkElementById(View view, Class<T> simuLinkType,
String elementId) {
getBlocksOfModel(view,elementId).filter[
it.id == elementId
].claimOne
}


static def claimSimuLinkBlockOfSubsystem(SubSystem subsystem, String blockname){
subsystem.subBlocks.filter[it.name == blockname].claimOne
Expand Down

0 comments on commit 595300d

Please sign in to comment.