当前位置: 首页>>代码示例>>Java>>正文


Java CTPException类代码示例

本文整理汇总了Java中uk.gov.ons.ctp.common.error.CTPException的典型用法代码示例。如果您正苦于以下问题:Java CTPException类的具体用法?Java CTPException怎么用?Java CTPException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CTPException类属于uk.gov.ons.ctp.common.error包,在下文中一共展示了CTPException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testProcessActionRequestHappyPathSMS

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * To test the happy path when processing an ActionRequest for SMS. Note emailAddress is at null.
 *
 * @throws CTPException when notifyService.process does
 * @throws NotificationClientException when censusNotificationClient does
 */
@Test
public void testProcessActionRequestHappyPathSMS() throws CTPException, NotificationClientException {
  Mockito.when(notificationClient.sendSms(any(String.class), any(String.class),
          any(HashMap.class),any(String.class))).thenReturn(buildSendSmsResponse());
  Mockito.when(notificationClient.getNotificationById(any(String.class))).thenReturn(buildNotificationForSMS());

  ActionFeedback result = notifyService.process(ObjectBuilder.buildActionRequest(ACTION_ID, FORENAME, SURNAME,
          PHONENUMBER, null, true));
  assertEquals(ACTION_ID, result.getActionId());
  assertEquals(NOTIFY_SMS_SENT, result.getSituation());
  assertEquals(Outcome.REQUEST_COMPLETED, result.getOutcome());

  HashMap<String, String> personalisation = new HashMap<>();
  personalisation.put(IAC_KEY, IAC_AS_DISPLAYED_IN_SMS);
  verify(notificationClient, times(1)).sendSms(any(String.class), eq(PHONENUMBER),
          eq(personalisation), any(String.class));
  verify(notificationClient, times(1)).getNotificationById(eq(NOTIFICATION_ID));
}
 
开发者ID:ONSdigital,项目名称:rm-notify-gateway,代码行数:25,代码来源:NotifyServiceImplTest.java

示例2: testProcessActionRequestErrorPathSMS

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * To test the error path when processing an ActionRequest for SMS. Note emailAddress is at null.
 *
 * @throws CTPException when notifyService.process does
 * @throws NotificationClientException when censusNotificationClient does
 */
@Test
public void testProcessActionRequestErrorPathSMS() throws CTPException, NotificationClientException {
  Mockito.when(notificationClient.sendSms(any(String.class), any(String.class),
      any(HashMap.class),any(String.class))).thenThrow(new NotificationClientException(new Exception()));

  try {
    notifyService.process(ObjectBuilder.buildActionRequest(ACTION_ID, FORENAME, SURNAME,
        INVALID_PHONENUMBER, null, true));
    fail();
  } catch (NotificationClientException e) {
    assertEquals(EXCEPTION_MSG, e.getMessage());

  }

  HashMap<String, String> personalisation = new HashMap<>();
  personalisation.put(IAC_KEY, IAC_AS_DISPLAYED_IN_SMS);
  verify(notificationClient, times(1)).sendSms(any(String.class), eq(INVALID_PHONENUMBER),
      eq(personalisation), any(String.class));
  verify(notificationClient, never()).getNotificationById(any(String.class));
}
 
开发者ID:ONSdigital,项目名称:rm-notify-gateway,代码行数:27,代码来源:NotifyServiceImplTest.java

示例3: testProcessActionRequestHappyPathEmail

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * To test the happy path when processing an ActionRequest for Email. Note phonenumber is at null.
 *
 * @throws CTPException when notifyService.process does
 * @throws NotificationClientException when censusNotificationClient does
 */
