Package move.

This commit is contained in:
kebernet 2011-04-01 05:02:52 +00:00
parent e078d8ce8d
commit 0e231ac7b4
8 changed files with 0 additions and 1156 deletions

View file

@ -1,452 +0,0 @@
/*
* Copyright 2007 Sun Microsystems, Inc.
*
* 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.sun.syndication.propono.atom.client;
import com.sun.syndication.feed.atom.Category;
import com.sun.syndication.feed.atom.Content;
import com.sun.syndication.propono.utils.ProponoException;
import com.sun.syndication.propono.atom.common.Categories;
import com.sun.syndication.propono.atom.common.Collection;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Simple APP test designed to run against a live Atom server.
*/
public class AtomClientTest extends TestCase {
private static Log log =
LogFactory.getFactory().getInstance(AtomClientTest.class);
private static ClientAtomService service = null;
// Basic Auth example
private static String endpoint = "http://localhost:8080/sample-atomserver/app";
private static String username = "admin";
private static String password = "admin";
static {
try {
service = AtomClientFactory.getAtomService(endpoint,
new BasicAuthStrategy(username, password));
} catch (Exception e) {
log.error("ERROR creating service", e);
}
}
/*
// Roller OAuth example
private static String endpoint = "http://macsnoopdave:8080/roller-services/app";
private static String consumerKey = "55132608a2fb68816bcd3d1caeafc933";
private static String consumerSecret = "bb420783-fdea-4270-ab83-36445c18c307";
private static String requestUri = "http://macsnoopdave:8080/roller-services/oauth/requestToken";
private static String authorizeUri = "http://macsnoopdave:8080/roller-services/oauth/authorize?userId=roller&oauth_callback=none";
private static String accessUri = "http://macsnoopdave:8080/roller-services/oauth/accessToken";
private static String username = "roller";
private static String password = "n/a";
static {
try {
service = AtomClientFactory.getAtomService(endpoint,
new OAuthStrategy(
username, consumerKey, consumerSecret, "HMAC-SHA1",
requestUri, authorizeUri, accessUri));
} catch (Exception e) {
log.error("ERROR creating service", e);
}
}
*/
// GData Blogger API
/*
private static String endpoint = "http://www.blogger.com/feeds/default/blogs?alt=atom-service";
private static String email = "EMAIL";
private static String password = "PASSWORD";
private static String serviceName = "blogger";
static {
try {
service = AtomClientFactory.getAtomService(endpoint,
new GDataAuthStrategy(email, password, serviceName));
} catch (Exception e) {
log.error("ERROR creating service", e);
}
}
*/
private int maxPagingEntries = 10;
public AtomClientTest(String testName) {
super(testName);
}
public String getEndpoint() {
return endpoint;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
protected void setUp() throws Exception {
}
protected void tearDown() throws Exception {
}
public static Test suite() {
TestSuite suite = new TestSuite(AtomClientTest.class);
return suite;
}
/**
* Tests that server has introspection doc with at least one workspace.
*/
public void testGetAtomService() throws Exception {
assertNotNull(service);
assertTrue(service.getWorkspaces().size() > 0);
for (Iterator it = service.getWorkspaces().iterator(); it.hasNext();) {
ClientWorkspace space = (ClientWorkspace) it.next();
assertNotNull(space.getTitle());
log.debug("Workspace: " + space.getTitle());
for (Iterator colit = space.getCollections().iterator(); colit.hasNext();) {
ClientCollection col = (ClientCollection) colit.next();
log.debug(" Collection: " + col.getTitle() + " Accepts: " + col.getAccepts());
log.debug(" href: " + col.getHrefResolved());
assertNotNull(col.getTitle());
}
}
}
/**
* Tests that entries can be posted and removed in all collections that
* accept entries. Fails if no collections found that accept entries.
*/
public void testSimpleEntryPostAndRemove() throws Exception {
assertNotNull(service);
assertTrue(service.getWorkspaces().size() > 0);
int count = 0;
for (Iterator it = service.getWorkspaces().iterator(); it.hasNext();) {
ClientWorkspace space = (ClientWorkspace) it.next();
assertNotNull(space.getTitle());
for (Iterator colit = space.getCollections().iterator(); colit.hasNext();) {
ClientCollection col = (ClientCollection) colit.next();
if (col.accepts(Collection.ENTRY_TYPE)) {
// we found a collection that accepts entries, so post one
ClientEntry m1 = col.createEntry();
m1.setTitle("Test post");
Content c = new Content();
c.setValue("This is a test post");
c.setType("html");
m1.setContent(c);
col.addEntry(m1);
// entry should now exist on server
ClientEntry m2 = col.getEntry(m1.getEditURI());
assertNotNull(m2);
// remove entry
m2.remove();
// fetching entry now should result in exception
boolean failed = false;
try {
col.getEntry(m1.getEditURI());
} catch (ProponoException e) {
failed = true;
}
assertTrue(failed);
count++;
}
}
}
assertTrue(count > 0);
}
/**
* Tests that entries can be posted, updated and removed in all collections that
* accept entries. Fails if no collections found that accept entries.
*/
public void testSimpleEntryPostUpdateAndRemove() throws Exception {
assertNotNull(service);
assertTrue(service.getWorkspaces().size() > 0);
int count = 0;
for (Iterator it = service.getWorkspaces().iterator(); it.hasNext();) {
ClientWorkspace space = (ClientWorkspace) it.next();
assertNotNull(space.getTitle());
for (Iterator colit = space.getCollections().iterator(); colit.hasNext();) {
ClientCollection col = (ClientCollection) colit.next();
if (col.accepts(Collection.ENTRY_TYPE)) {
// we found a collection that accepts entries, so post one
ClientEntry m1 = col.createEntry();
m1.setTitle(col.getTitle() + ": Test post");
Content c = new Content();
c.setValue("This is a test post");
c.setType("html");
m1.setContent(c);
col.addEntry(m1);
// entry should now exist on server
ClientEntry m2 = (ClientEntry)col.getEntry(m1.getEditURI());
assertNotNull(m2);
m2.setTitle(col.getTitle() + ": Updated title");
m2.update();
// entry should now be updated on server
ClientEntry m3 = (ClientEntry)col.getEntry(m1.getEditURI());
assertEquals(col.getTitle() + ": Updated title", m3.getTitle());
// remove entry
m3.remove();
// fetching entry now should result in exception
boolean failed = false;
try {
col.getEntry(m1.getEditURI());
} catch (ProponoException e) {
failed = true;
}
assertTrue(failed);
count++;
}
}
}
assertTrue(count > 0);
}
public void testFindWorkspace() throws Exception {
assertNotNull(service);
ClientWorkspace ws = (ClientWorkspace)service.findWorkspace("adminblog");
if (ws != null) {
ClientCollection col = (ClientCollection)ws.findCollection(null, "entry");
ClientEntry entry = col.createEntry();
entry.setTitle("NPE on submitting order query");
entry.setContent("This is a <b>bad</b> one!", Content.HTML);
col.addEntry(entry);
// entry should now exist on server
ClientEntry saved = (ClientEntry)col.getEntry(entry.getEditURI());
assertNotNull(saved);
// remove entry
saved.remove();
// fetching entry now should result in exception
boolean failed = false;
try {
col.getEntry(saved.getEditURI());
} catch (ProponoException e) {
failed = true;
}
assertTrue(failed);
}
}
/**
* Test posting an entry to every available collection with a fixed and
* an unfixed category if server support allows, then cleanup.
*/
public void testEntryPostWithCategories() throws Exception {
assertNotNull(service);
assertTrue(service.getWorkspaces().size() > 0);
int count = 0;
for (Iterator it = service.getWorkspaces().iterator(); it.hasNext();) {
ClientWorkspace space = (ClientWorkspace) it.next();
assertNotNull(space.getTitle());
for (Iterator colit = space.getCollections().iterator(); colit.hasNext();) {
ClientCollection col = (ClientCollection) colit.next();
if (col.accepts(Collection.ENTRY_TYPE)) {
// we found a collection that accepts GIF, so post one
ClientEntry m1 = col.createEntry();
m1.setTitle("Test post");
Content c = new Content();
c.setValue("This is a test post");
c.setType("html");
m1.setContent(c);
// if possible, pick one fixed an un unfixed category
Category fixedCat = null;
Category unfixedCat = null;
List entryCats = new ArrayList();
for (int i=0; i<col.getCategories().size(); i++) {
Categories cats = (Categories)col.getCategories().get(i);
if (cats.isFixed() && fixedCat == null) {
String scheme = cats.getScheme();
fixedCat = (Category)cats.getCategories().get(0);
if (fixedCat.getScheme() == null) fixedCat.setScheme(scheme);
entryCats.add(fixedCat);
} else if (!cats.isFixed() && unfixedCat == null) {
String scheme = cats.getScheme();
unfixedCat = new Category();
unfixedCat.setScheme(scheme);
unfixedCat.setTerm("tagster");
entryCats.add(unfixedCat);
}
}
m1.setCategories(entryCats);
col.addEntry(m1);
// entry should now exist on server
ClientEntry m2 = (ClientEntry)col.getEntry(m1.getEditURI());
assertNotNull(m2);
if (fixedCat != null) {
// we added a fixed category, let's make sure it's there
boolean foundCat = false;
for (Iterator catit = m2.getCategories().iterator(); catit.hasNext();) {
Category cat = (Category) catit.next();
if ( cat.getTerm().equals( fixedCat.getTerm())) {
foundCat = true;
}
}
assertTrue(foundCat);
}
if (unfixedCat != null) {
// we added an unfixed category, let's make sure it's there
boolean foundCat = false;
for (Iterator catit = m2.getCategories().iterator(); catit.hasNext();) {
Category cat = (Category) catit.next();
if (cat.getTerm().equals( unfixedCat.getTerm())) {
foundCat = true;
}
}
assertTrue(foundCat);
}
// remove entry
m2.remove();
// fetching entry now should result in exception
boolean failed = false;
try {
col.getEntry(m1.getEditURI());
} catch (ProponoException e) {
failed = true;
}
assertTrue(failed);
count++;
}
}
}
assertTrue(count > 0);
}
/**
* Post media entry to every media colletion avialable on server, then cleanup.
*/
public void testMediaPost() throws Exception {
assertNotNull(service);
assertTrue(service.getWorkspaces().size() > 0);
int count = 0;
for (Iterator it = service.getWorkspaces().iterator(); it.hasNext();) {
ClientWorkspace space = (ClientWorkspace) it.next();
assertNotNull(space.getTitle());
for (Iterator colit = space.getCollections().iterator(); colit.hasNext();) {
ClientCollection col = (ClientCollection) colit.next();
if (col.accepts("image/gif")) {
// we found a collection that accepts GIF, so post one
ClientMediaEntry m1 = col.createMediaEntry("duke"+count, "duke"+count, "image/gif",
new FileInputStream("test/testdata/duke-wave-shadow.gif"));
col.addEntry(m1);
// entry should now exist on server
ClientMediaEntry m2 = (ClientMediaEntry)col.getEntry(m1.getEditURI());
assertNotNull(m2);
// remove entry
m2.remove();
// fetching entry now should result in exception
boolean failed = false;
try {
col.getEntry(m1.getEditURI());
} catch (ProponoException e) {
failed = true;
}
assertTrue(failed);
count++;
}
}
}
assertTrue(count > 0);
}
/**
* Post X media entries each media collection found, test paging, then cleanup.
*
public void testMediaPaging() throws Exception {
ClientAtomService service = getClientAtomService();
assertNotNull(service);
assertTrue(service.getWorkspaces().size() > 0);
int count = 0;
for (Iterator it = service.getWorkspaces().iterator(); it.hasNext();) {
ClientWorkspace space = (ClientWorkspace) it.next();
assertNotNull(space.getTitle());
for (Iterator colit = space.getCollections().iterator(); colit.hasNext();) {
ClientCollection col = (ClientCollection) colit.next();
if (col.accepts("image/gif")) {
// we found a collection that accepts GIF, so post 100 of them
List posted = new ArrayList();
for (int i=0; i<maxPagingEntries; i++) {
ClientMediaEntry m1 = col.createMediaEntry("duke"+count, "duke"+count, "image/gif",
new FileInputStream("test/testdata/duke-wave-shadow.gif"));
col.addEntry(m1);
posted.add(m1);
}
int entryCount = 0;
for (Iterator iter = col.getEntries(); iter.hasNext();) {
ClientMediaEntry entry = (ClientMediaEntry) iter.next();
entryCount++;
}
for (Iterator delit = posted.iterator(); delit.hasNext();) {
ClientEntry entry = (ClientEntry) delit.next();
entry.remove();
}
assertTrue(entryCount >= maxPagingEntries);
count++;
break;
}
}
}
assertTrue(count > 0);
}*/
}

View file

@ -1,86 +0,0 @@
/*
* Copyright 2007 Sun Microsystems, Inc.
*
* 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.sun.syndication.propono.atom.client;
import com.sun.syndication.feed.atom.Content;
import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Simple APP test designed to run against Blogger.com.
*/
public class BloggerDotComTest extends TestCase {
private String collectionURI = "http://www.blogger.com/feeds/BLOGID/posts/default";
private String atomServiceURI= "http://www.blogger.com/feeds/default/blogs?alt=atom-service";
private String email = "EMAIL";
private String password = "PASSWORD";
public BloggerDotComTest(String testName) {
super(testName);
}
protected void setUp() throws Exception {
}
protected void tearDown() throws Exception {
}
public static Test suite() {
TestSuite suite = new TestSuite(BloggerDotComTest.class);
return suite;
}
/**
* Verify that server returns service document containing workspaces containing collections.
*/
public void testGetEntries() throws Exception {
// no auth necessary for iterating through entries
ClientCollection col = AtomClientFactory.getCollection(collectionURI,
new GDataAuthStrategy(email, password, "blogger"));
assertNotNull(col);
int count = 0;
for (Iterator it = col.getEntries(); it.hasNext();) {
ClientEntry entry = (ClientEntry) it.next();
assertNotNull(entry);
count++;
}
assertTrue(count > 0);
col = AtomClientFactory.getCollection(collectionURI,
new GDataAuthStrategy(email, password, "blogger"));
ClientEntry p1 = col.createEntry();
p1.setTitle("Propono post");
Content c = new Content();
c.setValue("This is content from ROME Propono");
p1.setContent(c);
col.addEntry(p1);
ClientEntry p2 = col.getEntry(p1.getEditURI());
assertNotNull(p2);
ClientAtomService atomService = AtomClientFactory.getAtomService(
collectionURI, new GDataAuthStrategy(email, password, "blogger"));
assertNotNull(atomService);
}
}

View file

@ -1,156 +0,0 @@
/*
* Copyright 2007 Sun Microsystems, Inc.
*
* 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.sun.syndication.propono.atom.common;
import com.sun.syndication.feed.atom.Category;
import java.io.FileInputStream;
import java.util.Iterator;
import junit.framework.*;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
/**
* Tests reading and writing of service document, no server needed.
*/
public class AtomServiceTest extends TestCase {
public AtomServiceTest(String testName) {
super(testName);
}
protected void setUp() throws Exception {
}
protected void tearDown() throws Exception {
}
public static Test suite() {
TestSuite suite = new TestSuite(AtomServiceTest.class);
return suite;
}
/**
* Test of documentToService method, of class AtomService.
*/
public void testDocumentToService() {
try {
// Load service document from disk
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new FileInputStream("test/testdata/servicedoc1.xml"));
assertNotNull(document);
AtomService service = AtomService.documentToService(document);
int workspaceCount = 0;
// Verify that service contains expected workspaces, collections and categories
for (Iterator it = service.getWorkspaces().iterator(); it.hasNext();) {
Workspace space = (Workspace)it.next();
assertNotNull(space.getTitle());
workspaceCount++;
int collectionCount = 0;
for (Iterator colit = space.getCollections().iterator(); colit.hasNext();) {
Collection col = (Collection)colit.next();
assertNotNull(col.getTitle());
assertNotNull(col.getHrefResolved());
collectionCount++;
int catCount = 0;
if (col.getCategories().size() > 0) {
for (Iterator catsit = col.getCategories().iterator(); catsit.hasNext();) {
Categories cats = (Categories) catsit.next();
for (Iterator catit = cats.getCategories().iterator(); catit.hasNext();) {
Category cat = (Category) catit.next();
catCount++;
}
assertTrue(catCount > 0);
}
}
}
}
assertTrue(workspaceCount > 0);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
/**
* Test of documentToService method, of class AtomService.
*/
public void testServiceToDocument() {
try {
// Create service with workspace and collections
AtomService service = new AtomService();
Workspace workspace1 = new Workspace("workspace1", null);
Workspace workspace2 = new Workspace("workspace1", null);
service.addWorkspace(workspace1);
service.addWorkspace(workspace2);
Collection collection11 =
new Collection("collection11", null, "http://example.com/app/col11");
Collection collection12 =
new Collection("collection12", null, "http://example.com/app/col12");
workspace1.addCollection(collection11);
workspace1.addCollection(collection12);
Collection collection21 =
new Collection("collection21", null, "http://example.com/app/col21");
Collection collection22 =
new Collection("collection22", null, "http://example.com/app/col22");
workspace2.addCollection(collection21);
workspace2.addCollection(collection22);
// TODO: add categories at collection level
// Convert to JDOM document
Document document = service.serviceToDocument();
// verify that JDOM document contains service, workspace and collection
assertEquals("service", document.getRootElement().getName());
int workspaceCount = 0;
for (Iterator spaceit = document.getRootElement().getChildren().iterator(); spaceit.hasNext();) {
Element elem = (Element) spaceit.next();
if ("workspace".equals(elem.getName())) {
workspaceCount++;
}
boolean workspaceTitle = false;
int collectionCount = 0;
for (Iterator colit = elem.getChildren().iterator(); colit.hasNext();) {
Element colelem = (Element) colit.next();
if ("title".equals(colelem.getName())) {
workspaceTitle = true;
} else if ("collection".equals(colelem.getName())){
collectionCount++;
}
// TODO: test for categories at the collection level
}
assertTrue(workspaceTitle);
assertTrue(collectionCount > 0);
}
assertTrue(workspaceCount > 0);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
}

View file

@ -1,67 +0,0 @@
/*
* Copyright 2007 Sun Microsystems, Inc.
*
* 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.sun.syndication.propono.atom.common;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import junit.framework.*;
/**
* Tests Collection class, no server needed.
*/
public class CollectionTest extends TestCase {
public CollectionTest(String testName) {
super(testName);
}
protected void setUp() throws Exception {
}
protected void tearDown() throws Exception {
}
/**
* Test of accepts method, of class com.sun.syndication.propono.atom.common.Collection.
*/
public void testAccepts() {
Collection col =
new Collection("dummy_title","dummy_titletype","dummy_href");
col.setAccepts(Collections.singletonList("image/*"));
assertTrue(col.accepts("image/gif"));
assertTrue(col.accepts("image/jpg"));
assertTrue(col.accepts("image/png"));
assertFalse(col.accepts("test/html"));
List accepts = new ArrayList();
accepts.add("image/*");
accepts.add("text/*");
col.setAccepts(accepts);
assertTrue(col.accepts("image/gif"));
assertTrue(col.accepts("image/jpg"));
assertTrue(col.accepts("image/png"));
assertTrue(col.accepts("text/html"));
col.setAccepts(Collections.singletonList("*/*"));
assertTrue(col.accepts("image/gif"));
assertTrue(col.accepts("image/jpg"));
assertTrue(col.accepts("image/png"));
assertTrue(col.accepts("text/html"));
}
}

View file

@ -1,122 +0,0 @@
/*
* Copyright 2007 Sun Microsystems, Inc.
*
* 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.sun.syndication.propono.atom.server;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.mortbay.http.HttpContext;
import org.mortbay.http.HttpServer;
import org.mortbay.http.SocketListener;
import org.mortbay.jetty.servlet.ServletHandler;
/**
* Test Propono Atom Client against Atom Server via Jetty. Extends
* <code>AtomClientTest</code> to start Jetty server, run tests and then stop
* the Jetty server.
*/
public class AtomClientServerTest { // extends AtomClientTest {
private HttpServer server;
public static final int TESTPORT = 8283;
public static final String ENDPOINT = "http://localhost:" + TESTPORT + "/rome/app";
public static final String USERNAME = "admin";
public static final String PASSWORD = "admin";
public AtomClientServerTest(String s) {
//super(s);
}
public String getEndpoint() {
return ENDPOINT;
}
public String getUsername() {
return USERNAME;
}
public String getPassword() {
return PASSWORD;
}
public static Test suite() {
TestSuite suite = new TestSuite(AtomClientServerTest.class);
return suite;
}
protected HttpServer getServer() {
return server;
}
protected void setUp() throws Exception {
ConsoleHandler handler = new ConsoleHandler();
Logger logger = Logger.getLogger("com.sun.syndication.propono");
logger.setLevel(Level.FINEST);
logger.addHandler(handler);
setupServer();
HttpContext context = createContext();
ServletHandler servlets = createServletHandler();
context.addHandler(servlets);
server.addContext(context);
server.start();
}
private void setupServer() throws InterruptedException {
// Create the server
if (server != null) {
server.stop();
server = null;
}
server = new HttpServer();
// Create a port listener
SocketListener listener = new SocketListener();
listener.setPort(TESTPORT);
server.addListener(listener);
}
private ServletHandler createServletHandler() {
System.setProperty(
"com.sun.syndication.propono.atom.server.AtomHandlerFactory",
"com.sun.syndication.propono.atom.server.TestAtomHandlerFactory");
ServletHandler servlets = new ServletHandler();
servlets.addServlet(
"app", "/app/*",
"com.sun.syndication.propono.atom.server.AtomServlet");
return servlets;
}
private HttpContext createContext() {
HttpContext context = new HttpContext();
context.setContextPath("/rome/*");
return context;
}
protected void tearDown() throws Exception {
if (server != null) {
server.stop();
server.destroy();
server = null;
}
}
}

View file

@ -1,27 +0,0 @@
/*
* Copyright 2007 Sun Microsystems, Inc.
*
* 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.sun.syndication.propono.atom.server;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestAtomHandlerFactory extends AtomHandlerFactory {
public AtomHandler newAtomHandler(HttpServletRequest req, HttpServletResponse res) {
return new TestAtomHandlerImpl(req, "build/testuploaddir");
}
}

View file

@ -1,31 +0,0 @@
/*
* Copyright 2007 Sun Microsystems, Inc.
*
* 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.sun.syndication.propono.atom.server;
import com.sun.syndication.propono.atom.server.impl.FileBasedAtomHandler;
import javax.servlet.http.HttpServletRequest;
public class TestAtomHandlerImpl extends FileBasedAtomHandler {
public TestAtomHandlerImpl(HttpServletRequest req, String uploaddir) {
super(req, uploaddir);
}
public boolean validateUser( String loginId, String password ) {
return AtomClientServerTest.USERNAME.equals(loginId)
&& AtomClientServerTest.PASSWORD.equals(password);
}
}

View file

@ -1,215 +0,0 @@
/*
* Copyright 2007 Sun Microsystems, Inc.
*
* 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.sun.syndication.propono.blogclient;
import com.sun.syndication.io.impl.Atom10Parser;
import com.sun.syndication.propono.utils.Utilities;
import java.io.File;
import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Tests Atom and MetaWeblog API CRUD via BlogClient.
* Exclude this from automated tests because it requires a live blog server.
*/
public class SimpleBlogClientTest extends TestCase {
private String metaweblogEndpoint = "http://localhost:8080/roller/roller-services/xmlrpc";
//private String atomEndpoint = "http://localhost:8080/roller/roller-services/app";
private String atomEndpoint = "http://localhost:8080/sample-atomserver/app";
private String endpoint = "http://localhost:8080/atom-fileserver/app";
private String username = "admin";
private String password = "admin";
public SimpleBlogClientTest(String testName) {
super(testName);
}
protected void setUp() throws Exception {
}
protected void tearDown() throws Exception {
}
public void testBlogClientAtom() throws Exception {
testBlogClient("atom", atomEndpoint);
}
public void testBlogClientMetaWeblog() throws Exception{
testBlogClient("metaweblog", metaweblogEndpoint);
}
public void testBlogClient(String type, String endpoint) throws Exception {
BlogConnection conn = BlogConnectionFactory
.getBlogConnection(type, endpoint, username, password);
int blogCount = 0;
for (Iterator it = conn.getBlogs().iterator(); it.hasNext();) {
Blog blog = (Blog) it.next();
System.out.println(blog.getName());
blogCount++;
}
assertTrue(blogCount > 0);
}
public void testPostAndDeleteAtom() throws Exception {
testPostAndDelete("atom", atomEndpoint);
}
public void testPostAndDeleteMetaWeblog() throws Exception {
testPostAndDelete("metaweblog", metaweblogEndpoint);
}
public void testMediaPostAtom() throws Exception {
testMediaPost("atom", atomEndpoint);
}
public void testMediaPostMetaWeblog() throws Exception {
testMediaPost("metaweblog", metaweblogEndpoint);
}
public void testPostAndDelete(String type, String endpoint) throws Exception {
BlogConnection conn = BlogConnectionFactory
.getBlogConnection(type, endpoint, username, password);
assertNotNull(conn);
String title1 = "Test content";
String content1 = "Test content";
Blog blog = (Blog)conn.getBlogs().get(0);
BlogEntry entry = blog.newEntry();
entry.setTitle(title1);
entry.setContent(new BlogEntry.Content(content1));
entry.save();
String token = entry.getToken();
assertNotNull(token);
entry = blog.getEntry(token);
assertEquals(title1, entry.getTitle());
assertEquals(content1, entry.getContent().getValue());
assertNotNull(entry);
entry.delete();
entry = null;
boolean notFound = false;
try {
entry = blog.getEntry(token);
} catch (Exception e) {
notFound = true;
}
assertTrue(notFound);
}
/**
* Post media entry to every media colletion avialable on server, then cleanup.
*/
public void testMediaPost(String type, String endpoint) throws Exception {
BlogConnection conn = BlogConnectionFactory
.getBlogConnection(type, endpoint, username, password);
assertNotNull(conn);
assertTrue(conn.getBlogs().size() > 0);
int count = 0;
for (Iterator it = conn.getBlogs().iterator(); it.hasNext();) {
Blog blog = (Blog) it.next();
assertNotNull(blog.getName());
for (Iterator colit = blog.getCollections().iterator(); colit.hasNext();) {
Blog.Collection col = (Blog.Collection) colit.next();
if (col.accepts("image/gif")) {
// we found a collection that accepts GIF, so post one
BlogResource m1 = col.newResource("duke"+count, "image/gif",
Utilities.getBytesFromFile(new File("test/testdata/duke-wave-shadow.gif")));
col.saveResource(m1);
if ("atom".equals(type)) { // additional tests for Atom
// entry should now exist on server
BlogResource m2 = (BlogResource)blog.getEntry(m1.getToken());
assertNotNull(m2);
// remove entry
m2.delete();
// fetching entry now should result in exception
boolean failed = false;
try {
blog.getEntry(m1.getToken());
} catch (Exception e) {
failed = true;
}
assertTrue(failed);
}
count++;
}
}
}
assertTrue(count > 0);
}
public void testEntryIterationAtom() throws Exception {
testEntryIteration("atom", atomEndpoint);
}
public void testEntryIterationMetaWeblog() throws Exception {
testEntryIteration("metaweblog", metaweblogEndpoint);
}
public void testEntryIteration(String type, String endpoint) throws Exception {
BlogConnection conn = BlogConnectionFactory
.getBlogConnection(type, endpoint, username, password);
assertNotNull(conn);
String title1 = "Test content";
String content1 = "Test content";
Blog blog = (Blog)conn.getBlogs().get(0);
for (int i=0; i<10; i++) {
BlogEntry entry = blog.newEntry();
entry.setTitle(title1);
entry.setContent(new BlogEntry.Content(content1));
entry.save();
String token = entry.getToken();
assertTrue(Atom10Parser.isAbsoluteURI(token));
assertNotNull(token);
}
for (Iterator it = blog.getEntries(); it.hasNext();) {
BlogEntry blogEntry = (BlogEntry)it.next();
assertTrue(Atom10Parser.isAbsoluteURI(blogEntry.getToken()));
blogEntry.delete();
}
}
public static Test suite() {
TestSuite suite = new TestSuite(SimpleBlogClientTest.class);
return suite;
}
}