test_class.declarator: mockMvc
test_class.modifier: private
test_class.original_string: private MockMvc mockMvc;
test_class.type: MockMvc
test_class.var_name: mockMvc
test_class.declarator: localRegistrations
test_class.modifier: @Mock
test_class.original_string: @Mock
      LocalRegistrations localRegistrations;
test_class.type: LocalRegistrations
test_class.var_name: localRegistrations
test_class.declarator: subscriptions
test_class.modifier: @Mock
test_class.original_string: @Mock
      Subscriptions subscriptions;
test_class.type: Subscriptions
test_class.var_name: subscriptions
test_class.declarator: ngsiClient
test_class.modifier: @Mock
test_class.original_string: @Mock
      NgsiClient ngsiClient;
test_class.type: NgsiClient
test_class.var_name: ngsiClient
test_class.declarator: configuration
test_class.modifier: @Mock
test_class.original_string: @Mock
      Configuration configuration;
test_class.type: Configuration
test_class.var_name: configuration
test_class.declarator: providingApplication
test_class.modifier: @Mock
test_class.original_string: @Mock
      Iterator<URI> providingApplication;
test_class.type: Iterator<URI>
test_class.var_name: providingApplication
test_class.declarator: matchedSubscriptions
test_class.modifier: @Mock
test_class.original_string: @Mock
      Iterator<Subscription> matchedSubscriptions;
test_class.type: Iterator<Subscription>
test_class.var_name: matchedSubscriptions
test_class.declarator: updateContextResponseListenableFuture
test_class.modifier: @Mock
test_class.original_string: @Mock
      ListenableFuture<UpdateContextResponse> updateContextResponseListenableFuture;
test_class.type: ListenableFuture<UpdateContextResponse>
test_class.var_name: updateContextResponseListenableFuture
test_class.declarator: queryContextResponseListenableFuture
test_class.modifier: @Mock
test_class.original_string: @Mock
      ListenableFuture<QueryContextResponse> queryContextResponseListenableFuture;
test_class.type: ListenableFuture<QueryContextResponse>
test_class.var_name: queryContextResponseListenableFuture
test_class.declarator: notifyContextResponseListenableFuture
test_class.modifier: @Mock
test_class.original_string: @Mock
      ListenableFuture<NotifyContextResponse> notifyContextResponseListenableFuture;
test_class.type: ListenableFuture<NotifyContextResponse>
test_class.var_name: notifyContextResponseListenableFuture
test_class.declarator: webApplicationContext
test_class.modifier: @Autowired
      private
test_class.original_string: @Autowired
      private WebApplicationContext webApplicationContext;
test_class.type: WebApplicationContext
test_class.var_name: webApplicationContext
test_class.declarator: mapper
test_class.modifier: @Autowired
      private
test_class.original_string: @Autowired
      private MappingJackson2HttpMessageConverter mapper;
test_class.type: MappingJackson2HttpMessageConverter
test_class.var_name: mapper
test_class.declarator: attributeArgumentCaptor
test_class.modifier: @Captor
      private
test_class.original_string: @Captor
      private ArgumentCaptor<Set<String>> attributeArgumentCaptor;
test_class.type: ArgumentCaptor<Set<String>>
test_class.var_name: attributeArgumentCaptor
test_class.declarator: entityIdArgumentCaptor
test_class.modifier: @Captor
      private
test_class.original_string: @Captor
      private ArgumentCaptor<EntityId> entityIdArgumentCaptor;
test_class.type: ArgumentCaptor<EntityId>
test_class.var_name: entityIdArgumentCaptor
test_class.declarator: ngsiController
test_class.modifier: @InjectMocks
      @Autowired
      private
test_class.original_string: @InjectMocks
      @Autowired
      private NgsiController ngsiController;