@Test
public void testProcessActionRequestHappyPathEmail() throws CTPException, NotificationClientException {
  Mockito.when(notificationClient.sendEmail(any(String.class), any(String.class),
      any(HashMap.class),any(String.class))).thenReturn(buildSendEmailResponse());
  Mockito.when(notificationClient.getNotificationById(any(String.class))).thenReturn(buildNotificationForEmail());

  ActionFeedback result = notifyService.process(ObjectBuilder.buildActionRequest(ACTION_ID, FORENAME, SURNAME,
      null, EMAIL_ADDRESS, true));
  assertEquals(ACTION_ID, result.getActionId());
  assertEquals(NOTIFY_EMAIL_SENT, result.getSituation());
  assertEquals(Outcome.REQUEST_COMPLETED, result.getOutcome());

  HashMap<String, String> personalisation = new HashMap<>();
  personalisation.put(REPORTING_UNIT_REF_KEY, SAMPLE_UNIT_REF);
  personalisation.put(SURVEY_NAME_KEY, SURVEY_NAME);
  personalisation.put(SURVEY_ID_KEY, SURVEY_REF);
  personalisation.put(FIRSTNAME_KEY, FORENAME);
  personalisation.put(LASTNAME_KEY, SURNAME);
  personalisation.put(RU_NAME_KEY, RU_NAME);
  personalisation.put(TRADING_STYLE_KEY, TRADING_STYLE);
  personalisation.put(RETURN_BY_DATE_KEY, RETURN_BY_DATE);
  verify(notificationClient, times(1)).sendEmail(any(String.class), eq(EMAIL_ADDRESS),
      eq(personalisation), any(String.class));
  verify(notificationClient, times(1)).getNotificationById(eq(NOTIFICATION_ID));
}
 
开发者ID:ONSdigital,项目名称:rm-notify-gateway,代码行数:32,代码来源:NotifyServiceImplTest.java

示例4: getStatusMessageFoundWithoutNotificationId

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * Scenario where message is found in the database but notificationId has not yet been populated
 *
 * @throws Exception when getJson does
 */
@Test
public void getStatusMessageFoundWithoutNotificationId() throws Exception {
    Message message = Message.builder().build();
    when(resilienceService.findMessageById(UUID.fromString(EXISTING_MSG_ID))).thenReturn(message);

    ResultActions actions = mockMvc.perform(getJson(String.format("/messages/%s", EXISTING_MSG_ID)));

    actions.andExpect(status().isNotFound())
            .andExpect(handler().handlerType(StatusEndpoint.class))
            .andExpect(handler().methodName(GET_STATUS))
            .andExpect(jsonPath("$.error.code", is(CTPException.Fault.RESOURCE_NOT_FOUND.name())))
            .andExpect(jsonPath("$.error.message",
                    is(String.format(ERRORMSG_NOTIFICATION_NOTDEFINED, EXISTING_MSG_ID))))
            .andExpect(jsonPath("$.error.timestamp", isA(String.class)));
}
 
开发者ID:ONSdigital,项目名称:rm-notify-gateway,代码行数:21,代码来源:StatusEndpointTest.java

示例5: getStatusMessageFoundNotificationNull

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * Scenario where message is found in the database but notification retrieved from GOV.UK Notify is null
 *
 * @throws Exception when getJson does
 */
@Test
public void getStatusMessageFoundNotificationNull() throws Exception {
    UUID notificationId = UUID.fromString(NOTIFICATION_ID);
    Message message = Message.builder().notificationId(notificationId).build();
    when(resilienceService.findMessageById(UUID.fromString(EXISTING_MSG_ID))).thenReturn(message);
    when(notifyService.findNotificationById(eq(notificationId))).thenReturn(null);

    ResultActions actions = mockMvc.perform(getJson(String.format("/messages/%s", EXISTING_MSG_ID)));

    actions.andExpect(status().isNotFound())
            .andExpect(handler().handlerType(StatusEndpoint.class))
            .andExpect(handler().methodName(GET_STATUS))
            .andExpect(jsonPath("$.error.code", is(CTPException.Fault.RESOURCE_NOT_FOUND.name())))
            .andExpect(jsonPath("$.error.message",
                    is(String.format(ERRORMSG_NOTIFICATION_NOTFOUND, EXISTING_MSG_ID))))
            .andExpect(jsonPath("$.error.timestamp", isA(String.class)));
}
 
开发者ID:ONSdigital,项目名称:rm-notify-gateway,代码行数:23,代码来源:StatusEndpointTest.java

示例6: getStatusMessageFoundNotificationException

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * Scenario where message is found in the database but notification retrieval from GOV.UK Notify throws Exception
 *
 * @throws Exception when getJson does
 */
