Exemplo n.º 1
0
        public void TestQueryByObjectId()
        {
            var sessionKey = Join();

            //SSAP con insert
            SSAPResource ssapInsert = new SSAPResource()
            {
                Data       = ONTOLOGY_INSTANCE,
                SessionKey = sessionKey,
                Ontology   = ONTOLOGY_NAME
            };
            var respInsert = _api.Insert(ssapInsert);

            respInsert.Wait();
            Trace.WriteLine("Codigo HTTP retorno INSERT: " + respInsert.Result.StatusCode.ToString());
            Assert.AreEqual(respInsert.Result.StatusCode, System.Net.HttpStatusCode.OK);

            string objectId = null;

            try
            {
                var respSSAP = _api.ResponseAsSSAP(respInsert.Result);
                respSSAP.Wait();
                objectId = respSSAP.Result.Data.ToString();
                //Trace.WriteLine("Instancia de la ontologia insertada en BDTR: " + respSSAP);
                Trace.WriteLine("Instancia de la ontologia insertada en BDTR: " + objectId);
            }
            catch (Exception ex)
            {
                Trace.Fail(ex.Message, ex.StackTrace);
                Assert.Fail(ex.Message);
            }

            if (!String.IsNullOrEmpty(objectId))
            {
                string objId = JObject.Parse(objectId.Trim())["_id"]["$oid"].Value <String>();

                var respQuery = this._api.Query(objId, sessionKey, ONTOLOGY_NAME);
                respQuery.Wait();

                Trace.WriteLine("Codigo HTTP retorno Query: " + respQuery.Result.StatusCode.ToString());
                Assert.AreEqual(respQuery.Result.StatusCode, System.Net.HttpStatusCode.OK);
                try
                {
                    var respSSAP = _api.ResponseAsSSAP(respQuery.Result);
                    respSSAP.Wait();
                    Trace.WriteLine("Respuesta de la Query: " + respSSAP.Result.Data);
                }
                catch (Exception ex)
                {
                    Trace.Fail(ex.Message, ex.StackTrace);
                    Assert.Fail(ex.Message);
                }
            }
            Leave(sessionKey);
        }
Exemplo n.º 2
0
        public void TestInsertUpdate()
        {
            var sessionKey = Join();

            //SSAP con insert
            SSAPResource ssapInsert = new SSAPResource()
            {
                Data       = ONTOLOGY_INSTANCE,
                SessionKey = sessionKey,
                Ontology   = ONTOLOGY_NAME
            };
            var respInsert = _api.Insert(ssapInsert);

            respInsert.Wait();
            Trace.WriteLine("Codigo HTTP retorno INSERT: " + respInsert.Result.StatusCode.ToString());
            Assert.AreEqual(respInsert.Result.StatusCode, System.Net.HttpStatusCode.OK);

            string objectId = null;

            try
            {
                var respSSAP = _api.ResponseAsSSAP(respInsert.Result);
                respSSAP.Wait();
                objectId = respSSAP.Result.Data.ToString();
                Trace.WriteLine("Instancia de la ontologia insertada en BDTR: " + objectId);
            }
            catch (Exception ex)
            {
                Trace.Fail(ex.Message, ex.StackTrace);
                Assert.Fail(ex.Message);
            }

            //Actualización del objeto que se acaba de insertar con UPDATE
            if (!String.IsNullOrEmpty(objectId))
            {
                string objId      = JObject.Parse(objectId.Trim())["_id"]["$oid"].Value <String>();
                string updateData = ONTOLOGY_UPDATE.Replace("{oid}", objId);

                //SSAP con Update
                SSAPResource ssapUpdate = new SSAPResource()
                {
                    SessionKey = sessionKey,
                    Ontology   = ONTOLOGY_NAME,
                    Data       = updateData
                };
                var respUpdate = _api.Update(ssapUpdate);
                respUpdate.Wait();
                Trace.WriteLine("Codigo HTTP retorno UPDATE: " + respUpdate.Result.StatusCode.ToString());
                Assert.AreEqual(respUpdate.Result.StatusCode, System.Net.HttpStatusCode.OK);
            }
            if (!String.IsNullOrEmpty(sessionKey))
            {
                Leave(sessionKey);
            }
        }
