@Test
public void testScopePrivilegeCheck() throws Exception {

  SecurityContextHolder.getContext().setAuthentication(
      TestAuthenticationFactory.createServiceOperator());
  AmbariManagementController amc = createMock(AmbariManagementController.class);
  Clusters clusters = createMock(Clusters.class);
  Cluster cluster = createMock(Cluster.class);
  expect(amc.getClusters()).andReturn(clusters).atLeastOnce();
  expect(clusters.getCluster((String) anyObject())).andReturn(cluster).atLeastOnce();
  expect(cluster.getClusterId()).andReturn(Long.valueOf(1)).atLeastOnce();
  Capture<WidgetEntity> entityCapture = EasyMock.newCapture();
  dao.create(capture(entityCapture));
  expectLastCall();
  replay(amc, clusters, cluster, dao);
  PowerMock.replayAll();
  Map<String, Object> requestProps = new HashMap<>();
  requestProps.put(WidgetResourceProvider.WIDGET_CLUSTER_NAME_PROPERTY_ID, "c1");
  requestProps.put(WidgetResourceProvider.WIDGET_WIDGET_NAME_PROPERTY_ID, "widget name");
  requestProps.put(WidgetResourceProvider.WIDGET_WIDGET_TYPE_PROPERTY_ID, "GAUGE");
  requestProps.put(WidgetResourceProvider.WIDGET_AUTHOR_PROPERTY_ID, "admin");
  requestProps.put(WidgetResourceProvider.WIDGET_SCOPE_PROPERTY_ID, "CLUSTER");
  Request request = PropertyHelper.getCreateRequest(
          Collections.singleton(requestProps), null);
  try {
    WidgetResourceProvider widgetResourceProvider = createProvider(amc);
    widgetResourceProvider.createResources(request);
  } catch (AccessDeniedException ex) {
    //Expected exception
  }
}