use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project siddhi by wso2.
the class SimpleQueryTestCase method test2.
@Test
public void test2() throws SiddhiParserException {
Query query = SiddhiCompiler.parseQuery("from StockStream [price >= 20]#window.lengthBatch(50) " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "having avgPrice>50 " + "insert into StockQuote; ");
AssertJUnit.assertNotNull(query);
Query api = Query.query().from(InputStream.stream("StockStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20))).window("lengthBatch", Expression.value(50))).select(Selector.selector().select(Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price"))).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.variable("avgPrice"), Compare.Operator.GREATER_THAN, Expression.value(50)))).insertInto("StockQuote");
AssertJUnit.assertEquals(api, query);
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project siddhi by wso2.
the class SimpleQueryTestCase method testCreatingNestedFilterQuery.
// from (from StockStream[win.length(50)][ price >= 20]
// return symbol, avg(price) as avgPrice
// group by symbol) [symbol=="IBM"]
// insert into IBMOutStockStream symbol, avgPrice
@Test
public void testCreatingNestedFilterQuery() {
Query query1 = SiddhiCompiler.parseQuery("from from StockStream[StockStream.price >= 20][ StockStream.price " + "is null] " + "select symbol, avg(price) as avgPrice " + "return " + "select symbol, avgPrice " + "insert into OutStockStream ;");
AssertJUnit.assertNotNull(query1);
Query query2 = SiddhiCompiler.parseQuery("from ( from StockStream[StockStream.price >= 20][ StockStream" + ".price is null] " + "select symbol, avg(price) as avgPrice " + "return ) " + "select symbol, avgPrice " + "insert into OutStockStream ;");
AssertJUnit.assertNotNull(query2);
Query api = Query.query();
api.from(InputStream.stream(Query.query().from(InputStream.stream("StockStream").filter(Expression.compare(Expression.variable("price").ofStream("StockStream"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20))).filter(Expression.isNull(Expression.variable("price").ofStream("StockStream")))).select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price")))).returns()));
api.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.variable("avgPrice")));
api.insertInto("OutStockStream");
AssertJUnit.assertEquals(api, query1);
AssertJUnit.assertEquals(api, query2);
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project siddhi by wso2.
the class SimpleQueryTestCase method test5.
@Test
public void test5() throws SiddhiParserException {
Query query = SiddhiCompiler.parseQuery("from AllStockQuotes[price==Foo.price and Foo.try<5] " + "select symbol, avg(price) as avgPrice " + "return ;");
AssertJUnit.assertNotNull(query);
Query api = Query.query().from(InputStream.stream("AllStockQuotes").filter(Expression.and(Expression.compare(Expression.variable("price"), Compare.Operator.EQUAL, Expression.variable("price").ofStream("Foo")), Expression.compare(Expression.variable("try").ofStream("Foo"), Compare.Operator.LESS_THAN, Expression.value(5))))).select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price"))));
AssertJUnit.assertEquals(api, query);
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project siddhi by wso2.
the class SimpleQueryTestCase method test3.
@Test
public void test3() throws SiddhiParserException {
Query query = SiddhiCompiler.parseQuery("from AllStockQuotes#window.time(10 min)\n" + "select symbol as symbol, price, avg(price) as averagePrice \n" + "group by symbol \n" + "having ( price > ( averagePrice*1.02) ) or ( averagePrice > price ) " + "insert into FastMovingStockQuotes \n;");
Query api = Query.query().from(InputStream.stream("AllStockQuotes").window("time", Expression.Time.minute(10))).select(Selector.selector().select("symbol", Expression.variable("symbol")).select(Expression.variable("price")).select("averagePrice", Expression.function("avg", Expression.variable("price"))).groupBy(Expression.variable("symbol")).having(Expression.or(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.multiply(Expression.variable("averagePrice"), Expression.value(1.02))), Expression.compare(Expression.variable("averagePrice"), Compare.Operator.GREATER_THAN, Expression.variable("price"))))).insertInto("FastMovingStockQuotes");
AssertJUnit.assertEquals(api, query);
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project product-apim by wso2.
the class APIMgtBaseIntegrationIT method init.
@BeforeClass
public void init() throws AMIntegrationTestException {
TokenInfo tokenInfo = TestUtil.getToken("admin", "admin");
apiPublisherClient = new ApiClient(TestUtil.OAUTH2_SECURITY).setBasePath("https://" + TestUtil.getIpAddressOfContainer() + ":9443/api/am/publisher/v1.0");
apiPublisherClient.setAccessToken(tokenInfo.getToken(), tokenInfo.getExpiryTime());
apiStoreClient = new org.wso2.carbon.apimgt.rest.integration.tests.store.ApiClient(TestUtil.OAUTH2_SECURITY).setBasePath("https://" + TestUtil.getIpAddressOfContainer() + ":9443/api/am/store/v1.0");
apiStoreClient.setAccessToken(tokenInfo.getToken(), tokenInfo.getExpiryTime());
apiAdminClient = new org.wso2.carbon.apimgt.rest.integration.tests.admin.ApiClient(TestUtil.OAUTH2_SECURITY).setBasePath("https://" + TestUtil.getIpAddressOfContainer() + ":9443/api/am/admin/v1.0");
apiAdminClient.setAccessToken(tokenInfo.getToken(), tokenInfo.getExpiryTime());
}
Aggregations