roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r448278 [2/2] - in /incubator/roller/trunk: ./ src/org/apache/roller/webservices/adminapi/ src/org/apache/roller/webservices/adminapi/sdk/ tests/org/apache/roller/webservices/adminapi/ tests/org/apache/roller/webservices/adminapi/sdk/
Date Wed, 20 Sep 2006 17:52:26 GMT
Modified: incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/AappTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/AappTest.java?view=diff&rev=448278&r1=448277&r2=448278
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/AappTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/AappTest.java Wed Sep 20 10:52:25 2006
@@ -1,104 +1,69 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* 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.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
 package org.apache.roller.webservices.adminapi;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.Date;
 import java.util.Locale;
 import java.util.TimeZone;
 import junit.framework.TestCase;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.DeleteMethod;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.util.Base64;
 import org.apache.roller.webservices.adminapi.sdk.MemberEntry;
 import org.apache.roller.webservices.adminapi.sdk.MemberEntrySet;
-import org.apache.roller.webservices.adminapi.sdk.MissingElementException;
-import org.apache.roller.webservices.adminapi.sdk.UnexpectedRootElementException;
 import org.apache.roller.webservices.adminapi.sdk.UserEntry;
 import org.apache.roller.webservices.adminapi.sdk.UserEntrySet;
 import org.apache.roller.webservices.adminapi.sdk.WeblogEntry;
 import org.apache.roller.webservices.adminapi.sdk.WeblogEntrySet;
-import org.jdom.JDOMException;
 
