@Test public void testReadUserContext() throws Exception { Map<Resource.Type, String> keyPropertyIds = Collections.emptyMap(); Set<String> propertyIds = Collections.emptySet(); AmbariManagementController ambariManagementController = mock(AmbariManagementController.class); RecommendationResourceProvider provider = new RecommendationResourceProvider(propertyIds, keyPropertyIds, ambariManagementController); Request request = mock(Request.class); Set<Map<String, Object>> propertiesSet = new HashSet<Map<String, Object>>(); Map<String, Object> propertiesMap = new HashMap<String, Object>(); propertiesMap.put(CONFIGURATIONS_PROPERTY_ID + "site/properties/string_prop", "string"); List<Object> array = new ArrayList<Object>(); array.add("array1"); array.add("array2"); propertiesMap.put(USER_CONTEXT_OPERATION_PROPERTY, "op1"); propertiesMap.put(USER_CONTEXT_OPERATION_DETAILS_PROPERTY, "op_det"); propertiesSet.add(propertiesMap); doReturn(propertiesSet).when(request).getProperties(); Map<String, String> userContext = provider.readUserContext(request); assertNotNull(userContext); assertEquals(2, userContext.size()); assertEquals("op1", userContext.get("operation")); assertEquals("op_det", userContext.get("operation_details")); }
protected Map<String, String> readUserContext(Request request) { HashMap<String, String> userContext = new HashMap<>(); if (null != getRequestProperty(request, USER_CONTEXT_OPERATION_PROPERTY)) { userContext.put(OPERATION_PROPERTY, (String) getRequestProperty(request, USER_CONTEXT_OPERATION_PROPERTY)); } if (null != getRequestProperty(request, USER_CONTEXT_OPERATION_DETAILS_PROPERTY)) { userContext.put(OPERATION_DETAILS_PROPERTY, (String) getRequestProperty(request, USER_CONTEXT_OPERATION_DETAILS_PROPERTY)); } return userContext; }
StackAdvisorResourceProvider extends ReadOnlyResourceProvider { protected Map<String, String> readUserContext(Request request) { HashMap<String, String> userContext = new HashMap<>(); if (null != getRequestProperty(request, USER_CONTEXT_OPERATION_PROPERTY)) { userContext.put(OPERATION_PROPERTY, (String) getRequestProperty(request, USER_CONTEXT_OPERATION_PROPERTY)); } if (null != getRequestProperty(request, USER_CONTEXT_OPERATION_DETAILS_PROPERTY)) { userContext.put(OPERATION_DETAILS_PROPERTY, (String) getRequestProperty(request, USER_CONTEXT_OPERATION_DETAILS_PROPERTY)); } return userContext; } }
StackAdvisorResourceProvider extends ReadOnlyResourceProvider { protected Map<String, String> readUserContext(Request request) { HashMap<String, String> userContext = new HashMap<>(); if (null != getRequestProperty(request, USER_CONTEXT_OPERATION_PROPERTY)) { userContext.put(OPERATION_PROPERTY, (String) getRequestProperty(request, USER_CONTEXT_OPERATION_PROPERTY)); } if (null != getRequestProperty(request, USER_CONTEXT_OPERATION_DETAILS_PROPERTY)) { userContext.put(OPERATION_DETAILS_PROPERTY, (String) getRequestProperty(request, USER_CONTEXT_OPERATION_DETAILS_PROPERTY)); } return userContext; } protected  StackAdvisorResourceProvider(Set<String> propertyIds, Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); }
StackAdvisorResourceProvider extends ReadOnlyResourceProvider { protected Map<String, String> readUserContext(Request request) { HashMap<String, String> userContext = new HashMap<>(); if (null != getRequestProperty(request, USER_CONTEXT_OPERATION_PROPERTY)) { userContext.put(OPERATION_PROPERTY, (String) getRequestProperty(request, USER_CONTEXT_OPERATION_PROPERTY)); } if (null != getRequestProperty(request, USER_CONTEXT_OPERATION_DETAILS_PROPERTY)) { userContext.put(OPERATION_DETAILS_PROPERTY, (String) getRequestProperty(request, USER_CONTEXT_OPERATION_DETAILS_PROPERTY)); } return userContext; } protected  StackAdvisorResourceProvider(Set<String> propertyIds, Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Inject static void init(StackAdvisorHelper instance); }
StackAdvisorResourceProvider extends ReadOnlyResourceProvider { protected Map<String, String> readUserContext(Request request) { HashMap<String, String> userContext = new HashMap<>(); if (null != getRequestProperty(request, USER_CONTEXT_OPERATION_PROPERTY)) { userContext.put(OPERATION_PROPERTY, (String) getRequestProperty(request, USER_CONTEXT_OPERATION_PROPERTY)); } if (null != getRequestProperty(request, USER_CONTEXT_OPERATION_DETAILS_PROPERTY)) { userContext.put(OPERATION_DETAILS_PROPERTY, (String) getRequestProperty(request, USER_CONTEXT_OPERATION_DETAILS_PROPERTY)); } return userContext; } protected  StackAdvisorResourceProvider(Set<String> propertyIds, Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Inject static void init(StackAdvisorHelper instance);  }