Esempio n. 1
0
        public void Test_CompileSuccess()
        {
            MockApiClient.setAPIResponse(
                new ApiResponse(
                    200,
                    "{\"hash\":\"" + TestData.definition_hash + "\",\"created_at\":\"2011-12-13 14:15:16\",\"dpu\":10}",
                    200, 150));

            Definition def = new Definition(m_user, TestData.definition);

            Assert.AreEqual(TestData.definition, def.get(), "Definition CSDL not set correctly");

            try
            {
                def.compile();
            }
            catch (InvalidDataException e)
            {
                Assert.Fail("InvalidDataException: " + e.Message);
            }
            catch (CompileFailedException e)
            {
                Assert.Fail("CompileFailedException: " + e.Message);
            }
            catch (ApiException e)
            {
                Assert.Fail("ApiException: " + e.Message);
            }

            Assert.AreEqual(200, m_user.getRateLimit(), "Incorrect rate limit");
            Assert.AreEqual(150, m_user.getRateLimitRemaining(), "Incorrect rate limit remaining");
            Assert.AreEqual(TestData.definition_hash, def.getHash(), "Incorrect hash");
            Assert.AreEqual(DateTime.ParseExact("2011-12-13 14:15:16", "yyyy-MM-dd HH:mm:ss", null), def.getCreatedAt(), "Incorrect created at date");
            Assert.AreEqual(10, def.getTotalDpu(), "Incorrect total DPU");
        }
Esempio n. 2
0
        public void Test_CompileFailure()
        {
            MockApiClient.setAPIResponse(
                new ApiResponse(
                    400,
                    "{\"error\":\"The target interactin.content does not exist\"}",
                    200, 150));

            Definition def = new Definition(m_user, TestData.invalid_definition);

            Assert.AreEqual(TestData.invalid_definition, def.get(), "Definition CSDL not set correctly");

            try
            {
                def.compile();
                Assert.Fail("Expected CompileFailedException was not thrown");
            }
            catch (InvalidDataException e)
            {
                Assert.Fail("InvalidDataException: " + e.Message);
            }
            catch (CompileFailedException e)
            {
                Assert.AreEqual("The target interactin.content does not exist", e.Message, "Incorrect compile error message in the CompileFailedException");
            }
            catch (ApiException e)
            {
                Assert.Fail("ApiException: " + e.Message);
            }
        }
Esempio n. 3
0
        public void Test_GetDpuBreakdown()
        {
            MockApiClient.setAPIResponse(
                new ApiResponse(
                    200,
                    "{\"hash\":\"" + TestData.definition_hash + "\",\"created_at\":\"2011-12-13 14:15:16\",\"dpu\":10}",
                    200, 150));

            Definition def = new Definition(m_user, TestData.definition);

            Assert.AreEqual(TestData.definition, def.get(), "Definition CSDL not set correctly");
            Assert.AreEqual(TestData.definition_hash, def.getHash(), "Incorrect hash");

            MockApiClient.setAPIResponse(
                new ApiResponse(
                    200,
                    "{\"detail\":{\"contains\":{\"count\":1,\"dpu\":4,\"targets\":{\"interaction.content\":{\"count\":1,\"dpu\":4}}}},\"dpu\":4}",
                    200, 150));

            Dpu dpu = def.getDpuBreakdown();

            Assert.AreEqual(4, dpu.getTotal(), "The total DPU is incorrect");
            Assert.AreEqual(1, dpu.getDpu().Count, "Incorrect number of detail items");
            Assert.AreEqual(1, dpu.getDpu()["contains"].getCount(), "Incorrect count for contains");
            Assert.AreEqual(4, dpu.getDpu()["contains"].getDpu(), "Incorrect DPU for contains");
            Assert.AreEqual(1, dpu.getDpu()["contains"].getTargets()["interaction.content"].getCount(), "Incorrect count for interaction.content");
            Assert.AreEqual(4, dpu.getDpu()["contains"].getTargets()["interaction.content"].getDpu(), "Incorrect DPU for interaction.content");
        }
Esempio n. 4
0
        public void Test_GetUsage()
        {
            MockApiClient.setAPIResponse(
                new ApiResponse(
                    200,
                    "{\"start\":\"Mon, 07 Nov 2011 10:25:00 +0000\",\"end\":\"Mon, 07 Nov 2011 11:25:00 +0000\",\"streams\":{\"6fd9d61afba0149e0f1d42080ccd9075\":{\"licenses\":{\"twitter\":3},\"seconds\":300}}}",
                    200, 150));

            Usage u = m_user.getUsage("day");

            Assert.AreEqual(DateTime.ParseExact("2011-11-07 10:25:00", "yyyy-MM-dd HH:mm:ss", null), u.getStartDate(), "Usage start date is incorrect");
            Assert.AreEqual(DateTime.ParseExact("2011-11-07 11:25:00", "yyyy-MM-dd HH:mm:ss", null), u.getEndDate(), "Usage end date is incorrect");
            Assert.AreEqual(3, u.getLicenseUsage("6fd9d61afba0149e0f1d42080ccd9075", "twitter"), "Twitter license usage is incorrect");
            Assert.AreEqual(300, u.getSeconds("6fd9d61afba0149e0f1d42080ccd9075"), "Usage seconds is incorrect");
        }
