/*
* 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.util.Set;
import com.semagia.atomico.dm.IAuthor;
import com.semagia.atomico.server.dm.impl.AbstractDataModelTestCase;
import com.semagia.atomico.server.feed.impl.AbstractFeed;
/**
* Tests against the {@link AbstractFeed}.
*
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
*/
public class TestAbstractFeed extends AbstractDataModelTestCase {
public void testProperties() {
final String id = "id";
final String title = "title";
final long updated = now();
Feed feed = new Feed(id, title, updated);
assertNull(feed.getSummary());
assertEquals(id, feed.getId());
assertEquals(title, feed.getTitle());
assertEquals(updated, feed.getUpdated());
assertEquals(0, feed.getAuthors().size());
assertEquals(0, feed.getEntries().size());
final String summary = "Summary";
feed = new Feed(id, title, updated, summary);
assertEquals(summary, feed.getSummary());
final String authorName = "author";
final String authorEmail = "email";
final String authorIRI = "iri";
feed = new Feed(id, title, updated);
feed.addAuthor(createAuthor(authorName, authorEmail, authorIRI));
final Set<IAuthor> authors = feed.getAuthors();
assertEquals(1, authors.size());
final IAuthor author = authors.iterator().next();
assertEquals(authorName, author.getName());
assertEquals(authorEmail, author.getEmail());
assertEquals(authorIRI, author.getIRI());
try {
feed.addAuthor(null);
fail("addAuthor(null) is not allowed");
}
catch (IllegalArgumentException ex) {
// noop.
}
try {
feed.addEntry(null);
fail("addEntry(null) is not allowed");
}
catch (IllegalArgumentException ex) {
// noop.
}
assertEquals(0, feed.getEntries().size());
final Object entry = new Object();
feed.addEntry(entry);
assertEquals(1, feed.getEntries().size());
assertEquals(entry, feed.getEntries().iterator().next());
}
public void testIllegalConstructor() {
try {
new Feed(null, "title", now());
fail("The id of a feed must not be null");
}
catch(IllegalArgumentException ex) {
// noop.
}
try {
new Feed("id", null, now());
fail("The title of a feed must not be null");
}
catch(IllegalArgumentException ex) {
// noop.
}
}
private static class Feed extends AbstractFeed<Object> {
public Feed(String id, String title, long updated) {
super(id, title, updated);
}
public Feed(String id, String title, long updated, final String summary) {
super(id, title, updated, summary);
}
}
}