Exemplo n.º 3
0
        public void TestInsertSQLLIKEStatement()
        {
            var sessionKey = Join();

            //SSAP con insert
            SSAPResource ssapInsert = new SSAPResource()
            {
                Data       = ONTOLOGY_INSTANCE,
                SessionKey = sessionKey,
                Ontology   = ONTOLOGY_NAME
            };
            var respInsert = _api.Insert(ssapInsert);

            respInsert.Wait();
            Trace.WriteLine("Codigo HTTP retorno INSERT: " + respInsert.Result.StatusCode.ToString());
            Assert.AreEqual(respInsert.Result.StatusCode, System.Net.HttpStatusCode.OK);

            string objectId = null;

            try
            {
                var respSSAP = _api.ResponseAsSSAP(respInsert.Result);
                respSSAP.Wait();
                objectId = respSSAP.Result.Data.ToString();
                Trace.WriteLine("Instancia de la ontologia insertada en BDTR: " + objectId);
            }
            catch (Exception ex)
            {
                Trace.Fail(ex.Message, ex.StackTrace);
                Assert.Fail(ex.Message);
            }

            if (String.IsNullOrEmpty(objectId))
            {
                var respQuery = this._api.Query(sessionKey, ONTOLOGY_NAME, ONTOLOGY_INSERT_SQLLIKE, null, "SQLLIKE");
                respQuery.Wait();

                Trace.WriteLine("Codigo HTTP retorno INSERT SQL: " + respQuery.Result.StatusCode.ToString());
                Assert.AreEqual(respInsert.Result.StatusCode, System.Net.HttpStatusCode.OK);
                try
                {
                    var respSSAP = _api.ResponseAsSSAP(respQuery.Result);
                    respSSAP.Wait();
                    Trace.WriteLine("Respuesta del Insert: " + respSSAP.Result.Data);
                }
                catch (Exception ex)
                {
                    Trace.Fail(ex.Message, ex.StackTrace);
                    Assert.Fail(ex.Message);
                }
            }
            Leave(sessionKey);
        }
Exemplo n.º 4
0
        public async Task <SSAPResource> ResponseAsSSAP(HttpResponseMessage resp)
        {
            if (resp.IsSuccessStatusCode)
            {
                SSAPResource ssap = await resp.Content.ReadAsAsync <SSAPResource>();

                return(ssap);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
 private void Leave(string sessionKey)
 {
     if (!String.IsNullOrEmpty(sessionKey))
     {
         SSAPResource ssapLeave = new SSAPResource()
         {
             Leave      = true,
             SessionKey = sessionKey
         };
         var respLeave = _api.Insert(ssapLeave);
         respLeave.Wait();
         Assert.AreEqual(respLeave.Result.StatusCode, System.Net.HttpStatusCode.OK);
     }
 }
Exemplo n.º 6
0
        public async Task <HttpResponseMessage> Update(SSAPResource ssap)
        {
            using (var client = new HttpClient())
            {
                //client config
                client.BaseAddress = new Uri(_serviceBaseUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(STR_APPLICATION_HEADER));

                //Update URI
                UriBuilder builder = new UriBuilder(_serviceBaseUrl + STR_PATH);

                return(await client.PutAsJsonAsync <SSAPResource>(builder.ToString(), ssap));
            }
        }
Exemplo n.º 7
0
        public void TestInsertBulk()
        {
            var sessionKey = Join();

            //SSAP con insert
            var msgBulk = new List <String>();

            msgBulk.Add(ONTOLOGY_INSTANCE);
            msgBulk.Add(ONTOLOGY_INSTANCE);
            msgBulk.Add(ONTOLOGY_INSTANCE);

            SSAPResource ssapInsert = new SSAPResource()
            {
                Data       = SerializationHelper <List <String> > .ToJson(msgBulk),
                SessionKey = sessionKey,
                Ontology   = ONTOLOGY_NAME
            };
            var respInsert = _api.Insert(ssapInsert);

            respInsert.Wait();
            Trace.WriteLine("Codigo HTTP retorno INSERT: " + respInsert.Result.StatusCode.ToString());
            Assert.AreEqual(respInsert.Result.StatusCode, System.Net.HttpStatusCode.OK);

            string objectId = null;

            try
            {
                var respSSAP = _api.ResponseAsSSAP(respInsert.Result);
                respSSAP.Wait();
                objectId = respSSAP.Result.Data.ToString();
                Trace.WriteLine("Instancia de la ontologia insertada en BDTR: " + objectId);
            }
            catch (Exception ex)
            {
                Trace.Fail(ex.Message, ex.StackTrace);
                Assert.Fail(ex.Message);
            }

            if (!String.IsNullOrEmpty(sessionKey))
            {
                Leave(sessionKey);
            }
        }
Exemplo n.º 8
0
        private string Join()
        {
            //Genera un recurso SSAP con un JOIN
            SSAPResource ssapJoin = new SSAPResource()
            {
                Join       = true,
                InstanceKP = KP_INSTANCE,
                Token      = TOKEN
            };

            //Hace un POST del recurso, equivalente a una petición SSAP JOIN
            SetUpClass();
            var respJoin = _api.Insert(ssapJoin);

            respJoin.Wait();

            Trace.WriteLine(String.Format("Código HTTP retorno Join: {0}", respJoin.GetAwaiter().GetResult().StatusCode.ToString()));
            string sessionKey = null;

            try
            {
                var respSsap = _api.ResponseAsSSAP(respJoin.Result);
                respJoin.Wait();
                sessionKey = respSsap.Result.SessionKey;
                Trace.WriteLine(String.Format("SessionKey: {0}", sessionKey));

                Assert.AreEqual(respJoin.Result.StatusCode, System.Net.HttpStatusCode.OK);
                return(sessionKey);
            }
            catch (Exception ex)
            {
                Trace.Fail(ex.Message, ex.StackTrace);
                Assert.Fail(ex.Message);
                throw ex;
            }
        }
Exemplo n.º 9
0
 public async Task <HttpResponseMessage> Delete(SSAPResource ssap)
 {
     return(await DeleteOid(ssap.Data.ToString(), ssap.SessionKey, ssap.Ontology));
 }