diff --git a/src/test/java/com/sun/syndication/propono/atom/client/AtomClientTest.java b/src/test/java/com/sun/syndication/propono/atom/client/AtomClientTest.java deleted file mode 100644 index 0ac6738..0000000 --- a/src/test/java/com/sun/syndication/propono/atom/client/AtomClientTest.java +++ /dev/null @@ -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 bad 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
AtomClientTest
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;
- }
- }
-}
-
-
diff --git a/src/test/java/com/sun/syndication/propono/atom/server/TestAtomHandlerFactory.java b/src/test/java/com/sun/syndication/propono/atom/server/TestAtomHandlerFactory.java
deleted file mode 100644
index ddf665e..0000000
--- a/src/test/java/com/sun/syndication/propono/atom/server/TestAtomHandlerFactory.java
+++ /dev/null
@@ -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");
- }
-}
diff --git a/src/test/java/com/sun/syndication/propono/atom/server/TestAtomHandlerImpl.java b/src/test/java/com/sun/syndication/propono/atom/server/TestAtomHandlerImpl.java
deleted file mode 100644
index 0fdec0e..0000000
--- a/src/test/java/com/sun/syndication/propono/atom/server/TestAtomHandlerImpl.java
+++ /dev/null
@@ -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);
- }
-}
\ No newline at end of file
diff --git a/src/test/java/com/sun/syndication/propono/blogclient/SimpleBlogClientTest.java b/src/test/java/com/sun/syndication/propono/blogclient/SimpleBlogClientTest.java
deleted file mode 100644
index 910dcaf..0000000
--- a/src/test/java/com/sun/syndication/propono/blogclient/SimpleBlogClientTest.java
+++ /dev/null
@@ -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;
- }
-}
-
-
-