Some additional test cases and cleanups
This commit is contained in:
parent
296ff102a9
commit
355c29d418
|
@ -22,7 +22,6 @@
|
||||||
package com.ibm.common.activitystreams.actions;
|
package com.ibm.common.activitystreams.actions;
|
||||||
|
|
||||||
import com.ibm.common.activitystreams.ASObject;
|
import com.ibm.common.activitystreams.ASObject;
|
||||||
import com.ibm.common.activitystreams.TypeValue;
|
|
||||||
import com.ibm.common.activitystreams.actions.StylesValue.Builder;
|
import com.ibm.common.activitystreams.actions.StylesValue.Builder;
|
||||||
import com.ibm.common.activitystreams.internal.Adapter;
|
import com.ibm.common.activitystreams.internal.Adapter;
|
||||||
import com.ibm.common.activitystreams.util.AbstractDictionaryObjectAdapter;
|
import com.ibm.common.activitystreams.util.AbstractDictionaryObjectAdapter;
|
||||||
|
|
|
@ -21,15 +21,10 @@
|
||||||
*/
|
*/
|
||||||
package com.ibm.common.activitystreams.actions;
|
package com.ibm.common.activitystreams.actions;
|
||||||
|
|
||||||
import static com.ibm.common.activitystreams.Makers.object;
|
|
||||||
import static com.ibm.common.activitystreams.Makers.type;
|
|
||||||
|
|
||||||
import java.io.ObjectStreamException;
|
import java.io.ObjectStreamException;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.ibm.common.activitystreams.ASObject;
|
import com.ibm.common.activitystreams.ASObject;
|
||||||
import com.ibm.common.activitystreams.TypeValue;
|
|
||||||
import com.ibm.common.activitystreams.actions.UrlTemplate.Builder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,7 +27,6 @@ import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.ibm.common.activitystreams.TypeValue;
|
|
||||||
import com.ibm.common.activitystreams.util.AbstractDictionaryObject;
|
import com.ibm.common.activitystreams.util.AbstractDictionaryObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,26 +1,28 @@
|
||||||
package com.ibm.common.activitystreams.actions.test;
|
package com.ibm.common.activitystreams.actions.test;
|
||||||
|
|
||||||
|
import static com.google.common.collect.Iterables.getFirst;
|
||||||
|
import static com.ibm.common.activitystreams.actions.ActionMakers.embedAction;
|
||||||
import static com.ibm.common.activitystreams.actions.ActionMakers.htmlForm;
|
import static com.ibm.common.activitystreams.actions.ActionMakers.htmlForm;
|
||||||
|
import static com.ibm.common.activitystreams.actions.ActionMakers.httpAction;
|
||||||
|
import static com.ibm.common.activitystreams.actions.ActionMakers.intentAction;
|
||||||
import static com.ibm.common.activitystreams.actions.ActionMakers.io;
|
import static com.ibm.common.activitystreams.actions.ActionMakers.io;
|
||||||
import static com.ibm.common.activitystreams.actions.ActionMakers.parameter;
|
import static com.ibm.common.activitystreams.actions.ActionMakers.parameter;
|
||||||
|
import static com.ibm.common.activitystreams.actions.ActionMakers.styles;
|
||||||
import static com.ibm.common.activitystreams.actions.ActionMakers.typedPayload;
|
import static com.ibm.common.activitystreams.actions.ActionMakers.typedPayload;
|
||||||
import static com.ibm.common.activitystreams.actions.ActionMakers.urlTemplate;
|
import static com.ibm.common.activitystreams.actions.ActionMakers.urlTemplate;
|
||||||
import static com.ibm.common.activitystreams.actions.ActionMakers.embedAction;
|
|
||||||
import static com.ibm.common.activitystreams.actions.ActionMakers.intentAction;
|
|
||||||
import static com.ibm.common.activitystreams.actions.ActionMakers.httpAction;
|
|
||||||
import static com.ibm.common.activitystreams.actions.ActionMakers.styles;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static com.google.common.collect.Iterables.*;
|
import com.google.common.base.Throwables;
|
||||||
|
|
||||||
import com.google.common.net.MediaType;
|
import com.google.common.net.MediaType;
|
||||||
import com.ibm.common.activitystreams.ASObject;
|
import com.ibm.common.activitystreams.ASObject;
|
||||||
import com.ibm.common.activitystreams.LinkValue;
|
import com.ibm.common.activitystreams.LinkValue;
|
||||||
|
@ -37,6 +39,121 @@ import com.ibm.common.activitystreams.actions.UrlTemplate;
|
||||||
|
|
||||||
public final class ActionsTest {
|
public final class ActionsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void roundtripHttpActionHandler2() {
|
||||||
|
|
||||||
|
HttpActionHandler hah1 =
|
||||||
|
httpAction()
|
||||||
|
.url("http://example.org")
|
||||||
|
.method("GET")
|
||||||
|
.get();
|
||||||
|
|
||||||
|
HttpActionHandler hah2 =
|
||||||
|
roundTrip2(hah1);
|
||||||
|
|
||||||
|
assertEquals("GET", hah2.method());
|
||||||
|
|
||||||
|
Iterable<LinkValue> i = hah2.url();
|
||||||
|
LinkValue lv = getFirst(i,null);
|
||||||
|
assertNotNull(lv);
|
||||||
|
assertTrue(lv instanceof SimpleLinkValue);
|
||||||
|
SimpleLinkValue slv = (SimpleLinkValue) lv;
|
||||||
|
assertEquals("http://example.org", slv.url());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void roundtripIntentActionHandler2() {
|
||||||
|
|
||||||
|
IntentActionHandler iah1 =
|
||||||
|
intentAction()
|
||||||
|
.id("urn:example:foo:1")
|
||||||
|
.get();
|
||||||
|
|
||||||
|
IntentActionHandler iah2 =
|
||||||
|
roundTrip2(iah1);
|
||||||
|
|
||||||
|
assertEquals("urn:example:foo:1", iah2.id());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void roundtripEmbedActionHandler2() {
|
||||||
|
|
||||||
|
EmbedActionHandler eah1 =
|
||||||
|
embedAction()
|
||||||
|
.style(
|
||||||
|
styles()
|
||||||
|
.set("width", "100px")
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
EmbedActionHandler eah2 =
|
||||||
|
roundTrip2(eah1);
|
||||||
|
|
||||||
|
Iterable<StylesValue> styles =
|
||||||
|
eah2.styles();
|
||||||
|
StylesValue style =
|
||||||
|
getFirst(styles, null);
|
||||||
|
assertNotNull(style);
|
||||||
|
assertTrue(style.has("width"));
|
||||||
|
assertEquals("100px", style.get("width"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void roundtripHtmlForm2() {
|
||||||
|
HtmlForm htmlForm1 =
|
||||||
|
htmlForm()
|
||||||
|
.parameter("foo", parameter().optional())
|
||||||
|
.get();
|
||||||
|
|
||||||
|
HtmlForm htmlForm2 =
|
||||||
|
roundTrip2(htmlForm1);
|
||||||
|
|
||||||
|
ParametersValue params =
|
||||||
|
htmlForm2.parameters();
|
||||||
|
assertTrue(params.has("foo"));
|
||||||
|
|
||||||
|
Parameter param = params.get("foo");
|
||||||
|
assertFalse(param.required());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void roundtripTypedValue2() {
|
||||||
|
TypedPayload typedPayload1 =
|
||||||
|
typedPayload()
|
||||||
|
.mediaType(MediaType.create("application", "json"))
|
||||||
|
.get();
|
||||||
|
|
||||||
|
TypedPayload typedPayload2 =
|
||||||
|
roundTrip2(typedPayload1);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
typedPayload1.mediaType(),
|
||||||
|
typedPayload2.mediaType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void roundtripUrlTemplate2() {
|
||||||
|
UrlTemplate template1 =
|
||||||
|
urlTemplate()
|
||||||
|
.template("http://example.org{/foo}")
|
||||||
|
.parameter("foo", "bar")
|
||||||
|
.get();
|
||||||
|
UrlTemplate template2 =
|
||||||
|
roundTrip2(template1);
|
||||||
|
assertEquals(
|
||||||
|
template1.template(),
|
||||||
|
template2.template());
|
||||||
|
ParametersValue value =
|
||||||
|
template2.parameters();
|
||||||
|
assertTrue(value.has("foo"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void roundtripHttpActionHandler() {
|
public void roundtripHttpActionHandler() {
|
||||||
|
|
||||||
|
@ -156,4 +273,22 @@ public final class ActionsTest {
|
||||||
new ByteArrayInputStream(out.toByteArray());
|
new ByteArrayInputStream(out.toByteArray());
|
||||||
return io.readAs(in);
|
return io.readAs(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private <T extends ASObject>T roundTrip2(T writable){
|
||||||
|
try {
|
||||||
|
ByteArrayOutputStream out =
|
||||||
|
new ByteArrayOutputStream();
|
||||||
|
ObjectOutputStream oos =
|
||||||
|
new ObjectOutputStream(out);
|
||||||
|
oos.writeObject(writable);
|
||||||
|
ByteArrayInputStream in =
|
||||||
|
new ByteArrayInputStream(out.toByteArray());
|
||||||
|
ObjectInputStream ois =
|
||||||
|
new ObjectInputStream(in);
|
||||||
|
return (T)ois.readObject();
|
||||||
|
} catch (Throwable t) {
|
||||||
|
throw Throwables.propagate(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue