Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.Link


    }

    @Test
    public void testFromString_WithTable_WithColonsInId() {
        String idString = "mytable:USER.12:34";
        Link link = Link.fromString(idString, idGenerator);

        assertEquals("mytable", link.getTable());
        assertEquals("USER.12:34", link.getMasterRecordId().toString());
    }
View Full Code Here


    }

    @Test
    public void testFromString_NoTable_WithColonsInId() {
        String idString = "USER.12:34";
        Link link = Link.fromString(idString, idGenerator);

        assertNull(link.getTable());
        assertEquals("USER.12:34", link.getMasterRecordId().toString());
    }
View Full Code Here

        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

    @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

    @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

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

    @Test
    public void testLinkToSelf() {
        Link link = Link.newBuilder().create();
        assertNull(link.getMasterRecordId());
        assertEquals(".", 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> 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

        assertEquals(recordId, resolved);
    }

    @Test
    public void testLinkToMaster() {
        Link link = Link.newBuilder().copyAll(false).create();
        assertNull(link.getMasterRecordId());
        assertEquals(".!*", 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> 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

        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
        }
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

    }

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

        assertEquals(recordId, link.getMasterRecordId());
        assertEquals("mytable", link.getTable());
    }
View Full Code Here

TOP

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

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.