@Test
public void getStatusMessageFoundNotificationException() throws Exception {
    UUID notificationId = UUID.fromString(NOTIFICATION_ID);
    Message message = Message.builder().notificationId(notificationId).build();
    when(resilienceService.findMessageById(UUID.fromString(EXISTING_MSG_ID))).thenReturn(message);
    when(notifyService.findNotificationById(eq(notificationId))).thenThrow(
            new NotificationClientException(new Exception()));

    ResultActions actions = mockMvc.perform(getJson(String.format("/messages/%s", EXISTING_MSG_ID)));

    actions.andExpect(status().is5xxServerError())
            .andExpect(handler().handlerType(StatusEndpoint.class))
            .andExpect(handler().methodName(GET_STATUS))
            .andExpect(jsonPath("$.error.code", is(CTPException.Fault.SYSTEM_ERROR.name())))
            .andExpect(jsonPath("$.error.message",
                    is(String.format(ERRORMSG_NOTIFICATION_ISSUE, GENERAL_EXCEPTION, GENERAL_EXCEPTION))))
            .andExpect(jsonPath("$.error.timestamp", isA(String.class)));
}
 
开发者ID:ONSdigital,项目名称:rm-notify-gateway,代码行数:24,代码来源:StatusEndpointTest.java

示例7: updateAction

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * PUT to update the specified Action.
 *
 * @param actionId Action Id of the Action to update
 * @param actionDTO Incoming ActionDTO with details to update
 * @return ActionDTO Returns the updated Action details
 * @throws CTPException if update operation fails
 */
@RequestMapping(value = "/{actionid}", method = RequestMethod.PUT, consumes = "application/json")
public ActionDTO updateAction(@PathVariable("actionid") final BigInteger actionId,
                              @RequestBody final ActionDTO actionDTO, BindingResult bindingResult)
    throws CTPException {
  log.info("Updating Action with {} {}", actionId, actionDTO);
  if (bindingResult.hasErrors()) {
    throw new InvalidRequestException("Binding errors for update action: ", bindingResult);
  }

  actionDTO.setActionId(actionId);
  Action action = actionService.updateAction(mapperFacade.map(actionDTO, Action.class));
  if (action == null) {
    throw new CTPException(CTPException.Fault.RESOURCE_NOT_FOUND, "Action not updated for id %s", actionId);
  }
  return mapperFacade.map(action, ActionDTO.class);
}
 
开发者ID:ONSdigital,项目名称:response-management-service,代码行数:25,代码来源:ActionEndpoint.java

示例8: cancelActions

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * PUT to cancel all the Actions for a specified caseId.
 *
 * @param caseId Case Id of the actions to cancel
 * @return List<ActionDTO> Returns a list of cancelled Actions
 * @throws CTPException if update operation fails
 */
@RequestMapping(value = "/case/{caseid}/cancel", method = RequestMethod.PUT, consumes = "application/json")
public ResponseEntity<?> cancelActions(@PathVariable("caseid") final int caseId)
    throws CTPException {
  log.info("Cancelling Actions for {}", caseId);

  ActionCase caze = actionCaseService.findActionCase(caseId);
  if (caze == null) {
    throw new CTPException(CTPException.Fault.RESOURCE_NOT_FOUND, "Case not found for caseId %s", caseId);
  }
  
  List<Action> actions = actionService.cancelActions(caseId);
  List<ActionDTO> results = mapperFacade.mapAsList(actions, ActionDTO.class);
  return CollectionUtils.isEmpty(results) ?
          ResponseEntity.noContent().build() : ResponseEntity.ok(results);
}
 
开发者ID:ONSdigital,项目名称:response-management-service,代码行数:23,代码来源:ActionEndpoint.java

示例9: executeActionPlan

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * To create a new Action Plan Job having received an action plan id and some json
 * @param actionPlanId the given action plan id.
 * @param actionPlanJobDTO the ActionPlanJobDTO representation of the provided json
 * @return the created ActionPlanJobDTO
 * @throws CTPException summats went wrong
 */
