test_class.declarator: ngsiClient
test_class.modifier: @Mock(answer = Answers.RETURNS_MOCKS)
      public
test_class.original_string: @Mock(answer = Answers.RETURNS_MOCKS)
      public NgsiClient ngsiClient;
test_class.type: NgsiClient
test_class.var_name: ngsiClient
test_class.declarator: statement
test_class.modifier: @Mock
      public
test_class.original_string: @Mock
      public EPStatement statement;
test_class.type: EPStatement
test_class.var_name: statement
test_class.declarator: provider
test_class.modifier: @Mock
      public
test_class.original_string: @Mock
      public EPServiceProvider provider;
test_class.type: EPServiceProvider
test_class.var_name: provider
test_class.declarator: eventSinkListener
test_class.modifier: @Autowired
      @InjectMocks
      public
test_class.original_string: @Autowired
      @InjectMocks
      public EventSinkListener eventSinkListener;
test_class.type: EventSinkListener
test_class.var_name: eventSinkListener
test_class.declarator: broker
test_class.modifier: private
test_class.original_string: private Broker broker;
test_class.type: Broker
test_class.var_name: broker
test_class.file: cepheus-cep/src/test/java/com/orange/cepheus/cep/EventSinkListenerTest.java
test_class.identifier: EventSinkListenerTest
test_case.body: @Test
      public void postMessageOnEventUpdate() {
  
          HttpHeaders httpHeaders = new HttpHeaders();
          httpHeaders.setContentType(MediaType.APPLICATION_JSON);
          httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
  
          when(statement.getText()).thenReturn("statement");
          when(ngsiClient.getRequestHeaders(any())).thenReturn(httpHeaders);
  
          // Trigger event update
          List<ContextAttribute> attributes = new LinkedList<>();
          attributes.add(new ContextAttribute("id", "string", "OUT1234"));
          attributes.add(new ContextAttribute("avgTemp", "double", 10.25));
          attributes.add(new ContextAttribute("avgTemp_unit","string","celcius"));
          EventBean[]beans = {buildEventBean("TempSensorAvg", attributes)};
          eventSinkListener.update(beans, null, statement, provider);
  
          // Capture updateContext when postUpdateContextRequest is called on updateContextRequest,
          ArgumentCaptor<UpdateContext> updateContextArg = ArgumentCaptor.forClass(UpdateContext.class);
          ArgumentCaptor<HttpHeaders> headersArg = ArgumentCaptor.forClass(HttpHeaders.class);
  
          verify(ngsiClient).updateContext(eq(broker.getUrl()), headersArg.capture(), updateContextArg.capture());
  
          // Check updateContext is valid
          UpdateContext updateContext = updateContextArg.getValue();
          assertEquals(UpdateAction.APPEND, updateContext.getUpdateAction());
          assertEquals(1, updateContext.getContextElements().size());
  
          // Check headers are valid
          HttpHeaders headers = headersArg.getValue();
          assertEquals(MediaType.APPLICATION_JSON, headers.getContentType());
          assertTrue(headers.getAccept().contains(MediaType.APPLICATION_JSON));
          assertEquals("SN", headers.getFirst("Fiware-Service"));
          assertEquals("SP", headers.getFirst("Fiware-ServicePath"));
          assertEquals("AUTH_TOKEN", headers.getFirst("X-Auth-Token"));
  
          ContextElement contextElement = updateContext.getContextElements().get(0);
          assertEquals("OUT1234", contextElement.getEntityId().getId());
          assertEquals("TempSensorAvg", contextElement.getEntityId().getType());
          assertFalse(contextElement.getEntityId().getIsPattern());
          assertEquals(1, contextElement.getContextAttributeList().size());
  
          ContextAttribute attr = contextElement.getContextAttributeList().get(0);
          assertEquals("avgTemp", attr.getName());
          assertEquals("double", attr.getType());
          assertEquals(10.25, attr.getValue());
          assertEquals(1, attr.getMetadata().size());
          assertEquals("unit", attr.getMetadata().get(0).getName());
          assertEquals("string", attr.getMetadata().get(0).getType());
          assertEquals("celcius", attr.getMetadata().get(0).getValue());
      }
