Package com.semagia.atomico.server.feed.impl

Source Code of com.semagia.atomico.server.feed.impl.TestAbstractLinkAwareEntity$LinkAwareEntity

/*
* Copyright 2008 Lars Heuer (heuer[at]semagia.com). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.semagia.atomico.server.feed.impl;

import java.net.URI;
import java.util.Collections;
import java.util.Set;

import com.semagia.atomico.dm.IAuthor;
import com.semagia.atomico.dm.IAuthorAwareEntity;
import com.semagia.atomico.dm.IEntity;
import com.semagia.atomico.dm.ISummaryAwareEntity;
import com.semagia.atomico.server.dm.impl.AbstractDataModelTestCase;

/**
* Tests against {@link AbstractLinkAwareEntity}.
*
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
* @version $Rev: 117 $ - $Date: 2010-11-06 09:39:35 -0500 (Sat, 06 Nov 2010) $
*/
public class TestAbstractLinkAwareEntity extends AbstractDataModelTestCase {

    public void testIllegalEntity() {
        try {
            new LinkAwareEntity(null, URI.create("http://www.semagia.com/"));
            fail("Expected an error if the entity is null");
        }
        catch (IllegalArgumentException ex) {
            // noop-
        }
    }

    public void testIllegalLink() {
        try {
            new LinkAwareEntity(new MockEntity("id", "title", now()), null);
            fail("Expected an error if the link is null");
        }
        catch (IllegalArgumentException ex) {
            // noop-
        }
    }

    public void testProperties() {
        final String id = "id";
        final String title = "title";
        final long updated = now();
        final String link = "http://www.semagia.com/";
        final MockEntity entity = new MockEntity(id, title, updated);
        LinkAwareEntity info = new LinkAwareEntity(entity, URI.create(link));
        assertEquals(id, info.getId());
        assertEquals(title, info.getTitle());
        assertEquals(updated, info.getUpdated());
        assertEquals(link, info.getLink());
        assertTrue(info.getAuthors().isEmpty());
        assertNull(info.getSummary());
        final String summary = "Summary";
        entity._summary = summary;
        assertEquals(summary, info.getSummary());
        final IAuthor author = createAuthor();
        entity._authors = Collections.singleton(author);
        assertEquals(1, info.getAuthors().size());
        assertEquals(author, info.getAuthors().iterator().next());
    }


    private static class LinkAwareEntity extends AbstractLinkAwareEntity<MockEntity> {

        protected LinkAwareEntity(MockEntity entity, URI link) {
            super(entity, link);
        }
    }

    private static class MockEntity implements IEntity, ISummaryAwareEntity, IAuthorAwareEntity {

        private String _id;
        private String _title;
        private long _updated;
        private String _summary;
        private Set<IAuthor> _authors;

        public MockEntity(String id, String title, long updated) {
            _id = id;
            _title = title;
            _updated = updated;
        }

        @Override
        public String getId() {
            return _id;
        }

        @Override
        public String getTitle() {
            return _title;
        }

        @Override
        public long getUpdated() {
            return _updated;
        }

        @Override
        public String getSummary() {
            return _summary;
        }

        @Override
        public Set<IAuthor> getAuthors() {
            return _authors == null ? Collections.<IAuthor>emptySet() : _authors;
        }

    }
}
TOP

Related Classes of com.semagia.atomico.server.feed.impl.TestAbstractLinkAwareEntity$LinkAwareEntity

TOP
Copyright © 2018 www.massapi.com. 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.