/** * Return whether the lookingFor event is contained in this bundle. */ public boolean hasEvent(EventType eventType) { for (Event event : events) { if (event.getType() == eventType) { return true; } } return false; }
/** * Converts a string into an {@link EventType} ignoring case in the process. * * @param name the name of the event type. * @return the converted event type. */ public static EventType valueOfIgnoreCase(String name) { try { return valueOf(name.toUpperCase()); } catch (IllegalArgumentException e) { return UNKNOWN; } }
private static void assertEquals(Event expected, Event actual) { assertEquals(expected.getType(), actual.getType()); assertEquals(expected.getWavelet(), actual.getWavelet()); assertEquals(expected.getModifiedBy(), actual.getModifiedBy()); assertEquals(expected.getTimestamp(), actual.getTimestamp()); assertEquals(expected.getBlip(), actual.getBlip()); assertEquals(expected.getBundle(), actual.getBundle()); } }
public void refactor_testSerializeAndDeserializeOperationErrorEvent() throws Exception { Wavelet wavelet = mock(Wavelet.class); EventMessageBundle bundle = new EventMessageBundle("http://10.1.1.1", "http://wave-active-api.example.com"); OperationErrorEvent expected = new OperationErrorEvent(wavelet, bundle, "foo@google.com", 123l, "op1", "Error!"); Context context = new Context(); Event actual = EventSerializer.deserialize(wavelet, bundle, EventSerializer.serialize(expected, context), context); assertEquals(expected, actual); }
public void testAllEventClassesHaveConversionStaticMethod() throws Exception { for (EventType eventType : EventType.values()) { if (eventType == EventType.UNKNOWN) { continue; } try { Method method = eventType.getClazz().getDeclaredMethod("as", Event.class); assertEquals(eventType.getClazz(), method.getReturnType()); } catch (NoSuchMethodException e) { fail(eventType.getClazz().getName() + " should implement a no-arg constructor that will " + "be used for deserialization."); } } }
public void testAllEventClassesHaveTheAppropriateConstructor() throws Exception { for (EventType eventType : EventType.values()) { if (eventType == EventType.UNKNOWN) { continue; } try { Class<? extends Event> clazz = eventType.getClazz(); clazz.getDeclaredConstructor(); } catch (NoSuchMethodException e) { fail(eventType.getClazz().getName() + " should implement a no-arg constructor that will " + "be used for deserialization."); } } }
@Override public void processEvent(OperationRequest operation, Event event) throws InvalidRequestException { // Create JSON-RPC error response. if (event.getType() == EventType.OPERATION_ERROR) { constructErrorResponse(operation, OperationErrorEvent.as(event).getMessage()); return; } // Create JSON-RPC success response. try { constructResponse(operation, EventSerializer.extractPropertiesToParamsPropertyMap(event)); } catch (EventSerializationException e) { LOG.severe("Internal Error occurred, when serializing events", e); throw new InvalidRequestException("Unable to serialize events", operation); } }
@Capability(contexts = {Context.PARENT, Context.SELF, Context.CHILDREN}, filter=".*") @Override public void onBlipSubmitted(BlipSubmittedEvent e) { calledEvents.add(e.getType()); }
@Override public void onDocumentChanged(DocumentChangedEvent e) { calledEvents.add(e.getType()); } }
@Override public void onBlipContributorsChanged(BlipContributorsChangedEvent e) { calledEvents.add(e.getType()); } };
@Override public void onWaveletTagsChanged(WaveletTagsChangedEvent e) { calledEvents.add(e.getType()); }
private static void assertEquals(Event expected, Event actual) { assertEquals(expected.getType(), actual.getType()); assertEquals(expected.getWavelet(), actual.getWavelet()); assertEquals(expected.getModifiedBy(), actual.getModifiedBy()); assertEquals(expected.getTimestamp(), actual.getTimestamp()); assertEquals(expected.getBlip(), actual.getBlip()); assertEquals(expected.getBundle(), actual.getBundle()); } }
public void refactor_testSerializeAndDeserializeOperationErrorEvent() throws Exception { Wavelet wavelet = mock(Wavelet.class); EventMessageBundle bundle = new EventMessageBundle("http://10.1.1.1", "http://wave-active-api.example.com"); OperationErrorEvent expected = new OperationErrorEvent(wavelet, bundle, "foo@google.com", 123l, "op1", "Error!"); Context context = new Context(); Event actual = EventSerializer.deserialize(wavelet, bundle, EventSerializer.serialize(expected, context), context); assertEquals(expected, actual); }
public void testAllEventClassesHaveConversionStaticMethod() throws Exception { for (EventType eventType : EventType.values()) { if (eventType == EventType.UNKNOWN) { continue; } try { Method method = eventType.getClazz().getDeclaredMethod("as", Event.class); assertEquals(eventType.getClazz(), method.getReturnType()); } catch (NoSuchMethodException e) { fail(eventType.getClazz().getName() + " should implement a no-arg constructor that will " + "be used for deserialization."); } } }
public void testAllEventClassesHaveTheAppropriateConstructor() throws Exception { for (EventType eventType : EventType.values()) { if (eventType == EventType.UNKNOWN) { continue; } try { Class<? extends Event> clazz = eventType.getClazz(); clazz.getDeclaredConstructor(); } catch (NoSuchMethodException e) { fail(eventType.getClazz().getName() + " should implement a no-arg constructor that will " + "be used for deserialization."); } } }
@Capability(contexts = {Context.PARENT, Context.SELF, Context.CHILDREN}, filter=".*") @Override public void onBlipSubmitted(BlipSubmittedEvent e) { calledEvents.add(e.getType()); }
@Override public void onDocumentChanged(DocumentChangedEvent e) { calledEvents.add(e.getType()); } }
@Override public void onBlipContributorsChanged(BlipContributorsChangedEvent e) { calledEvents.add(e.getType()); } };
@Override public void onBlipSubmitted(BlipSubmittedEvent e) { calledEvents.add(e.getType()); }
@Override public void onDocumentChanged(DocumentChangedEvent e) { calledEvents.add(e.getType()); }