/*
* 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 com.semagia.atomico.MediaType;
import com.semagia.atomico.dm.IResource;
import com.semagia.atomico.dm.impl.Resource;
import com.semagia.atomico.server.dm.IFragmentInfo;
import com.semagia.atomico.server.dm.impl.AbstractDataModelTestCase;
import com.semagia.atomico.server.dm.impl.FragmentInfo;
import com.semagia.atomico.server.feed.impl.IFragmentsFeed.IFragmentEntry;
/**
* Tests against the {@link FragmentsFeed}.
*
* @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
*/
public class TestFragmentsFeed extends AbstractDataModelTestCase {
public void testEntry() {
final FragmentsFeed feed = new FragmentsFeed("id", "title", now());
assertTrue(feed.getEntries().isEmpty());
final String linkAdr = "http://www.semagia.com/link";
final URI link = URI.create(linkAdr);
final String id = "http://www.semagia.com/test";
final String title = "title";
final long updated = now();
final MediaType mt = MediaType.ATOM_XML;
final String sid = "http://psi.semagia.com/subject-identifier";
final IResource res = new Resource(sid);
final IFragmentInfo fragInfo = new FragmentInfo(id, title, updated, mt, "fragId", res);
feed.addEntry(fragInfo, link);
assertEquals(1, feed.getEntries().size());
final IFragmentEntry entry = feed.getEntries().iterator().next();
assertNotNull(entry);
assertEquals(id, entry.getId());
assertEquals(title, entry.getTitle());
assertEquals(linkAdr, entry.getLink());
assertEquals(updated, entry.getUpdated());
assertEquals(1, entry.getResources().size());
assertEquals(res, entry.getResources().iterator().next());
assertEquals(1, entry.getMediaTypes().size());
assertEquals(mt, entry.getMediaTypes().iterator().next());
}
public void testIllegalEntry() {
final FragmentsFeed feed = new FragmentsFeed("id", "title", now());
try {
feed.addEntry(null);
fail("feed.addEntry(null) is illegal");
}
catch (IllegalArgumentException ex) {
// noop.
}
try {
feed.addEntry(null, URI.create("http://www.semagia.com/"));
fail("feed.addEntry(null, uri) is illegal");
}
catch (IllegalArgumentException ex) {
// noop.
}
final String id = "http://www.semagia.com/test";
final String title = "title";
final long updated = now();
final MediaType mt = MediaType.ATOM_XML;
final String sid = "http://psi.semagia.com/subject-identifier";
final IResource res = new Resource(sid);
final IFragmentInfo fragInfo = new FragmentInfo(id, title, updated, mt, "fragId", res);
try {
feed.addEntry(fragInfo, null);
fail("feed.addEntry(info, null) is illegal");
}
catch (IllegalArgumentException ex) {
// noop.
}
}
}