Search in sources :

Example 6 with API

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);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 7 with API

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);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 8 with API

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);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 9 with API

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);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 10 with API

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());
}
Also used : TokenInfo(org.wso2.carbon.apimgt.rest.integration.tests.util.TokenInfo) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)582 ArrayList (java.util.ArrayList)374 API (org.wso2.carbon.apimgt.core.models.API)359 Test (org.testng.annotations.Test)350 HashMap (java.util.HashMap)318 Test (org.junit.Test)316 API (org.wso2.carbon.apimgt.api.model.API)307 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)255 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)253 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)234 SQLException (java.sql.SQLException)190 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)186 IOException (java.io.IOException)181 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)179 PreparedStatement (java.sql.PreparedStatement)169 Connection (java.sql.Connection)158 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)154 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)149 JSONObject (org.json.simple.JSONObject)142 Resource (org.wso2.carbon.registry.core.Resource)139