Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.RecordId


    public void testRecordIdWithVarProps() {
        Map<String, String> varProps = new HashMap<String, String>();
        varProps.put("lang", "en");
        varProps.put("branch", "dev");

        RecordId masterRecordId = idGenerator.newRecordId("123");
        RecordId recordId = idGenerator.newRecordId(masterRecordId, varProps);

        Link link = Link.newBuilder().recordId(recordId).copyAll(false).create();
        assertEquals(masterRecordId, link.getMasterRecordId());
        assertEquals("USER.123.!*,branch=dev,lang=en", link.toString());
        assertEquals(link, Link.fromString(link.toString(), idGenerator));
        DataOutput dataOutput = new DataOutputImpl();
        link.write(dataOutput);
        assertEquals(link, Link.read(new DataInputImpl(dataOutput.toByteArray()), idGenerator));


        assertEquals(2, link.getVariantProps().size());
        assertEquals(Link.PropertyMode.SET, link.getVariantProps().get("lang").getMode());
        assertEquals("en", link.getVariantProps().get("lang").getValue());

        Map<String, String> ctxVarProps = new HashMap<String, String>();
        varProps.put("a", "1");
        varProps.put("b", "2");
        varProps.put("lang", "nl");

        RecordId ctx = idGenerator.newRecordId(idGenerator.newRecordId("0"), ctxVarProps);
        RecordId resolved = link.resolve(ctx, idGenerator);

        // Nothing from the context should have been copied
        assertEquals(2, resolved.getVariantProperties().size());
        assertEquals("en", resolved.getVariantProperties().get("lang"));
        assertEquals("dev", resolved.getVariantProperties().get("branch"));
    }
View Full Code Here


        assertEquals("dev", resolved.getVariantProperties().get("branch"));
    }

    @Test
    public void testIndividualRemove() {
        RecordId recordId = idGenerator.newRecordId("123");

        Link link = Link.newBuilder().recordId(recordId).remove("lang").set("x", "1").create();
        assertEquals("USER.123.-lang,x=1", link.toString());
        assertEquals(link, Link.fromString(link.toString(), idGenerator));
        DataOutput dataOutput = new DataOutputImpl();
        link.write(dataOutput);
        assertEquals(link, Link.read(new DataInputImpl(dataOutput.toByteArray()), idGenerator));


        Map<String, String> ctxVarProps = new HashMap<String, String>();
        ctxVarProps.put("lang", "en");
        ctxVarProps.put("branch", "dev");

        RecordId ctx = idGenerator.newRecordId(idGenerator.newRecordId("0"), ctxVarProps);
        RecordId resolved = link.resolve(ctx, idGenerator);

        assertNull(resolved.getVariantProperties().get("lang"));
        assertEquals("dev", resolved.getVariantProperties().get("branch"));
        assertEquals("1", resolved.getVariantProperties().get("x"));
        assertEquals(2, resolved.getVariantProperties().size());
    }
View Full Code Here

        assertEquals(2, resolved.getVariantProperties().size());
    }

    @Test
    public void testIndividualCopy() {
        RecordId recordId = idGenerator.newRecordId("123");

        Link link = Link.newBuilder().recordId(recordId).copyAll(false).copy("branch").set("x", "1").create();
        assertEquals("USER.123.!*,+branch,x=1", link.toString());
        assertEquals(link, Link.fromString(link.toString(), idGenerator));
        DataOutput dataOutput = new DataOutputImpl();
        link.write(dataOutput);
        assertEquals(link, Link.read(new DataInputImpl(dataOutput.toByteArray()), idGenerator));


        Map<String, String> ctxVarProps = new HashMap<String, String>();
        ctxVarProps.put("lang", "en");
        ctxVarProps.put("branch", "dev");

        RecordId ctx = idGenerator.newRecordId(idGenerator.newRecordId("0"), ctxVarProps);
        RecordId resolved = link.resolve(ctx, idGenerator);

        assertNull(resolved.getVariantProperties().get("lang"));
        assertEquals("dev", resolved.getVariantProperties().get("branch"));
        assertEquals("1", resolved.getVariantProperties().get("x"));
        assertEquals(2, resolved.getVariantProperties().size());
    }