Esempio n. 5
0
        public void Test_RateLimits()
        {
            MockApiClient.setAPIResponse(
                new ApiResponse(
                    200,
                    "{\"hash\":\"" + TestData.definition_hash + "\",\"created_at\":\"2011-12-13 14:15:16\",\"dpu\":10}",
                    200, 150));

            Definition def = m_user.createDefinition(TestData.definition);

            def.compile();

            Assert.AreEqual(200, m_user.getRateLimit(), "Rate limit is incorrect");
            Assert.AreEqual(150, m_user.getRateLimitRemaining(), "Rate limit remaining is incorrect");
        }
Esempio n. 6
0
        public void Test_GetBuffered()
        {
            MockApiClient.setAPIResponse(
                new ApiResponse(
                    200,
                    "{\"hash\":\"" + TestData.definition_hash + "\",\"created_at\":\"2011-12-13 14:15:16\",\"dpu\":10}",
                    200, 150));

            Definition def = new Definition(m_user, TestData.definition);

            Assert.AreEqual(TestData.definition, def.get(), "Definition CSDL not set correctly");
            Assert.AreEqual(TestData.definition_hash, def.getHash(), "Incorrect hash");

            MockApiClient.setAPIResponse(
                new ApiResponse(
                    200,
                    "{\"stream\":[{\"interaction\":{\"source\":\"Snaptu\",\"author\":{\"username\":\"nittolexia\",\"name\":\"nittosoetreznoe\",\"id\":172192091,\"avatar\":\"http://a0.twimg.com/profile_images/1429378181/gendowor_normal.jpg\",\"link\":\"http://twitter.com/nittolexia\"},\"type\":\"twitter\",\"link\":\"http://twitter.com/nittolexia/statuses/89571192838684672\",\"created_at\":\"Sat, 09 Jul 2011 05:46:51 +0000\",\"content\":\"RT @ayyuchadel: Haha RT @nittolexia: Mending gak ush maen twitter dehh..RT @sansan_arie:\",\"id\":\"1e0a9eedc207acc0e074ea8aecb2c5ea\"},\"twitter\":{\"user\":{\"name\":\"nittosoetreznoe\",\"description\":\"f**k all\",\"location\":\"denpasar, bali\",\"statuses_count\":6830,\"followers_count\":88,\"friends_count\":111,\"screen_name\":\"nittolexia\",\"lang\":\"en\",\"time_zone\":\"Alaska\",\"id\":172192091,\"geo_enabled\":true},\"mentions\":[\"ayyuchadel\",\"nittolexia\",\"sansan_arie\"],\"id\":\"89571192838684672\",\"text\":\"RT @ayyuchadel: Haha RT @nittolexia: Mending gak ush maen twitter dehh..RT @sansan_arie:\",\"source\":\"<a href=\\\"http://www.snaptu.com\\\" rel=\\\"nofollow\\\">Snaptu</a>\",\"created_at\":\"Sat, 09 Jul 2011 05:46:51 +0000\"},\"klout\":{\"score\":45,\"network\":55,\"amplification\":17,\"true_reach\":31,\"slope\":0,\"class\":\"Networker\"},\"peerindex\":{\"score\":30},\"language\":{\"tag\":\"da\"}}]}",
                    200, 150));

            Interaction[] interactions = def.getBuffered();
            Assert.AreEqual("nittosoetreznoe", interactions[0].getStringVal("twitter.user.name"), "The Twitter username is incorrect");
            Assert.AreEqual(89571192838684672, interactions[0].getLongVal("twitter.id"), "The Twitter ID is incorrect");
            Assert.AreEqual("http://a0.twimg.com/profile_images/1429378181/gendowor_normal.jpg", interactions[0].getStringVal("interaction.author.avatar"), "The author avatar is incorrect");
        }
Esempio n. 7
0
        public void Test_UsageWithApiErrors()
        {
            try
            {
                MockApiClient.setAPIResponse(
                    new ApiResponse(
                        400,
                        "{\"error\":\"Bad request from user supplied data\"}",
                        200, 150));
                Usage u = m_user.getUsage();
                Assert.Fail("Expected ApiException not thrown");
            }
            catch (ApiException e)
            {
                Assert.AreEqual("Bad request from user supplied data", e.Message, "400 exception messages is not as expected");
            }

            try
            {
                MockApiClient.setAPIResponse(
                    new ApiResponse(
                        401,
                        "{\"error\":\"User banned because they are a very bad person\"}",
                        200, 150));
                Usage u = m_user.getUsage();
                Assert.Fail("Expected ApiException not thrown");
            }
            catch (AccessDeniedException e)
            {
                Assert.AreEqual("User banned because they are a very bad person", e.Message, "401 exception messages is not as expected");
            }

            try
            {
                MockApiClient.setAPIResponse(
                    new ApiResponse(
                        404,
                        "{\"error\":\"Endpoint or data not found\"}",
                        200, 150));
                Usage u = m_user.getUsage();
                Assert.Fail("Expected ApiException not thrown");
            }
            catch (ApiException e)
            {
                Assert.AreEqual("Endpoint or data not found", e.Message, "404 exception messages is not as expected");
            }

            try
            {
                MockApiClient.setAPIResponse(
                    new ApiResponse(
                        500,
                        "{\"error\":\"Problem with an internal service\"}",
                        200, 150));
                Usage u = m_user.getUsage();
                Assert.Fail("Expected ApiException not thrown");
            }
            catch (ApiException e)
            {
                Assert.AreEqual("Problem with an internal service", e.Message, "500 exception messages is not as expected");
            }
        }