@RequestMapping(value = "/{actionplanid}/jobs", method = RequestMethod.POST, consumes = "application/json")
public final ResponseEntity<?> executeActionPlan(@PathVariable("actionplanid") final Integer actionPlanId,
    final @RequestBody @Valid ActionPlanJobDTO actionPlanJobDTO, BindingResult bindingResult) throws CTPException {
  log.info("Entering executeActionPlan with {}", actionPlanId);

  if (bindingResult.hasErrors()) {
    throw new InvalidRequestException("Binding errors for execute action plan: ", bindingResult);
  }

  if (actionPlanJobDTO == null) {
    throw new CTPException(CTPException.Fault.VALIDATION_FAILED, "Provided json is incorrect.");
  }

  ActionPlanJob job = mapperFacade.map(actionPlanJobDTO, ActionPlanJob.class);
  job.setActionPlanId(actionPlanId);
  Optional<ActionPlanJob> actionPlanJob = actionPlanJobService.createAndExecuteActionPlanJob(job);
  return ResponseEntity.created(URI.create("TODO")).body(
          mapperFacade.map(actionPlanJob.orElseThrow(() -> new CTPException(CTPException.Fault.RESOURCE_NOT_FOUND,
          "ActionPlan not found for id %s", actionPlanId)), ActionPlanJobDTO.class));
}
 
开发者ID:ONSdigital,项目名称:response-management-service,代码行数:28,代码来源:ActionPlanJobEndpoint.java

示例10: updateActionPlanByActionPlanId

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * This method returns the associated action plan after it has been updated. Note that only the description and
 * the lastGoodRunDatetime can be updated.
 *
 * @param actionPlanId This is the action plan id
 * @param requestObject The object created by ActionPlanDTOMessageBodyReader from the json found in the request body
 * @return ActionPlanDTO This returns the updated action plan.
 * @throws CTPException if the json provided is incorrect or if the action plan id does not exist.
 */
@RequestMapping(value = "/{actionplanid}", method = RequestMethod.PUT, consumes = "application/json")
public final ActionPlanDTO updateActionPlanByActionPlanId(@PathVariable("actionplanid") final Integer actionPlanId,
                                                          @RequestBody final ActionPlanDTO requestObject,
                                                          BindingResult bindingResult) throws CTPException {
  log.info("UpdateActionPlanByActionPlanId with actionplanid {} - actionPlan {}", actionPlanId, requestObject);
  if (bindingResult.hasErrors()) {
    throw new InvalidRequestException("Binding errors for update action plan: ", bindingResult);
  }

  ActionPlan actionPlan = actionPlanService.updateActionPlan(actionPlanId,
      mapperFacade.map(requestObject, ActionPlan.class));
  if (actionPlan == null) {
    throw new CTPException(CTPException.Fault.RESOURCE_NOT_FOUND, "ActionPlan not found for id %s", actionPlanId);
  } 
  return mapperFacade.map(actionPlan, ActionPlanDTO.class);
}
 
开发者ID:ONSdigital,项目名称:response-management-service,代码行数:26,代码来源:ActionPlanEndpoint.java

示例11: returnActionRulesForActionPlanId

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * Returns all action rules for the given action plan id.
 * @param actionPlanId the action plan id
 * @return Returns all action rules for the given action plan id.
 * @throws CTPException summats went wrong
 */
@RequestMapping(value = "/{actionplanid}/rules", method = RequestMethod.GET)
public final ResponseEntity<?>  returnActionRulesForActionPlanId(
    @PathVariable("actionplanid") final Integer actionPlanId)
    throws CTPException {
  log.info("Entering returnActionRulesForActionPlanId with {}", actionPlanId);
  ActionPlan actionPlan = actionPlanService.findActionPlan(actionPlanId);
  if (actionPlan == null) {
    throw new CTPException(CTPException.Fault.RESOURCE_NOT_FOUND, "ActionPlan not found for id %s", actionPlanId);
  }

  List<ActionRule> actionRules = actionPlanService.findActionRulesForActionPlan(actionPlanId);
  List<ActionRuleDTO> actionRuleDTOs = mapperFacade.mapAsList(actionRules, ActionRuleDTO.class);
  return CollectionUtils.isEmpty(actionRuleDTOs) ?
          ResponseEntity.noContent().build() : ResponseEntity.ok(actionRuleDTOs);
}
 
开发者ID:ONSdigital,项目名称:response-management-service,代码行数:22,代码来源:ActionPlanEndpoint.java

