Is ternary operator available in stibo MDM? - master-data-management

I'm new to Stibo MDM. For some requirement i'm writing javascript to check the condition (Business Condition) and this condition will return true/false. I want to generate logger message for both true and false value. I have used ternary operator for this but getting syntax error i.e ? and : is not recognizing.
How can i use this operator in stibo MDM
Thanks in advance

You should be able to use the ternary operator just as you would elsewhere for JavaScript. STEP uses the Mozilla JavaScript engine so pretty much anything that's valid there should work.
As an example, this definitely works:
var testVal = "a";
var isA = testVal == "a" ? true : false; // Result is true

Related

Server side validation library for Kotlin

Can anyone please suggest me good server side validation library for kotlin.
Which can perform basic validation like below
Checking for spaces and new line in a string
Checking the minimum and maximum of character in a string
Checking empty string
As I need to use a validation library instead of below code
val data.name = "test test"
val nameMaxLimit: Int = 256
if (data.name.contains(" ") || data.name.isNullOrEmpty() || data.name.length > nameMaxLimit) {
return true
}
My project is a Gradle Project, So gradle supported validation library will be blessed
You can use beans validation. I think it is the best way.
You would need to annotate each field with the rules you want.
Then you would tell the validations to run.
It would return to you an array of violations.
Here an example:
import javax.validation.Validator
val violations = validator.validate(data)
if (violations.isEmpty()) {
successAction()
}

Comparing entire url through Assert.assertEquals

I want to compare the url and print, so I have used the below code. But it was comparing the whole url like as below
Actual comparison done for the below url :
https://accounts.google.com/signin/v2/identifier?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&scc=1&ltmpl=default&ltmplcache=
Code I have used :
String URL = driver.getCurrentUrl();
Assert.assertEquals(URL, "https://accounts.google.com" );
System.out.println(URL);
Solution needed:
I want compare only the 'https://accounts.google.com'
Please help me out to solve this issue
When you access the url https://accounts.google.com the url is set as :
https://accounts.google.com/signin/v2/identifier?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&scc=1&ltmpl=default&ltmplcache=
This url is dynamic in nature. So you won't be able to use assertEquals() as :
assertEquals() is defined as :
void org.testng.Assert.assertEquals(String actual, String expected)
Asserts that two Strings are equal. If they are not, an AssertionError is thrown.
Parameters:
actual the actual value
expected the expected value
So assertEquals() will validate if two Strings are identical. Hence you see the error.
Solution
To assert the presence of https://accounts.google.com within the current url you can use the function Assert.assertTrue() as follows :
String URL = driver.getCurrentUrl();
Assert.assertTrue(URL.contains("https://accounts.google.com"));
System.out.println(URL);
Explanation
assertTrue() is defined as :
void org.testng.Assert.assertTrue(boolean condition)
Asserts that a condition is true. If it isn't, an AssertionError is thrown.
Parameters:
condition the condition to evaluate
In your case, you should not use 'assertEquals' instead use 'assertTrue'
Assert.assertTrue(URL.startsWith("https://accounts.google.com"));
I have used below code and it working fine for me
String URL = driver.getCurrentUrl();
if(URL.contains("url name"))
{
System.out.println("Landed in correct URL" +
"" + URL);
}else
{
System.out.println("Landed in wrong URL");
}
If You want to remove the Assert.assertTrue and check your url then use this simple technique as below code. AssertEquals, Assertions
Assert.assertTrue(url.equals("https://www.instagram.com/hiteshsingh00/?hl=en"));
can also be written as
Assert.assertEquals(true,url.equals("https://www.instagram.com/hiteshsingh00/?hl=en"));
also assertTrue(x == 2);
assertEquals(2,x);

Is there way in karate to get the assertion status like pass or fail in variable for further processing in java?

In feature file i am writing assertion as
match response contains {token_type: '#string' }
Is there a way to get the output status of the above assertion value like true or false,
so that i can extend that into java for further processing?
The whole point of Karate is to avoid Java, and I don't recommend doing anything else.
But since you insist, if you want to get the equivalent of the above, just do something like this. Yes, you have to use "normal" JS fundas.
* def response = { token_type: 'foo' }
* def isString = typeof(response.token_type) === "string"
* match isString == true

