Munit - Part1

27 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.59
List Price:  €93.70
You save:  €28.11
£56.03
List Price:  £80.05
You save:  £24.01
CA$96.39
List Price:  CA$137.71
You save:  CA$41.31
A$107.98
List Price:  A$154.26
You save:  A$46.28
S$95.50
List Price:  S$136.44
You save:  S$40.93
HK$547.57
List Price:  HK$782.28
You save:  HK$234.70
CHF 64.43
List Price:  CHF 92.05
You save:  CHF 27.61
NOK kr776.82
List Price:  NOK kr1,109.79
You save:  NOK kr332.97
DKK kr489.21
List Price:  DKK kr698.91
You save:  DKK kr209.69
NZ$118.81
List Price:  NZ$169.74
You save:  NZ$50.92
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,729.18
List Price:  ৳11,042.16
You save:  ৳3,312.97
₹5,842.93
List Price:  ₹8,347.41
You save:  ₹2,504.47
RM333.67
List Price:  RM476.70
You save:  RM143.02
₦92,745.84
List Price:  ₦132,499.74
You save:  ₦39,753.90
₨19,599.98
List Price:  ₨28,001.17
You save:  ₨8,401.19
฿2,600.12
List Price:  ฿3,714.62
You save:  ฿1,114.50
₺2,271.31
List Price:  ₺3,244.87
You save:  ₺973.56
B$363.64
List Price:  B$519.51
You save:  B$155.87
R1,308.28
List Price:  R1,869.05
You save:  R560.77
Лв128.30
List Price:  Лв183.29
You save:  Лв54.99
₩96,996.60
List Price:  ₩138,572.52
You save:  ₩41,575.91
₪261.41
List Price:  ₪373.46
You save:  ₪112.04
₱4,045.59
List Price:  ₱5,779.67
You save:  ₱1,734.07
¥11,052.75
List Price:  ¥15,790.32
You save:  ¥4,737.57
MX$1,197.81
List Price:  MX$1,711.23
You save:  MX$513.42
QR257.31
List Price:  QR367.61
You save:  QR110.29
P1,000.11
List Price:  P1,428.79
You save:  P428.68
KSh9,335.98
List Price:  KSh13,337.69
You save:  KSh4,001.70
E£3,349.95
List Price:  E£4,785.86
You save:  E£1,435.90
ብር4,013.63
List Price:  ብር5,734.01
You save:  ብር1,720.37
Kz58,409.45
List Price:  Kz83,445.65
You save:  Kz25,036.20
CLP$67,298.07
List Price:  CLP$96,144.23
You save:  CLP$28,846.15
CN¥506.79
List Price:  CN¥724.02
You save:  CN¥217.23
RD$4,121.81
List Price:  RD$5,888.55
You save:  RD$1,766.74
DA9,423.87
List Price:  DA13,463.25
You save:  DA4,039.38
FJ$159.96
List Price:  FJ$228.52
You save:  FJ$68.56
Q547.38
List Price:  Q782
You save:  Q234.62
GY$14,742.16
List Price:  GY$21,061.13
You save:  GY$6,318.97
ISK kr9,832.89
List Price:  ISK kr14,047.59
You save:  ISK kr4,214.70
DH712.24
List Price:  DH1,017.53
You save:  DH305.29
L1,243.01
List Price:  L1,775.81
You save:  L532.79
ден4,046.68
List Price:  ден5,781.23
You save:  ден1,734.54
MOP$564.08
List Price:  MOP$805.87
You save:  MOP$241.78
N$1,315.96
List Price:  N$1,880.02
You save:  N$564.06
C$2,592.36
List Price:  C$3,703.54
You save:  C$1,111.17
रु9,349.94
List Price:  रु13,357.63
You save:  रु4,007.69
S/263.70
List Price:  S/376.73
You save:  S/113.03
K271.96
List Price:  K388.53
You save:  K116.57
SAR262.49
List Price:  SAR375.01
You save:  SAR112.51
ZK1,886.12
List Price:  ZK2,694.57
You save:  ZK808.45
L326.39
List Price:  L466.29
You save:  L139.90
Kč1,650.20
List Price:  Kč2,357.53
You save:  Kč707.33
Ft25,629.21
List Price:  Ft36,614.73
You save:  Ft10,985.52
SEK kr770.71
List Price:  SEK kr1,101.06
You save:  SEK kr330.35
ARS$61,698.11
List Price:  ARS$88,143.94
You save:  ARS$26,445.82
Bs486.86
List Price:  Bs695.54
You save:  Bs208.68
COP$271,471.23
List Price:  COP$387,832.67
You save:  COP$116,361.43
₡35,819.54
List Price:  ₡51,172.97
You save:  ₡15,353.42
L1,740.31
List Price:  L2,486.27
You save:  L745.95
₲526,285.13
List Price:  ₲751,868.13
You save:  ₲225,582.99
$U2,699.91
List Price:  $U3,857.19
You save:  $U1,157.27
zł284.80
List Price:  zł406.88
You save:  zł122.07
Already have an account? Log In

