Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.Link$LinkBuilder


        when(valueType.getBaseName()).thenReturn("BOOLEAN");
        assertEquals(Boolean.TRUE, FieldValueStringConverter.fromString("true", valueType, idGenerator));
        assertEquals(Boolean.FALSE, FieldValueStringConverter.fromString("false", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("LINK");
        assertEquals(new Link(idGenerator.newRecordId("foobar")),
                FieldValueStringConverter.fromString("USER.foobar", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("DATE");
        assertEquals(new LocalDate(2012, 6, 28), FieldValueStringConverter.fromString("2012-06-28", valueType, idGenerator));
View Full Code Here


        Record record2 = createDefaultRecord();

        // Create record with link to record
        Record recordWithLinks = repository.newRecord();
        recordWithLinks.setRecordType(recordTypeWithLink.getName());
        Link link = Link.newBuilder().recordId(record.getId()).copyAll(false).create();
        recordWithLinks.setField(linkFieldType.getName(), link);
        recordWithLinks = repository.create(recordWithLinks);

        // Validate link is created
        link = (Link) recordWithLinks.getField(linkFieldType.getName());
        assertEquals(record.getId(), link.getMasterRecordId());

        // Read record again and validate link is there
        recordWithLinks = repository.read(recordWithLinks.getId());
        link = (Link) recordWithLinks.getField(linkFieldType.getName());
        assertEquals(record.getId(), link.getMasterRecordId());

        // Update record with link to record2
        recordWithLinks = repository.newRecord(recordWithLinks.getId());
        link = Link.newBuilder().recordId(record2.getId()).copyAll(false).create();
        recordWithLinks.setField(linkFieldType.getName(), link);
        recordWithLinks = repository.update(recordWithLinks);

        // Validate link is updated
        link = (Link) recordWithLinks.getField(linkFieldType.getName());
        assertEquals(record2.getId(), link.getMasterRecordId());

        // Read record and validate link is still updated
        recordWithLinks = repository.read(recordWithLinks.getId());
        link = (Link) recordWithLinks.getField(linkFieldType.getName());
        assertEquals(record2.getId(), link.getMasterRecordId());
    }
View Full Code Here

        }

    }

    public Link generateLink() {
        return new Link(repository.getIdGenerator().newRecordId());
    }
View Full Code Here

        if (linkedRecordSource != null) {
            TestRecord record = testActionContext.records.getRecord(linkedRecordSource);
            if (record == null) {
                return new ActionResult(false, null, 0);
            }
            return new ActionResult(true, new Link(record.getRecordId()), 0);
        }
        // Generate a link that possibly (most likely) points to a non-existing record
        return new ActionResult(true, testFieldType.generateLink(), 0);
    }
View Full Code Here

        expectEvent(CREATE, ALTERNATE_TABLE, record1.getId(), nvfield1.getId(), nvTag.getId());
        record1 = alternateTable.create(record1);

        Record record2 = alternateTable.newRecord();
        record2.setRecordType(nvRecordType1.getName());
        record2.setField(nvLinkField1.getName(), new Link(ALTERNATE_TABLE, record1.getId()));
        record2.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, ALTERNATE_TABLE, record2.getId(), nvLinkField1.getId(), nvTag.getId());
        record2 = alternateTable.create(record2);

        commitIndex();
View Full Code Here

        expectEvent(CREATE, ALTERNATE_TABLE, record1.getId(), nvfield1.getId(), nvTag.getId());
        record1 = alternateTable.create(record1);

        Record record2 = alternateTable.newRecord();
        record2.setRecordType(nvRecordType1.getName());
        record2.setField(nvLinkField1.getName(), new Link(record1.getId()));
        record2.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, ALTERNATE_TABLE, record2.getId(), nvLinkField1.getId(), nvTag.getId());
        record2 = alternateTable.create(record2);

        commitIndex();