Ability to set the context of the expression

Is there a way to set the context of the expression in Dynamic Expresso library, so that we can do something like the following:
interpreter.Eval("FirstName", new Parameter("person", new { FirstName="Homer", LastName="Simpson"}));
rather than
interpreter.Eval("person.FirstName", new Parameter("person", new { FirstName="Homer", LastName="Simpson"}));
Maybe we could have a another option that would say that the first parameter is to be used as the context for the expression.
I guess there could also be another version of Parse and Eval methods that simply takes the expression text and a simple object value that will serve as the expression context.
Other than that and the lack of support for dynamic types, I am really liking this library. I had worked on something similar, but had not added support for extension methods and generic method calls.
Thanks for the great library,
Neal
There isn't a built-in solution but you can simulate it in many ways:
Option 1: Inject an expression
var workingContext = new { FirstName = "homer" };
var workingContextExpression = Expression.Constant(workingContext);
var firstNameExpression = Expression.Property(workingContextExpression, "FirstName");
var interpreter = new Interpreter();
interpreter.SetExpression("FirstName", firstNameExpression);
Assert.AreEqual(workingContext.FirstName, interpreter.Eval("FirstName"));
Basically I inject an expression using SetExpression method. The injected expression is the property that you want to be available.
Option 2: Use this/me/it variable
You can inject a variable that will contain your working object. I usually call it this (or me or it depending on the application).
var workingContext = new { FirstName = "homer" };
var interpreter = new Interpreter();
interpreter.SetVariable("this", workingContext);
Assert.AreEqual(workingContext.FirstName, interpreter.Eval("this.FirstName"));
Option 3: A combination of the previous solutions
var workingContext = new { FirstName = "homer" };
var interpreter = new Interpreter();
interpreter.SetVariable("this", workingContext);
var firstNameExpression = interpreter.Parse("this.FirstName").LambdaExpression.Body;
interpreter.SetExpression("FirstName", firstNameExpression);
Assert.AreEqual(workingContext.FirstName, interpreter.Eval("FirstName"));
Equal to the first solution but I generate the expression using the parser itself.
Consider that all solutions assume that you must have an Interpreter instance for each context.
Disclaimer: I'm the author of Dynamic Expresso library.
Starting with DynamicExpresso v2.13.0, it's possible to define a variable named "this", that will be used for implicit resolution:
var target = new Interpreter();
target.SetVariable("this", new { FirstName="Homer", LastName="Simpson"});
// 'this' variable is used implicitly
Assert.AreEqual("Homer", target.Eval("FirstName"));
// 'this' variable can also be used explicitly
Assert.AreEqual("Homer", target.Eval("this.FirstName"));

Parsing Expression Tree To Sqlstring - Not Reinventing the wheel

I need to parse an expressiontree to get a sql where clause.
Aren't there any classes in the .NET FX or any third party library which already have this abilities ?
I mean Linq2SQL, EntityFramework , all of them have to do this, so does anyone know, if there is something that can be reused instead of reinventing the wheel?
MyType.Where(Func<TEntity,bool>((entity)=>entity.Id == 5)))
now i need to get the corresponding string representing a where clause:
where abc.Id = "5"
this is just an simple example. it should also work with logical conjunctions.
I know I can create the expressiontree and parse it on my own, but i think there could be something already existing, which I'm missing
You could create an ExpressionVisitor with the sole purpose of finding and processing the where calls. Making this task very easy to handle.
e.g.,
public class WhereCallVisitor : ExpressionVisitor
{
protected override Expression VisitMethodCall(MethodCallExpression node)
{
var method = node.Method;
if (method.Name == "Where" && method.DeclaringType == typeof(Queryable))
{ // we are in a Queryable.Where() call
ProcessWhereCall(node);
}
return base.VisitMethodCall(node);
}
private void ProcessWhereCall(MethodCallExpression whereCall)
{
// extract the predicate expression
var predicateExpr = ((dynamic)whereCall.Arguments[1]).Operand as LambdaExpression;
// do stuff with predicateExpr
}
// p.s., dynamic used here to simplify the extraction
}
Then to use it:
var query = from row in table
where row.Foo == "Bar"
select row.Baz;
var visitor = new WhereCallVisitor();
visitor.Visit(query.Expression);