Transcript

Hi, welcome back. In this video, you'll understand about how to use m unit for doing unit testing and integration testing. So, for demonstrating this m unit I have a very good use case where I can show you various scenarios. First let me describe about this use case. I have a main flow where I have HTTP listener, okay. This listener is listening at what URL slash TEST TEST Okay.

Then, after that I have set payload, what it is doing. I configured to set the payload by extracting a query parameter called as you are l underscore key. So that means if I give a request to this flow using localhost Colon 8081 slash test. Question mark, you are l underscore key is equals to my underscore payload. Okay. So payload will be what?

My underscore payload, then I'm calling a floor reference, this floor reference pointing to choice flow. What does this choice flow doing? Here it is having conditions. If payload is equals to payload underscore one, then we are calling sub flow one else we're calling some photo. So that means if I pass URL underscore key as a node underscore one so now the choice This will be executed and it is referencing to sub flow. What is this doing?

It is setting a variable my variable the value is a variable one. And if the payload is not fair underscore one to four suffered to were suffered with setting a variable, same variable, my variable but the value is my variable two. That means the outcome of this choice flow will be setting a variable called as my variable the value can be either my variable one or my variable two based on the payload. Okay. Now again the request comes to mean flow here I have one more choice what is doing here if you see the configuration the crowd Choice is having a condition what is the first choice conditions whereas what my response to my will be one set the variable value is my variable one this will be executed where am setting the payload is as fast as quote period and score one yes, the payload will be responsible for relevance to.

So, summarize. If I pass the value of URL underscore p as paler underscore one, this will be executed and sub flow called local set variable. It will set a variable my variable value may well be one. The control counts here The responsible way as Constance corpulent core one so let me run this test first. I want to restart to see the console. Yep, I'll wait until it distracts.

Okay, it got deployed. So let's give a request I should get a response from Scott builder and score one. If it was you or something else, I should get response and score buildings. That's it right. So, basically, I want to write a unit test case and integration test case. What is the difference between integration test case and unit test case if I talk about this main flow so the different simple differences in integration test case, see here The first flow the mainframe is calling other for right?

You want the main flow to call the other flow if you are writing an integration test case, but if you are writing a unit test case, you just want to see the logic inside this particular flow. So in unit test case, you will actually mock any external calls, right. We'll see how to mock this floor reference later. So let's see first of all, how to write integration test case. Okay. So if you want to start writing a test case, all you have to do is right click on the flow for which you want to add a test case and simply add a Munich create new suit.

Right. So you start Wait, yep, you can see the perspective is changed. And you can see importantly when I added the amulet modules it got added m unit and M your tools also got added automatically once I created my first so that's great. Now, if you see the amulet test case will be under SRC test m unit and this is the file which got generated right now. See here in every test so, there are three parts first one is behavior on the top, here is execution where you need to invoke the flow which you want to test and validation, we can write assertions. So there are three parts of a test case.

