use of org.wso2.siddhi.query.api.expression.condition.Compare in project carbon-apimgt by wso2.
the class ApplicationDAOImplIT method testUpdateApplication.
@Test
public void testUpdateApplication() throws Exception {
// add new app
Application currentApp = TestUtil.addTestApplication();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
Application newApp = SampleTestObjectCreator.createAlternativeApplication();
newApp.setId(currentApp.getId());
newApp.setCreatedTime(currentApp.getCreatedTime());
// update app
applicationDAO.updateApplication(currentApp.getId(), newApp);
// get app
Application appFromDB = applicationDAO.getApplication(newApp.getId());
Assert.assertNotNull(appFromDB);
// compare
Assert.assertEquals(appFromDB, newApp, TestUtil.printDiff(appFromDB, newApp));
validateAppTimestamps(appFromDB, newApp);
}
use of org.wso2.siddhi.query.api.expression.condition.Compare in project ballerina by ballerina-lang.
the class CodeGenerator method generateURILookupInstructions.
private void generateURILookupInstructions(Map<Name, BXMLNSSymbol> namespaces, RegIndex localNameRegIndex, RegIndex uriRegIndex, RegIndex targetQNameRegIndex, DiagnosticPos pos, SymbolEnv symbolEnv) {
if (namespaces.isEmpty()) {
createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
return;
}
Stack<Operand> endJumpInstrStack = new Stack<>();
String prefix;
for (Entry<Name, BXMLNSSymbol> keyValues : namespaces.entrySet()) {
prefix = keyValues.getKey().getValue();
// skip the default namespace
if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
continue;
}
// Below section creates the condition to compare the namespace URIs
// store the comparing uri as string
BXMLNSSymbol nsSymbol = keyValues.getValue();
int opcode = getOpcode(TypeTags.STRING, InstructionCodes.IEQ);
RegIndex conditionExprIndex = getRegIndex(TypeTags.BOOLEAN);
emit(opcode, uriRegIndex, getNamespaceURIIndex(nsSymbol, symbolEnv), conditionExprIndex);
Operand ifCondJumpAddr = getOperand(-1);
emit(InstructionCodes.BR_FALSE, conditionExprIndex, ifCondJumpAddr);
// Below section creates instructions to be executed, if the above condition succeeds (then body)
// create the prefix literal
RegIndex prefixIndex = createStringLiteral(prefix, null, env);
// create a qname
emit(InstructionCodes.NEWQNAME, localNameRegIndex, uriRegIndex, prefixIndex, targetQNameRegIndex);
Operand endJumpAddr = getOperand(-1);
emit(InstructionCodes.GOTO, endJumpAddr);
endJumpInstrStack.add(endJumpAddr);
ifCondJumpAddr.value = nextIP();
}
// else part. create a qname with empty prefix
createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
while (!endJumpInstrStack.isEmpty()) {
endJumpInstrStack.pop().value = nextIP();
}
}
use of org.wso2.siddhi.query.api.expression.condition.Compare in project ballerina by ballerina-lang.
the class IterableCodeDesugar method generateCompareAggregator.
/**
* Generates following.
*
* result = result (Operator) value ? result : value
*
* @param blockStmt target
* @param ctx current context
* @param operator compare operator
*/
private void generateCompareAggregator(BLangBlockStmt blockStmt, IterableContext ctx, OperatorKind operator) {
final DiagnosticPos pos = blockStmt.pos;
final BLangSimpleVarRef resultVar = ASTBuilderUtil.createVariableRef(pos, ctx.resultVar.symbol);
final BLangSimpleVarRef valueVar = ASTBuilderUtil.createVariableRef(pos, ctx.iteratorResultVariables.get(0).symbol);
final BLangBinaryExpr compare = (BLangBinaryExpr) TreeBuilder.createBinaryExpressionNode();
compare.pos = pos;
compare.type = symTable.booleanType;
compare.opKind = operator;
compare.lhsExpr = resultVar;
compare.rhsExpr = valueVar;
compare.opSymbol = (BOperatorSymbol) symResolver.resolveBinaryOperator(operator, resultVar.symbol.type, valueVar.symbol.type);
final BLangTernaryExpr ternaryExpr = (BLangTernaryExpr) TreeBuilder.createTernaryExpressionNode();
ternaryExpr.pos = pos;
ternaryExpr.expr = compare;
ternaryExpr.thenExpr = resultVar;
ternaryExpr.elseExpr = valueVar;
ternaryExpr.type = compare.type;
final BLangAssignment countAdd = ASTBuilderUtil.createAssignmentStmt(pos, blockStmt);
countAdd.varRefs.add(resultVar);
countAdd.expr = ternaryExpr;
}
use of org.wso2.siddhi.query.api.expression.condition.Compare in project carbon-apimgt by wso2.
the class ApiDAOImplIT method compareResults.
/**
* Compare the results of attribute search in store
*
* @param userRoles List of the roles of the user.
* @param attributeMap Map containing the attributes to be searched
* @param expectedAPINames List of expected APIs.
* @return true if returned API list has all expected APIs, false otherwise
* @throws APIMgtDAOException if error occurs while accessing data layer
*/
private boolean compareResults(List<String> userRoles, List<String> labels, Map<String, String> attributeMap, String[] expectedAPINames) throws APIMgtDAOException {
ApiDAO apiDAO = DAOFactory.getApiDAO();
List<API> apiList = apiDAO.searchAPIsByAttributeInStore(userRoles, labels, attributeMap, 10, 0);
List<String> resultAPINameList = new ArrayList<>();
for (API api : apiList) {
resultAPINameList.add(api.getName());
}
List<String> expectedAPINameList = Arrays.asList(expectedAPINames);
// check if returned API list has all expected APIs
return resultAPINameList.containsAll(expectedAPINameList) && expectedAPINameList.containsAll(resultAPINameList);
}
use of org.wso2.siddhi.query.api.expression.condition.Compare in project carbon-apimgt by wso2.
the class ApplicationDAOImplIT method testGetApplicationByName.
@Test
public void testGetApplicationByName() throws Exception {
// add app
Application app = TestUtil.addTestApplication();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
// get app by name
Application appFromDB = applicationDAO.getApplicationByName(app.getName(), app.getCreatedUser());
Assert.assertNotNull(appFromDB);
// compare
Assert.assertEquals(appFromDB, app, TestUtil.printDiff(appFromDB, app));
validateAppTimestamps(appFromDB, app);
}
Aggregations