test_class.declarator: context = new SlingContext()
test_class.modifier: @Rule
      public
test_class.original_string: @Rule
      public SlingContext context = new SlingContext();
test_class.type: SlingContext
test_class.var_name: context
test_class.declarator: user
test_class.modifier: private
test_class.original_string: private User user;
test_class.type: User
test_class.var_name: user
test_class.file: core/src/test/java/org/apache/sling/cms/core/internal/operations/CreateUserOperationTest.java
test_class.identifier: CreateUserOperationTest
test_case.body: @Test
      public void testExisting() throws RepositoryException {
          CreateUserOperation createUserOperation = new CreateUserOperation();
          PostResponse response = new JSONResponse();
  
          context.currentResource("/home/users");
          context.request().setParameterMap(
                  ImmutableMap.<String, Object>builder().put(SlingPostConstants.RP_NODE_NAME, "test5").build());
  
          UserManager userManager = CommonUtils.getUserManager(context.resourceResolver());
          Mockito.when(userManager.getAuthorizable(Mockito.any(Principal.class))).thenReturn(Mockito.mock(Group.class));
  
          createUserOperation.run(context.request(), response, null);
  
          assertNotNull(response.getError());
      }
test_case.class_method_signature: CreateUserOperationTest.testExisting()
test_case.full_signature: @Test public void testExisting()
test_case.identifier: testExisting
test_case.invocations: currentResource setParameterMap request build put builder getUserManager resourceResolver thenReturn when getAuthorizable any mock run request assertNotNull getError
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testExisting()
focal_class.declarator: log = LoggerFactory.getLogger(CreateUserOperation.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(CreateUserOperation.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: PN_PASSWORD = ":password"
focal_class.modifier: @SuppressWarnings("squid:S2068") // Just the parameter key, not the value
      public static final
focal_class.original_string: @SuppressWarnings("squid:S2068") // Just the parameter key, not the value
      public static final String PN_PASSWORD = ":password";
focal_class.type: String
focal_class.var_name: PN_PASSWORD
focal_class.file: core/src/main/java/org/apache/sling/cms/core/internal/operations/CreateUserOperation.java
focal_class.identifier: CreateUserOperation
focal_class.interfaces: implements PostOperation
focal_class.class_method_signature: CreateUserOperation.run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_class.full_signature: @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_class.identifier: run
focal_class.modifiers: @Override public
focal_class.parameters: (SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_class.return: void
focal_class.signature: void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_method.body: @Override
      public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) {
          final List<Modification> changes = new ArrayList<>();
          try {
  
              String name = request.getParameter(SlingPostConstants.RP_NODE_NAME);
              String password = request.getParameter(PN_PASSWORD);
  
              ResourceResolver resolver = request.getResourceResolver();
              UserManager userManager = CommonUtils.getUserManager(resolver);
  
              if (userManager.getAuthorizable(new SimplePrincipal(name)) != null) {
                  throw new RepositoryException("Authorizable with id " + name + " already exists");
              }
              String intermediatePath = StringUtils.substringBeforeLast(request.getResource().getPath(), "/")
                      .replaceAll("\\/home\\/users\\/?", "");
  
              User user = userManager.createUser(name, password, new SimplePrincipal(name), intermediatePath);
  
              // invoke processors
              if (processors != null) {
                  for (SlingPostProcessor processor : processors) {
                      processor.process(request, changes);
                  }
              }
  
              request.getResourceResolver().commit();
  
              response.setPath(user.getPath());
              response.onCreated(user.getPath());
          } catch (Exception e) {
              log.warn("Failed to create user", e);
              response.setError(e);
          }
      }
focal_method.class_method_signature: CreateUserOperation.run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_method.full_signature: @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_method.identifier: run
focal_method.invocations: getParameter getParameter getResourceResolver getUserManager getAuthorizable replaceAll substringBeforeLast getPath getResource createUser process commit getResourceResolver setPath getPath onCreated getPath warn setError
focal_method.modifiers: @Override public
focal_method.parameters: (SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_method.return: void
focal_method.signature: void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)