Permalink
Browse files

Various minor updates.

git-svn-id: https://svn.apache.org/repos/asf/pivot/branches/1.5.x@955030 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
Gregory K. Brown
Gregory K. Brown committed Jun 15, 2010
1 parent 23758a9 commit ef036a689b9d32a8e3bc823b889915ad4d47ab5b
@@ -64,7 +64,9 @@ public void testCRUD() throws IOException, SerializationException, QueryExceptio
// Read
GetQuery getQuery = new GetQuery(hostname, port, path, secure);
- assertEquals(contact, getQuery.execute());
+ Object result = getQuery.execute();
+ assertEquals(JSON.get(contact, "address.street"), JSON.get(result, "address.street"));
+ assertEquals(contact, result);
// Update
JSON.put(contact, "name", "Joseph User");
@@ -81,4 +83,10 @@ public void testCRUD() throws IOException, SerializationException, QueryExceptio
assertEquals(deleteQuery.getStatus(), Query.Status.NO_CONTENT);
}
+
+ @Test(expected=QueryException.class)
+ public void testException() throws IOException, SerializationException, QueryException {
+ GetQuery getQuery = new GetQuery(hostname, port, "/pivot-demos/rest_demo/foo", secure);
+ getQuery.execute();
+ }
}
@@ -24,7 +24,7 @@
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
WTKXSerializer wtkxSerializer = new WTKXSerializer();
- HashMap<String, Object> hashMap =
+ HashMap<String, Object> hashMap =
(HashMap<String, Object>)wtkxSerializer.readObject(WTKXDictionaryTest.class.getResource("wtkx_dictionary_test.wtkx"));
System.out.println(JSONSerializer.toString(hashMap));
}
@@ -24,4 +24,5 @@ limitations under the License.
<bar>
<wtkx:include src="wtkx_dictionary_test_include.wtkx"/>
</bar>
+ <baz>Quux</baz>
</HashMap>
@@ -16,6 +16,6 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
-<HashMap a="456"
+<HashMap a="456"
xmlns:wtkx="http://pivot.apache.org/wtkx"
xmlns="org.apache.pivot.collections"/>
@@ -252,13 +252,12 @@ public int getLength() {
public static final String MESSAGE_KEY = "message";
/**
- * Creates a new flag with a type of {@link MessageType.ERROR} and
- * no message.
+ * Creates a new flag with a type of "error" and no message.
*/
public Flag() {
this(MessageType.ERROR, null);
}
-
+
/**
* Creates a new flag with the given message type and no message.
*
@@ -297,30 +296,30 @@ public Flag(MessageType messageType, String message) {
public MessageType getMessageType() {
return messageType;
}
-
+
/**
* Sets the flag's message type.
- *
+ *
* @param messageType
*/
public void setMessageType(MessageType messageType) {
if (messageType == null) {
throw new IllegalArgumentException();
}
-
+
this.messageType = messageType;
}
-
+
/**
* Sets the flag's message type.
- *
+ *
* @param messageType
*/
public void setMessageType(String messageType) {
if (messageType == null) {
throw new IllegalArgumentException();
}
-
+
setMessageType(MessageType.valueOf(messageType.toUpperCase()));
}
@@ -334,10 +333,10 @@ public void setMessageType(String messageType) {
public String getMessage() {
return message;
}
-
+
/**
* Sets the flag message.
- *
+ *
* @param message
* The message text associated with the flag, or <tt>null</tt> if
* there is no message.
@@ -170,7 +170,7 @@ public int size() {
public Object value;
public final int lineNumber;
- public Element(Element parent, String namespaceURI, String localName, List<Attribute> attributes,
+ public Element(Element parent, String namespaceURI, String localName, List<Attribute> attributes,
Type type, String id, Object value, int lineNumber) {
this.parent = parent;
this.namespaceURI = namespaceURI;
@@ -681,7 +681,7 @@ private void processStartElement(XMLStreamReader xmlStreamReader) throws Seriali
}
Location xmlStreamLocation = xmlStreamReader.getLocation();
- element = new Element(element, namespaceURI, localName, attributes, elementType,
+ element = new Element(element, namespaceURI, localName, attributes, elementType,
id, value, xmlStreamLocation.getLineNumber());
// If this is the root, set it
@@ -829,10 +829,10 @@ private void processEndElement(XMLStreamReader xmlStreamReader)
// Split the local name
String[] localNameComponents = attribute.localName.split("\\.");
if (localNameComponents.length != 2) {
- throw new SerializationException("\"" + attribute.localName
+ throw new SerializationException("\"" + attribute.localName
+ "\" is not a valid attribute name.");
}
-
+
// Determine the type of the attribute
String propertyClassName = attribute.namespaceURI + "." + localNameComponents[0];
@@ -868,7 +868,7 @@ private void processEndElement(XMLStreamReader xmlStreamReader)
}
// Create an invocation handler for this listener
- ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(language);
+ ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(language);
AttributeInvocationHandler handler =
new AttributeInvocationHandler(scriptEngine,
localNameComponents[1],
@@ -895,7 +895,7 @@ private void processEndElement(XMLStreamReader xmlStreamReader)
}
} else {
// The attribute represents a static setter
- setStaticProperty(element.value, propertyClass, localNameComponents[1],
+ setStaticProperty(element.value, propertyClass, localNameComponents[1],
resolve(attribute.value));
}
}
@@ -934,37 +934,37 @@ private void processEndElement(XMLStreamReader xmlStreamReader)
if (element.parent.value instanceof Dictionary) {
dictionary = (Dictionary<String, Object>)element.parent.value;
} else {
- dictionary = new BeanAdapter(element.parent.value);
+ dictionary = new BeanAdapter(element.parent.value);
}
-
+
if (Character.isUpperCase(element.localName.charAt(0))) {
if (element.parent == null
|| element.parent.value == null) {
throw new SerializationException("Element does not have a parent.");
}
-
+
// Set static property
String[] localNameComponents = element.localName.split("\\.");
if (localNameComponents.length != 2) {
- throw new SerializationException("\"" + element.localName
+ throw new SerializationException("\"" + element.localName
+ "\" is not a valid attribute name.");
}
-
+
String propertyClassName = element.namespaceURI + "." + localNameComponents[0];
-
+
Class<?> propertyClass = null;
try {
propertyClass = Class.forName(propertyClassName);
} catch (ClassNotFoundException exception) {
throw new SerializationException(exception);
}
-
- setStaticProperty(element.parent.value, propertyClass, localNameComponents[1],
- element.value);
+
+ setStaticProperty(element.parent.value, propertyClass, localNameComponents[1],
+ element.value);
} else {
dictionary.put(localName, element.value);
}
-
+
break;
}
@@ -1517,9 +1517,9 @@ private static Method getStaticSetterMethod(Class<?> propertyClass, String prope
return method;
}
-
- private static void setStaticProperty(Object object, Class<?> propertyClass,
- String propertyName, Object value)
+
+ private static void setStaticProperty(Object object, Class<?> propertyClass,
+ String propertyName, Object value)
throws SerializationException {
Class<?> objectType = object.getClass();
propertyName = Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
@@ -1545,7 +1545,7 @@ private static void setStaticProperty(Object object, Class<?> propertyClass,
}
if (setterMethod == null) {
- throw new SerializationException(propertyClass.getName() + "." + propertyName
+ throw new SerializationException(propertyClass.getName() + "." + propertyName
+ " is not valid static property.");
}

0 comments on commit ef036a6

Please sign in to comment.