test_class.type: NgsiController
test_class.var_name: ngsiController
test_class.declarator: httpHeaders = new HttpHeaders()
test_class.modifier: private
test_class.original_string: private HttpHeaders httpHeaders = new HttpHeaders();
test_class.type: HttpHeaders
test_class.var_name: httpHeaders
test_class.file: cepheus-broker/src/test/java/com/orange/cepheus/broker/controller/NgsiControllerTest.java
test_class.identifier: NgsiControllerTest
test_case.body: @Test
      public void postUpdateContextWithoutProvidingApplicationAndWithoutRemoteBrokerButWithEmptyOriginator() throws Exception {
  
          when(configuration.getRemoteUrl()).thenReturn(null);
          when(configuration.getLocalUrl()).thenReturn("");
  
          //localRegistrations mock return always without providingApplication
          when(providingApplication.hasNext()).thenReturn(false);
          when(localRegistrations.findProvidingApplication(any(), any())).thenReturn(providingApplication);
  
          //subscriptions mock return always with matched subscriptions
          when(matchedSubscriptions.hasNext()).thenReturn(true, false);
          SubscribeContext subscribeContext = createSubscribeContextTemperature();
          Subscription subscription = new Subscription("999999", Instant.now().plus(1, ChronoUnit.DAYS), subscribeContext);
          when(matchedSubscriptions.next()).thenReturn(subscription);
          when(subscriptions.findSubscriptions(any(), any())).thenReturn(matchedSubscriptions);
  
          //ngsiclient mock return always createUpdateContextREsponseTemperature when call updateContext
          when(ngsiClient.updateContext(any(), any(), any())).thenReturn(updateContextResponseListenableFuture);
  
          //ngsiClient mock return always CODE_200
          when(ngsiClient.notifyContext(any(), any(), any())).thenReturn(notifyContextResponseListenableFuture);
  
          mockMvc.perform(post("/v1/updateContext")
                  .content(json(mapper, createUpdateContextTempSensorAndPressure()))
                  .contentType(MediaType.APPLICATION_JSON))
                  .andExpect(status().isOk())
                  .andExpect(MockMvcResultMatchers.jsonPath("$.errorCode").doesNotExist())
                  .andExpect(MockMvcResultMatchers.jsonPath("$.contextResponses[0].contextElement.id").value("S1"))
                  .andExpect(MockMvcResultMatchers.jsonPath("$.contextResponses[0].contextElement.type").value("TempSensor"))
                  .andExpect(MockMvcResultMatchers.jsonPath("$.contextResponses[0].contextElement.attributes[0].name").value("temp"))
                  .andExpect(MockMvcResultMatchers.jsonPath("$.contextResponses[0].contextElement.attributes[0].type").value("float"))
                  .andExpect(MockMvcResultMatchers.jsonPath("$.contextResponses[0].contextElement.attributes[0].value").value("15.5"))
                  .andExpect(MockMvcResultMatchers.jsonPath("$.contextResponses[0].contextElement.attributes[1].name").value("pressure"))
                  .andExpect(MockMvcResultMatchers.jsonPath("$.contextResponses[0].contextElement.attributes[1].type").value("int"))
                  .andExpect(MockMvcResultMatchers.jsonPath("$.contextResponses[0].contextElement.attributes[1].value").value("1015"))
                  .andExpect(MockMvcResultMatchers.jsonPath("$.contextResponses[0].statusCode.code").value("200"));
  
          //Capture attributes (Set<String> searchAttributes) when findProvidingApplication is called on localRegistrations Set<String> searchAttributes
          verify(localRegistrations).findProvidingApplication(entityIdArgumentCaptor.capture(), attributeArgumentCaptor.capture());
  
          //check entityId
          assertEquals("S1", entityIdArgumentCaptor.getValue().getId());
          assertEquals("TempSensor", entityIdArgumentCaptor.getValue().getType());
          assertFalse(entityIdArgumentCaptor.getValue().getIsPattern());
  
          //check attributes
          assertEquals(2, attributeArgumentCaptor.getValue().size());
          assertTrue(attributeArgumentCaptor.getValue().contains("temp"));
          assertTrue(attributeArgumentCaptor.getValue().contains("pressure"));
  
          //check ListenableFuture is called never and with addCallback method
          verify(updateContextResponseListenableFuture, never()).addCallback(any(), any());
  
          //verify ngsiClient.updateContext is never called
          verify(ngsiClient, never()).updateContext(any(), any(), any());
  
          //check ngsiClient.notify is never called
          verify(notifyContextResponseListenableFuture, never()).addCallback(any(), any());
          verify(ngsiClient, never()).notifyContext(any(), any(), any());
      }