示例12: storeTemplate

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
@Override
public TemplateExpression storeTemplate(String templateName, InputStream fileContents) throws CTPException {
  String stringValue = getStringFromInputStream(fileContents);
  if (StringUtils.isEmpty(stringValue)) {
    log.error(EXCEPTION_STORE_TEMPLATE);
    throw new CTPException(CTPException.Fault.SYSTEM_ERROR, EXCEPTION_STORE_TEMPLATE);
  }

  TemplateExpression template = new TemplateExpression();
  template.setContent(stringValue);
  template.setName(templateName);
  template.setDateModified(new Date());
  template = repository.save(template);

  configuration.clearTemplateCache();

  return template;
}
 
开发者ID:ONSdigital,项目名称:response-management-service,代码行数:19,代码来源:TemplateServiceImpl.java

示例13: export

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * To export a specific ActionRequest
 * 
 * @param actionId the actionId of the specific ActionRequest
 * @return 201 if successful
 * @throws CTPException if specific ActionRequest not found
 */
@RequestMapping(value = "/{actionId}", method = RequestMethod.POST)
public ResponseEntity<?> export(@PathVariable("actionId") final BigInteger actionId) throws CTPException {
  log.debug("Entering export with actionId {}", actionId);
  ActionRequestInstruction actionRequest = actionRequestService.retrieveActionRequest(actionId);
  if (actionRequest == null) {
    throw new CTPException(CTPException.Fault.RESOURCE_NOT_FOUND,
        String.format("%s %d", ACTION_REQUEST_NOT_FOUND, actionId));
  }
  ExportMessage message = new ExportMessage();
  transformationService.processActionRequest(message, actionRequest);
  if (message.isEmpty()) {
    throw new CTPException(CTPException.Fault.SYSTEM_ERROR,
        String.format("%s %d", ACTION_REQUEST_TRANSFORM_ERROR, actionId));
  }
  message.getOutputStreams().forEach((fileName, stream) -> {
    sftpService.sendMessage(fileName, message.getActionRequestIds(fileName), stream);
  });

  ActionRequestInstructionDTO actionRequestDTO = mapperFacade.map(actionRequest, ActionRequestInstructionDTO.class);
  return ResponseEntity.created(URI.create("TODO")).body(actionRequestDTO);
}
 
开发者ID:ONSdigital,项目名称:response-management-service,代码行数:29,代码来源:ActionRequestEndpoint.java

示例14: findCategory

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * the GET endpoint to retrieve the category with categoryType
 * 
 * @param categoryType the categoryType
 * @return the list of categories
 */
@RequestMapping(value = "/{categoryName}", method = RequestMethod.GET)
public CategoryDTO findCategory(@PathVariable("categoryName") final String categoryType) throws CTPException {
  log.info("Entering findCategory with categoryName {}", categoryType);

  Category category = null;
  Optional<CategoryDTO.CategoryType> catTypeEnum = CategoryDTO.CategoryType.fromString(categoryType);
  if (catTypeEnum.isPresent()) {
    category = categoryService.findCategory(catTypeEnum.get());
  }
  if (category == null) {
    throw new CTPException(CTPException.Fault.RESOURCE_NOT_FOUND,
            String.format("%s categoryName %s", ERRORMSG_CATEGORYNOTFOUND, categoryType));
  }
  return mapperFacade.map(category, CategoryDTO.class);
}
 
开发者ID:ONSdigital,项目名称:response-management-service,代码行数:22,代码来源:CategoryEndpoint.java

示例15: findCaseByIac

import uk.gov.ons.ctp.common.error.CTPException; //导入依赖的package包/类
/**
 * the GET endpoint to find a Case by IAC
 *
 * @param iac to find by
 * @return the case found
 * @throws CTPException something went wrong
 */
@RequestMapping(value = "/iac/{iac}", method = RequestMethod.GET)
public CaseDTO findCaseByIac(@PathVariable("iac") final String iac) throws CTPException {
  log.info("Entering findCaseByIac with {}", iac);
  Case caseObj = caseService.findCaseByIac(iac);


  if (caseObj == null) {
    throw new CTPException(CTPException.Fault.RESOURCE_NOT_FOUND,
        String.format("%s iac id %s", ERRORMSG_CASENOTFOUND, iac));
  }
  
  createNewEventForIACAuthenticated(caseObj);
  
  return mapperFacade.map(caseObj, CaseDTO.class);
}
 
开发者ID:ONSdigital,项目名称:response-management-service,代码行数:23,代码来源:CaseEndpoint.java


注:本文中的uk.gov.ons.ctp.common.error.CTPException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。