AdminResource { @GET @Produces({MediaType.TEXT_PLAIN}) @Path("init") @SecurityHole(noAuth = true) @ApiOperation(notes = "Initializes the Candlepin database. Currently this just" + " creates the admin user for standalone deployments using the" + " default user service adapter. It must be called once after" + " candlepin is installed, repeat calls are not required, but" + " will be harmless. The String returned is the description if" + " the db was or already is initialized.", value = "initialize") public String initialize() { log.debug("Called initialize()"); log.info("Initializing Candlepin database."); if (userService instanceof DefaultUserServiceAdapter && userCurator.getUserCount() == 0) { ResteasyContext.pushContext(Principal.class, new SystemPrincipal()); log.info("Creating default super admin."); User defaultAdmin = new User("admin", "admin", true); userService.createUser(defaultAdmin); return "Initialized!"; } else { return "Already initialized."; } } @Inject  AdminResource(UserServiceAdapter userService, UserCurator userCurator,
        EventSink dispatcher, Configuration config, CandlepinCache candlepinCache); @GET @Produces({MediaType.TEXT_PLAIN}) @Path("init") @SecurityHole(noAuth = true) @ApiOperation(notes = "Initializes the Candlepin database. Currently this just" + " creates the admin user for standalone deployments using the" + " default user service adapter. It must be called once after" + " candlepin is installed, repeat calls are not required, but" + " will be harmless. The String returned is the description if" + " the db was or already is initialized.", value = "initialize") String initialize(); @GET @Produces({MediaType.APPLICATION_JSON}) @Path("queues") @ApiOperation( notes = "Basic information on the ActiveMQ queues and how many messages are pending in each.", value = "Get Queue Stats") List<QueueStatus> getQueueStats();  }
@Test public void initialize() { when(uc.getUserCount()).thenReturn(new Long(0)); assertEquals("Initialized!", ar.initialize()); verify(usa).createUser(any(User.class)); }
@Test public void initWithNonDefaultUserService() { ar = new AdminResource(mock(UserServiceAdapter.class), uc, null, config, null); assertEquals("Already initialized.", ar.initialize()); }
@Test public void alreadyInitialized() { when(uc.getUserCount()).thenReturn(new Long(1000)); assertEquals("Already initialized.", ar.initialize()); }