### Question:
StageResourceProvider extends AbstractControllerResourceProvider implements ExtendedResourceProvider { @Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { Map<String,Object> updateProperties = iterator.next(); List<StageEntity> entities = dao.findAll(request, predicate); for (StageEntity entity : entities) { String stageStatus = (String) updateProperties.get(STAGE_STATUS); if (stageStatus != null) { HostRoleStatus desiredStatus = HostRoleStatus.valueOf(stageStatus); dao.updateStageStatus(entity, desiredStatus, getManagementController().getActionManager()); } } } notifyUpdate(Resource.Type.Stage, request, predicate); return getRequestStatus(null); } StageResourceProvider(AmbariManagementController managementController); @Override RequestStatus createResources(Request request); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override QueryResponse queryForResources(Request request, Predicate predicate); static final String STAGE_STAGE_ID; static final String STAGE_CLUSTER_NAME; static final String STAGE_REQUEST_ID; static final String STAGE_LOG_INFO; static final String STAGE_CONTEXT; static final String STAGE_COMMAND_PARAMS; static final String STAGE_HOST_PARAMS; static final String STAGE_SKIPPABLE; static final String STAGE_PROGRESS_PERCENT; static final String STAGE_STATUS; static final String STAGE_DISPLAY_STATUS; static final String STAGE_START_TIME; static final String STAGE_END_TIME; }### Answer:
@Test public void testUpdateResources() throws Exception { StageResourceProvider provider = new StageResourceProvider(managementController); Request request = createNiceMock(Request.class); Predicate predicate = createNiceMock(Predicate.class); expect(clusters.getClusterById(anyLong())).andReturn(cluster).anyTimes(); expect(request.getProperties()).andReturn(Collections.emptySet()); replay(clusters, cluster, request, predicate); provider.updateResources(request, predicate); verify(clusters, cluster); }
@Test public void testUpdateStageStatus_aborted() throws Exception { StageResourceProvider provider = new StageResourceProvider(managementController); ActionManager actionManager = createNiceMock(ActionManager.class); Predicate predicate = new PredicateBuilder().property(StageResourceProvider.STAGE_STAGE_ID).equals(2L).and(). property(StageResourceProvider.STAGE_REQUEST_ID).equals(1L).toPredicate(); Map<String, Object> requestProps = new HashMap<>(); requestProps.put(StageResourceProvider.STAGE_STATUS, HostRoleStatus.ABORTED.name()); Request request = PropertyHelper.getUpdateRequest(requestProps, null); List<StageEntity> entities = getStageEntities(HostRoleStatus.HOLDING); expect(dao.findAll(request, predicate)).andReturn(entities); expect(managementController.getActionManager()).andReturn(actionManager).anyTimes(); dao.updateStageStatus(entities.get(0), HostRoleStatus.ABORTED, actionManager); EasyMock.expectLastCall().atLeastOnce(); replay(dao, clusters, cluster, actionManager, managementController); provider.updateResources(request, predicate); verify(dao, clusters, cluster, actionManager, managementController); }