コード例 #1
0
 /**
  * Tests for {@link MmiReceiver#receiveObject(Object, org.umundo.core.Message)}.
  *
  * @throws Exception test failed
  */
 @Test(timeout = 5000)
 public void testReceiveObject() throws Exception {
   final TypedPublisher publisher = new TypedPublisher("test");
   publishingNode.addPublisher(publisher);
   publisher.waitForSubscribers(1);
   final String requestId = "requestId1";
   final String source = "source1";
   final String target = "target1";
   final String context = "context1";
   final String content = "content1";
   final String contentUrl = "contentUrl1";
   final LifeCycleEvents.PrepareRequest prepareRequest =
       LifeCycleEvents.PrepareRequest.newBuilder()
           .setContent(content)
           .setContentURL(contentUrl)
           .build();
   final LifeCycleEvents.LifeCycleRequest lifeCycleRequest =
       LifeCycleEvents.LifeCycleRequest.newBuilder()
           .setContext(context)
           .setExtension(LifeCycleEvents.PrepareRequest.request, prepareRequest)
           .build();
   final LifeCycleEvents.LifeCycleEvent event1 =
       LifeCycleEvents.LifeCycleEvent.newBuilder()
           .setType(LifeCycleEventType.PREPARE_REQUEST)
           .setRequestID(requestId)
           .setSource(source)
           .setTarget(target)
           .setExtension(LifeCycleEvents.LifeCycleRequest.request, lifeCycleRequest)
           .build();
   publisher.sendObject("LifeCycleEvent", event1);
   synchronized (lock) {
     lock.wait();
   }
   Assert.assertNotNull(receivedEvent);
   Assert.assertTrue(receivedEvent instanceof PrepareRequest);
 }
コード例 #2
0
ファイル: MmiReceiver.java プロジェクト: ridixcr/JVoiceXML
 /**
  * Converts the received object into a {@link LifeCycleEvent} that can be handled by the {@link
  * org.jvoicexml.callmananager.mmi.MMICallManager}.
  *
  * @param object the received object
  * @return the converted lifecycle event, <code>null</code> if the object could not be converted
  *     or is not addressed to this modality component
  * @throws ParserConfigurationException
  * @throws TransformerException
  * @throws IOException
  * @throws SAXException
  */
 private LifeCycleEvent convertToLifeCycleEvent(final Object object)
     throws SAXException, IOException, TransformerException, ParserConfigurationException {
   if (!(object instanceof LifeCycleEvents.LifeCycleEvent)) {
     return null;
   }
   final LifeCycleEvents.LifeCycleEvent receivedEvent = (LifeCycleEvents.LifeCycleEvent) object;
   final String target = receivedEvent.getTarget();
   if (!target.equals(sourceUrl)) {
     return null;
   }
   final LifeCycleEvent event;
   final LifeCycleEvents.LifeCycleEvent.LifeCycleEventType type = receivedEvent.getType();
   if (type.equals(LifeCycleEvents.LifeCycleEvent.LifeCycleEventType.PREPARE_REQUEST)) {
     final PrepareRequest request = new PrepareRequest();
     final LifeCycleEvents.LifeCycleRequest decodedLifeCycleRequest =
         extractContext(receivedEvent, request);
     final LifeCycleEvents.PrepareRequest decodedPrepareRequest =
         decodedLifeCycleRequest.getExtension(LifeCycleEvents.PrepareRequest.request);
     request.setContentURL(decodedPrepareRequest.getContentURL());
     final String content = decodedPrepareRequest.getContent();
     if ((content != null) && !content.isEmpty()) {
       final AnyComplexType any = new AnyComplexType();
       final Object convertedContent = convertContent(content);
       any.getContent().add(convertedContent);
       request.setContent(any);
     }
     event = request;
   } else if (type.equals(LifeCycleEvents.LifeCycleEvent.LifeCycleEventType.NEW_CONTEXT_REQUEST)) {
     final NewContextRequest request = new NewContextRequest();
     extractContext(receivedEvent, request);
     event = request;
   } else if (type.equals(LifeCycleEvents.LifeCycleEvent.LifeCycleEventType.START_REQUEST)) {
     final StartRequest request = new StartRequest();
     final LifeCycleEvents.LifeCycleRequest decodedLifeCycleRequest =
         extractContext(receivedEvent, request);
     final LifeCycleEvents.StartRequest decodedStartRequest =
         decodedLifeCycleRequest.getExtension(LifeCycleEvents.StartRequest.request);
     request.setContentURL(decodedStartRequest.getContentURL());
     final String content = decodedStartRequest.getContent();
     if ((content != null) && !content.isEmpty()) {
       final AnyComplexType any = new AnyComplexType();
       final Object convertedContent = convertContent(content);
       any.getContent().add(convertedContent);
       request.setContent(any);
     }
     event = request;
   } else if (type.equals(LifeCycleEvents.LifeCycleEvent.LifeCycleEventType.CANCEL_REQUEST)) {
     final NewContextRequest request = new NewContextRequest();
     extractContext(receivedEvent, request);
     event = request;
   } else if (type.equals(LifeCycleEvents.LifeCycleEvent.LifeCycleEventType.PAUSE_REQUEST)) {
     final NewContextRequest request = new NewContextRequest();
     extractContext(receivedEvent, request);
     event = request;
   } else if (type.equals(LifeCycleEvents.LifeCycleEvent.LifeCycleEventType.RESUME_REQUEST)) {
     final NewContextRequest request = new NewContextRequest();
     extractContext(receivedEvent, request);
     event = request;
   } else if (type.equals(
       LifeCycleEvents.LifeCycleEvent.LifeCycleEventType.CLEAR_CONTEXT_REQUEST)) {
     final NewContextRequest request = new NewContextRequest();
     extractContext(receivedEvent, request);
     event = request;
   } else {
     event = null;
   }
   event.setTarget(receivedEvent.getTarget());
   event.setRequestId(receivedEvent.getRequestID());
   event.setSource(receivedEvent.getSource());
   return event;
 }