test_case.class_method_signature: NgsiControllerTest.postUpdateContextWithoutProvidingApplicationAndWithoutRemoteBrokerButWithEmptyOriginator()
test_case.full_signature: @Test public void postUpdateContextWithoutProvidingApplicationAndWithoutRemoteBrokerButWithEmptyOriginator()
test_case.identifier: postUpdateContextWithoutProvidingApplicationAndWithoutRemoteBrokerButWithEmptyOriginator
test_case.invocations: thenReturn when getRemoteUrl thenReturn when getLocalUrl thenReturn when hasNext thenReturn when findProvidingApplication any any thenReturn when hasNext createSubscribeContextTemperature plus now thenReturn when next thenReturn when findSubscriptions any any thenReturn when updateContext any any any thenReturn when notifyContext any any any andExpect andExpect andExpect andExpect andExpect andExpect andExpect andExpect andExpect andExpect andExpect perform contentType content post json createUpdateContextTempSensorAndPressure isOk status doesNotExist jsonPath value jsonPath value jsonPath value jsonPath value jsonPath value jsonPath value jsonPath value jsonPath value jsonPath value jsonPath findProvidingApplication verify capture capture assertEquals getId getValue assertEquals getType getValue assertFalse getIsPattern getValue assertEquals size getValue assertTrue contains getValue assertTrue contains getValue addCallback verify never any any updateContext verify never any any any addCallback verify never any any notifyContext verify never any any any
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void postUpdateContextWithoutProvidingApplicationAndWithoutRemoteBrokerButWithEmptyOriginator()
focal_class.declarator: logger = LoggerFactory.getLogger(NgsiController.class)
focal_class.modifier: private static
focal_class.original_string: private static Logger logger = LoggerFactory.getLogger(NgsiController.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: localRegistrations
focal_class.modifier: @Autowired
focal_class.original_string: @Autowired
      LocalRegistrations localRegistrations;
focal_class.type: LocalRegistrations
focal_class.var_name: localRegistrations
focal_class.declarator: subscriptions
focal_class.modifier: @Autowired
focal_class.original_string: @Autowired
      Subscriptions subscriptions;
focal_class.type: Subscriptions
focal_class.var_name: subscriptions
focal_class.declarator: ngsiClient
focal_class.modifier: @Autowired
focal_class.original_string: @Autowired
      NgsiClient ngsiClient;
focal_class.type: NgsiClient
focal_class.var_name: ngsiClient
focal_class.declarator: configuration
focal_class.modifier: @Autowired
focal_class.original_string: @Autowired
      Configuration configuration;
focal_class.type: Configuration
focal_class.var_name: configuration
focal_class.file: cepheus-broker/src/main/java/com/orange/cepheus/broker/controller/NgsiController.java
focal_class.identifier: NgsiController
focal_class.class_method_signature: NgsiController.registerContext(final RegisterContext register)
focal_class.full_signature: @Override public RegisterContextResponse registerContext(final RegisterContext register)
focal_class.identifier: registerContext
focal_class.modifiers: @Override public
focal_class.parameters: (final RegisterContext register)
focal_class.return: RegisterContextResponse
focal_class.signature: RegisterContextResponse registerContext(final RegisterContext register)
focal_class.class_method_signature: NgsiController.updateContext(final UpdateContext update)
focal_class.full_signature: @Override public UpdateContextResponse updateContext(final UpdateContext update)
focal_class.identifier: updateContext
focal_class.modifiers: @Override public
focal_class.parameters: (final UpdateContext update)
focal_class.return: UpdateContextResponse
focal_class.signature: UpdateContextResponse updateContext(final UpdateContext update)
focal_class.class_method_signature: NgsiController.queryContext(final QueryContext query)
focal_class.full_signature: @Override public QueryContextResponse queryContext(final QueryContext query)
focal_class.identifier: queryContext
focal_class.modifiers: @Override public
focal_class.parameters: (final QueryContext query)
focal_class.return: QueryContextResponse
focal_class.signature: QueryContextResponse queryContext(final QueryContext query)
focal_class.class_method_signature: NgsiController.subscribeContext(final SubscribeContext subscribe)
focal_class.full_signature: @Override public SubscribeContextResponse subscribeContext(final SubscribeContext subscribe)
focal_class.identifier: subscribeContext
focal_class.modifiers: @Override public
focal_class.parameters: (final SubscribeContext subscribe)
focal_class.return: SubscribeContextResponse
focal_class.signature: SubscribeContextResponse subscribeContext(final SubscribeContext subscribe)
focal_class.class_method_signature: NgsiController.updateContextSubscription(final UpdateContextSubscription updateContextSubscription)
focal_class.full_signature: @Override public UpdateContextSubscriptionResponse updateContextSubscription(final UpdateContextSubscription updateContextSubscription)
focal_class.identifier: updateContextSubscription
focal_class.modifiers: @Override public
focal_class.parameters: (final UpdateContextSubscription updateContextSubscription)
focal_class.return: UpdateContextSubscriptionResponse
focal_class.signature: UpdateContextSubscriptionResponse updateContextSubscription(final UpdateContextSubscription updateContextSubscription)
focal_class.class_method_signature: NgsiController.unsubscribeContext(final UnsubscribeContext unsubscribe)
focal_class.full_signature: @Override public UnsubscribeContextResponse unsubscribeContext(final UnsubscribeContext unsubscribe)
focal_class.identifier: unsubscribeContext
focal_class.modifiers: @Override public
focal_class.parameters: (final UnsubscribeContext unsubscribe)
focal_class.return: UnsubscribeContextResponse
focal_class.signature: UnsubscribeContextResponse unsubscribeContext(final UnsubscribeContext unsubscribe)
focal_class.class_method_signature: NgsiController.registrationExceptionHandler(HttpServletRequest req, RegistrationException registrationException)
focal_class.full_signature: @ExceptionHandler(RegistrationException.class) public ResponseEntity<Object> registrationExceptionHandler(HttpServletRequest req, RegistrationException registrationException)
focal_class.identifier: registrationExceptionHandler
focal_class.modifiers: @ExceptionHandler(RegistrationException.class) public
focal_class.parameters: (HttpServletRequest req, RegistrationException registrationException)
focal_class.return: ResponseEntity<Object>
focal_class.signature: ResponseEntity<Object> registrationExceptionHandler(HttpServletRequest req, RegistrationException registrationException)
focal_class.class_method_signature: NgsiController.missingRemoteBrokerExceptionHandler(HttpServletRequest req, MissingRemoteBrokerException missingRemoteBrokerException)
focal_class.full_signature: @ExceptionHandler(MissingRemoteBrokerException.class) public ResponseEntity<Object> missingRemoteBrokerExceptionHandler(HttpServletRequest req, MissingRemoteBrokerException missingRemoteBrokerException)
focal_class.identifier: missingRemoteBrokerExceptionHandler
focal_class.modifiers: @ExceptionHandler(MissingRemoteBrokerException.class) public
focal_class.parameters: (HttpServletRequest req, MissingRemoteBrokerException missingRemoteBrokerException)
focal_class.return: ResponseEntity<Object>
focal_class.signature: ResponseEntity<Object> missingRemoteBrokerExceptionHandler(HttpServletRequest req, MissingRemoteBrokerException missingRemoteBrokerException)
focal_class.class_method_signature: NgsiController.subscriptionExceptionHandler(HttpServletRequest req, SubscriptionException subscriptionException)
focal_class.full_signature: @ExceptionHandler(SubscriptionException.class) public ResponseEntity<Object> subscriptionExceptionHandler(HttpServletRequest req, SubscriptionException subscriptionException)
focal_class.identifier: subscriptionExceptionHandler
focal_class.modifiers: @ExceptionHandler(SubscriptionException.class) public
focal_class.parameters: (HttpServletRequest req, SubscriptionException subscriptionException)
focal_class.return: ResponseEntity<Object>
focal_class.signature: ResponseEntity<Object> subscriptionExceptionHandler(HttpServletRequest req, SubscriptionException subscriptionException)
focal_class.class_method_signature: NgsiController.subscriptionPersistenceExceptionHandler(HttpServletRequest req, SubscriptionPersistenceException subscriptionPersistenceException)
focal_class.full_signature: @ExceptionHandler(SubscriptionPersistenceException.class) public ResponseEntity<Object> subscriptionPersistenceExceptionHandler(HttpServletRequest req, SubscriptionPersistenceException subscriptionPersistenceException)
focal_class.identifier: subscriptionPersistenceExceptionHandler
focal_class.modifiers: @ExceptionHandler(SubscriptionPersistenceException.class) public
focal_class.parameters: (HttpServletRequest req, SubscriptionPersistenceException subscriptionPersistenceException)
focal_class.return: ResponseEntity<Object>
focal_class.signature: ResponseEntity<Object> subscriptionPersistenceExceptionHandler(HttpServletRequest req, SubscriptionPersistenceException subscriptionPersistenceException)
focal_class.class_method_signature: NgsiController.registrationPersistenceExceptionHandler(HttpServletRequest req, RegistrationPersistenceException registrationPersistenceException)
focal_class.full_signature: @ExceptionHandler(RegistrationPersistenceException.class) public ResponseEntity<Object> registrationPersistenceExceptionHandler(HttpServletRequest req, RegistrationPersistenceException registrationPersistenceException)
focal_class.identifier: registrationPersistenceExceptionHandler
focal_class.modifiers: @ExceptionHandler(RegistrationPersistenceException.class) public
focal_class.parameters: (HttpServletRequest req, RegistrationPersistenceException registrationPersistenceException)
focal_class.return: ResponseEntity<Object>
focal_class.signature: ResponseEntity<Object> registrationPersistenceExceptionHandler(HttpServletRequest req, RegistrationPersistenceException registrationPersistenceException)
focal_class.class_method_signature: NgsiController.getRemoteBrokerHeaders(String brokerUrl)
focal_class.full_signature: private HttpHeaders getRemoteBrokerHeaders(String brokerUrl)
focal_class.identifier: getRemoteBrokerHeaders
focal_class.modifiers: private
focal_class.parameters: (String brokerUrl)
focal_class.return: HttpHeaders
focal_class.signature: HttpHeaders getRemoteBrokerHeaders(String brokerUrl)
focal_class.class_method_signature: NgsiController.logUpdateContextResponse(UpdateContextResponse updateContextResponse, String brokerUrl)
focal_class.full_signature: private void logUpdateContextResponse(UpdateContextResponse updateContextResponse, String brokerUrl)
focal_class.identifier: logUpdateContextResponse
focal_class.modifiers: private
focal_class.parameters: (UpdateContextResponse updateContextResponse, String brokerUrl)
focal_class.return: void
focal_class.signature: void logUpdateContextResponse(UpdateContextResponse updateContextResponse, String brokerUrl)
focal_class.class_method_signature: NgsiController.logNotifyContextResponse(NotifyContextResponse notifyContextResponse, String providerUrl)
focal_class.full_signature: private void logNotifyContextResponse(NotifyContextResponse notifyContextResponse, String providerUrl)
focal_class.identifier: logNotifyContextResponse
focal_class.modifiers: private
focal_class.parameters: (NotifyContextResponse notifyContextResponse, String providerUrl)
focal_class.return: void
focal_class.signature: void logNotifyContextResponse(NotifyContextResponse notifyContextResponse, String providerUrl)
focal_class.superclass: extends NgsiBaseController
focal_method.body: @Override
      public UpdateContextResponse updateContext(final UpdateContext update) throws ExecutionException, InterruptedException, URISyntaxException {
  
          //TODO : search providingApplication for all contextElement of updateContext
          ContextElement contextElement = update.getContextElements().get(0);
          Set<String> attributesName = contextElement.getContextAttributeList().stream().map(ContextAttribute::getName).collect(Collectors.toSet());
  
          logger.debug("<= updateContext with entityId: {} and attributes: {} ", contextElement.getEntityId().toString(), attributesName);
  
          /*
           * If a registration matches the updateContext, the updateContext is forwarded to the corresponding providingURL.
           * Else, the update is forwarded to the remote broker and the subscribers are notified.
           */
  
          // Search registrations to forward updateContext
          Iterator<URI> providingApplication = localRegistrations.findProvidingApplication(contextElement.getEntityId(), attributesName);
          if (providingApplication.hasNext()) {
              // Forward the update to the first providing Application (command)
              final String providerUrl = providingApplication.next().toString();
              HttpHeaders httpHeaders = ngsiClient.getRequestHeaders(providerUrl);
              logger.debug("=> updateContext forwarded to {} with Content-Type {}", providerUrl, httpHeaders.getContentType());
              return ngsiClient.updateContext(providerUrl, httpHeaders, update).get();
          }
  
          // Forward the update to the remote broker
          if (configuration.isRemoteForwardUpdateContext()) {
              final String brokerUrl = configuration.getRemoteUrl();
              if (brokerUrl == null || brokerUrl.isEmpty()) {
                  logger.warn("No remote.url parameter defined to forward updateContext");
              } else {
                  HttpHeaders httpHeaders = getRemoteBrokerHeaders(brokerUrl);
                  logger.debug("=> updateContext forwarded to remote broker {} with Content-Type {}", brokerUrl, httpHeaders.getContentType());
                  ngsiClient.updateContext(brokerUrl, httpHeaders, update)
                          .addCallback(updateContextResponse -> logUpdateContextResponse(updateContextResponse, brokerUrl),
                                  throwable -> logger.warn("UpdateContext failed for {}: {}", brokerUrl, throwable.getMessage(), throwable));
              }
          }
  
          List<ContextElementResponse> contextElementResponseList = new ArrayList<>();
          StatusCode statusCode = new StatusCode(CodeEnum.CODE_200);
          for (ContextElement c : update.getContextElements()) {
              contextElementResponseList.add(new ContextElementResponse(c, statusCode));
          }
  
          String originator = configuration.getLocalUrl();
          if (originator == null || originator.isEmpty()) {
              logger.warn("No local.url parameter defined to use as originator for sending notifyContext");
          } else {
              // Send notifications to matching subscriptions
              Iterator<Subscription> matchingSubscriptions = subscriptions.findSubscriptions(contextElement.getEntityId(), attributesName);
              while (matchingSubscriptions.hasNext()) {
                  Subscription subscription = matchingSubscriptions.next();
                  NotifyContext notifyContext = new NotifyContext(subscription.getSubscriptionId(), new URI(originator));
                  notifyContext.setContextElementResponseList(contextElementResponseList);
                  String providerUrl = subscription.getSubscribeContext().getReference().toString();
  
                  HttpHeaders httpHeaders = ngsiClient.getRequestHeaders(providerUrl);
                  logger.debug("=> notifyContext to {} with Content-Type {}", providerUrl, httpHeaders.getContentType());
  
                  ngsiClient.notifyContextCustomURL(providerUrl, httpHeaders, notifyContext).addCallback(
                                  notifyContextResponse -> logNotifyContextResponse(notifyContextResponse, providerUrl),
                          throwable -> logger.warn("NotifyContext failed for {}", providerUrl, throwable));
              }
          }
  
          UpdateContextResponse updateContextResponse = new UpdateContextResponse();
          updateContextResponse.setContextElementResponses(contextElementResponseList);
          return updateContextResponse;
      }
focal_method.class_method_signature: NgsiController.updateContext(final UpdateContext update)
focal_method.full_signature: @Override public UpdateContextResponse updateContext(final UpdateContext update)
focal_method.identifier: updateContext
focal_method.invocations: get getContextElements collect map stream getContextAttributeList toSet debug toString getEntityId findProvidingApplication getEntityId hasNext toString next getRequestHeaders debug getContentType get updateContext isRemoteForwardUpdateContext getRemoteUrl isEmpty warn getRemoteBrokerHeaders debug getContentType addCallback updateContext logUpdateContextResponse warn getMessage getContextElements add getLocalUrl isEmpty warn findSubscriptions getEntityId hasNext next getSubscriptionId setContextElementResponseList toString getReference getSubscribeContext getRequestHeaders debug getContentType addCallback notifyContextCustomURL logNotifyContextResponse warn setContextElementResponses
focal_method.modifiers: @Override public
focal_method.parameters: (final UpdateContext update)
focal_method.return: UpdateContextResponse
focal_method.signature: UpdateContextResponse updateContext(final UpdateContext update)