Esempio n. 1
0
        internal void setManager(GroupManager manager)
        {
            // Set up the first schedule.
            Schedule schedule1 = new Schedule();
            RepetitiveInterval interval11 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 5, 10, 2,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);
            RepetitiveInterval interval12 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 6, 8, 1,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);
            RepetitiveInterval interval13 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 7, 8);
            schedule1.addWhiteInterval(interval11);
            schedule1.addWhiteInterval(interval12);
            schedule1.addBlackInterval(interval13);

            // Set up the second schedule.
            Schedule schedule2 = new Schedule();
            RepetitiveInterval interval21 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 9, 12, 1,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);
            RepetitiveInterval interval22 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 6, 8);
            RepetitiveInterval interval23 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 2, 4);
            schedule2.addWhiteInterval(interval21);
            schedule2.addWhiteInterval(interval22);
            schedule2.addBlackInterval(interval23);

            // Add them to the group manager database.
            manager.addSchedule("schedule1", schedule1);
            manager.addSchedule("schedule2", schedule2);

            // Make some adaptions to certificate.
            Blob dataBlob = certificate.wireEncode();

            Data memberA = new Data();
            memberA.wireDecode(dataBlob, net.named_data.jndn.encoding.TlvWireFormat.get());
            memberA.setName(new Name("/ndn/memberA/KEY/ksk-123/ID-CERT/123"));
            Data memberB = new Data();
            memberB.wireDecode(dataBlob, net.named_data.jndn.encoding.TlvWireFormat.get());
            memberB.setName(new Name("/ndn/memberB/KEY/ksk-123/ID-CERT/123"));
            Data memberC = new Data();
            memberC.wireDecode(dataBlob, net.named_data.jndn.encoding.TlvWireFormat.get());
            memberC.setName(new Name("/ndn/memberC/KEY/ksk-123/ID-CERT/123"));

            // Add the members to the database.
            manager.addMember("schedule1", memberA);
            manager.addMember("schedule1", memberB);
            manager.addMember("schedule2", memberC);
        }
Esempio n. 2
0
        public void testCalculateIntervalWithoutWhite()
        {
            Schedule schedule = new Schedule();
            RepetitiveInterval interval1 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 5, 10, 2,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);
            RepetitiveInterval interval2 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 6, 8, 1,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);

            schedule.addBlackInterval(interval1);
            schedule.addBlackInterval(interval2);

            Schedule.Result result;

            // timePoint1 --> negative 8.25 4-10
            double timePoint1 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T063000");
            result = schedule.getCoveringInterval(timePoint1);
            Assert.AssertEquals(false, result.isPositive);
            Assert.AssertEquals(false, result.interval.isEmpty());
            Assert.AssertEquals("20150825T050000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150825T100000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            // timePoint2 --> negative 8.25 0-4
            double timePoint2 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T013000");
            result = schedule.getCoveringInterval(timePoint2);
            Assert.AssertEquals(false, result.isPositive);
            Assert.AssertEquals(false, result.interval.isEmpty());
            Assert.AssertEquals("20150825T000000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150826T000000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));
        }
Esempio n. 3
0
        public void testEncodeAndDecode()
        {
            Schedule schedule = new Schedule();

            RepetitiveInterval interval1 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150828T000000"), 5, 10, 2,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);
            RepetitiveInterval interval2 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150828T000000"), 6, 8, 1,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);
            RepetitiveInterval interval3 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 7, 8);
            RepetitiveInterval interval4 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"), 4, 7);

            schedule.addWhiteInterval(interval1);
            schedule.addWhiteInterval(interval2);
            schedule.addWhiteInterval(interval4);
            schedule.addBlackInterval(interval3);

            Blob encoding = schedule.wireEncode();
            Blob encoding2 = new Blob(SCHEDULE, false);
            Assert.AssertTrue(encoding.equals(encoding2));

            Schedule schedule2 = new Schedule();
            try {
                schedule2.wireDecode(encoding);
            } catch (EncodingException ex) {
                Assert.Fail("Error decoding Schedule: " + ex.Message);
            }

            Schedule.Result result;

            // timePoint1 --> positive 8.25 4-10
            double timePoint1 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T063000");
            result = schedule.getCoveringInterval(timePoint1);
            Assert.AssertEquals(true, result.isPositive);
            Assert.AssertEquals("20150825T040000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150825T100000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            // timePoint2 --> positive 8.26 6-8
            double timePoint2 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150826T073000");
            result = schedule.getCoveringInterval(timePoint2);
            Assert.AssertEquals(true, result.isPositive);
            Assert.AssertEquals("20150826T060000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150826T080000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));
        }
Esempio n. 4
0
        public void testCalculateIntervalWithBlackAndWhite()
        {
            Schedule schedule = new Schedule();
            RepetitiveInterval interval1 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 5, 10, 2,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);
            RepetitiveInterval interval2 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 6, 8, 1,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);
            RepetitiveInterval interval3 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T000000"), 7, 8);
            RepetitiveInterval interval4 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"), 4, 7);

            schedule.addWhiteInterval(interval1);
            schedule.addWhiteInterval(interval2);
            schedule.addWhiteInterval(interval4);
            schedule.addBlackInterval(interval3);

            Schedule.Result result;

            // timePoint1 --> positive 8.25 4-10
            double timePoint1 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T063000");
            result = schedule.getCoveringInterval(timePoint1);
            Assert.AssertEquals(true, result.isPositive);
            Assert.AssertEquals("20150825T040000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150825T100000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            // timePoint2 --> positive 8.26 6-8
            double timePoint2 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150826T073000");
            result = schedule.getCoveringInterval(timePoint2);
            Assert.AssertEquals(true, result.isPositive);
            Assert.AssertEquals("20150826T060000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150826T080000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            // timePoint3 --> positive 8.27 5-7
            double timePoint3 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T053000");
            result = schedule.getCoveringInterval(timePoint3);
            Assert.AssertEquals(true, result.isPositive);
            Assert.AssertEquals("20150827T050000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150827T070000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            // timePoint4 --> positive 8.27 5-7
            double timePoint4 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T063000");
            result = schedule.getCoveringInterval(timePoint4);
            Assert.AssertEquals(true, result.isPositive);
            Assert.AssertEquals("20150827T050000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150827T070000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            // timePoint5 --> negative 8.27 7-8
            double timePoint5 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150827T073000");
            result = schedule.getCoveringInterval(timePoint5);
            Assert.AssertEquals(false, result.isPositive);
            Assert.AssertEquals(false, result.interval.isEmpty());
            Assert.AssertEquals("20150827T070000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150827T080000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            // timePoint6 --> negative 8.25 10-24
            double timePoint6 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T113000");
            result = schedule.getCoveringInterval(timePoint6);
            Assert.AssertEquals(false, result.isPositive);
            Assert.AssertEquals(false, result.interval.isEmpty());
            Assert.AssertEquals("20150825T100000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150826T000000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));
        }