View Full Code Here

        expectEvent(CREATE, ALTERNATE_TABLE, record1.getId(), nvfield1.getId(), nvTag.getId());
        record1 = alternateTable.create(record1);

        Record record2 = defaultTable.newRecord();
        record2.setRecordType(nvRecordType1.getName());
        record2.setField(nvLinkField1.getName(), new Link(ALTERNATE_TABLE, record1.getId()));
        record2.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, Table.RECORD.name, record2.getId(), nvLinkField1.getId(), nvTag.getId());
        record2 = defaultTable.create(record2);

        commitIndex();
View Full Code Here

            expectEvent(CREATE, Table.RECORD.name, record1.getId(), nvfield1.getId(), nvTag.getId());
            record1 = defaultTable.create(record1);

            Record record2 = defaultTable.newRecord();
            record2.setRecordType(nvRecordType1.getName());
            record2.setField(nvLinkField1.getName(), new Link(record1.getId()));
            record2.setField(nvTag.getName(), 0L);
            expectEvent(CREATE, Table.RECORD.name, record2.getId(), nvLinkField1.getId(), nvTag.getId());
            record2 = defaultTable.create(record2);

            commitIndex();
            verifyResultCount("nv_deref1:nvpear", 1);
        }


        //
        // Variant deref
        //
        {
            log.debug("Begin test NV7");
            Record masterRecord = defaultTable.newRecord();
            masterRecord.setRecordType(nvRecordType1.getName());
            masterRecord.setField(nvfield1.getName(), "yellow");
            masterRecord.setField(nvTag.getName(), 0L);
            expectEvent(CREATE, Table.RECORD.name, masterRecord.getId(), nvfield1.getId(), nvTag.getId());
            masterRecord = defaultTable.create(masterRecord);

            RecordId var1Id = idGenerator.newRecordId(masterRecord.getId(), Collections.singletonMap("lang", "en"));
            Record var1Record = defaultTable.newRecord(var1Id);
            var1Record.setRecordType(nvRecordType1.getName());
            var1Record.setField(nvfield1.getName(), "green");
            var1Record.setField(nvTag.getName(), 0L);
            expectEvent(CREATE, Table.RECORD.name, var1Id, nvfield1.getId(), nvTag.getId());
            defaultTable.create(var1Record);

            Map<String, String> varProps = new HashMap<String, String>();
            varProps.put("lang", "en");
            varProps.put("branch", "dev");
            RecordId var2Id = idGenerator.newRecordId(masterRecord.getId(), varProps);
            Record var2Record = defaultTable.newRecord(var2Id);
            var2Record.setRecordType(nvRecordType1.getName());
            var2Record.setField(nvfield1.getName(), "blue");
            var2Record.setField(nvTag.getName(), 0L);
            expectEvent(CREATE, Table.RECORD.name, var2Id, nvfield1.getId(), nvTag.getId());
            defaultTable.create(var2Record);

            commitIndex();
            verifyResultCount("nv_deref2:yellow", 1);
            verifyResultCount("nv_deref3:yellow", 2);
            verifyResultCount("nv_deref4:green", 1);
            verifyResultCount("nv_deref3:green", 0);
            verifyResultCount("nv_deref5:blue", 1);
            verifyResultCount("nv_deref5:green", 0);
            verifyResultCount("nv_deref5:yellow", 0);
            verifyResultCount("nv_deref6:blue", 2);
            verifyResultCount("nv_deref7:blue", 1);
            verifyResultCount("nv_deref8:blue", 0);
        }

        //
        // Update denormalized data
        //
        {
            log.debug("Begin test NV8");
            Record record1 = defaultTable.newRecord(idGenerator.newRecordId("boe"));
            record1.setRecordType(nvRecordType1.getName());
            record1.setField(nvfield1.getName(), "cucumber");
            record1.setField(nvTag.getName(), 0L);
            expectEvent(CREATE, Table.RECORD.name, record1.getId(), nvfield1.getId(), nvTag.getId());
            record1 = defaultTable.create(record1);

            // Create a record which will contain denormalized data through linking
            Record record2 = defaultTable.newRecord();
            record2.setRecordType(nvRecordType1.getName());
            record2.setField(nvLinkField1.getName(), new Link(record1.getId()));
            record2.setField(nvfield1.getName(), "mushroom");
            record2.setField(nvTag.getName(), 0L);
            expectEvent(CREATE, Table.RECORD.name, record2.getId(), nvLinkField1.getId(), nvfield1.getId(), nvTag.getId());
            record2 = defaultTable.create(record2);
View Full Code Here

            expectEvent(CREATE, Table.RECORD.name, record1.getId(), 1L, null, vfield1.getId(), liveTag.getId());
            record1 = defaultTable.create(record1);

            Record record2 = defaultTable.newRecord();
            record2.setRecordType(vRecordType1.getName());
            record2.setField(vLinkField1.getName(), new Link(record1.getId()));
            record2.setField(liveTag.getName(), Long.valueOf(1));
            expectEvent(CREATE, Table.RECORD.name, record2.getId(), 1L, null, vLinkField1.getId(), liveTag.getId());
            record2 = defaultTable.create(record2);

            commitIndex();
            verifyResultCount("v_deref1:fig", 1);

            log.debug("Begin test V6.1");
            RecordId record3Id = idGenerator.newRecordId(record1.getId(), Collections.singletonMap("lang", "en"));
            Record record3 = defaultTable.newRecord(record3Id);
            record3.setRecordType(vRecordType1.getName());
            record3.setField(vfield1.getName(), "banana");
            record3.setField(liveTag.getName(), Long.valueOf(1));
            expectEvent(CREATE, Table.RECORD.name, record3.getId(), 1L, null, vfield1.getId(), liveTag.getId());
            record3 = defaultTable.create(record3);

            commitIndex();
            verifyResultCount("v_deref3:fig", 1);

            log.debug("Begin test V6.2");
            Map<String, String> varprops = new HashMap<String, String>();
            varprops.put("lang", "en");
            varprops.put("branch", "dev");
            RecordId record4Id = idGenerator.newRecordId(record1.getId(), varprops);
            Record record4 = defaultTable.newRecord(record4Id);
            record4.setRecordType(vRecordType1.getName());
            record4.setField(vfield1.getName(), "coconut");
            record4.setField(liveTag.getName(), Long.valueOf(1));
            expectEvent(CREATE, Table.RECORD.name, record4.getId(), 1L, null, vfield1.getId(), liveTag.getId());
            record4 = defaultTable.create(record4);

            commitIndex();
            verifyResultCount("v_deref3:fig", 2);       //master=>v_field1 (record3 and record4)
            verifyResultCount("v_deref2:fig", 1);       //-branch,-lang=>v_field1 (record4)
            verifyResultCount("v_deref4:banana", 1);    //-branch=>v_field1 (record4)
            verifyResultCount("v_deref5:coconut", 1);   //+branch=>v_field1 (record3)

            // remove the live tag from record1
            log.debug("Begin test V7");
            record1.delete(liveTag.getName(), true);
            expectEvent(UPDATE, Table.RECORD.name, record1.getId(), liveTag.getId());
            record1 = defaultTable.update(record1);

            commitIndex();
            verifyResultCount("v_deref1:fig", 0);

            // and add the live tag again record1
            log.debug("Begin test V8");
            record1.setField(liveTag.getName(), Long.valueOf(1));
            expectEvent(UPDATE, Table.RECORD.name, record1.getId(), liveTag.getId());
            record1 = defaultTable.update(record1);

            commitIndex();
            verifyResultCount("v_deref1:fig", 1);

            // Make second version of record1, assign both versions different tags, and assign these tags also
            // to version1 of record2.
            log.debug("Begin test V9");
            record1.setField(vfield1.getName(), "strawberries");
            record1.setField(previewTag.getName(), Long.valueOf(2));
            expectEvent(UPDATE, Table.RECORD.name, record1.getId(), 2L, null, vfield1.getId(), previewTag.getId());
            record1 = defaultTable.update(record1);

            record2.setField(previewTag.getName(), Long.valueOf(1));
            expectEvent(UPDATE, Table.RECORD.name, record2.getId(), previewTag.getId());
            record2 = defaultTable.update(record2);

            commitIndex();
            verifyResultCount("+v_deref1:strawberries +lily.vtagId:" + qesc(previewTag.getId().toString()), 1);
            verifyResultCount("+v_deref1:strawberries +lily.vtagId:" + qesc(liveTag.getId().toString()), 0);
            verifyResultCount("+v_deref1:strawberries", 1);
            verifyResultCount("+v_deref1:fig +lily.vtagId:" + qesc(liveTag.getId().toString()), 1);
            verifyResultCount("+v_deref1:fig +lily.vtagId:" + qesc(previewTag.getId().toString()), 0);
            verifyResultCount("+v_deref1:fig", 1);

            // Now do something similar with a 3th version, but first update record2 and then record1
            log.debug("Begin test V10");
            record2.setField(latestTag.getName(), Long.valueOf(1));
            expectEvent(UPDATE, Table.RECORD.name, record2.getId(), latestTag.getId());
            record2 = defaultTable.update(record2);

            record1.setField(vfield1.getName(), "kiwi");
            record1.setField(latestTag.getName(), Long.valueOf(3));
            expectEvent(UPDATE, Table.RECORD.name, record1.getId(), 3L, null, vfield1.getId(), latestTag.getId());
            record1 = defaultTable.update(record1);

            commitIndex();
            verifyResultCount("+v_deref1:kiwi +lily.vtag:latest", 1);
            verifyResultCount("+v_deref1:strawberries +lily.vtag:preview", 1);
            verifyResultCount("+v_deref1:fig +lily.vtag:live", 1);
            verifyResultCount("+v_deref1:kiwi +lily.vtag:live", 0);
            verifyResultCount("+v_field1:kiwi +lily.vtag:latest", 1);
            verifyResultCount("+v_field1:fig +lily.vtag:live", 1);

            // Perform updates to record3 and check if denorm'ed data in index of record4 follows
            log.debug("Begin test V11");
            record3.delete(vfield1.getName(), true);
            expectEvent(UPDATE, Table.RECORD.name, record3.getId(), 2L, null, vfield1.getId());
            record3 = defaultTable.update(record3);

            commitIndex();
            verifyResultCount("v_deref4:banana", 1); // live tag still points to version 1!

            log.debug("Begin test V11.1");
            defaultTable.read(record3Id, Long.valueOf(2)); // check version 2 really exists
            record3.setField(liveTag.getName(), Long.valueOf(2));
            expectEvent(UPDATE, Table.RECORD.name, record3.getId(), liveTag.getId());
            defaultTable.update(record3);

            commitIndex();
            verifyResultCount("v_deref4:banana", 0);
            verifyResultCount("v_field1:coconut", 1);

            // Perform updates to record4 and check if denorm'ed data in index of record3 follows
            log.debug("Begin test V12");
            record4.delete(vfield1.getName(), true);
            expectEvent(UPDATE, Table.RECORD.name, record4.getId(), 2L, null, vfield1.getId());
            record4 = defaultTable.update(record4);

            commitIndex();
            verifyResultCount("v_deref5:coconut", 1); // live tag still points to version 1!

            log.debug("Begin test V12.1");
            defaultTable.read(record4Id, Long.valueOf(2)); // check version 2 really exists
            record4.setField(liveTag.getName(), Long.valueOf(2));
            expectEvent(UPDATE, Table.RECORD.name, record4.getId(), liveTag.getId());
            defaultTable.update(record4);

            commitIndex();
            verifyResultCount("v_deref5:coconut", 0); // now it's gone

            // Delete master
            log.debug("Begin test V13");
            expectEvent(DELETE, Table.RECORD.name, record1.getId());
            defaultTable.delete(record1.getId());

            commitIndex();
            verifyResultCount("v_deref1:fig", 0);
            verifyResultCount("v_deref2:fig", 0);
            verifyResultCount("v_deref3:fig", 0);
        }

        //
        // Test that when using vtag pointing to version '0', versioned content is not accessible
        //
        {
            // Plain (without deref)
            log.debug("Begin test V14");
            Record record1 = defaultTable.newRecord();
            record1.setRecordType(vRecordType1.getName());
            record1.setField(nvfield1.getName(), "rollerblades");
            record1.setField(vfield1.getName(), "bicycle");
            record1.setField(liveTag.getName(), 1L);
            record1.setField(nvTag.getName(), 0L);
            expectEvent(CREATE, Table.RECORD.name, record1.getId(), 1L, null, nvfield1.getId(), vfield1.getId(), liveTag.getId(),
                    nvTag.getId());
            record1 = defaultTable.create(record1);

            commitIndex();
            verifyResultCount("+lily.vtagId:" + qesc(nvTag.getId().toString()) + " +nv_field1:rollerblades", 1);
            verifyResultCount("+lily.vtagId:" + qesc(nvTag.getId().toString()) + " +v_field1:bicycle", 0);
            verifyResultCount("+lily.vtagId:" + qesc(liveTag.getId().toString()) + " +nv_field1:rollerblades", 1);
            verifyResultCount("+lily.vtagId:" + qesc(liveTag.getId().toString()) + " +v_field1:bicycle", 1);

            // With deref
            log.debug("Begin test V15");
            Record record2 = defaultTable.newRecord();
            record2.setRecordType(vRecordType1.getName());
            record2.setField(nvLinkField2.getName(), new Link(record1.getId()));
            record2.setField(nvTag.getName(), 0L);
            record2.setField(liveTag.getName(), 0L);
            expectEvent(CREATE, Table.RECORD.name, record2.getId(), nvLinkField2.getId(), nvTag.getId(), liveTag.getId());
            record2 = defaultTable.create(record2);

            commitIndex();
            verifyResultCount("+lily.vtagId:" + qesc(nvTag.getId().toString()) + " +nv_v_deref:bicycle", 0);
            verifyResultCount("+lily.vtagId:" + qesc(liveTag.getId().toString()) + " +nv_v_deref:bicycle", 1);
        }

        //
        // Test deref from a versionless record via a versioned field to a non-versioned field.
        // From the moment a versioned field is in the deref chain, when the vtag points to version 0,
        // the deref should evaluate to null.
        //
        {
            log.debug("Begin test V18");
            Record record1 = defaultTable.newRecord();
            record1.setRecordType(vRecordType1.getName());
            record1.setField(nvfield1.getName(), "Brussels");
            record1.setField(nvTag.getName(), 0L);
            expectEvent(CREATE, Table.RECORD.name, record1.getId(), (Long) null, null, nvfield1.getId(), nvTag.getId());
            record1 = defaultTable.create(record1);

            Record record2 = defaultTable.newRecord();
            record2.setRecordType(vRecordType1.getName());
            record2.setField(vLinkField1.getName(), new Link(record1.getId()));
            record2.setField(nvTag.getName(), 0L);
            expectEvent(CREATE, Table.RECORD.name, record2.getId(), 1L, null, vLinkField1.getId(), nvTag.getId());
            record2 = defaultTable.create(record2);

            Record record3 = defaultTable.newRecord();
            record3.setRecordType(vRecordType1.getName());
            record3.setField(nvLinkField2.getName(), new Link(record2.getId()));
            record3.setField(nvTag.getName(), 0L);
            expectEvent(CREATE, Table.RECORD.name, record3.getId(), (Long) null, null, nvLinkField2.getId(), nvTag.getId());
            record3 = defaultTable.create(record3);

            commitIndex();
            verifyResultCount("+lily.vtagId:" + qesc(nvTag.getId().toString()) + " +nv_v_nv_deref:Brussels", 0);

            // Give the records a live tag
            log.debug("Begin test V19");
            record1.setField(liveTag.getName(), 0L);
            expectEvent(UPDATE, Table.RECORD.name, record1.getId(), liveTag.getId());
            record1 = defaultTable.update(record1);

            record2.setField(liveTag.getName(), 1L);
            expectEvent(UPDATE, Table.RECORD.name, record2.getId(), liveTag.getId());
            record2 = defaultTable.update(record2);

            record3.setField(liveTag.getName(), 0L);
            expectEvent(UPDATE, Table.RECORD.name, record3.getId(), liveTag.getId());
            record3 = defaultTable.update(record3);

            commitIndex();
            verifyResultCount("+lily.vtagId:" + qesc(liveTag.getId().toString()) + " +nv_v_nv_deref:Brussels", 1);
        }

        //
        // Test many-to-one dereferencing (= deref where there's actually more than one record pointing to another
        // record)
        // (Besides correctness, this test was also added to check/evaluate the processing time)
        //
        {
            log.debug("Begin test V19.1");

            final int COUNT = 5;

            Record record1 = defaultTable.newRecord();
            record1.setRecordType(vRecordType1.getName());
            record1.setField(vfield1.getName(), "hyponiem");
            record1.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record1.getId(), 1L, null, vfield1.getId(), liveTag.getId());
            record1 = defaultTable.create(record1);

            // Create multiple records
            for (int i = 0; i < COUNT; i++) {
                Record record2 = defaultTable.newRecord();
                record2.setRecordType(vRecordType1.getName());
                record2.setField(vLinkField1.getName(), new Link(record1.getId()));
                record2.setField(liveTag.getName(), 1L);
                expectEvent(CREATE, Table.RECORD.name, record2.getId(), 1L, null, vLinkField1.getId(), liveTag.getId());
                record2 = defaultTable.create(record2);
            }

            commitIndex();
            verifyResultCount("v_deref1:hyponiem", COUNT);

            record1.setField(vfield1.getName(), "hyperoniem");
            record1.setField(liveTag.getName(), 2L);
            expectEvent(UPDATE, Table.RECORD.name, record1.getId(), 2L, null, vfield1.getId(), liveTag.getId());
            record1 = defaultTable.update(record1);
            commitIndex();
            verifyResultCount("v_deref1:hyperoniem", COUNT);
        }

        //
        // Multi-value field tests
        //
        {
            // Test multi-value field
            log.debug("Begin test V30");
            Record record1 = defaultTable.newRecord();
            record1.setRecordType(vRecordType1.getName());
            record1.setField(vStringMvField.getName(), Arrays.asList("Dog", "Cat"));
            record1.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record1.getId(), 1L, null, vStringMvField.getId(), liveTag.getId());
            record1 = defaultTable.create(record1);

            commitIndex();
            verifyResultCount("v_string_mv:Dog", 1);
            verifyResultCount("v_string_mv:Cat", 1);
            verifyResultCount("v_string_mv:(Dog Cat)", 1);
            verifyResultCount("v_string_mv:(\"Dog Cat\")", 0);

            // Test multiple single-valued fields indexed into one MV field
            // TODO

            // Test single-value field turned into multivalue by formatter
            // TODO

            // Test multi-valued deref to single-valued field
            // TODO
        }

        //
        // Long type tests
        //
        {
            log.debug("Begin test V40");
            Record record1 = defaultTable.newRecord();
            record1.setRecordType(vRecordType1.getName());
            record1.setField(vLongField.getName(), 123L);
            record1.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record1.getId(), 1L, null, vLongField.getId(), liveTag.getId());
            record1 = defaultTable.create(record1);

            commitIndex();
            verifyResultCount("v_long:123", 1);
            verifyResultCount("v_long:[100 TO 150]", 1);
        }

        //
        // Datetime type test
        //
        {
            log.debug("Begin test V50");
            Record record1 = defaultTable.newRecord();
            record1.setRecordType(vRecordType1.getName());
            record1.setField(vDateTimeField.getName(), new DateTime(2010, 10, 14, 15, 30, 12, 756, DateTimeZone.UTC));
            record1.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record1.getId(), 1L, null, vDateTimeField.getId(), liveTag.getId());
            record1 = defaultTable.create(record1);

            commitIndex();
            verifyResultCount("v_datetime:\"2010-10-14T15:30:12.756Z\"", 1);
            verifyResultCount("v_datetime:\"2010-10-14T15:30:12Z\"", 0);

            // Test without milliseconds
            log.debug("Begin test V51");
            Record record2 = defaultTable.newRecord();
            record2.setRecordType(vRecordType1.getName());
            record2.setField(vDateTimeField.getName(), new DateTime(2010, 10, 14, 15, 30, 12, 000, DateTimeZone.UTC));
            record2.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record2.getId(), 1L, null, vDateTimeField.getId(), liveTag.getId());
            record2 = defaultTable.create(record2);

            commitIndex();
            verifyResultCount("v_datetime:\"2010-10-14T15:30:12Z\"", 1);
            verifyResultCount("v_datetime:\"2010-10-14T15:30:12.000Z\"", 1);
            verifyResultCount("v_datetime:\"2010-10-14T15:30:12.000Z/SECOND\"", 1);
        }

        //
        // Date type test
        //
        {
            log.debug("Begin test V60");
            Record record1 = defaultTable.newRecord();
            record1.setRecordType(vRecordType1.getName());
            record1.setField(vDateField.getName(), new LocalDate(2020, 1, 30));
            record1.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record1.getId(), 1L, null, vDateField.getId(), liveTag.getId());
            record1 = defaultTable.create(record1);

            commitIndex();
            verifyResultCount("v_date:\"2020-01-30T00:00:00Z/DAY\"", 1);
            verifyResultCount("v_date:\"2020-01-30T00:00:00.000Z\"", 1);
            verifyResultCount("v_date:\"2020-01-30T00:00:00Z\"", 1);
            verifyResultCount("v_date:\"2020-01-30T00:00:01Z\"", 0);

            verifyResultCount("v_date:[2020-01-29T00:00:00Z/DAY TO 2020-01-31T00:00:00Z/DAY]", 1);

            log.debug("Begin test V61");
            Record record2 = defaultTable.newRecord();
            record2.setRecordType(vRecordType1.getName());
            record2.setField(vDateField.getName(), new LocalDate(2020, 1, 30));
            record2.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record2.getId(), 1L, null, vDateField.getId(), liveTag.getId());
            record2 = defaultTable.create(record2);

            commitIndex();
            verifyResultCount("v_date:\"2020-01-30T00:00:00Z/DAY\"", 2);
        }

        //
        // Blob tests
        //
        {
            log.debug("Begin test V70");
            Blob blob1 = createBlob("blob1_msword.doc", "application/msword", "blob1_msword.doc");
            Blob blob1dup = createBlob("blob1_msword.doc", "application/msword", "blob1_msword.doc");
            Blob blob2 = createBlob("blob2.pdf", "application/pdf", "blob2.pdf");
            Blob blob3 =
                    createBlob("blob3_oowriter.odt", "application/vnd.oasis.opendocument.text", "blob3_oowriter.odt");
            Blob blob4 = createBlob("blob4_excel.xls", "application/excel", "blob4_excel.xls");

            // Single-valued blob field
            Record record1 = defaultTable.newRecord();
            record1.setRecordType(vRecordType1.getName());
            record1.setField(vBlobField.getName(), blob1);
            record1.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record1.getId(), 1L, null, vBlobField.getId(), liveTag.getId());
            record1 = defaultTable.create(record1);

            commitIndex();
            verifyResultCount("v_blob:sollicitudin", 1);
            verifyResultCount("v_blob:\"Sed pretium pretium lorem\"", 1);
            verifyResultCount("v_blob:lily", 0);

            // Multi-value and hierarchical blob field
            log.debug("Begin test V71");
            HierarchyPath path1 = new HierarchyPath(blob1dup, blob2);
            HierarchyPath path2 = new HierarchyPath(blob3, blob4);
            List<HierarchyPath> blobs = Arrays.asList(path1, path2);

            Record record2 = defaultTable.newRecord();
            record2.setRecordType(vRecordType1.getName());
            record2.setField(vBlobMvHierField.getName(), blobs);
            record2.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record2.getId(), 1L, null, vBlobMvHierField.getId(), liveTag.getId());
            record2 = defaultTable.create(record2);

            commitIndex();
            verifyResultCount("v_blob:blob1", 2);
            verifyResultCount("v_blob:blob2", 1);
            verifyResultCount("v_blob:blob3", 1);
            verifyResultCount("+v_blob:blob4 +v_blob:\"Netherfield Park\"", 1);

            // Nested blob field
            log.debug("Begin test V72");
            List<List<List<Blob>>> nestedBlobs = Arrays.asList(
                    Arrays.<List<Blob>>asList(
                            Arrays.<Blob>asList(
                                    createBlob("niobium".getBytes(), "text/plain", "foo.txt"),
                                    createBlob("tantalum".getBytes(), "text/plain", "foo.txt")
                            ),
                            Arrays.<Blob>asList(
                                    createBlob("fermium".getBytes(), "text/plain", "foo.txt"),
                                    createBlob("seaborgium".getBytes(), "text/plain", "foo.txt")
                            )
                    ),
                    Arrays.<List<Blob>>asList(
                            Arrays.<Blob>asList(
                                    createBlob("einsteinium".getBytes(), "text/plain", "foo.txt")
                            )
                    )
            );

            Record record3 = defaultTable.newRecord();
            record3.setRecordType(vRecordType1.getName());
            record3.setField(vBlobNestedField.getName(), nestedBlobs);
            record3.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record3.getId(), 1L, null, vBlobNestedField.getId(), liveTag.getId());
            record3 = defaultTable.create(record3);

            commitIndex();
            verifyResultCount("v_blob:niobium", 1);
            verifyResultCount("v_blob:tantalum", 1);
            verifyResultCount("v_blob:fermium", 1);
            verifyResultCount("v_blob:seaborgium", 1);
            verifyResultCount("v_blob:einsteinium", 1);
        }

        //
        // Test field with explicitly configured formatter
        //
        {
            log.debug("Begin test V80");
            Record record1 = defaultTable.newRecord();
            record1.setRecordType(vRecordType1.getName());
            record1.setField(vDateTimeField.getName(), new DateTime(2058, 10, 14, 15, 30, 12, 756, DateTimeZone.UTC));
            record1.setField(vStringMvField.getName(), Arrays.asList("wood", "plastic"));
            record1.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record1.getId(), 1L, null, vDateTimeField.getId(), vStringMvField.getId(),
                    liveTag.getId());
            record1 = defaultTable.create(record1);

            commitIndex();
            verifyResultCount("year:2058", 1);
            verifyResultCount("firstValue:wood", 1);
            verifyResultCount("firstValue:plastic", 0);
        }

        //
        // Test inheritance of variant properties for link fields
        //
        {
            log.debug("Begin test V100");
            Map<String, String> varProps = new HashMap<String, String>();
            varProps.put("lang", "nl");
            varProps.put("user", "ali");

            RecordId record1Id = repository.getIdGenerator().newRecordId(varProps);
            Record record1 = defaultTable.newRecord(record1Id);
            record1.setRecordType(vRecordType1.getName());
            record1.setField(vfield1.getName(), "venus");
            record1.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record1.getId(), 1L, null, vfield1.getId(), liveTag.getId());
            record1 = defaultTable.create(record1);

            RecordId record2Id = repository.getIdGenerator().newRecordId(varProps);
            Record record2 = defaultTable.newRecord(record2Id);
            record2.setRecordType(vRecordType1.getName());
            // Notice we make the link to the record without variant properties
            record2.setField(vLinkField1.getName(), new Link(record1.getId().getMaster()));
            record2.setField(liveTag.getName(), 1L);
            expectEvent(CREATE, Table.RECORD.name, record2.getId(), 1L, null, vLinkField1.getId(), liveTag.getId());
            record2 = defaultTable.create(record2);

            commitIndex();
View Full Code Here

        // Create a record which links to one of the other records
        log.debug("Begin test V406");
        Record record3 = defaultTable.newRecord(idGenerator.newRecordId());
        record3.setRecordType(rt.getName());
        record3.setField(field2.getName(), new Link(record2.getId()));
        expectEvent(CREATE, Table.RECORD.name, record3.getId(), 1L, null, field2.getId());
        record3 = defaultTable.createOrUpdate(record3);

        //
        // Test searches
View Full Code Here

TOP

Related Classes of org.lilyproject.repository.api.Link$LinkBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.