View Full Code Here

        Map<String, String> varProps = new HashMap<String, String>();
        varProps.put("lang", "en");
        varProps.put("branch", "dev");

        RecordId recordId = idGenerator.newRecordId(idGenerator.newRecordId("123"), varProps);

        RecordId resolved = link.resolve(recordId, idGenerator);

        assertEquals(recordId, resolved);
    }
View Full Code Here

        Map<String, String> varProps = new HashMap<String, String>();
        varProps.put("lang", "en");
        varProps.put("branch", "dev");

        RecordId recordId = idGenerator.newRecordId(idGenerator.newRecordId("123"), varProps);

        RecordId resolved = link.resolve(recordId, idGenerator);

        assertEquals(recordId.getMaster(), resolved);
    }
View Full Code Here

    public void testImmutability() {
        Map<String, String> varProps = new HashMap<String, String>();
        varProps.put("lang", "en");
        varProps.put("branch", "dev");

        RecordId masterRecordId = idGenerator.newRecordId("123");
        RecordId recordId = idGenerator.newRecordId(masterRecordId, varProps);

        Link link = Link.newBuilder().recordId(recordId).copyAll(false).create();

        try {
            link.getVariantProps().put("z", null);
            fail("expected exception");
        } catch (UnsupportedOperationException e) {
            // ok
        }

        try {
            link.getMasterRecordId().getVariantProperties().put("z", "z");
            fail("expected exception");
        } catch (UnsupportedOperationException e) {
            // ok
        }

        try {
            recordId.getVariantProperties().put("z", "z");
            fail("expected exception");
        } catch (UnsupportedOperationException e) {
            // ok
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testEquals() {
        RecordId recordId1 = idGenerator.newRecordId("123");
        RecordId recordId2 = idGenerator.newRecordId("678");
        Link link1 = Link.newBuilder().recordId(recordId1).copyAll(false).create();
        Link link2 = Link.newBuilder().recordId(recordId2).copyAll(false).create();

        Assert.assertEquals(link1, link1);
        Assert.assertFalse(link1.equals(link2));

        Map<String, String> varProps1 = new HashMap<String, String>();
        varProps1.put("lang", "en");
        varProps1.put("branch", "dev");

        Map<String, String> varProps2 = new HashMap<String, String>();
        varProps1.put("lang", "fr");
        varProps1.put("branch", "dev");

        RecordId recordId3 = idGenerator.newRecordId("123", varProps1);
        RecordId recordId4 = idGenerator.newRecordId("123", varProps2);
        Link link3 = Link.newBuilder().recordId(recordId3).copyAll(false).create();
        Link link4 = Link.newBuilder().recordId(recordId4).copyAll(false).create();

        Assert.assertEquals(link3, link3);
        Assert.assertFalse(link3.equals(link4));
View Full Code Here

        Assert.assertFalse(link3.equals(link4));
    }

    @Test
    public void testLinkBuilder_WithTable() {
        RecordId recordId = idGenerator.newRecordId("42");
        Link link = Link.newBuilder()
                        .recordId(recordId)
                        .table("mytable")
                        .create();
View Full Code Here

        assertEquals("mytable", link.getTable());
    }

    @Test
    public void testLinkBuilder_WithoutTable() {
        RecordId recordId = idGenerator.newRecordId("42");
        Link link = Link.newBuilder()
                         .recordId(recordId)
                         .create();

        assertEquals(recordId, link.getMasterRecordId());
View Full Code Here

                extract(item, collector, ctxField, ctxRecord, repository);
            }
        } else if (value instanceof Record) {
            extractRecord((Record)value, collector, ctxField, ctxRecord, repository);
        } else if (value instanceof Link) {
            RecordId recordId = ((Link)value).resolve(ctxRecord, repository.getIdGenerator());
            collector.addLink(recordId, ctxField.getId());
        } else {
            throw new RuntimeException("Encountered an unexpected kind of object from a link field: " +
                    value.getClass().getName());
        }
View Full Code Here

TOP

Related Classes of org.lilyproject.repository.api.RecordId

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.