-public class AappTest extends TestCase {
-    public static class HttpResponse {
-        private int status;
-        private InputStream responseBody;
-        
-        public HttpResponse(int status) {
-            this(status, null);
-        }
-        
-        public HttpResponse(int status, InputStream responseBody) {
-            this.status = status;
-            this.responseBody = responseBody;
-        }
-        
-        public int getStatus() {
-            return status;
-        }
-        
-        public InputStream getResponseBody() {
-            return responseBody;
-        }
-    }
-    
+public abstract class AappTest extends TestCase {
     private static final Date sampleDate = new Date();
-    private static final String DEFAULT_ENDPOINT_URL = "http://localhost:8080/roller/aapp";
+    private static final String DEFAULT_ENDPOINT_URL = "http://localhost:8080/roller/roller-services/aapp";
     private static final String DEFAULT_USER = "jtb";
     private static final String DEFAULT_PASSWORD = "iplanet";
-    
+        
     protected static String getEndpointUrl() {
         String endpoint = System.getProperty("aapp.endpoint");
         if (endpoint == null) {
             endpoint = DEFAULT_ENDPOINT_URL;
         }
         
-        System.err.println("endpoint=" + endpoint);
+        //System.err.println("endpoint=" + endpoint);
         return endpoint;
     }
-
+    
     protected static String getUser() {
         String user = System.getProperties().getProperty("aapp.user");
         if (user == null) {
             user = DEFAULT_USER;
         }
         
-        System.err.println("user=" + user);
+        //System.err.println("user=" + user);
         return user;
     }
-
+    
     protected static String getPassword() {
         String password = System.getProperties().getProperty("aapp.password");
         if (password == null) {
             password = DEFAULT_PASSWORD;
         }
         
-        System.err.println("password=" + password);        
+        //System.err.println("password=" + password);
         return password;
     }
-
+    
     protected static UserEntry getSampleUserEntry() {
         UserEntry ue = new UserEntry("foo", getEndpointUrl());
         ue.setEmailAddress("foo@bar.org");
@@ -106,10 +71,11 @@
         ue.setLocale(Locale.getDefault());
         ue.setTimezone(TimeZone.getDefault());
         ue.setPassword("foo");
+        ue.setEnabled(Boolean.TRUE);
         
         return ue;
     }
-
+    
     protected static MemberEntry getSampleMemberEntry() {
         MemberEntry me = new MemberEntry("fooblog", "foo", getEndpointUrl());
         me.setPermission(MemberEntry.Permissions.AUTHOR);
@@ -123,10 +89,11 @@
         ueUpdate.setLocale(new Locale("ms", "MY"));
         ueUpdate.setTimezone(TimeZone.getTimeZone("Asia/Kuala_Lumpur"));
         ueUpdate.setPassword("billy");
+        ueUpdate.setEnabled(Boolean.FALSE);
         
         return ueUpdate;
     }
-
+    
     protected static WeblogEntry updateSampleWeblogEntry(WeblogEntry we) {
         WeblogEntry weUpdate = new WeblogEntry(we.getHandle(), getEndpointUrl());
         weUpdate.setEmailAddress("billy@bob.org");
@@ -135,10 +102,11 @@
         weUpdate.setTimezone(TimeZone.getTimeZone("Asia/Kuala_Lumpur"));
         weUpdate.setDescription("Billy Bob Weblog Description");
         weUpdate.setCreatingUser(we.getCreatingUser());
+        weUpdate.setEnabled(Boolean.FALSE);
         
         return weUpdate;
     }
-
+    
     protected static MemberEntry updateSampleMemberEntry(MemberEntry me) {
         MemberEntry meUpdate = new MemberEntry(me.getHandle(), me.getName(), getEndpointUrl());
         meUpdate.setPermission(MemberEntry.Permissions.LIMITED);
@@ -148,7 +116,7 @@
     
     protected static UserEntrySet updateSampleUserEntrySet(UserEntrySet ues) {
         UserEntry ue = (UserEntry)ues.getEntries()[0];
-        UserEntry ueUpdated = updateSampleUserEntry(ue);        
+        UserEntry ueUpdated = updateSampleUserEntry(ue);
         UserEntrySet uesUpdated = new UserEntrySet(getEndpointUrl());
         uesUpdated.setEntries(new UserEntry[] { ueUpdated });
         
@@ -157,22 +125,22 @@
     
     protected static WeblogEntrySet updateSampleWeblogEntrySet(WeblogEntrySet wes) {
         WeblogEntry we = (WeblogEntry)wes.getEntries()[0];
-        WeblogEntry weUpdated = updateSampleWeblogEntry(we);        
+        WeblogEntry weUpdated = updateSampleWeblogEntry(we);
         WeblogEntrySet wesUpdated = new WeblogEntrySet(getEndpointUrl());
         wesUpdated.setEntries(new WeblogEntry[] { weUpdated });
         
         return wesUpdated;
     }
-
+    
     protected static MemberEntrySet updateSampleMemberEntrySet(MemberEntrySet mes) {
         MemberEntry me = (MemberEntry)mes.getEntries()[0];
-        MemberEntry meUpdated = updateSampleMemberEntry(me);        
+        MemberEntry meUpdated = updateSampleMemberEntry(me);
         MemberEntrySet mesUpdated = new MemberEntrySet(getEndpointUrl());
         mesUpdated.setEntries(new MemberEntry[] { meUpdated });
         
         return mesUpdated;
     }
-
+    
     protected static WeblogEntry getSampleWeblogEntry() {
         WeblogEntry we = new WeblogEntry("fooblog", getEndpointUrl());
         we.setEmailAddress("foo@bar.org");
@@ -181,9 +149,10 @@
         we.setLocale(Locale.getDefault());
         we.setTimezone(TimeZone.getDefault());
         we.setName("Foo Weblog Name");
+        we.setEnabled(Boolean.TRUE);
         
         return we;
-    }    
+    }
     
     protected static UserEntrySet getSampleUserEntrySet() {
         UserEntry ue = getSampleUserEntry();
@@ -208,289 +177,5 @@
         
         return mes;
     }
-
-    protected UserEntrySet createSampleUser() throws IOException, JDOMException, MissingElementException, UnexpectedRootElementException {
-        UserEntrySet ues = getSampleUserEntrySet();
-        
-        String url = ues.getHref();
-        String user = getUser();
-        String password = getPassword();
-        
-        String body = ues.toString();
-        
-        HttpResponse res = post(url, user, password, body);
-        assertEquals(201, res.getStatus());
-        
-        UserEntrySet uesResponse = null;
-        InputStream responseBody = res.getResponseBody();
-        if (responseBody != null) {
-           uesResponse = new UserEntrySet(responseBody, getEndpointUrl());
-        }
-        
-        return uesResponse;
-    }
-
-    protected UserEntrySet updateSampleUser() throws IOException, JDOMException, MissingElementException, UnexpectedRootElementException {
-        UserEntrySet ues = updateSampleUserEntrySet(getSampleUserEntrySet());
-        
-        String url = ues.getHref();
-        String user = getUser();
-        String password = getPassword();
-        
-        String body = ues.toString();
-        
-        HttpResponse res = put(url, user, password, body);
-        assertEquals(200, res.getStatus());
-        
-        UserEntrySet uesResponse = null;
-        InputStream responseBody = res.getResponseBody();
-        if (responseBody != null) {
-           uesResponse = new UserEntrySet(responseBody, getEndpointUrl());
-        }
-        
-        return uesResponse;
-    }
-
-    protected WeblogEntrySet updateSampleWeblog() throws IOException, JDOMException, MissingElementException, UnexpectedRootElementException {
-        WeblogEntrySet wes = updateSampleWeblogEntrySet(getSampleWeblogEntrySet());
-        
-        String url = wes.getHref();
-        String user = getUser();
-        String password = getPassword();
-        
-        String body = wes.toString();
-        
-        HttpResponse res = put(url, user, password, body);
-        assertEquals(200, res.getStatus());
-        
-        WeblogEntrySet wesResponse = null;
-        InputStream responseBody = res.getResponseBody();
-        if (responseBody != null) {
-           wesResponse = new WeblogEntrySet(responseBody, getEndpointUrl());
-        }
-        
-        return wesResponse;
-    }
-
-    protected MemberEntrySet updateSampleMember() throws IOException, JDOMException, MissingElementException, UnexpectedRootElementException {
-        MemberEntrySet mes = updateSampleMemberEntrySet(getSampleMemberEntrySet());
-        
-        String url = mes.getHref();
-        String user = getUser();
-        String password = getPassword();
-        
-        String body = mes.toString();
-        
-        HttpResponse res = put(url, user, password, body);
-        assertEquals(200, res.getStatus());
-        
-        MemberEntrySet mesResponse = null;
-        InputStream responseBody = res.getResponseBody();
-        if (responseBody != null) {
-           mesResponse = new MemberEntrySet(responseBody, getEndpointUrl());
-        }
-        
-        return mesResponse;
-    }
-    
-    protected WeblogEntrySet createSampleWeblog() throws IOException, JDOMException, MissingElementException, UnexpectedRootElementException {
-        WeblogEntrySet wes = getSampleWeblogEntrySet();
-        
-        String url = wes.getHref();
-        String user = getUser();
-        String password = getPassword();
-        
-        String body = wes.toString();
-        
-        HttpResponse res = post(url, user, password, body);
-        assertEquals(201, res.getStatus());
-        
-        WeblogEntrySet wesResponse = null;
-        InputStream responseBody = res.getResponseBody();
-        if (responseBody != null) {
-           wesResponse = new WeblogEntrySet(responseBody, getEndpointUrl());
-        }
-        
-        return wesResponse;
-    }
-
-    protected MemberEntrySet createSampleMember() throws IOException, JDOMException, MissingElementException, UnexpectedRootElementException {
-        MemberEntrySet mes = getSampleMemberEntrySet();
-        
-        String url = mes.getHref();
-        String user = getUser();
-        String password = getPassword();
-        
-        String body = mes.toString();
-        
-        HttpResponse res = post(url, user, password, body);
-        assertEquals(201, res.getStatus());
-        
-        MemberEntrySet mesResponse = null;
-        InputStream responseBody = res.getResponseBody();
-        if (responseBody != null) {
-           mesResponse = new MemberEntrySet(responseBody, getEndpointUrl());
-        }
-        
-        return mesResponse;
-    }
-    
-    protected UserEntrySet deleteSampleUser() throws IOException, JDOMException, MissingElementException, UnexpectedRootElementException {
-        UserEntry ue = getSampleUserEntry();
-        
-        HttpResponse res = delete(ue.getHref(), getUser(), getPassword());
-        assertEquals(200, res.getStatus());
-        
-        UserEntrySet uesResponse = null;
-        InputStream responseBody = res.getResponseBody();
-        if (responseBody != null) {
-           uesResponse = new UserEntrySet(responseBody, getEndpointUrl());
-        }
-        
-        return uesResponse;
-    }
-
-    protected UserEntrySet fetchSampleUser() throws IOException, JDOMException, MissingElementException, UnexpectedRootElementException {
-        UserEntry ue = getSampleUserEntry();
-        
-        HttpResponse res = get(ue.getHref(), getUser(), getPassword());
-        assertEquals(200, res.getStatus());
-        
-        UserEntrySet uesResponse = null;
-        InputStream responseBody = res.getResponseBody();
-        if (responseBody != null) {
-           uesResponse = new UserEntrySet(responseBody, getEndpointUrl());
-        }
-        
-        return uesResponse;
-    }
-
-    protected WeblogEntrySet fetchSampleWeblog() throws IOException, JDOMException, MissingElementException, UnexpectedRootElementException {
-        WeblogEntry we = getSampleWeblogEntry();
-        
-        HttpResponse res = get(we.getHref(), getUser(), getPassword());
-        assertEquals(200, res.getStatus());
-        
-        WeblogEntrySet wesResponse = null;
-        InputStream responseBody = res.getResponseBody();
-        if (responseBody != null) {
-           wesResponse = new WeblogEntrySet(responseBody, getEndpointUrl());
-        }
-        
-        return wesResponse;
-    }
-
-    protected MemberEntrySet fetchSampleMember() throws IOException, JDOMException, MissingElementException, UnexpectedRootElementException {
-        MemberEntry me = getSampleMemberEntry();
-        
-        HttpResponse res = get(me.getHref(), getUser(), getPassword());
-        assertEquals(200, res.getStatus());
-        
-        MemberEntrySet mesResponse = null;
-        InputStream responseBody = res.getResponseBody();
-        if (responseBody != null) {
-           mesResponse = new MemberEntrySet(responseBody, getEndpointUrl());
-        }
-        
-        return mesResponse;
-    }
-    
-    protected WeblogEntrySet deleteSampleWeblog() throws IOException, JDOMException, MissingElementException, UnexpectedRootElementException {
-        WeblogEntry we = getSampleWeblogEntry();
-        
-        HttpResponse res = delete(we.getHref(), getUser(), getPassword());
-        assertEquals(200, res.getStatus());
-        
-        WeblogEntrySet wesResponse = null;
-        InputStream responseBody = res.getResponseBody();
-        if (responseBody != null) {
-           wesResponse = new WeblogEntrySet(responseBody, getEndpointUrl());
-        }
-        
-        return wesResponse;
-    }
-
-    protected MemberEntrySet deleteSampleMember() throws IOException, JDOMException, MissingElementException, UnexpectedRootElementException {
-        MemberEntry me = getSampleMemberEntry();
-        
-        HttpResponse res = delete(me.getHref(), getUser(), getPassword());
-        assertEquals(200, res.getStatus());
-        
-        MemberEntrySet mesResponse = null;
-        InputStream responseBody = res.getResponseBody();
-        if (responseBody != null) {
-           mesResponse = new MemberEntrySet(responseBody, getEndpointUrl());
-        }
-        
-        return mesResponse;
-    }
-    
-    protected static HttpResponse post(String url, String user, String password, String body) throws IOException {
-        HttpClient httpClient = new HttpClient();
-        EntityEnclosingMethod method = new PostMethod(url);
-        addAuthHeader(method, user, password);
-        
-        method.setRequestBody(body);
-        
-        String contentType = "application/xml; charset=utf-8";
-        method.setRequestHeader("Content-type", contentType);
-        
-        int status = httpClient.executeMethod(method);
-        InputStream responseBody = method.getResponseBodyAsStream();
-        
-        HttpResponse res = new HttpResponse(status, responseBody);
-        return res;
-    }
-
-    protected static HttpResponse put(String url, String user, String password, String body) throws IOException {
-        HttpClient httpClient = new HttpClient();
-        EntityEnclosingMethod method = new PutMethod(url);
-        addAuthHeader(method, user, password);
-        
-        method.setRequestBody(body);
-        
-        String contentType = "application/xml; charset=utf-8";
-        method.setRequestHeader("Content-type", contentType);
-        
-        int status = httpClient.executeMethod(method);
-        InputStream responseBody = method.getResponseBodyAsStream();
-        
-        HttpResponse res = new HttpResponse(status, responseBody);
-        return res;
-    }
-    
-    protected static HttpResponse get(String url, String user, String password) throws IOException {
-        HttpClient httpClient = new HttpClient();
-        HttpMethod method = new GetMethod(url);
-        addAuthHeader(method, user, password);
-        
-        String contentType = "application/xml; charset=utf-8";
-        method.setRequestHeader("Content-type", contentType);
-        
-        int status = httpClient.executeMethod(method);
-        InputStream responseBody = method.getResponseBodyAsStream();
-        
-        HttpResponse res = new HttpResponse(status, responseBody);
-        return res;
-    }
-    
-    protected static HttpResponse delete(String url, String user, String password) throws IOException {
-        HttpClient httpClient = new HttpClient();
-        HttpMethod method = new DeleteMethod(url);
-        addAuthHeader(method, user, password);
-                
-        String contentType = "application/xml; charset=utf-8";
-        method.setRequestHeader("Content-type", contentType);
-        
-        int status = httpClient.executeMethod(method);
-        InputStream responseBody = method.getResponseBodyAsStream();
-        
-        HttpResponse res = new HttpResponse(status, responseBody);
-        return res;
-    }
     
-    private static void addAuthHeader(HttpMethod method, String user, String password) {
-        String credentials = user + ":" + password;
-        method.setRequestHeader("Authorization", "Basic "  + new String(Base64.encode(credentials.getBytes())));
-    }   
 }

Added: incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/HandlerBaseTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/HandlerBaseTest.java?view=auto&rev=448278
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/HandlerBaseTest.java (added)
+++ incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/HandlerBaseTest.java Wed Sep 20 10:52:25 2006
@@ -0,0 +1,398 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.roller.webservices.adminapi;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.util.Base64;
+import org.apache.roller.webservices.adminapi.sdk.MemberEntry;
+import org.apache.roller.webservices.adminapi.sdk.MemberEntrySet;
+import org.apache.roller.webservices.adminapi.sdk.UnexpectedRootElementException;
+import org.apache.roller.webservices.adminapi.sdk.UserEntry;
+import org.apache.roller.webservices.adminapi.sdk.UserEntrySet;
+import org.apache.roller.webservices.adminapi.sdk.WeblogEntry;
+import org.apache.roller.webservices.adminapi.sdk.WeblogEntrySet;
+import org.jdom.JDOMException;
+
+public abstract class HandlerBaseTest extends AappTest {
+    public static class HttpResponse {
+        private int status;
+        private InputStream responseBody;
+        
+        public HttpResponse(int status) {
+            this(status, null);
+        }
+        
+        public HttpResponse(int status, InputStream responseBody) {
+            this.status = status;
+            this.responseBody = responseBody;
+        }
+        
+        public int getStatus() {
+            return status;
+        }
+        
+        public InputStream getResponseBody() {
+            return responseBody;
+        }
+    }
+    
+    protected void setUp() throws Exception {
+        //System.err.println("HandlerTest.setUp()");
+        try {
+            deleteSampleMember(false);
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+        try {
+            deleteSampleWeblog(false);
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+        try {
+            deleteSampleUser(false);
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+    
+    protected void tearDown() throws Exception {
+        //System.err.println("HandlerTest.tearDown()");
+        try {
+            deleteSampleMember(false);
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+        try {
+            deleteSampleWeblog(false);
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+        try {
+            deleteSampleUser(false);
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    }
+    
+    protected UserEntrySet createSampleUser() throws IOException, JDOMException, UnexpectedRootElementException {
+        UserEntrySet ues = getSampleUserEntrySet();
+        
+        String url = ues.getHref();
+        String user = getUser();
+        String password = getPassword();
+        
+        String body = ues.toString();
+        
+        HttpResponse res = post(url, user, password, body);
+        assertEquals(201, res.getStatus());
+        
+        UserEntrySet uesResponse = null;
+        InputStream responseBody = res.getResponseBody();
+        if (responseBody != null) {
+            uesResponse = new UserEntrySet(responseBody, getEndpointUrl());
+        }
+        
+        return uesResponse;
+    }
+    
+    protected UserEntrySet updateSampleUser() throws IOException, JDOMException, UnexpectedRootElementException {
+        UserEntrySet ues = updateSampleUserEntrySet(getSampleUserEntrySet());
+        
+        String url = ues.getHref();
+        String user = getUser();
+        String password = getPassword();
+        
+        String body = ues.toString();
+        
+        HttpResponse res = put(url, user, password, body);
+        assertEquals(200, res.getStatus());
+        
+        UserEntrySet uesResponse = null;
+        InputStream responseBody = res.getResponseBody();
+        if (responseBody != null) {
+            uesResponse = new UserEntrySet(responseBody, getEndpointUrl());
+        }
+        
+        return uesResponse;
+    }
+    
+    protected WeblogEntrySet updateSampleWeblog() throws IOException, JDOMException, UnexpectedRootElementException {
+        WeblogEntrySet wes = updateSampleWeblogEntrySet(getSampleWeblogEntrySet());
+        
+        String url = wes.getHref();
+        String user = getUser();
+        String password = getPassword();
+        
+        String body = wes.toString();
+        
+        HttpResponse res = put(url, user, password, body);
+        assertEquals(200, res.getStatus());
+        
+        WeblogEntrySet wesResponse = null;
+        InputStream responseBody = res.getResponseBody();
+        if (responseBody != null) {
+            wesResponse = new WeblogEntrySet(responseBody, getEndpointUrl());
+        }
+        
+        return wesResponse;
+    }
+    
+    protected MemberEntrySet updateSampleMember() throws IOException, JDOMException, UnexpectedRootElementException {
+        MemberEntrySet mes = updateSampleMemberEntrySet(getSampleMemberEntrySet());
+        
+        String url = mes.getHref();
+        String user = getUser();
+        String password = getPassword();
+        
+        String body = mes.toString();
+        
+        HttpResponse res = put(url, user, password, body);
+        assertEquals(200, res.getStatus());
+        
+        MemberEntrySet mesResponse = null;
+        InputStream responseBody = res.getResponseBody();
+        if (responseBody != null) {
+            mesResponse = new MemberEntrySet(responseBody, getEndpointUrl());
+        }
+        
+        return mesResponse;
+    }
+    
+    protected WeblogEntrySet createSampleWeblog() throws IOException, JDOMException, UnexpectedRootElementException {
+        WeblogEntrySet wes = getSampleWeblogEntrySet();
+        
+        String url = wes.getHref();
+        String user = getUser();
+        String password = getPassword();
+        
+        String body = wes.toString();
+        
+        HttpResponse res = post(url, user, password, body);
+        assertEquals(201, res.getStatus());
+        
+        WeblogEntrySet wesResponse = null;
+        InputStream responseBody = res.getResponseBody();
+        if (responseBody != null) {
+            wesResponse = new WeblogEntrySet(responseBody, getEndpointUrl());
+        }
+        
+        return wesResponse;
+    }
+    
+    protected MemberEntrySet createSampleMember() throws IOException, JDOMException, UnexpectedRootElementException {
+        MemberEntrySet mes = getSampleMemberEntrySet();
+        
+        String url = mes.getHref();
+        String user = getUser();
+        String password = getPassword();
+        
+        String body = mes.toString();
+        
+        HttpResponse res = post(url, user, password, body);
+        assertEquals(201, res.getStatus());
+        
+        MemberEntrySet mesResponse = null;
+        InputStream responseBody = res.getResponseBody();
+        if (responseBody != null) {
+            mesResponse = new MemberEntrySet(responseBody, getEndpointUrl());
+        }
+        
+        return mesResponse;
+    }
+    
+    protected UserEntrySet deleteSampleUser(boolean test) throws IOException, JDOMException, UnexpectedRootElementException {
+        UserEntry ue = getSampleUserEntry();
+        
+        HttpResponse res = delete(ue.getHref(), getUser(), getPassword());
+        if (test) {
+            assertEquals(200, res.getStatus());
+        } else if (res.getStatus() != 200) {
+            return null;
+        }
+        
+        UserEntrySet uesResponse = null;
+        InputStream responseBody = res.getResponseBody();
+        if (responseBody != null) {
+            uesResponse = new UserEntrySet(responseBody, getEndpointUrl());
+        }
+        
+        return uesResponse;
+    }
+    
+    protected UserEntrySet fetchSampleUser() throws IOException, JDOMException, UnexpectedRootElementException {
+        UserEntry ue = getSampleUserEntry();
+        
+        HttpResponse res = get(ue.getHref(), getUser(), getPassword());
+        assertEquals(200, res.getStatus());
+        
+        UserEntrySet uesResponse = null;
+        InputStream responseBody = res.getResponseBody();
+        if (responseBody != null) {
+            uesResponse = new UserEntrySet(responseBody, getEndpointUrl());
+        }
+        
+        return uesResponse;
+    }
+    
+    protected WeblogEntrySet fetchSampleWeblog() throws IOException, JDOMException, UnexpectedRootElementException {
+        WeblogEntry we = getSampleWeblogEntry();
+        
+        HttpResponse res = get(we.getHref(), getUser(), getPassword());
+        assertEquals(200, res.getStatus());
+        
+        WeblogEntrySet wesResponse = null;
+        InputStream responseBody = res.getResponseBody();
+        if (responseBody != null) {
+            wesResponse = new WeblogEntrySet(responseBody, getEndpointUrl());
+        }
+        
+        return wesResponse;
+    }
+    
+    protected MemberEntrySet fetchSampleMember() throws IOException, JDOMException, UnexpectedRootElementException {
+        MemberEntry me = getSampleMemberEntry();
+        
+        HttpResponse res = get(me.getHref(), getUser(), getPassword());
+        assertEquals(200, res.getStatus());
+        
+        MemberEntrySet mesResponse = null;
+        InputStream responseBody = res.getResponseBody();
+        if (responseBody != null) {
+            mesResponse = new MemberEntrySet(responseBody, getEndpointUrl());
+        }
+        
+        return mesResponse;
+    }
+    
+    protected WeblogEntrySet deleteSampleWeblog(boolean test) throws IOException, JDOMException, UnexpectedRootElementException {
+        WeblogEntry we = getSampleWeblogEntry();
+        
+        HttpResponse res = delete(we.getHref(), getUser(), getPassword());
+        if (test) {
+            assertEquals(200, res.getStatus());
+        } else if (res.getStatus() != 200) {
+            return null;
+        }
+        
+        WeblogEntrySet wesResponse = null;
+        InputStream responseBody = res.getResponseBody();
+        if (responseBody != null) {
+            wesResponse = new WeblogEntrySet(responseBody, getEndpointUrl());
+        }
+        
+        return wesResponse;
+    }
+    
+    protected MemberEntrySet deleteSampleMember(boolean test) throws IOException, JDOMException, UnexpectedRootElementException {
+        MemberEntry me = getSampleMemberEntry();
+        
+        HttpResponse res = delete(me.getHref(), getUser(), getPassword());
+        if (test) {
+            assertEquals(200, res.getStatus());
+        } else if (res.getStatus() != 200) {
+            return null;
+        }
+        
+        MemberEntrySet mesResponse = null;
+        InputStream responseBody = res.getResponseBody();
+        if (responseBody != null) {
+            mesResponse = new MemberEntrySet(responseBody, getEndpointUrl());
+        }
+        
+        return mesResponse;
+    }
+    
+    protected static HttpResponse post(String url, String user, String password, String body) throws IOException {
+        HttpClient httpClient = new HttpClient();
+        EntityEnclosingMethod method = new PostMethod(url);
+        addAuthHeader(method, user, password);
+        
+        method.setRequestBody(body);
+        
+        String contentType = "application/xml; charset=utf-8";
+        method.setRequestHeader("Content-type", contentType);
+        
+        int status = httpClient.executeMethod(method);
+        InputStream responseBody = method.getResponseBodyAsStream();
+        
+        HttpResponse res = new HttpResponse(status, responseBody);
+        return res;
+    }
+    
+    protected static HttpResponse put(String url, String user, String password, String body) throws IOException {
+        HttpClient httpClient = new HttpClient();
+        EntityEnclosingMethod method = new PutMethod(url);
+        addAuthHeader(method, user, password);
+        
+        method.setRequestBody(body);
+        
+        String contentType = "application/xml; charset=utf-8";
+        method.setRequestHeader("Content-type", contentType);
+        
+        int status = httpClient.executeMethod(method);
+        InputStream responseBody = method.getResponseBodyAsStream();
+        
+        HttpResponse res = new HttpResponse(status, responseBody);
+        return res;
+    }
+    
+    protected static HttpResponse get(String url, String user, String password) throws IOException {
+        HttpClient httpClient = new HttpClient();
+        HttpMethod method = new GetMethod(url);
+        addAuthHeader(method, user, password);
+        
+        String contentType = "application/xml; charset=utf-8";
+        method.setRequestHeader("Content-type", contentType);
+        
+        int status = httpClient.executeMethod(method);
+        InputStream responseBody = method.getResponseBodyAsStream();
+        
+        HttpResponse res = new HttpResponse(status, responseBody);
+        return res;
+    }
+    
+    protected static HttpResponse delete(String url, String user, String password) throws IOException {
+        HttpClient httpClient = new HttpClient();
+        HttpMethod method = new DeleteMethod(url);
+        addAuthHeader(method, user, password);
+        
+        String contentType = "application/xml; charset=utf-8";
+        method.setRequestHeader("Content-type", contentType);
+        
+        int status = httpClient.executeMethod(method);
+        InputStream responseBody = method.getResponseBodyAsStream();
+        
+        HttpResponse res = new HttpResponse(status, responseBody);
+        return res;
+    }
+    
+    private static void addAuthHeader(HttpMethod method, String user, String password) {
+        String credentials = user + ":" + password;
+        method.setRequestHeader("Authorization", "Basic "  + new String(Base64.encode(credentials.getBytes())));
+    }
+    
+}
+

Modified: incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/MemberHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/MemberHandlerTest.java?view=diff&rev=448278&r1=448277&r2=448278
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/MemberHandlerTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/MemberHandlerTest.java Wed Sep 20 10:52:25 2006
@@ -19,11 +19,10 @@
 
 import java.io.IOException;
 import org.apache.roller.webservices.adminapi.sdk.MemberEntrySet;
-import org.apache.roller.webservices.adminapi.sdk.MissingElementException;
 import org.apache.roller.webservices.adminapi.sdk.UnexpectedRootElementException;
 import org.jdom.JDOMException;
 
-public class MemberHandlerTest extends AappTest {
+public class MemberHandlerTest extends HandlerBaseTest {
     public void testHandler() {
         try {
             createSampleUser();
@@ -51,34 +50,20 @@
             assertEquals(mesUpdate, updateSampleMemberEntrySet(getSampleMemberEntrySet()));
             
             //delete
-            MemberEntrySet mesDelete = deleteSampleMember();
+            MemberEntrySet mesDelete = deleteSampleMember(true);
             assertNotNull(mesDelete);
             assertNotNull(mesCreate.getEntries());
             assertEquals(mesCreate.getEntries().length, 1);
             assertEquals(mesDelete, mesUpdate);
-            
-            deleteSampleWeblog();
-            deleteSampleUser();
         } catch (IOException ioe) {
             ioe.printStackTrace();            
             fail(ioe.getMessage());
         } catch (JDOMException je) {
             je.printStackTrace();
             fail(je.getMessage());
-        } catch (MissingElementException mee) {
-            mee.printStackTrace();            
-            fail(mee.getMessage());
         } catch (UnexpectedRootElementException uree) {
             uree.printStackTrace();            
             fail(uree.getMessage());
-        } finally {
-            try {
-                delete(getSampleMemberEntry().getHref(), getUser(), getPassword());
-                delete(getSampleWeblogEntry().getHref(), getUser(), getPassword());                
-                delete(getSampleUserEntry().getHref(), getUser(), getPassword());                                
-            } catch (Exception e) {
-                // nothing
-            }
         }
     }
 }

Modified: incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/UserHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/UserHandlerTest.java?view=diff&rev=448278&r1=448277&r2=448278
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/UserHandlerTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/UserHandlerTest.java Wed Sep 20 10:52:25 2006
@@ -18,8 +18,8 @@
 package org.apache.roller.webservices.adminapi;
 
 import java.io.IOException;
-import org.apache.roller.webservices.adminapi.sdk.MissingElementException;
 import org.apache.roller.webservices.adminapi.sdk.UnexpectedRootElementException;
+import org.apache.roller.webservices.adminapi.sdk.UserEntry;
 import org.apache.roller.webservices.adminapi.sdk.UserEntrySet;
 import org.jdom.JDOMException;
 
@@ -27,7 +27,7 @@
  *
  * @author jtb
  */
-public class UserHandlerTest extends AappTest {
+public class UserHandlerTest extends HandlerBaseTest {
     public void testHandler() {
         try {
             //create
@@ -52,7 +52,7 @@
             assertEquals(uesUpdate, updateSampleUserEntrySet(getSampleUserEntrySet()));
             
             //delete
-            UserEntrySet uesDelete = deleteSampleUser();
+            UserEntrySet uesDelete = deleteSampleUser(true);
             assertNotNull(uesDelete);
             assertNotNull(uesCreate.getEntries());
             assertEquals(uesCreate.getEntries().length, 1);
@@ -63,18 +63,35 @@
         } catch (JDOMException je) {
             je.printStackTrace();            
             fail(je.getMessage());
-        } catch (MissingElementException mee) {
-            mee.printStackTrace();            
-            fail(mee.getMessage());
         } catch (UnexpectedRootElementException uree) {
             uree.printStackTrace();            
             fail(uree.getMessage());
-        } finally {
-            try {
-                delete(getSampleUserEntry().getHref(), getUser(), getPassword());
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
         }
     }
+
+    public void testEnabled() {
+        try {
+            UserEntrySet ues = createSampleUser();
+            UserEntry ue = (UserEntry)ues.getEntries()[0];
+            assertEquals(Boolean.TRUE, ue.getEnabled());
+            
+            ues = updateSampleUser();
+            ue = (UserEntry)ues.getEntries()[0];
+            assertEquals(Boolean.FALSE, ue.getEnabled());
+
+            ues = fetchSampleUser();
+            ue = (UserEntry)ues.getEntries()[0];
+            assertEquals(Boolean.FALSE, ue.getEnabled());
+        } catch (IOException ioe) {
+            fail(ioe.getMessage());
+            ioe.printStackTrace();
+        } catch (JDOMException je) {
+            fail(je.getMessage());
+            je.printStackTrace();
+        } catch (UnexpectedRootElementException uree) {
+            fail(uree.getMessage());
+            uree.printStackTrace();
+        }
+    }    
+    
 }

Modified: incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/WeblogHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/WeblogHandlerTest.java?view=diff&rev=448278&r1=448277&r2=448278
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/WeblogHandlerTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/WeblogHandlerTest.java Wed Sep 20 10:52:25 2006
@@ -1,29 +1,29 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* 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.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
 package org.apache.roller.webservices.adminapi;
 
 import java.io.IOException;
-import org.apache.roller.webservices.adminapi.sdk.MissingElementException;
 import org.apache.roller.webservices.adminapi.sdk.UnexpectedRootElementException;
+import org.apache.roller.webservices.adminapi.sdk.WeblogEntry;
 import org.apache.roller.webservices.adminapi.sdk.WeblogEntrySet;
 import org.jdom.JDOMException;
 
-public class WeblogHandlerTest extends AappTest {
+public class WeblogHandlerTest extends HandlerBaseTest {
     public void testHandler() {
         try {
             createSampleUser();
@@ -50,32 +50,53 @@
             assertEquals(wesUpdate, updateSampleWeblogEntrySet(getSampleWeblogEntrySet()));
             
             //delete
-            WeblogEntrySet wesDelete = deleteSampleWeblog();
+            WeblogEntrySet wesDelete = deleteSampleWeblog(true);
             assertNotNull(wesDelete);
             assertNotNull(wesCreate.getEntries());
             assertEquals(wesCreate.getEntries().length, 1);
             assertEquals(wesDelete, wesUpdate);
-            
-            deleteSampleUser();
         } catch (IOException ioe) {
             fail(ioe.getMessage());
-            ioe.printStackTrace();            
+            ioe.printStackTrace();
         } catch (JDOMException je) {
             fail(je.getMessage());
             je.printStackTrace();
-        } catch (MissingElementException mee) {
-            fail(mee.getMessage());
-            mee.printStackTrace();
         } catch (UnexpectedRootElementException uree) {
             fail(uree.getMessage());
             uree.printStackTrace();
         } finally {
             try {
-                delete(getSampleWeblogEntry().getHref(), getUser(), getPassword());
-                delete(getSampleUserEntry().getHref(), getUser(), getPassword());                
+                deleteSampleWeblog(false);
+                deleteSampleUser(false);
             } catch (Exception e) {
-                // nothing
+                e.printStackTrace();
             }
         }
     }
+
+    public void testEnabled() {
+        try {
+            createSampleUser();
+            WeblogEntrySet wes = createSampleWeblog();
+            WeblogEntry we = (WeblogEntry)wes.getEntries()[0];
+            assertEquals(we.getEnabled(), Boolean.TRUE);
+            
+            wes = updateSampleWeblog();
+            we = (WeblogEntry)wes.getEntries()[0];
+            assertEquals(Boolean.FALSE, we.getEnabled());
+
+            wes = fetchSampleWeblog();
+            we = (WeblogEntry)wes.getEntries()[0];
+            assertEquals(Boolean.FALSE, we.getEnabled());
+        } catch (IOException ioe) {
+            fail(ioe.getMessage());
+            ioe.printStackTrace();
+        } catch (JDOMException je) {
+            fail(je.getMessage());
+            je.printStackTrace();
+        } catch (UnexpectedRootElementException uree) {
+            fail(uree.getMessage());
+            uree.printStackTrace();
+        }
+    }    
 }

Modified: incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/sdk/MemberEntryTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/sdk/MemberEntryTest.java?view=diff&rev=448278&r1=448277&r2=448278
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/sdk/MemberEntryTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/sdk/MemberEntryTest.java Wed Sep 20 10:52:25 2006
@@ -40,8 +40,6 @@
             MemberEntrySet wes2 = new MemberEntrySet(d, getEndpointUrl());
             
             assertEquals(wes1, wes2);
-        } catch (MissingElementException mee) {
-            fail(mee.getMessage());
         } catch (UnexpectedRootElementException uree) {
             fail(uree.getMessage());
         }
@@ -56,8 +54,6 @@
             MemberEntrySet wes2 = new MemberEntrySet(stream, getEndpointUrl());
             
             assertEquals(wes1, wes2);
-        } catch (MissingElementException mee) {
-            fail(mee.getMessage());
         } catch (UnexpectedRootElementException uree) {
             fail(uree.getMessage());
         } catch (IOException ioe) {

Modified: incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/sdk/UserEntryTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/sdk/UserEntryTest.java?view=diff&rev=448278&r1=448277&r2=448278
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/sdk/UserEntryTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/sdk/UserEntryTest.java Wed Sep 20 10:52:25 2006
@@ -40,8 +40,6 @@
             UserEntrySet ues2 = new UserEntrySet(d, getEndpointUrl());
             
             assertEquals(ues1, ues2);
-        } catch (MissingElementException mee) {
-            fail(mee.getMessage());
         } catch (UnexpectedRootElementException uree) {
             fail(uree.getMessage());
         }
@@ -56,8 +54,6 @@
             UserEntrySet ues2 = new UserEntrySet(stream, getEndpointUrl());
             
             assertEquals(ues1, ues2);
-        } catch (MissingElementException mee) {
-            fail(mee.getMessage());
         } catch (UnexpectedRootElementException uree) {
             fail(uree.getMessage());
         } catch (IOException ioe) {

Modified: incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/sdk/WeblogEntryTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/sdk/WeblogEntryTest.java?view=diff&rev=448278&r1=448277&r2=448278
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/sdk/WeblogEntryTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/webservices/adminapi/sdk/WeblogEntryTest.java Wed Sep 20 10:52:25 2006
@@ -40,8 +40,6 @@
             WeblogEntrySet wes2 = new WeblogEntrySet(d, getEndpointUrl());
             
             assertEquals(wes1, wes2);
-        } catch (MissingElementException mee) {
-            fail(mee.getMessage());
         } catch (UnexpectedRootElementException uree) {
             fail(uree.getMessage());
         }
@@ -56,8 +54,6 @@
             WeblogEntrySet wes2 = new WeblogEntrySet(stream, getEndpointUrl());
             
             assertEquals(wes1, wes2);
-        } catch (MissingElementException mee) {
-            fail(mee.getMessage());
         } catch (UnexpectedRootElementException uree) {
             fail(uree.getMessage());
         } catch (IOException ioe) {



Mime
View raw message