Search in sources :

Example 6 with Compare

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);
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 7 with Compare

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();
    }
}
Also used : BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) Stack(java.util.Stack) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.ballerinalang.model.Name) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 8 with Compare

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;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangTernaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTernaryExpr) BLangBinaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr)

Example 9 with Compare

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);
}
Also used : ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO)

Example 10 with Compare

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);
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)7 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)7 Application (org.wso2.carbon.apimgt.core.models.Application)7 AttributeFunction (org.wso2.siddhi.query.api.expression.AttributeFunction)3 Variable (org.wso2.siddhi.query.api.expression.Variable)3 And (org.wso2.siddhi.query.api.expression.condition.And)3 Compare (org.wso2.siddhi.query.api.expression.condition.Compare)3 In (org.wso2.siddhi.query.api.expression.condition.In)3 IsNull (org.wso2.siddhi.query.api.expression.condition.IsNull)3 Not (org.wso2.siddhi.query.api.expression.condition.Not)3 Or (org.wso2.siddhi.query.api.expression.condition.Or)3 Constant (org.wso2.siddhi.query.api.expression.constant.Constant)3 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)2 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)2 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)2 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)2 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)2 AbstractDefinition (org.wso2.siddhi.query.api.definition.AbstractDefinition)2