Пример #1
0
class TestConfig(unittest.TestCase):
    
    KP = "KPTestTemperatura"
    INSTANCE = "KPTestTemperatura01"
    TOKEN = "e5e8a005d0a248f1ad2cd60a821e6838"
    ASSET_SERVICE_PARAMS = {}
    ASSET_SERVICE = "testConfig"

    def setUp(self):
        self.__serverURL = 'ws://sofia2.com/sib/api_websocket'        
        self.__callback = TestCallback()
        self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(self.__serverURL, self.__callback, True)
        
    def tearDown(self):
        pass

    def testConfig(self):        
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.config(TestConfig.KP, TestConfig.INSTANCE, TestConfig.TOKEN, TestConfig.ASSET_SERVICE, TestConfig.ASSET_SERVICE_PARAMS)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
Пример #2
0
 def setUp(self):
     self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
     self.__callback = TestCallback()
     self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(
         self.__serverURL, self.__callback, True)
Пример #3
0
class TestJoinsAndLeaves(unittest.TestCase):

    TOKEN = "3f8d3638215a4d59ad5cffad19c81379"
    INSTANCE = "KPTestTemperatura:KPTestTemperatura01"

    def setUp(self):
        self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
        self.__callback = TestCallback()
        self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(
            self.__serverURL, self.__callback, True)

    def tearDown(self):
        pass

    def testSuccessfulJoinAndLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestJoinsAndLeaves.TOKEN,
                                      TestJoinsAndLeaves.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testUnsuccessfulJoin(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken("token inválido",
                                      TestJoinsAndLeaves.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())

    def testInvalidLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.assertRaises(InvalidSSAPOperation, self.__endpoint.leave)

    def testRenovateSessionKey(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestJoinsAndLeaves.TOKEN,
                                      TestJoinsAndLeaves.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.renovateSessionKey()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
Пример #4
0
 def setUp(self):
     self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
     self.__callback = TestCallback(True)
     self.__doJoin()
Пример #5
0
class TestQueries(unittest.TestCase):
    
    ONTOLOGY = "TestSensorTemperatura"
    TOKEN = "e5e8a005d0a248f1ad2cd60a821e6838"
    INSTANCE = "KPTestTemperatura:KPTestTemperatura01"
    SQLLIKE_QUERY = "SELECT * FROM TestSensorTemperatura LIMIT 10"    
    NATIVE_QUERY = "db.TestSensorTemperatura.find().limit(10)"  
    SIB_DEFINED_QUERY = "MiConsulta"
    SIB_DEFINED_QUERY_WITH_PARAMS = "selectAllWithParam"

    def setUp(self):
        self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
        self.__callback = TestCallback(True)
        self.__doJoin()

    def tearDown(self):
        self.__doLeave()
    
    def buildJsonObject(self):
        jsonObject = {}
        jsonObject["Sensor"] = {}
        jsonObject["Sensor"]["geometry"] = {}
        jsonObject["Sensor"]["geometry"]["coordinates"] = [ 40.512967, -3.67495 ]
        jsonObject["Sensor"]["geometry"]["type"] = "Point"
        jsonObject["Sensor"]["assetId"] = "S_Temperatura_00066"
        jsonObject["Sensor"]["measure"] = 10
        jsonObject["Sensor"]["timestamp"] = {"$date" : "2014-04-29T08:24:54.005Z"}
        return jsonObject
    
    def __doJoin(self):
        self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(self.__serverURL, self.__callback, True)
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestQueries.TOKEN, TestQueries.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
    
    def __doLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        
    def testSuccessfulNativeQuery(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.query(TestQueries.ONTOLOGY, TestQueries.NATIVE_QUERY)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        
    def testUnsuccessfulNativeQuery(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.query(TestQueries.ONTOLOGY, "wrong query")
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
        
    def testSuccessfulSqlLikeQuery(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.query(TestQueries.ONTOLOGY, TestQueries.SQLLIKE_QUERY, SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        
    def testUnsuccessfulSqlLikeQuery(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.query(TestQueries.ONTOLOGY, "", SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
        
    def testSibDefinedQuery(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.query(TestQueries.ONTOLOGY, TestQueries.SIB_DEFINED_QUERY, SSAP_QUERY_TYPE.SIB_DEFINED)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
     
    def testSibDefinedQueryWithParams(self):
        self.__callback.prepareToReceiveSsapResponse()
        queryParams = {}
        queryParams["PARAM1"] = "S_Temperatura_00001"
        self.__endpoint.query(TestQueries.ONTOLOGY, TestQueries.SIB_DEFINED_QUERY_WITH_PARAMS, SSAP_QUERY_TYPE.SIB_DEFINED, queryParams)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())    
Пример #6
0
 def setUp(self):
     self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
     self.__callback = TestCallback()
     self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(self.__serverURL, self.__callback, True)
Пример #7
0
class TestJoinsAndLeaves(unittest.TestCase):
    
    TOKEN = "3f8d3638215a4d59ad5cffad19c81379"
    INSTANCE = "KPTestTemperatura:KPTestTemperatura01"

    def setUp(self):
        self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
        self.__callback = TestCallback()
        self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(self.__serverURL, self.__callback, True)
        
    def tearDown(self):
        pass

    def testSuccessfulJoinAndLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestJoinsAndLeaves.TOKEN, TestJoinsAndLeaves.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
    
    def testUnsuccessfulJoin(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken("token inválido", TestJoinsAndLeaves.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
        
    def testInvalidLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.assertRaises(InvalidSSAPOperation, self.__endpoint.leave) 
        
    def testRenovateSessionKey(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestJoinsAndLeaves.TOKEN, TestJoinsAndLeaves.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.renovateSessionKey()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
Пример #8
0
class TestUpdates(unittest.TestCase):
    
    ONTOLOGY = "TestSensorTemperatura"
    TOKEN = "e5e8a005d0a248f1ad2cd60a821e6838"
    INSTANCE = "KPTestTemperatura:KPTestTemperatura01"
    NATIVE_UPDATE = "{\"Sensor\": { \"geometry\": { \"coordinates\": [ 40.512967, -3.67495 ], \"type\": \"Point\" }, \"assetId\": \"S_Temperatura_00066\", \"measure\": 20, \"timestamp\": { \"$date\": \"2014-04-29T08:24:54.005Z\"}}}"
    NATIVE_UPDATE_QUERY = "{Sensor.assetId:\"S_Temperatura_00066\"}"
    SQLLIKE_UPDATE = "UPDATE TestSensorTemperatura SET TestSensorTemperatura.assetId=\"S_Temperatura_00066\" WHERE TestSensorTemperatura.assetId=\"S_Temperatura_00066\""

    def setUp(self):
        self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
        self.__callback = TestCallback(True)
        self.__doJoin()

    def tearDown(self):
        self.__doLeave()
    
    def buildJsonObject(self):
        jsonObject = {}
        jsonObject["Sensor"] = {}
        jsonObject["Sensor"]["geometry"] = {}
        jsonObject["Sensor"]["geometry"]["coordinates"] = [ 40.512967, -3.67495 ]
        jsonObject["Sensor"]["geometry"]["type"] = "Point"
        jsonObject["Sensor"]["assetId"] = "S_Temperatura_00066"
        jsonObject["Sensor"]["measure"] = 10
        jsonObject["Sensor"]["timestamp"] = {"$date" : "2014-04-29T08:24:54.005Z"}
        return jsonObject
    
    def __doJoin(self):
        self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(self.__serverURL, self.__callback, True)
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestUpdates.TOKEN, TestUpdates.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
    
    def __doLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        
    def testSuccessfulNativeUpdate(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.update(TestUpdates.ONTOLOGY, "", TestUpdates.NATIVE_UPDATE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        
    def testSuccessfulNativeUpdateWithQuery(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.update(TestUpdates.ONTOLOGY, TestUpdates.NATIVE_UPDATE_QUERY, TestUpdates.NATIVE_UPDATE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        
    def testSuccessfulSqlLikeUpdate(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.update(TestUpdates.ONTOLOGY, TestUpdates.SQLLIKE_UPDATE, "", SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        
    def testUnsuccessfulSqlLikeUpdate(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.update(TestUpdates.ONTOLOGY, "", "", SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
Пример #9
0
 def setUp(self):
     self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
     self.__callback = TestCallback(True)
     self.__doJoin()
Пример #10
0
class TestDeletes(unittest.TestCase):

    ONTOLOGY = "TestSensorTemperatura"
    TOKEN = "e5e8a005d0a248f1ad2cd60a821e6838"
    INSTANCE = "KPTestTemperatura:KPTestTemperatura01"
    SQLLIKE_DELETE = "DELETE FROM TestSensorTemperatura WHERE assetId='S_Temperatura_00066'"
    NATIVE_DELETE = "db.TestSensorTemperatura.remove({'assetId': 'S_Temperatura_00066'})"

    def setUp(self):
        self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
        self.__callback = TestCallback(True)
        self.__doJoin()

    def tearDown(self):
        self.__doLeave()

    def buildJsonObject(self):
        jsonObject = {}
        jsonObject["Sensor"] = {}
        jsonObject["Sensor"]["geometry"] = {}
        jsonObject["Sensor"]["geometry"]["coordinates"] = [40.512967, -3.67495]
        jsonObject["Sensor"]["geometry"]["type"] = "Point"
        jsonObject["Sensor"]["assetId"] = "S_Temperatura_00066"
        jsonObject["Sensor"]["measure"] = 10
        jsonObject["Sensor"]["timestamp"] = {
            "$date": "2014-04-29T08:24:54.005Z"
        }
        return jsonObject

    def __doJoin(self):
        self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(
            self.__serverURL, self.__callback, True)
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestDeletes.TOKEN, TestDeletes.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def __doLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testSuccessfulNativeDelete(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.delete(TestDeletes.ONTOLOGY, TestDeletes.NATIVE_DELETE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testUnsuccessfulNativeDelete(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.delete(TestDeletes.ONTOLOGY, "")
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())

    def testSuccessfulSqlLikeDelete(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.delete(TestDeletes.ONTOLOGY,
                               TestDeletes.SQLLIKE_DELETE,
                               SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testUnsuccessfulSqlLikeDelete(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.delete(TestDeletes.ONTOLOGY, "",
                               SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
Пример #11
0
class TestSubscribes(unittest.TestCase):
    
    ONTOLOGY = "TestSensorTemperatura"
    TOKEN = "e5e8a005d0a248f1ad2cd60a821e6838"
    INSTANCE = "KPTestTemperatura:KPTestTemperatura01"
    SQLLIKE_SUBSCRIBE = "SELECT * FROM TestSensorTemperatura WHERE TestSensorTemperatura.assetId = \"S_Temperatura_00066\""
    NATIVE_SUBSCRIBE = "db.TestSensorTemperatura.find()"
    CEP_RULE = "API_CEP_EVENTS"
    
    def setUp(self):
        self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
        self.__callback = TestCallback(True)
        self.__doJoin()

    def tearDown(self):
        self.__doLeave()
    
    def buildJsonObject(self):
        jsonObject = {}
        jsonObject["Sensor"] = {}
        jsonObject["Sensor"]["geometry"] = {}
        jsonObject["Sensor"]["geometry"]["coordinates"] = [ 40.512967, -3.67495 ]
        jsonObject["Sensor"]["geometry"]["type"] = "Point"
        jsonObject["Sensor"]["assetId"] = "S_Temperatura_00066"
        jsonObject["Sensor"]["measure"] = 10
        jsonObject["Sensor"]["timestamp"] = {"$date" : "2014-04-29T08:24:54.005Z"}
        return jsonObject
    
    def __doJoin(self):
        self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(self.__serverURL, self.__callback, True)
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestSubscribes.TOKEN, TestSubscribes.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
    
    def __doLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        
    def testSuccessfulNativeSubscribeUnsubscribe(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.subscribe(TestSubscribes.ONTOLOGY, TestSubscribes.NATIVE_SUBSCRIBE, SSAP_QUERY_TYPE.NATIVE, 100)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.unsubscribe(self.__callback.getSubscriptionId())
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
          
    def testUnsuccessfulNativeSubscribeUnsubscribe(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.subscribe(TestSubscribes.ONTOLOGY, "wrong query", SSAP_QUERY_TYPE.NATIVE, 100)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
         
    def testIndication(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.subscribe(TestSubscribes.ONTOLOGY, TestSubscribes.NATIVE_SUBSCRIBE, SSAP_QUERY_TYPE.NATIVE, 100)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.insert(TestSubscribes.ONTOLOGY, self.buildJsonObject())
        self.__callback.waitForSsapIndication()
        self.assertTrue(self.__callback.wasIndicationReceived())
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.unsubscribe(self.__callback.getSubscriptionId())
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
  
    def testSuccessfulSqlLikeSubscribeUnsubscribe(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.subscribe(TestSubscribes.ONTOLOGY, TestSubscribes.SQLLIKE_SUBSCRIBE, SSAP_QUERY_TYPE.SQLLIKE, 100)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.unsubscribe(self.__callback.getSubscriptionId())
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
           
    def testUnsuccessfulSqlLikeSubscribeUnsubscribe(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.subscribe(TestSubscribes.ONTOLOGY, "wrong query", SSAP_QUERY_TYPE.SQLLIKE, 100)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
Пример #12
0
class TestUpdates(unittest.TestCase):

    ONTOLOGY = "TestSensorTemperatura"
    TOKEN = "e5e8a005d0a248f1ad2cd60a821e6838"
    INSTANCE = "KPTestTemperatura:KPTestTemperatura01"
    NATIVE_UPDATE = "{\"Sensor\": { \"geometry\": { \"coordinates\": [ 40.512967, -3.67495 ], \"type\": \"Point\" }, \"assetId\": \"S_Temperatura_00066\", \"measure\": 20, \"timestamp\": { \"$date\": \"2014-04-29T08:24:54.005Z\"}}}"
    NATIVE_UPDATE_QUERY = "{Sensor.assetId:\"S_Temperatura_00066\"}"
    SQLLIKE_UPDATE = "UPDATE TestSensorTemperatura SET TestSensorTemperatura.assetId=\"S_Temperatura_00066\" WHERE TestSensorTemperatura.assetId=\"S_Temperatura_00066\""

    def setUp(self):
        self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
        self.__callback = TestCallback(True)
        self.__doJoin()

    def tearDown(self):
        self.__doLeave()

    def buildJsonObject(self):
        jsonObject = {}
        jsonObject["Sensor"] = {}
        jsonObject["Sensor"]["geometry"] = {}
        jsonObject["Sensor"]["geometry"]["coordinates"] = [40.512967, -3.67495]
        jsonObject["Sensor"]["geometry"]["type"] = "Point"
        jsonObject["Sensor"]["assetId"] = "S_Temperatura_00066"
        jsonObject["Sensor"]["measure"] = 10
        jsonObject["Sensor"]["timestamp"] = {
            "$date": "2014-04-29T08:24:54.005Z"
        }
        return jsonObject

    def __doJoin(self):
        self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(
            self.__serverURL, self.__callback, True)
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestUpdates.TOKEN, TestUpdates.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def __doLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testSuccessfulNativeUpdate(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.update(TestUpdates.ONTOLOGY, "",
                               TestUpdates.NATIVE_UPDATE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testSuccessfulNativeUpdateWithQuery(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.update(TestUpdates.ONTOLOGY,
                               TestUpdates.NATIVE_UPDATE_QUERY,
                               TestUpdates.NATIVE_UPDATE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testSuccessfulSqlLikeUpdate(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.update(TestUpdates.ONTOLOGY,
                               TestUpdates.SQLLIKE_UPDATE, "",
                               SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testUnsuccessfulSqlLikeUpdate(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.update(TestUpdates.ONTOLOGY, "", "",
                               SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
Пример #13
0
class TestInserts(unittest.TestCase):
    
    ONTOLOGY = "TestSensorTemperatura"
    TOKEN = "e5e8a005d0a248f1ad2cd60a821e6838"
    INSTANCE = "KPTestTemperatura:KPTestTemperatura01"
    ONTOLOGY_INSERT_SQLLIKE = "INSERT INTO TestSensorTemperatura(geometry, assetId, measure, timestamp) values (\"{ 'coordinates': [ 40.512967, -3.67495 ], 'type': 'Point' }\", \"S_Temperatura_00066\", 15, \"{ '$date': '2014-04-29T08:24:54.005Z'}\")";

    def setUp(self):
        self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
        self.__callback = TestCallback(True)
        self.__doJoin()

    def tearDown(self):
        self.__doLeave()
    
    def buildJsonObject(self):
        jsonObject = {}
        jsonObject["Sensor"] = {}
        jsonObject["Sensor"]["geometry"] = {}
        jsonObject["Sensor"]["geometry"]["coordinates"] = [ 40.512967, -3.67495 ]
        jsonObject["Sensor"]["geometry"]["type"] = "Point"
        jsonObject["Sensor"]["assetId"] = "S_Temperatura_00066"
        jsonObject["Sensor"]["measure"] = 10
        jsonObject["Sensor"]["timestamp"] = {"$date" : "2014-04-29T08:24:54.005Z"}
        return jsonObject
    
    def __doJoin(self):
        self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(self.__serverURL, self.__callback, True)
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestInserts.TOKEN, TestInserts.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
    
    def __doLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testSuccessfulNativeInsert(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.insert(TestInserts.ONTOLOGY, self.buildJsonObject())
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        
    def testUnsuccessfulNativeInsert(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.insert(TestInserts.ONTOLOGY, {})
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
        
    def testSuccessfulSqlLikeInsert(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.insert(TestInserts.ONTOLOGY, TestInserts.ONTOLOGY_INSERT_SQLLIKE, SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
    
    def testUnsuccessfulSqlLikeInsert(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.insert(TestInserts.ONTOLOGY, "Insert into foo values ('moo')", SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
Пример #14
0
class TestInserts(unittest.TestCase):

    ONTOLOGY = "TestSensorTemperatura"
    TOKEN = "e5e8a005d0a248f1ad2cd60a821e6838"
    INSTANCE = "KPTestTemperatura:KPTestTemperatura01"
    ONTOLOGY_INSERT_SQLLIKE = "INSERT INTO TestSensorTemperatura(geometry, assetId, measure, timestamp) values (\"{ 'coordinates': [ 40.512967, -3.67495 ], 'type': 'Point' }\", \"S_Temperatura_00066\", 15, \"{ '$date': '2014-04-29T08:24:54.005Z'}\")"

    def setUp(self):
        self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
        self.__callback = TestCallback(True)
        self.__doJoin()

    def tearDown(self):
        self.__doLeave()

    def buildJsonObject(self):
        jsonObject = {}
        jsonObject["Sensor"] = {}
        jsonObject["Sensor"]["geometry"] = {}
        jsonObject["Sensor"]["geometry"]["coordinates"] = [40.512967, -3.67495]
        jsonObject["Sensor"]["geometry"]["type"] = "Point"
        jsonObject["Sensor"]["assetId"] = "S_Temperatura_00066"
        jsonObject["Sensor"]["measure"] = 10
        jsonObject["Sensor"]["timestamp"] = {
            "$date": "2014-04-29T08:24:54.005Z"
        }
        return jsonObject

    def __doJoin(self):
        self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(
            self.__serverURL, self.__callback, True)
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestInserts.TOKEN, TestInserts.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def __doLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testSuccessfulNativeInsert(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.insert(TestInserts.ONTOLOGY, self.buildJsonObject())
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testUnsuccessfulNativeInsert(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.insert(TestInserts.ONTOLOGY, {})
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())

    def testSuccessfulSqlLikeInsert(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.insert(TestInserts.ONTOLOGY,
                               TestInserts.ONTOLOGY_INSERT_SQLLIKE,
                               SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testUnsuccessfulSqlLikeInsert(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.insert(TestInserts.ONTOLOGY,
                               "Insert into foo values ('moo')",
                               SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
Пример #15
0
class TestSubscribes(unittest.TestCase):

    ONTOLOGY = "TestSensorTemperatura"
    TOKEN = "e5e8a005d0a248f1ad2cd60a821e6838"
    INSTANCE = "KPTestTemperatura:KPTestTemperatura01"
    SQLLIKE_SUBSCRIBE = "SELECT * FROM TestSensorTemperatura WHERE TestSensorTemperatura.assetId = \"S_Temperatura_00066\""
    NATIVE_SUBSCRIBE = "db.TestSensorTemperatura.find()"
    CEP_RULE = "API_CEP_EVENTS"

    def setUp(self):
        self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
        self.__callback = TestCallback(True)
        self.__doJoin()

    def tearDown(self):
        self.__doLeave()

    def buildJsonObject(self):
        jsonObject = {}
        jsonObject["Sensor"] = {}
        jsonObject["Sensor"]["geometry"] = {}
        jsonObject["Sensor"]["geometry"]["coordinates"] = [40.512967, -3.67495]
        jsonObject["Sensor"]["geometry"]["type"] = "Point"
        jsonObject["Sensor"]["assetId"] = "S_Temperatura_00066"
        jsonObject["Sensor"]["measure"] = 10
        jsonObject["Sensor"]["timestamp"] = {
            "$date": "2014-04-29T08:24:54.005Z"
        }
        return jsonObject

    def __doJoin(self):
        self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(
            self.__serverURL, self.__callback, True)
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestSubscribes.TOKEN,
                                      TestSubscribes.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def __doLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testSuccessfulNativeSubscribeUnsubscribe(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.subscribe(TestSubscribes.ONTOLOGY,
                                  TestSubscribes.NATIVE_SUBSCRIBE,
                                  SSAP_QUERY_TYPE.NATIVE, 100)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.unsubscribe(self.__callback.getSubscriptionId())
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testUnsuccessfulNativeSubscribeUnsubscribe(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.subscribe(TestSubscribes.ONTOLOGY, "wrong query",
                                  SSAP_QUERY_TYPE.NATIVE, 100)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())

    def testIndication(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.subscribe(TestSubscribes.ONTOLOGY,
                                  TestSubscribes.NATIVE_SUBSCRIBE,
                                  SSAP_QUERY_TYPE.NATIVE, 100)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.insert(TestSubscribes.ONTOLOGY, self.buildJsonObject())
        self.__callback.waitForSsapIndication()
        self.assertTrue(self.__callback.wasIndicationReceived())
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.unsubscribe(self.__callback.getSubscriptionId())
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testSuccessfulSqlLikeSubscribeUnsubscribe(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.subscribe(TestSubscribes.ONTOLOGY,
                                  TestSubscribes.SQLLIKE_SUBSCRIBE,
                                  SSAP_QUERY_TYPE.SQLLIKE, 100)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.unsubscribe(self.__callback.getSubscriptionId())
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())

    def testUnsuccessfulSqlLikeSubscribeUnsubscribe(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.subscribe(TestSubscribes.ONTOLOGY, "wrong query",
                                  SSAP_QUERY_TYPE.SQLLIKE, 100)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())
Пример #16
0
class TestDeletes(unittest.TestCase):
    
    ONTOLOGY = "TestSensorTemperatura"
    TOKEN = "e5e8a005d0a248f1ad2cd60a821e6838"
    INSTANCE = "KPTestTemperatura:KPTestTemperatura01"
    SQLLIKE_DELETE = "DELETE FROM TestSensorTemperatura WHERE assetId='S_Temperatura_00066'";
    NATIVE_DELETE = "db.TestSensorTemperatura.remove({'assetId': 'S_Temperatura_00066'})"

    def setUp(self):
        self.__serverURL = 'ws://sofia2.com/sib/api_websocket'
        self.__callback = TestCallback(True)
        self.__doJoin()

    def tearDown(self):
        self.__doLeave()
    
    def buildJsonObject(self):
        jsonObject = {}
        jsonObject["Sensor"] = {}
        jsonObject["Sensor"]["geometry"] = {}
        jsonObject["Sensor"]["geometry"]["coordinates"] = [ 40.512967, -3.67495 ]
        jsonObject["Sensor"]["geometry"]["type"] = "Point"
        jsonObject["Sensor"]["assetId"] = "S_Temperatura_00066"
        jsonObject["Sensor"]["measure"] = 10
        jsonObject["Sensor"]["timestamp"] = {"$date" : "2014-04-29T08:24:54.005Z"}
        return jsonObject
    
    def __doJoin(self):
        self.__endpoint = SSAPEndpointFactory.buildWebsocketBasedSSAPEndpoint(self.__serverURL, self.__callback, True)
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.joinWithToken(TestDeletes.TOKEN, TestDeletes.INSTANCE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
    
    def __doLeave(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.leave()
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        
    def testSuccessfulNativeDelete(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.delete(TestDeletes.ONTOLOGY, TestDeletes.NATIVE_DELETE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        
    def testUnsuccessfulNativeDelete(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.delete(TestDeletes.ONTOLOGY, "")
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())

    def testSuccessfulSqlLikeDelete(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.delete(TestDeletes.ONTOLOGY, TestDeletes.SQLLIKE_DELETE, SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertTrue(self.__callback.isSsapResponseOk())
        
    def testUnsuccessfulSqlLikeDelete(self):
        self.__callback.prepareToReceiveSsapResponse()
        self.__endpoint.delete(TestDeletes.ONTOLOGY, "", SSAP_QUERY_TYPE.SQLLIKE)
        self.__callback.waitForSsapResponse()
        self.assertFalse(self.__callback.isSsapResponseOk())