test_case.class_method_signature: EventSinkListenerTest.postMessageOnEventUpdate()
test_case.full_signature: @Test public void postMessageOnEventUpdate()
test_case.identifier: postMessageOnEventUpdate
test_case.invocations: setContentType setAccept singletonList thenReturn when getText thenReturn when getRequestHeaders any add add add buildEventBean update forClass forClass updateContext verify eq getUrl capture capture getValue assertEquals getUpdateAction assertEquals size getContextElements getValue assertEquals getContentType assertTrue contains getAccept assertEquals getFirst assertEquals getFirst assertEquals getFirst get getContextElements assertEquals getId getEntityId assertEquals getType getEntityId assertFalse getIsPattern getEntityId assertEquals size getContextAttributeList get getContextAttributeList assertEquals getName assertEquals getType assertEquals getValue assertEquals size getMetadata assertEquals getName get getMetadata assertEquals getType get getMetadata assertEquals getValue get getMetadata
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void postMessageOnEventUpdate()
focal_class.declarator: logger = LoggerFactory.getLogger(EventSinkListener.class)
focal_class.modifier: private static
focal_class.original_string: private static Logger logger = LoggerFactory.getLogger(EventSinkListener.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: ngsiClient
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private NgsiClient ngsiClient;
focal_class.type: NgsiClient
focal_class.var_name: ngsiClient
focal_class.declarator: eventMapper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private EventMapper eventMapper;
focal_class.type: EventMapper
focal_class.var_name: eventMapper
focal_class.declarator: configuration
focal_class.modifier: private
focal_class.original_string: private Configuration configuration;
focal_class.type: Configuration
focal_class.var_name: configuration
focal_class.declarator: outgoingEvents
focal_class.modifier: private
focal_class.original_string: private Map<String, EventTypeOut> outgoingEvents;
focal_class.type: Map<String, EventTypeOut>
focal_class.var_name: outgoingEvents
focal_class.file: cepheus-cep/src/main/java/com/orange/cepheus/cep/EventSinkListener.java
focal_class.identifier: EventSinkListener
focal_class.interfaces: implements StatementAwareUpdateListener
focal_class.class_method_signature: EventSinkListener.update(EventBean[] added, EventBean[] removed, EPStatement epStatement, EPServiceProvider epServiceProvider)
focal_class.full_signature: @Override public void update(EventBean[] added, EventBean[] removed, EPStatement epStatement, EPServiceProvider epServiceProvider)
focal_class.identifier: update
focal_class.modifiers: @Override public
focal_class.parameters: (EventBean[] added, EventBean[] removed, EPStatement epStatement, EPServiceProvider epServiceProvider)
focal_class.return: void
focal_class.signature: void update(EventBean[] added, EventBean[] removed, EPStatement epStatement, EPServiceProvider epServiceProvider)
focal_class.class_method_signature: EventSinkListener.setConfiguration(Configuration configuration)
focal_class.full_signature: public void setConfiguration(Configuration configuration)
focal_class.identifier: setConfiguration
focal_class.modifiers: public
focal_class.parameters: (Configuration configuration)
focal_class.return: void
focal_class.signature: void setConfiguration(Configuration configuration)
focal_class.class_method_signature: EventSinkListener.getEventTypeOut(String eventBeanType)
focal_class.full_signature: private EventTypeOut getEventTypeOut(String eventBeanType)
focal_class.identifier: getEventTypeOut
focal_class.modifiers: private
focal_class.parameters: (String eventBeanType)
focal_class.return: EventTypeOut
focal_class.signature: EventTypeOut getEventTypeOut(String eventBeanType)
focal_class.class_method_signature: EventSinkListener.buildUpdateContextRequest(EventBean eventBean, EventTypeOut eventTypeOut)
focal_class.full_signature: private UpdateContext buildUpdateContextRequest(EventBean eventBean, EventTypeOut eventTypeOut)
focal_class.identifier: buildUpdateContextRequest
focal_class.modifiers: private
focal_class.parameters: (EventBean eventBean, EventTypeOut eventTypeOut)
focal_class.return: UpdateContext
focal_class.signature: UpdateContext buildUpdateContextRequest(EventBean eventBean, EventTypeOut eventTypeOut)
focal_class.class_method_signature: EventSinkListener.getHeadersForBroker(Broker broker)
focal_class.full_signature: private HttpHeaders getHeadersForBroker(Broker broker)
focal_class.identifier: getHeadersForBroker
focal_class.modifiers: private
focal_class.parameters: (Broker broker)
focal_class.return: HttpHeaders
focal_class.signature: HttpHeaders getHeadersForBroker(Broker broker)
focal_method.body: @Override
      public void update(EventBean[] added, EventBean[] removed, EPStatement epStatement, EPServiceProvider epServiceProvider) {
  
          // ignore updates for removed events
          if (added == null) {
              return;
          }
  
          for (EventBean eventBean : added) {
  
              // Debug some information about the event
              if (logger.isInfoEnabled()) {
                  StringBuilder sb = new StringBuilder();
                  for (String propertyName : eventBean.getEventType().getPropertyNames()) {
                      sb.append(" / ").append(propertyName).append(':').append(eventBean.get(propertyName));
                  }
                  logger.info("EventOut: {}{} from {}", eventBean.getEventType().getName(), sb.toString(), epStatement.getText());
              }
  
              // Send updateContext requests to each broker
              final String type = eventBean.getEventType().getName();
              final EventTypeOut eventTypeOut = getEventTypeOut(type);
              if (eventTypeOut == null) {
                  logger.debug("EventTypeOut {} doesn't exist in Configuration, updateContext not sent", type);
              } else {
                  UpdateContext updateContext = buildUpdateContextRequest(eventBean, eventTypeOut);
                  if (updateContext != null) {
                      for (Broker broker : eventTypeOut.getBrokers()) {
                          assert broker != null;
                          HttpHeaders httpHeaders = getHeadersForBroker(broker);
                          ngsiClient.updateContext(broker.getUrl(), httpHeaders, updateContext).addCallback(
                                  updateContextResponse ->
                                      logger.debug("UpdateContext completed for {}", broker.getUrl()),
                                  throwable ->
                                      logger.warn("UpdateContext failed for {}", broker.getUrl(), throwable)
                          );
                      }
                  }
              }
          }
      }
focal_method.class_method_signature: EventSinkListener.update(EventBean[] added, EventBean[] removed, EPStatement epStatement, EPServiceProvider epServiceProvider)
focal_method.full_signature: @Override public void update(EventBean[] added, EventBean[] removed, EPStatement epStatement, EPServiceProvider epServiceProvider)
focal_method.identifier: update
focal_method.invocations: isInfoEnabled getPropertyNames getEventType append append append append get info getName getEventType toString getText getName getEventType getEventTypeOut debug buildUpdateContextRequest getBrokers getHeadersForBroker addCallback updateContext getUrl debug getUrl warn getUrl
focal_method.modifiers: @Override public
focal_method.parameters: (EventBean[] added, EventBean[] removed, EPStatement epStatement, EPServiceProvider epServiceProvider)
focal_method.return: void
focal_method.signature: void update(EventBean[] added, EventBean[] removed, EPStatement epStatement, EPServiceProvider epServiceProvider)