So this whole file, we called as a suit in one suit, that can be any number of tests right now. So, this created with only one test. Now, if you see here in the execution part it is referencing to my main it is referencing to actually my main for which I want to really test Normally, if you see this main flow normally, in this case, whenever any HTTP request is coming, this listener will convert the HTTP methods to a mule event is it such a pleasure we'll create a new event automatically. And what it will it will populate the newly events, payload attributes everything. But remember, whenever we're calling the same flow using flow reference, any inbound endpoints will be ignored and the mule even deadly kuzia so If I'm using flow reference to call from my test case, who is responsible to create a new Levent?

In earlier case the listener was creating a mule event by taking HTTP request, but not from calling the same flow using for reference. I have to create a new Levent add a set of newly went even before calling the for reference. So, what I can do is I can just go to this amulet module. Here there is something an operation called set event which will drag and drop so here I can create a mule. So, as you know, the mule event will have some payload. You can write an expression or dw expression and you can set the payload is it and you can use the values and here attributes.

So as you know even will contain attributes and you can view attributes here. Right? So what all does what all does a mule even contain relavant we'll continue now, payload attributes attributes are nothing but key value pairs. And then what else maybe some variables again here. Here you can add property type is variable, variable name it variable value. So that's all right, I even will continually payload attributes and variables.

You can add variables also like this. So right now in this scenario to test I don't want to set any payload but I want to set an attribute attributes is nothing but map is it So you know how to write a map. So I'll just try to show you for Notepad. So this is a map in dw right? curly braces, okay. tattered versus a map.

And normally when you're making HTTP requests in attributes they will be what? query params. Right. So if we select Set payload, just to show you I'll drag and drop transfer message here. If you just observe here on the left side of transform message, under attributes there is query params. query params is again an app which can continue on to to query params.

So in this map, query params is a key So what I'm going to do is write, really, column. Again, the value is a map that I can have multiple query params, right URL underscore, key, colon, a load underscore one. So we are setting we're creating a map inside which query params is on the map, because you are in Skokie, Illinois for one. So I will copy this and I want to write this as an expression to attribute Okay Oh What happened? I think got deleted sorry. Drag and drop city went again before for reference.

And here are four attributes and paste a URL copied. Yep, it appears like this. But if I go to XML and see I can be perfect Oh, no. You're again go to that salmon fish at Yeah, this is what I want to paste. Actually a small thing I missed he's also should be in Singapore. Okay, no, I will copy, copy this and go here and paste it.

Okay. But this is a mule expression, which has to be dw expression which has to be evaluated right at key within that square bracket, then only it will be evaluated. So what I have done is I've created a muli whatever city you live in with these attributes, and then I'm invoking the floor reference, the flow will be called, what is the output of executing the flow in this case? I'm expecting the pillar to be response underscore payload underscore one. I want to assert that the payload is this one. So what I will do is here in the sessions part validation part I can add an assertion.

So, if you see here under m unit tools assert that there is an assert that I will just drag and drop assert that I read an expression is and the message right. So who I want to assert that the payload, I want to assert the payload so I write hash a lot easier is actually m unit tools are having a lot of operations. So, if I want to use anything, how to use hash, young unit tools colon and I'll press Ctrl Space c these are the operations which are available in M unit tools. I can use it in my dw L. So m unit colon colon, they can use any of the function equal to I can use equals to, I just paste this response on Scorpio underscore one. So this one I must setting amyl tolls equals to EZ Pass underscore filter underscore one The reason I just save it.

Actually, if we just come back here and check, there's not an error actually, if we save it there, our method is gone. And here I'll write a message. If this assertion fails, I'll say just try to error My payload is not as expected. Okay, now I will run this run em unit. So let's observe actually for Alina, so do you want the mid server run? Is profit and run em unit suit.

