How to show the flow termination in Sequence Diagram - uml

Basically, I'd like to depict the below logic in a Sequence Diagram:
if (ShopIsOpen) {
if (AccessTokenIsExpired) {
if (RefreshTokenInExpired) {
return "Not Authorized";
}
IdentityServer.RequestAccessTokenByRefreshToken();
return Resource.RequestResourceByAccessToken();
}
} else {
return "Shop is closed";
}
I've come up with the below diagram, but I am not sure if it is correct.
Mainly, I am not sure if break in the diagram correctly communicates the intention of termination of flow: does it imply jumping out of the outer opt or the outer alt?
Any help is much appreciated.

The break fragment leaves the immediately enclosing fragment. In your case that would be the opt fragment. So, it is not correct. Why don’t you use nested alt fragments?
Some additional remarks: The reply to a synchronous message is shown with a dashed line and the returned value is shown with a leading colon (and the name of the original message, but I think it is obvious here anyway).

Related

Antlr4 - gated semantic predicates

Since Antlr4 no longer supports gated semantic predicates, I came up with a workaround. However, if anyone has run into this, I would like to know if there are any caveats to doing something like this and also am I following best practices.
I'm following the standard 'C' if statement in the form of:
if (evaluation) {
...code block
}
Here is the code in the code block:
if ($result == false) { // If the statement evealuates to false
// Consume tokens until the end of block marker
while (getCurrentToken().getText().compareTo("}") != 0){
consume();
}
// Set the parser state as if it had executed the tokens
_localctx.start = getCurrentToken();
_ctx.start = getCurrentToken();
setState(220);
_errHandler.sync(this);
consume(); // Consume the end of block marker
return _localctx; // Exit the rule
}
I figure that Terrance Parr must have had a good reason to take out the support for a gated semantic predicate and this seems like a simple workaround. I'm just wondering if I'm missing something.
I tested it and it works, even with an 'else'. I have not tried it with compound evaluation statements (ie conditions separated with '&&' or '||'. I have a high confidence that it will work though.

How to update Actor after applying Transformation?

Currently I apply translation to an actor through below code:
vtkSmartPointer<vtkTransform> translation =
vtkSmartPointer<vtkTransform>::New();
translation->PostMultiply(); //this is the key line
translation->Translate(translationVector);
patella->getActor()->SetUserTransform(translation);
However, if I apply
patella->getActor()->SetUserTransform(translation);
again. The actor stays at the same position as if I applied it only once. I know it's because the origin is not updated. Thus, how can I update the origin/actor after each translation?
You want to concatenate the transforms. Something like:
vtkActor* patellaActor = patella->GetActor();
vtkTransform* patellaXfm = patellaActor->GetUserTransform();
if (!patellaXfm) {
patellaActor->SetUserTransform(translation);
} else {
patellaXfm->Concatenate(translation);
}

Greenfoot Actor not in World error

When my enemy gets to the bottom of the screen I want to remove and if the enemy gets hit by bullets i want to remove it. The error is : java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
I think the problem is because there is two calls to removeObject or the getOneIntersectingObject method is causing an error. How do I fix this?
This is the code causing the error
public class Enemy extends Actor
{
public void act()
{
setLocation(getX(), getY() + 3);
if (getY() > getWorld().getHeight() + 30 )
getWorld().removeObject(this);
Actor fire = getOneIntersectingObject(Fire.class);
if(fire != null)
getWorld().removeObject(this);
}
}
Greenfoot doesn't allow any interactions with the world after an actor has been removed from it. If your Y coordinate causes this actor to be removed from the world in the first if statement, it is an error to call getOneIntersectingObject afterwards.
There's several ways to solve this: you could wrap the ensuing lines in an else clause, you could make an early return if you remove yourself in the first if, or you could use a boolean flag to keep track of whether you want to remove yourself, but only do the removal as the very last item in the act() method.

Sequence diagram multiple calls to same method from different locations

I want to create a sequence diagram of my program.
The code goes like this:
I have a class SFC, this class starts with the method parseScenario(). The parseScenario() method is a loop until all elements in a list are looped over. In this loop I call the parseEntryLine(e) method, where e is an entry in that list.
Now my problem occurs.
In parseEntryLine(e) there is an IF statement as follows:
if (currentGM.isBrick ()) {
animateExpr(currentGM);
//Check if it has a next
if (currentGM._next != null) { parseEntryLine (currentGM._next); }
} else {
//random code
parseEntryLine(buttonStringClicked);
}
}
How do I model this in a sequence diagram?
I managed to work until this point:
(I realize this might already be a wrong start).

how to check nothing has changed in cucumber?

The business scenario I'm trying to test with cucumber/gherkin (specflow, actually) is that given a set of inputs on a web form, I make a request, and need to ensure that (under certain conditions), when the result is returned, a particular field hasn't changed (under other condition, it does). E.g.
Given I am on the data entry screen
When I select "do not update frobnicator"
And I submit the form
And the result is displayed
Then the frobnicator is not updated
How would I write the step "the frobnicator is not updated"?
One option is to have a step that runs before "I submit the form" that reads something like "I remember the value of the frobnicator", but that's a bit rubbish - it's a horrible leak of an implementation detail. It distracts from the test, and is not how the business would describe this. In fact, I have to explain such a line any time anyone sees it.
Does anyone have any ideas on how this could be implemented a bit nicer, ideally as written?
I disagree with the previous answer.
The gherkin text you felt like you wanted to write is probably right.
I'm going to modify it just a little to make it so that the When step is the specific action that is being tested.
Given I am on the data entry screen
And I have selected "do not update frobnicator"
When I submit the form
Then the frobnicator is not updated
How exactly you Assert the result will depend on how your program updates the frobnicator, and what options that gives you.. but to show it is possible, I'll assume you have decoupled your data access layer from your UI and are able to mock it - and therefore monitor updates.
The mock syntax I am using is from Moq.
...
private DataEntryScreen _testee;
[Given(#"I am on the data entry screen")]
public void SetUpDataEntryScreen()
{
var dataService = new Mock<IDataAccessLayer>();
var frobby = new Mock<IFrobnicator>();
dataService.Setup(x => x.SaveRecord(It.IsAny<IFrobnicator>())).Verifiable();
ScenarioContext.Current.Set(dataService, "mockDataService");
_testee = new DataEntryScreen(dataService.Object, frobby.Object);
}
The important thing to note here, is that the given step sets up the object we are testing with ALL the things it needs... We didn't need a separate clunky step to say "and i have a frobnicator that i'm going to memorise" - that would be bad for the stakeholders and bad for your code flexibility.
[Given(#"I have selected ""do not update frobnicator""")]
public void FrobnicatorUpdateIsSwitchedOff()
{
_testee.Settings.FrobnicatorUpdate = false;
}
[When(#"I submit the form")]
public void Submit()
{
_testee.Submit();
}
[Then(#"the frobnicator is not updated")]
public void CheckFrobnicatorUpdates()
{
var dataService = ScenarioContext.Current.Get<Mock<IDataAccessLayer>>("mockDataService");
dataService.Verify(x => x.SaveRecord(It.IsAny<IFrobnicator>()), Times.Never);
}
Adapt the principle of Arrange, Act, Assert depending on your circumstances.
Think about how you would test it manually:
Given I am on the data entry screen
And the blah is set to "foo"
When I set the blah to "bar"
And I select "do not update frobnicator"
And I submit the form
Then the blah should be "foo"

Resources