### Question:
LdapSyncEventResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request event, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> resources = new HashSet<>(); Set<String> requestedIds = getRequestPropertyIds(event, predicate); for (LdapSyncEventEntity eventEntity : events.values()) { resources.add(toResource(eventEntity, requestedIds)); } return resources; } LdapSyncEventResourceProvider(AmbariManagementController managementController); @Override RequestStatus createResourcesAuthorized(Request event); @Override Set<Resource> getResources(Request event, Predicate predicate); @Override RequestStatus updateResources(Request event, Predicate predicate); @Override RequestStatus deleteResourcesAuthorized(Request request, Predicate predicate); @Override Map<Resource.Type, String> getKeyPropertyIds(); static final String EVENT_ID_PROPERTY_ID; static final String EVENT_STATUS_PROPERTY_ID; static final String EVENT_STATUS_DETAIL_PROPERTY_ID; static final String EVENT_START_TIME_PROPERTY_ID; static final String EVENT_END_TIME_PROPERTY_ID; static final String USERS_CREATED_PROPERTY_ID; static final String USERS_UPDATED_PROPERTY_ID; static final String USERS_REMOVED_PROPERTY_ID; static final String USERS_SKIPPED_PROPERTY_ID; static final String GROUPS_CREATED_PROPERTY_ID; static final String GROUPS_UPDATED_PROPERTY_ID; static final String GROUPS_REMOVED_PROPERTY_ID; static final String MEMBERSHIPS_CREATED_PROPERTY_ID; static final String MEMBERSHIPS_REMOVED_PROPERTY_ID; static final String EVENT_SPECS_PROPERTY_ID; }### Answer:
@Test public void testCreateResources() throws Exception { AmbariManagementController amc = createMock(AmbariManagementController.class); LdapSyncEventResourceProvider provider = new TestLdapSyncEventResourceProvider(amc); Set<Map<String, Object>> properties = new HashSet<>(); Map<String, Object> propertyMap = new HashMap<>(); Set<Map<String, String>> specs = new HashSet<>(); propertyMap.put(LdapSyncEventResourceProvider.EVENT_SPECS_PROPERTY_ID, specs); properties.add(propertyMap); provider.createResources(PropertyHelper.getCreateRequest(properties, null)); Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest(), null); Assert.assertEquals(1, resources.size()); }
@Test public void testGetResources() throws Exception { AmbariManagementController amc = createMock(AmbariManagementController.class); LdapSyncEventResourceProvider provider = new TestLdapSyncEventResourceProvider(amc); Set<Map<String, Object>> properties = new HashSet<>(); Map<String, Object> propertyMap = new HashMap<>(); Set<Map<String, String>> specs = new HashSet<>(); propertyMap.put(LdapSyncEventResourceProvider.EVENT_SPECS_PROPERTY_ID, specs); properties.add(propertyMap); provider.createResources(PropertyHelper.getCreateRequest(properties, null)); Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest(), null); Assert.assertEquals(1, resources.size()); }
@Test public void testDeleteResources() throws Exception { AmbariManagementController amc = createMock(AmbariManagementController.class); LdapSyncEventResourceProvider provider = new TestLdapSyncEventResourceProvider(amc); Set<Map<String, Object>> properties = new HashSet<>(); Map<String, Object> propertyMap = new HashMap<>(); Set<Map<String, String>> specs = new HashSet<>(); propertyMap.put(LdapSyncEventResourceProvider.EVENT_SPECS_PROPERTY_ID, specs); properties.add(propertyMap); provider.createResources(PropertyHelper.getCreateRequest(properties, null)); Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest(), null); Assert.assertEquals(1, resources.size()); provider.deleteResources(new RequestImpl(null, null, null, null), null); resources = provider.getResources(PropertyHelper.getReadRequest(), null); Assert.assertEquals(0, resources.size()); }