001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: package org.apache.roller.webservices.adminapi;
019:
020: import java.util.Date;
021: import java.util.Locale;
022: import java.util.TimeZone;
023: import junit.framework.TestCase;
024: import org.apache.roller.webservices.adminapi.sdk.MemberEntry;
025: import org.apache.roller.webservices.adminapi.sdk.MemberEntrySet;
026: import org.apache.roller.webservices.adminapi.sdk.UserEntry;
027: import org.apache.roller.webservices.adminapi.sdk.UserEntrySet;
028: import org.apache.roller.webservices.adminapi.sdk.WeblogEntry;
029: import org.apache.roller.webservices.adminapi.sdk.WeblogEntrySet;
030:
031: public abstract class AappTest extends TestCase {
032: private static final Date sampleDate = new Date();
033: private static final String DEFAULT_ENDPOINT_URL = "http://localhost:8080/roller/roller-services/aapp";
034: private static final String DEFAULT_USER = "jtb";
035: private static final String DEFAULT_PASSWORD = "iplanet";
036:
037: protected static String getEndpointUrl() {
038: String endpoint = System.getProperty("aapp.endpoint");
039: if (endpoint == null) {
040: endpoint = DEFAULT_ENDPOINT_URL;
041: }
042:
043: //System.err.println("endpoint=" + endpoint);
044: return endpoint;
045: }
046:
047: protected static String getUser() {
048: String user = System.getProperties().getProperty("aapp.user");
049: if (user == null) {
050: user = DEFAULT_USER;
051: }
052:
053: //System.err.println("user=" + user);
054: return user;
055: }
056:
057: protected static String getPassword() {
058: String password = System.getProperties().getProperty(
059: "aapp.password");
060: if (password == null) {
061: password = DEFAULT_PASSWORD;
062: }
063:
064: //System.err.println("password=" + password);
065: return password;
066: }
067:
068: protected static UserEntry getSampleUserEntry() {
069: UserEntry ue = new UserEntry("foo", getEndpointUrl());
070: ue.setEmailAddress("foo@bar.org");
071: ue.setFullName("Foo Bar");
072: ue.setLocale(Locale.getDefault());
073: ue.setTimezone(TimeZone.getDefault());
074: ue.setPassword("foo");
075: ue.setEnabled(Boolean.TRUE);
076:
077: return ue;
078: }
079:
080: protected static MemberEntry getSampleMemberEntry() {
081: MemberEntry me = new MemberEntry("fooblog", "foo",
082: getEndpointUrl());
083: me.setPermission(MemberEntry.Permissions.AUTHOR);
084: return me;
085: }
086:
087: protected static UserEntry updateSampleUserEntry(UserEntry ue) {
088: UserEntry ueUpdate = new UserEntry(ue.getName(),
089: getEndpointUrl());
090: ueUpdate.setEmailAddress("billy@bob.org");
091: ueUpdate.setFullName("Billy Bob");
092: ueUpdate.setLocale(new Locale("ms", "MY"));
093: ueUpdate.setTimezone(TimeZone.getTimeZone("Asia/Kuala_Lumpur"));
094: ueUpdate.setPassword("billy");
095: ueUpdate.setEnabled(Boolean.FALSE);
096:
097: return ueUpdate;
098: }
099:
100: protected static WeblogEntry updateSampleWeblogEntry(WeblogEntry we) {
101: WeblogEntry weUpdate = new WeblogEntry(we.getHandle(),
102: getEndpointUrl());
103: weUpdate.setEmailAddress("billy@bob.org");
104: weUpdate.setName("Billy Bob Weblog Name");
105: weUpdate.setLocale(new Locale("ms", "MY"));
106: weUpdate.setTimezone(TimeZone.getTimeZone("Asia/Kuala_Lumpur"));
107: weUpdate.setDescription("Billy Bob Weblog Description");
108: weUpdate.setCreatingUser(we.getCreatingUser());
109: weUpdate.setEnabled(Boolean.FALSE);
110:
111: return weUpdate;
112: }
113:
114: protected static MemberEntry updateSampleMemberEntry(MemberEntry me) {
115: MemberEntry meUpdate = new MemberEntry(me.getHandle(), me
116: .getName(), getEndpointUrl());
117: meUpdate.setPermission(MemberEntry.Permissions.LIMITED);
118:
119: return meUpdate;
120: }
121:
122: protected static UserEntrySet updateSampleUserEntrySet(
123: UserEntrySet ues) {
124: UserEntry ue = (UserEntry) ues.getEntries()[0];
125: UserEntry ueUpdated = updateSampleUserEntry(ue);
126: UserEntrySet uesUpdated = new UserEntrySet(getEndpointUrl());
127: uesUpdated.setEntries(new UserEntry[] { ueUpdated });
128:
129: return uesUpdated;
130: }
131:
132: protected static WeblogEntrySet updateSampleWeblogEntrySet(
133: WeblogEntrySet wes) {
134: WeblogEntry we = (WeblogEntry) wes.getEntries()[0];
135: WeblogEntry weUpdated = updateSampleWeblogEntry(we);
136: WeblogEntrySet wesUpdated = new WeblogEntrySet(getEndpointUrl());
137: wesUpdated.setEntries(new WeblogEntry[] { weUpdated });
138:
139: return wesUpdated;
140: }
141:
142: protected static MemberEntrySet updateSampleMemberEntrySet(
143: MemberEntrySet mes) {
144: MemberEntry me = (MemberEntry) mes.getEntries()[0];
145: MemberEntry meUpdated = updateSampleMemberEntry(me);
146: MemberEntrySet mesUpdated = new MemberEntrySet(getEndpointUrl());
147: mesUpdated.setEntries(new MemberEntry[] { meUpdated });
148:
149: return mesUpdated;
150: }
151:
152: protected static WeblogEntry getSampleWeblogEntry() {
153: WeblogEntry we = new WeblogEntry("fooblog", getEndpointUrl());
154: we.setEmailAddress("foo@bar.org");
155: we.setCreatingUser("foo");
156: we.setDescription("Foo Weblog Description");
157: we.setLocale(Locale.getDefault());
158: we.setTimezone(TimeZone.getDefault());
159: we.setName("Foo Weblog Name");
160: we.setEnabled(Boolean.TRUE);
161:
162: return we;
163: }
164:
165: protected static UserEntrySet getSampleUserEntrySet() {
166: UserEntry ue = getSampleUserEntry();
167: UserEntrySet ues = new UserEntrySet(getEndpointUrl());
168: ues.setEntries(new UserEntry[] { ue });
169:
170: return ues;
171: }
172:
173: protected static WeblogEntrySet getSampleWeblogEntrySet() {
174: WeblogEntry we = getSampleWeblogEntry();
175: WeblogEntrySet wes = new WeblogEntrySet(getEndpointUrl());
176: wes.setEntries(new WeblogEntry[] { we });
177:
178: return wes;
179: }
180:
181: protected static MemberEntrySet getSampleMemberEntrySet() {
182: MemberEntry me = getSampleMemberEntry();
183: MemberEntrySet mes = new MemberEntrySet(getEndpointUrl());
184: mes.setEntries(new MemberEntry[] { me });
185:
186: return mes;
187: }
188:
189: }
|