### Question:
KerberosDescriptorResourceProvider extends AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { String name = getNameFromRequest(request); String descriptor = getRawKerberosDescriptorFromRequest(request); KerberosDescriptor kerberosDescriptor = kerberosDescriptorFactory.createKerberosDescriptor(name, descriptor); kerberosDescriptorDAO.create(kerberosDescriptor.toEntity()); return getRequestStatus(null); } @Inject  KerberosDescriptorResourceProvider(KerberosDescriptorDAO kerberosDescriptorDAO,
                                     KerberosDescriptorFactory kerberosDescriptorFactory,
                                     @Assisted AmbariManagementController managementController); @Override Set<String> checkPropertyIds(Set<String> propertyIds); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate);  }### Answer:
@Test(expected = UnsupportedPropertyException.class) public void testCreateShouldThrowExceptionWhenNoDescriptorProvided() throws Exception { EasyMock.expect(request.getProperties()).andReturn(requestPropertySet(KERBEROS_DESCRIPTORS_KERBEROS_DESCRIPTOR_NAME, TEST_KERBEROS_DESCRIPTOR_NAME)).times(3); EasyMock.expect(request.getRequestInfoProperties()).andReturn(requestInfoPropertyMap("", "")).times(2); EasyMock.replay(request); kerberosDescriptorResourceProvider = new KerberosDescriptorResourceProvider(kerberosDescriptorDAO, kerberosDescriptorFactory, null); kerberosDescriptorResourceProvider.createResources(request); }
@Test(expected = UnsupportedPropertyException.class) public void testCreateShouldThrowExceptionWhenNoNameProvided() throws Exception { EasyMock.expect(request.getProperties()).andReturn(emptyRequestPropertySet()).times(2); EasyMock.replay(request); kerberosDescriptorResourceProvider = new KerberosDescriptorResourceProvider(kerberosDescriptorDAO, kerberosDescriptorFactory, null); kerberosDescriptorResourceProvider.createResources(request); }
@Test public void testShoudCreateResourceWhenNameAndDescriptorProvided() throws Exception { kerberosDescriptorResourceProvider = new KerberosDescriptorResourceProvider(kerberosDescriptorDAO, kerberosDescriptorFactory, null); EasyMock.expect(request.getProperties()) .andReturn(requestPropertySet(KERBEROS_DESCRIPTORS_KERBEROS_DESCRIPTOR_NAME, TEST_KERBEROS_DESCRIPTOR_NAME)) .times(3); EasyMock.expect(request.getRequestInfoProperties()) .andReturn(requestInfoPropertyMap(Request.REQUEST_INFO_BODY_PROPERTY, TEST_KERBEROS_DESCRIPTOR)) .times(3); EasyMock.expect(kerberosDescriptorFactory.createKerberosDescriptor(anyString(), anyString())) .andReturn(new KerberosDescriptorImpl(TEST_KERBEROS_DESCRIPTOR_NAME, TEST_KERBEROS_DESCRIPTOR)); Capture<KerberosDescriptorEntity> entityCapture = EasyMock.newCapture(); kerberosDescriptorDAO.create(capture(entityCapture)); EasyMock.replay(request, kerberosDescriptorFactory, kerberosDescriptorDAO); kerberosDescriptorResourceProvider.createResources(request); Assert.assertNotNull(entityCapture.getValue()); Assert.assertEquals("The resource name is invalid!", TEST_KERBEROS_DESCRIPTOR_NAME, entityCapture.getValue() .getName()); }