So let's wait. Yep. mld starting that application internally you just have to wait On the left side, you can observe the only one cases. And you should observe that this succeeded because our session is success. Now, all I know is that it just to just make less failure, I'll try to assert that the expected value is something else other than the size. As I said to this one, now run the test again.

Running this so there's only one case again, X sub so what will be the result of this execution? Hmm. Can I expect the test to fail? Yes, the test failed. And you can see here The reason actually when I will click if I click on it if I click on this maximize, I'll maximize this window. Yep.

You're if I click on this one, the assertion error is displayed. payload is not expected expected response on score, but it was response on score failed and score one. So yeah, as expected the assertion failed assertion fraud and error right. So now we have written a simple test case one test case. Let us see A test case. Now we want to write another test case where I want to verify actually, that supply one is called Actually, we can see after I run my test case, you can see tick marks, the control went into this one, right.

So here, it went to this one, this one, this one and so once you're on the testicles to show him that Okay, now, what I want to do is I want to make sure that sub flow one is called whenever I invoke main flow, I want to validate that sub flow one is called. So I can write one more case for the scenario. I can directly call the same flow m unit, create and save it first. I'll close and open ones okay. Now what I want to do is I'll right click on this m unit demo flow. Right click and create new.

Yeah. So again, you can see that in the same XML, one more case has been added. Now, here also I want to set an event with same values. So I'll drag and drop. In m unit, I can drag and drop set event. And what is event I want to configure attributes just like earlier.

Go to XML and check. Oh an XML again. It's Like this I will paste the actual value whatever I want to paste Okay, I'll set an attribute. Now I want to verify a call to sub flow. So, what I can do is I can drag and drop verify call I want to verify on. So, in the validation drag and drop a call to what to which processor you want to verify a call to which processor Actually, I want to verify a call went into sub flow right.

Am I calling? If I want to verify that the call went is of law I need to verify that the call went to this floor FM's whose name is supply one is it sexually section if you cannot verify a call to the flow we can verify a call to flow reference That means the half was called right. So, I want to verify a call to processor whose tag name is new column. flawed as ref. I want to verify a call to which processor, a processor whose tag name is meal, column, flow dash. And with what attributes I want to add in when there is an attribute, name, name and it's valueless sub flow one.

I want to actually validate that the call went to a processor with this tag name and an attribute name whose name is whose values suffer one is it Yes, see his actual file I want to make sure that the call goes to this flow calm graph, where name values sub flow one name is an attribute and its value sub flow one. So I configured with a call and let me run this suit. Actually, there are two cases right now. First case should fail because I intentionally made it to a set wrongly. Second one is a very free quality pass. Hmm, yes, you can see that.

Oh the first one and Second one assertion payload but first we're not saying that error message is saying you call the function Oh, the mistake good good to do the mistake actually index Amal. I should wrap this insert the hash square back at night I want it to be evaluated right. So good. Hash runs decorated Okay. So now I should be able to run it again and, and I'll change these assert also assert that again as expected. So then both of them will pass.

Hello sir, exactly. Okay, now if I run both cases should pass Yep, let us see here actually Again this failed we can check expected one what got three calls? Three days expected one call. got three way maybe you didn't do something wrong. Oh, your times I should have given one. Oh, here this was not saved I guess it inline.

This was not saved sometimes there's a problem with stereo. I'll give the name as what Name and value is sub flow one. So sometimes is the problem in studio, even though we write it here, sometimes it might not have been saved. So make sure that you go here and verify in the XML whether it is written or not. Yep, now it is here. I think this was gone.

Number of times is one. Okay, now, if I run I hope this should run successfully right now. I'm running it again. Yep. The two test cases passed. Right?

Is it? Yeah, so you're able to verify that call. There are a lot of other features of a minute. I will see you next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.