@Override public RawAttachmentData createInstance(Type type) { return new RawAttachmentData("", "", new byte[0]); } }
/** * Factory method to create a tuple. * * @param <A> Type of the tuple element. * @param elements The elements of the tuple * @return A new tuple that contains {@code elements} */ @SuppressWarnings("unchecked") public static <A> Tuple<A> of(A ... elements) { return new Tuple<A>(elements); }
@Override public EventMessageBundle createInstance(Type type) { return new EventMessageBundle("", "http://opensocial.example.com"); }
public WaveletData(WaveletData wavelet) { this.creationTime = wavelet.getCreationTime(); this.creator = wavelet.getCreator(); this.lastModifiedTime = wavelet.getLastModifiedTime(); this.participants = wavelet.getParticipants(); this.participantRoles = new HashMap<String, String>(wavelet.getParticipantRoles()); this.rootBlipId = wavelet.getRootBlipId(); this.title = wavelet.getTitle(); this.version = wavelet.getVersion(); this.waveId = wavelet.getWaveId(); this.waveletId = wavelet.getWaveletId(); this.dataDocuments = new HashMap<String, String>(wavelet.getDataDocuments()); this.tags = new ArrayList<String>(wavelet.getTags()); }
ElementGsonAdaptor elementGsonAdaptor = new ElementGsonAdaptor(); GsonBuilder builder = new GsonBuilder() .setExclusionStrategies(new NonSerializableExclusionStrategy()) .registerTypeAdapter(EventMessageBundle.class, new EventMessageBundleGsonAdaptor()) .registerTypeAdapter(OperationRequest.class, new OperationRequestGsonAdaptor(opNamespace)) .registerTypeAdapter(Element.class, elementGsonAdaptor) .registerTypeAdapter(Attachment.class, elementGsonAdaptor) .registerTypeAdapter(JsonRpcResponse.class, new JsonRpcResponseGsonAdaptor()) .registerTypeAdapter(Annotation.class, new AnnotationInstanceCreator()) .registerTypeAdapter(Range.class, new RangeInstanceCreator()) .registerTypeAdapter(BlipThread.class, new ThreadInstanceCreator()) .registerTypeAdapter(SearchResult.class, new SearchResultInstanceCreator()) .registerTypeAdapter(SearchResult.Digest.class, new SearchResultDigestInstanceCreator()) .registerTypeAdapter(WaveletId.class, new WaveletIdInstanceCreator()) .registerTypeAdapter(RawAttachmentData.class, new AttachmentDataInstanceCreator()) .registerTypeAdapter(byte[].class, new ByteArrayGsonAdaptor());
public void testDeserializeJsonRpcErrorResponse() throws Exception { String response = "{'id':'op1','error':{'message':'Not authorized!'}}"; JsonElement jsonElement = new JsonParser().parse(response); JsonRpcResponseGsonAdaptor adaptor = new JsonRpcResponseGsonAdaptor(); JsonRpcResponse result = adaptor.deserialize(jsonElement, null, null); assertTrue(result.isError()); assertEquals("op1", result.getId()); assertEquals("Not authorized!", result.getErrorMessage()); }
public void testHashCode() { assertTrue(tuple.hashCode() == tuple.hashCode()); assertTrue(tuple.hashCode() == Tuple.of(FOO, BAR).hashCode()); assertFalse(tuple.hashCode() == Tuple.of(BAR, FOO).hashCode()); } }
public void testEquals() { assertFalse(tuple.equals(null)); assertFalse(tuple.equals(new String[] {FOO, BAR})); assertFalse(tuple.equals(Tuple.of(FOO))); assertTrue(tuple.equals(tuple)); assertTrue(tuple.equals(Tuple.of(FOO, BAR))); }
public void testGet() { assertEquals(FOO, tuple.get(0)); assertEquals(BAR, tuple.get(1)); try { tuple.get(-1); fail("Should have thrown IndexOutOfBoundsException when accessing index -1."); } catch (ArrayIndexOutOfBoundsException e) { // Expected. } try { tuple.get(2); fail("Should have thrown IndexOutOfBoundsException when accessing index that is greater " + "than the size of the tuple."); } catch (ArrayIndexOutOfBoundsException e) { // Expected. } }
public void testSize() { assertEquals(2, tuple.size()); }
/** * Creates a {@link Gson} instance, with additional type adapters for these * types: * <ul> * <li>{@link EventMessageBundle}</li> * <li>{@link OperationRequest}</li> * <li>{@link Element}</li> * </ul> * * @return an instance of {@link Gson} with pre-registered type adapters. */ public Gson create() { return create(""); }
public void testGenerateWaveletSelfRemovedEvent() throws Exception { wavelet.removeParticipant(ROBOT); EventMessageBundle messages = generateAndCheckEvents(EventType.WAVELET_SELF_REMOVED); // Participant changed event, after self removed event is filtered. assertEquals("Expected only one event", 1, messages.getEvents().size()); }
/** * Adds a single {@link ConversationBlip} to the {@link EventMessageBundle}. * * @param eventMessageBundle to add the blip to * @param blip {@link ConversationBlip} to add * @param wavelet {@link Wavelet} that the blip is based on * @param eventDataConverter {@link EventDataConverter} used for conversion */ private static void addBlipToEventMessages(EventMessageBundle eventMessageBundle, ConversationBlip blip, Wavelet wavelet, EventDataConverter eventDataConverter) { if (blip != null && !eventMessageBundle.hasBlipId(blip.getId())) { eventMessageBundle.addBlip( blip.getId(), eventDataConverter.toBlipData(blip, wavelet, eventMessageBundle)); } }
/** * Registers this {@link ElementGsonAdaptorV2} with the given * {@link GsonFactory}. * @param factory {@link GsonFactory} to register the type adapters with * @return the given {@link GsonFactory} with the registered adapters */ public static GsonFactory registerTypeAdapters(GsonFactory factory) { ElementGsonAdaptorV2 elementGsonAdaptorV2 = new ElementGsonAdaptorV2(); factory.registerTypeAdapter(Element.class, elementGsonAdaptorV2); factory.registerTypeAdapter(Attachment.class, elementGsonAdaptorV2); return factory; } }
@Override public JsonElement serialize(Element src, Type typeOfSrc, JsonSerializationContext context) { if (src.getType() == ElementType.ATTACHMENT) { src = new Element(ElementType.IMAGE, createImageProperties(src.getProperties())); } return super.serialize(src, typeOfSrc, context); }
public void testDeserializeJsonRpcErrorResponse() throws Exception { String response = "{'id':'op1','error':{'message':'Not authorized!'}}"; JsonElement jsonElement = new JsonParser().parse(response); JsonRpcResponseGsonAdaptor adaptor = new JsonRpcResponseGsonAdaptor(); JsonRpcResponse result = adaptor.deserialize(jsonElement, null, null); assertTrue(result.isError()); assertEquals("op1", result.getId()); assertEquals("Not authorized!", result.getErrorMessage()); }
public void testHashCode() { assertTrue(tuple.hashCode() == tuple.hashCode()); assertTrue(tuple.hashCode() == Tuple.of(FOO, BAR).hashCode()); assertFalse(tuple.hashCode() == Tuple.of(BAR, FOO).hashCode()); } }
public void testEquals() { assertFalse(tuple.equals(null)); assertFalse(tuple.equals(new String[] {FOO, BAR})); assertFalse(tuple.equals(Tuple.of(FOO))); assertTrue(tuple.equals(tuple)); assertTrue(tuple.equals(Tuple.of(FOO, BAR))); }
public void testGet() { assertEquals(FOO, tuple.get(0)); assertEquals(BAR, tuple.get(1)); try { tuple.get(-1); fail("Should have thrown IndexOutOfBoundsException when accessing index -1."); } catch (ArrayIndexOutOfBoundsException e) { // Expected. } try { tuple.get(2); fail("Should have thrown IndexOutOfBoundsException when accessing index that is greater " + "than the size of the tuple."); } catch (ArrayIndexOutOfBoundsException e) { // Expected. } }
public void testSize() { assertEquals(2, tuple.size()); }