OwnerResource { @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(notes = "Creates an Owner", value = "Create Owner", response = OwnerDTO.class) @ApiResponses({ @ApiResponse(code = 400, message = "Invalid owner specified in body") }) public OwnerDTO createOwner(@ApiParam(name = "owner", required = true) OwnerDTO dto) { if (StringUtils.isBlank(dto.getKey())) { throw new BadRequestException(i18n.tr("Owners must be created with a valid key")); } Owner owner = new Owner(); owner.setKey(dto.getKey()); if (!StringUtils.isBlank(dto.getDefaultServiceLevel())) { throw new BadRequestException( i18n.tr("The default service level cannot be specified during owner creation")); } boolean configureContentAccess = false; final String defaultContentAccess = ContentAccessMode.getDefault().toDatabaseValue(); String contentAccessModeList = dto.getContentAccessModeList(); String contentAccessMode = dto.getContentAccessMode(); if (!StringUtils.isBlank(contentAccessMode) && !contentAccessMode.equals(defaultContentAccess)) { if (config.getBoolean(ConfigProperties.STANDALONE)) { throw new BadRequestException( i18n.tr("The owner content access mode and content access mode list cannot be set " + "directly in standalone mode.")); } configureContentAccess = true; } else { contentAccessMode = defaultContentAccess; } if (!StringUtils.isBlank(contentAccessModeList) && !contentAccessModeList.equals(defaultContentAccess)) { configureContentAccess = true; } else { contentAccessModeList = defaultContentAccess; } this.validateContentAccessModeChanges(owner, contentAccessModeList, contentAccessMode); this.populateEntity(owner, dto); owner.setContentAccessModeList(contentAccessModeList); owner.setContentAccessMode(contentAccessMode); try { owner = this.ownerCurator.create(owner); if (owner == null) { throw new BadRequestException(i18n.tr("Could not create the Owner: {0}", owner)); } if (configureContentAccess) { owner = this.contentAccessManager .updateOwnerContentAccess(owner, contentAccessModeList, contentAccessMode); } } catch (Exception e) { log.debug("Unable to create owner: ", e); throw new BadRequestException(i18n.tr("Could not create the Owner: {0}", owner)); } log.info("Created owner: {}", owner); sink.emitOwnerCreated(owner); return this.translator.translate(owner, OwnerDTO.class); } @Inject  OwnerResource(OwnerCurator ownerCurator,
        ActivationKeyCurator activationKeyCurator,
        ConsumerCurator consumerCurator,
        I18n i18n,
        EventSink sink,
        EventFactory eventFactory,
        EventAdapter eventAdapter,
        ContentAccessManager contentAccessManager,
        ManifestManager manifestManager,
        PoolManager poolManager,
        OwnerManager ownerManager,
        ExporterMetadataCurator exportCurator,
        OwnerInfoCurator ownerInfoCurator,
        ImportRecordCurator importRecordCurator,
        EntitlementCurator entitlementCurator,
        UeberCertificateCurator ueberCertCurator,
        UeberCertificateGenerator ueberCertGenerator,
        EnvironmentCurator envCurator,
        CalculatedAttributesUtil calculatedAttributesUtil,
        ContentOverrideValidator contentOverrideValidator,
        ServiceLevelValidator serviceLevelValidator,
        OwnerServiceAdapter ownerService,
        Configuration config,
        ResolverUtil resolverUtil,
        ConsumerTypeValidator consumerTypeValidator,
        OwnerProductCurator ownerProductCurator,
        ModelTranslator translator,
        JobManager jobManager); @GET @Produces(MediaType.APPLICATION_JSON) @Wrapped(element = "owners") @ApiOperation(notes = "Retrieves a list of Owners", value = "List Owners", response = OwnerDTO.class, responseContainer = "list") CandlepinQuery<OwnerDTO> list(@QueryParam("key") String keyFilter); @GET @Path("/{owner_key}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(notes = "Retrieves a single Owner", value = "Get Owner", response = OwnerDTO.class) @ApiResponses({ @ApiResponse(code = 404, message = "An owner not found") }) OwnerDTO getOwner(@PathParam("owner_key") @Verify(Owner.class) String ownerKey); @GET @Path("/{owner_key}/info") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(notes = "Retrieves the Owner Info for an Owner", value = "Get Owner Info") @ApiResponses({ @ApiResponse(code = 404, message = "An owner not found") }) OwnerInfo getOwnerInfo(@PathParam("owner_key")
        @Verify(value = Owner.class, subResource = SubResource.CONSUMERS) String ownerKey); @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(notes = "Creates an Owner", value = "Create Owner", response = OwnerDTO.class) @ApiResponses({ @ApiResponse(code = 400, message = "Invalid owner specified in body") }) OwnerDTO createOwner(@ApiParam(name = "owner", required = true) OwnerDTO dto); @PUT @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Path("{owner_key}") @Transactional @ApiOperation(notes = "To un-set the defaultServiceLevel for an owner, submit an empty string.", value = "Update Owner", response = OwnerDTO.class) @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) OwnerDTO updateOwner(@PathParam("owner_key") @Verify(Owner.class) String key,
        @ApiParam(name = "owner", required = true) OwnerDTO dto); @DELETE @Path("/{owner_key}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(notes = "Removes an Owner", value = "Delete Owner") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) void deleteOwner(@PathParam("owner_key") String ownerKey,
        @QueryParam("revoke") @DefaultValue("true") boolean revoke,
        @QueryParam("force") @DefaultValue("false") boolean force); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/entitlements") @ApiOperation(notes = "Retrieves the list of Entitlements for an Owner", value = "List Owner Entitlements") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) List<EntitlementDTO> ownerEntitlements(
        @PathParam("owner_key") @Verify(Owner.class) String ownerKey,
        @QueryParam("product") String productId,
        @QueryParam("matches") String matches,
        @QueryParam("attribute") List<KeyValueParameter> attrFilters,
        @Context PageRequest pageRequest); @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.WILDCARD) @Path("{owner_key}/entitlements") @ApiOperation(notes = "Starts an asynchronous healing for the given Owner." + " At the end of the process the idea is that all of the consumers " + "in the owned by the Owner will be up to date.", value = "Heal owner") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) AsyncJobStatusDTO healEntire(
        @ApiParam("ownerKey id of the owner to be healed.") @PathParam("owner_key") @Verify(Owner.class)
        String ownerKey); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/servicelevels") @ApiOperation(notes = "Retrieves a list of Support Levels for an Owner", value = "Get Service Levels") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) Set<String> ownerServiceLevels(
        @ApiParam("ownerKey id of the owner whose support levels are sought.")
        @PathParam("owner_key") @Verify(value = Owner.class,
        subResource = SubResource.SERVICE_LEVELS) String ownerKey,
        @Context Principal principal,
        @QueryParam("exempt") @DefaultValue("false") String exempt); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/activation_keys") @ApiOperation(notes = "Retrieves a list of Activation Keys for an Owner", value = "Owner Activation Keys", response = ActivationKeyDTO.class, responseContainer = "List") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) CandlepinQuery<ActivationKeyDTO> ownerActivationKeys(
        @PathParam("owner_key") @Verify(Owner.class) String ownerKey,
        @QueryParam("name") String keyName); @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Path("{owner_key}/activation_keys") @ApiOperation(notes = "Creates an Activation Key for the Owner", value = "Create Activation Key") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 400, message = "Invalid activation key") }) ActivationKeyDTO createActivationKey(@PathParam("owner_key") @Verify(Owner.class) String ownerKey,
        @ApiParam(name = "activation_key", required = true) ActivationKeyDTO dto); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/environments") @ApiOperation(notes = "Creates an Environment for an Owner", value = "Create environment") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found")}) EnvironmentDTO createEnv(
        @PathParam("owner_key") @Verify(Owner.class) String ownerKey,
        @ApiParam(name = "environment", required = true) EnvironmentDTO envDTO); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/environments") @Wrapped(element = "environments") @ApiOperation(notes = "Retrieves a list of Environments for an Owner", value = "List environments", response = EnvironmentDTO.class, responseContainer = "List") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found")}) CandlepinQuery<EnvironmentDTO> listEnvironments(@PathParam("owner_key")
        @Verify(Owner.class) String ownerKey,
        @ApiParam("Environment name filter to search for.")
        @QueryParam("name") String envName); @PUT @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.WILDCARD) @Path("{owner_key}/log") @ApiOperation(notes = "Sets the Log Level for an Owner", value = "Set Log Level") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found")}) OwnerDTO setLogLevel(@PathParam("owner_key") String ownerKey,
        @QueryParam("level") @DefaultValue("DEBUG")
        @ApiParam(allowableValues = "ALL, TRACE, DEBUG, INFO, WARN, ERROR, OFF") String level); @DELETE @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/log") @ApiOperation(notes = "Remove the Log Level of an Owner", value = "Remove Log Level") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found")}) void deleteLogLevel(@PathParam("owner_key") String ownerKey); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/consumers") @SuppressWarnings("checkstyle:indentation") @ApiOperation(notes = "Retrieve a list of Consumers for the Owner", value = "List Consumers", response = ConsumerDTO.class, responseContainer = "list") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 400, message = "Invalid request") }) CandlepinQuery<ConsumerDTO> listConsumers(
        @PathParam("owner_key")
        @Verify(value = Owner.class, subResource = SubResource.CONSUMERS) String ownerKey,
        @QueryParam("username") String userName,
        @QueryParam("type") Set<String> typeLabels,
        @QueryParam("uuid") @Verify(value = Consumer.class, nullable = true) List<String> uuids,
        @QueryParam("hypervisor_id") List<String> hypervisorIds,
        @QueryParam("fact") List<KeyValueParameter> attrFilters,
        @QueryParam("sku") List<String> skus,
        @QueryParam("subscription_id") List<String> subscriptionIds,
        @QueryParam("contract") List<String> contracts,
        @Context PageRequest pageRequest); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/consumers/count") @SuppressWarnings("checkstyle:indentation") @ApiOperation(notes = "Retrieve a count of Consumers for the Owner", value = "consumers count") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 400, message = "Invalid request") }) int countConsumers(
        @PathParam("owner_key")
        @Verify(value = Owner.class, subResource = SubResource.CONSUMERS) String ownerKey,
        @QueryParam("type") Set<String> typeLabels,
        @QueryParam("sku") List<String> skus,
        @QueryParam("subscription_id") List<String> subscriptionIds,
        @QueryParam("contract") List<String> contracts); @Transactional @GET @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/pools") @SuppressWarnings("checkstyle:indentation") @ApiOperation(notes = "Retrieves a list of Pools for an Owner", value = "List Pools") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 400, message = "Invalid request") }) List<PoolDTO> listPools(
        @PathParam("owner_key") @Verify(value = Owner.class, subResource = SubResource.POOLS) String ownerKey,
        @QueryParam("consumer") String consumerUuid,
        @QueryParam("activation_key") String activationKeyName,
        @QueryParam("product") String productId,
        @QueryParam("subscription") String subscriptionId,
        @ApiParam("Include pools that are not suited to the unit's facts.")
        @QueryParam("listall") @DefaultValue("false") boolean listAll,
        @ApiParam("Date to use as current time for lookup criteria. Defaults" +
                " to current date if not specified.")
        @QueryParam("activeon") @DefaultValue(DateFormat.NOW) @DateFormat Date activeOn,
        @ApiParam("Find pools matching the given pattern in a variety of fields;" +
                " * and ? wildcards are supported; may be specified multiple times")
        @QueryParam("matches") List<String> matches,
        @ApiParam("The attributes to return based on the specified types.")
        @QueryParam("attribute") List<KeyValueParameter> attrFilters,
        @ApiParam("When set to true, it will add future dated pools to the result, " +
                "based on the activeon date.")
        @QueryParam("add_future") @DefaultValue("false") boolean addFuture,
        @ApiParam("When set to true, it will return only future dated pools to the result, " +
                "based on the activeon date.")
        @QueryParam("only_future") @DefaultValue("false") boolean onlyFuture,
        @ApiParam("Will only return pools with a start date after the supplied date. " +
                "Overrides the activeOn date.")
        @QueryParam("after") @DateFormat Date after,
        @ApiParam("One or more pool IDs to use to filter the output; only pools with IDs matching " +
                "those provided will be returned; may be specified multiple times")
        @QueryParam("poolid") List<String> poolIds,
        @Context Principal principal,
        @Context PageRequest pageRequest); @GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/subscriptions") @ApiOperation(notes = "Retrieves a list of Subscriptions for an Owner", value = "List Subscriptions") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) List<Subscription> getSubscriptions(@PathParam("owner_key") String ownerKey); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/subscriptions") @Deprecated @ApiOperation(notes = "Creates a Subscription for an Owner DEPRECATED: Please create " + "pools directly with POST /pools.", value = "Create Subscription") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) Subscription createSubscription(
        @PathParam("owner_key") @Verify(Owner.class) String ownerKey,
        Subscription subscription); @PUT @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Path("/subscriptions") @Deprecated @ApiOperation( notes = "Updates a Subscription for an Owner. Please " + "update pools directly with POST /pools.", value = "Update Subscription") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) void updateSubscription(
        @ApiParam(name = "subscription", required = true) Subscription subscription); @PUT @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.WILDCARD) @Path("{owner_key}/subscriptions") @ApiOperation(notes = "Tickle an owner to have all of their entitlement pools synced with their " + "subscriptions. This method (and the one below may not be entirely RESTful, " + "as the updated data is not supplied as an argument. " + "This API call is only relevant in a top level hosted deployment where " + "subscriptions and products are sourced from adapters. Calling this in " + "an on-site deployment is just a no-op.", value = "Update Subscription") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 202, message = "") }) AsyncJobStatusDTO refreshPools(
        @PathParam("owner_key") String ownerKey,
        @QueryParam("auto_create_owner") @DefaultValue("false") Boolean autoCreateOwner,
        @QueryParam("lazy_regen") @DefaultValue("true") Boolean lazyRegen); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/pools") @ApiOperation(notes = "Creates a custom pool for an Owner. Floating pools are not tied to any " + "upstream subscription, and are most commonly used for custom content delivery " + "in Satellite. Also helps in on-site deployment testing", value = "Create Pool") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) PoolDTO createPool(@PathParam("owner_key") @Verify(Owner.class) String ownerKey,
        @ApiParam(name = "pool", required = true) PoolDTO inputPoolDTO); @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/pools") @ApiOperation( notes = "Updates a pool for an Owner. assumes this is a normal pool, and " + "errors out otherwise cause we cannot create master pools from bonus pools ", value = "Update Pool") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) void updatePool(@PathParam("owner_key") @Verify(Owner.class) String ownerKey,
        @ApiParam(name = "pool", required = true) PoolDTO newPoolDTO); @DELETE @Path("{owner_key}/imports") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(notes = "Removes Imports for an Owner. Cleans out all imported subscriptions " + "and triggers a background refresh pools. Link to an upstream distributor is " + "removed for the owner, so they can import from another distributor. Other " + "owners can also now import the manifests originally used in this owner. This " + "call does not differentiate between any specific import, it just destroys all " + "subscriptions with an upstream pool ID, essentially anything from an import." + " Custom subscriptions will be left alone. Imports do carry rules and product " + "information which is global to the candlepin server. This import data is *not* " + "undone, we assume that updates to this data can be safely kept. ", value = "Undo Imports") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found")}) AsyncJobStatusDTO undoImports(
        @PathParam("owner_key") @Verify(Owner.class) String ownerKey, @Context Principal principal); @POST @Path("{owner_key}/imports") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @ApiOperation( notes = "Imports a manifest zip file for the given organization. " + "This will bring in any products, content, and subscriptions that were " + "assigned to the distributor who generated the manifest.", value = "Import Manifest") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 409, message = "") }) @Deprecated ImportRecordDTO importManifest(
        @PathParam("owner_key") @Verify(Owner.class) String ownerKey,
        @QueryParam("force") String[] overrideConflicts,
        MultipartInput input); @POST @Path("{owner_key}/imports/async") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @ApiOperation( notes = "Initiates an asynchronous manifest import for the given organization. " + "This will bring in any products, content, and subscriptions that were " + "assigned to the distributor who generated the manifest.", value = "Import Manifest Asynchronously") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 409, message = "")}) AsyncJobStatusDTO importManifestAsync(
        @PathParam("owner_key") @Verify(Owner.class) String ownerKey,
        @QueryParam("force") String[] overrideConflicts,
        MultipartInput input); @GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/imports") @ApiOperation(notes = " Retrieves a list of Import Records for an Owner", value = "Get Imports", response = ImportRecord.class, responseContainer = "list") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) CandlepinQuery<ImportRecord> getImports(
        @PathParam("owner_key") @Verify(Owner.class) String ownerKey); @ApiOperation(notes = "Retrieves the system purpose settings available to an owner", value = "getSyspurpose") @ApiResponses({@ApiResponse(code = 404, message = "Owner not found")}) @GET @Path("{owner_key}/system_purpose") @Produces(MediaType.APPLICATION_JSON) SystemPurposeAttributesDTO getSyspurpose(
        @PathParam("owner_key")
        @Verify(value = Owner.class, subResource = SubResource.POOLS, require = Access.READ_ONLY)
        String ownerKey); @ApiOperation(notes = "Retrieves an aggregate of the system purpose settings of the owner's consumers", value = "getConsumersSyspurpose") @ApiResponses({@ApiResponse(code = 404, message = "Owner not found")}) @GET @Path("{owner_key}/consumers_system_purpose") @Produces(MediaType.APPLICATION_JSON) SystemPurposeAttributesDTO getConsumersSyspurpose(
        @PathParam("owner_key") @Verify(Owner.class) String ownerKey); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/uebercert") @ApiOperation(notes = "Creates an Ueber Entitlement Certificate. If a certificate " + "already exists, it will be regenerated.", value = "Create Ueber Entitlement Certificate") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 400, message = "") }) UeberCertificateDTO createUeberCertificate(@Context Principal principal,
        @Verify(Owner.class) @PathParam("owner_key") String ownerKey); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/uebercert") @ApiOperation(notes = "Retrieves the Ueber Entitlement Certificate", value = "Get Ueber Entitlement Certificate") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) UeberCertificateDTO getUeberCertificate(@Context Principal principal,
        @Verify(Owner.class) @PathParam("owner_key") String ownerKey); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{owner_key}/upstream_consumers") @ApiOperation(notes = " Retrieves a list of Upstream Consumers for an Owner", value = "Get Upstream Consumers") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) List<UpstreamConsumerDTO> getUpstreamConsumers(@Context Principal principal,
        @Verify(Owner.class) @PathParam("owner_key") String ownerKey); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{owner_key}/hypervisors") @ApiOperation(notes = "Retrieves a list of Hypervisors for an Owner", value = "Get Hypervisors", response = ConsumerDTO.class, responseContainer = "list") @ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") }) CandlepinQuery<ConsumerDTO> getHypervisors(
        @PathParam("owner_key") @Verify(Owner.class) String ownerKey,
        @QueryParam("hypervisor_id") List<String> hypervisorIds);  }
@Test public void testCreateOwner() { assertNotNull(owner); assertNotNull(ownerCurator.get(owner.getId())); assertTrue(owner.getPools().isEmpty()); }
@Test public void ownerWithParentOwnerCanBeCreated() { OwnerDTO parent = new OwnerDTO(); parent.setKey("parent"); parent.setDisplayName("parent"); OwnerDTO child = new OwnerDTO(); child.setKey("child"); child.setDisplayName("child"); child.setParentOwner(parent); OwnerDTO pout = this.ownerResource.createOwner(parent); assertNotNull(pout); assertNotNull(pout.getId()); assertNotNull(this.ownerCurator.get(pout.getId())); OwnerDTO cout = this.ownerResource.createOwner(child); assertNotNull(cout); assertNotNull(cout.getId()); Owner owner = this.ownerCurator.get(cout.getId()); assertNotNull(owner); assertNotNull(owner.getParentOwner()); assertEquals(pout.getId(), owner.getParentOwner().getId()); }
@Test public void ownerWithInvalidParentIdCannotBeCreated() { OwnerDTO child = new OwnerDTO(); child.setKey("child"); child.setDisplayName("child"); OwnerDTO parent = new OwnerDTO(); parent.setId("parent"); parent.setDisplayName("parent"); child.setParentOwner(parent); assertThrows(NotFoundException.class, () -> this.ownerResource.createOwner(child)); }
@Test public void ownerWithInvalidParentKeyCannotBeCreated() { OwnerDTO child = new OwnerDTO(); child.setKey("child"); child.setDisplayName("child"); OwnerDTO parent = new OwnerDTO(); parent.setKey("parent"); parent.setDisplayName("parent"); child.setParentOwner(parent); assertThrows(NotFoundException.class, () -> this.ownerResource.createOwner(child)); }
@Test public void ownerWithInvalidParentWhoseIdAndKeyIsNullCannotBeCreated() { OwnerDTO child = new OwnerDTO(); child.setKey("child"); child.setDisplayName("child"); OwnerDTO parent = new OwnerDTO(); parent.setDisplayName("parent"); child.setParentOwner(parent); assertThrows(NotFoundException.class, () -> this.ownerResource.createOwner(child)); }
@Test public void testCreateOwnerSetContentAccessListAndMode() { this.config.setProperty(ConfigProperties.STANDALONE, "false"); String entitlementMode = ContentAccessMode.ENTITLEMENT.toDatabaseValue(); String orgEnvMode = ContentAccessMode.ORG_ENVIRONMENT.toDatabaseValue(); OwnerDTO changes = new OwnerDTO() .setKey("test_owner") .setDisplayName("test_owner") .setContentAccessModeList(entitlementMode + "," + orgEnvMode) .setContentAccessMode(orgEnvMode); OwnerDTO output = this.ownerResource.createOwner(changes); assertNotNull(output); assertEquals(entitlementMode + "," + orgEnvMode, output.getContentAccessModeList()); assertEquals(orgEnvMode, output.getContentAccessMode()); }
@Test public void testCreateOwnerSetContentAccessList() { this.config.setProperty(ConfigProperties.STANDALONE, "false"); String entitlementMode = ContentAccessMode.ENTITLEMENT.toDatabaseValue(); String orgEnvMode = ContentAccessMode.ORG_ENVIRONMENT.toDatabaseValue(); OwnerDTO changes = new OwnerDTO() .setKey("test_owner") .setDisplayName("test_owner") .setContentAccessModeList(entitlementMode + "," + orgEnvMode); OwnerDTO output = this.ownerResource.createOwner(changes); assertNotNull(output); assertEquals(entitlementMode + "," + orgEnvMode, output.getContentAccessModeList()); assertEquals(entitlementMode, output.getContentAccessMode()); }
@Test public void testCreateOwnerSetContentAccessModeCannotUseInvalidModeInList() { this.config.setProperty(ConfigProperties.STANDALONE, "false"); String entitlementMode = ContentAccessMode.ENTITLEMENT.toDatabaseValue(); String orgEnvMode = ContentAccessMode.ORG_ENVIRONMENT.toDatabaseValue(); OwnerDTO changes = new OwnerDTO() .setKey("test_owner") .setDisplayName("test_owner") .setContentAccessModeList(entitlementMode + ",unsupported_mode"); assertThrows(BadRequestException.class, () -> ownerResource.createOwner(changes)); }
@Test public void testCreateOwnerSetContentAccessModeCannotUseInvalidMode() { this.config.setProperty(ConfigProperties.STANDALONE, "false"); String entitlementMode = ContentAccessMode.ENTITLEMENT.toDatabaseValue(); String orgEnvMode = ContentAccessMode.ORG_ENVIRONMENT.toDatabaseValue(); OwnerDTO changes = new OwnerDTO() .setKey("test_owner") .setDisplayName("test_owner") .setContentAccessModeList(entitlementMode) .setContentAccessMode(orgEnvMode); assertThrows(BadRequestException.class, () -> ownerResource.createOwner(changes)); }
@Test public void testCreateOwnerSetContentAccessModeCannotUseImpliedDefault() { this.config.setProperty(ConfigProperties.STANDALONE, "false"); String entitlementMode = ContentAccessMode.ENTITLEMENT.toDatabaseValue(); String orgEnvMode = ContentAccessMode.ORG_ENVIRONMENT.toDatabaseValue(); OwnerDTO changes = new OwnerDTO() .setKey("test_owner") .setDisplayName("test_owner") .setContentAccessModeList(orgEnvMode); assertThrows(BadRequestException.class, () -> ownerResource.createOwner(changes)); }
@Test public void testCreateOwnerCannotUseNonDefaultContentAccessModeInStandalone() { this.config.setProperty(ConfigProperties.STANDALONE, "true"); String entitlementMode = ContentAccessMode.ENTITLEMENT.toDatabaseValue(); String orgEnvMode = ContentAccessMode.ORG_ENVIRONMENT.toDatabaseValue(); OwnerDTO changes = new OwnerDTO() .setKey("test_owner") .setDisplayName("test_owner") .setContentAccessModeList(orgEnvMode) .setContentAccessMode(orgEnvMode); assertThrows(BadRequestException.class, () -> ownerResource.createOwner(changes)); }
@Test public void testCreateOwnerCanSetNonDefaultContentAccessModeListInStandalone() { this.config.setProperty(ConfigProperties.STANDALONE, "true"); String entitlementMode = ContentAccessMode.ENTITLEMENT.toDatabaseValue(); String orgEnvMode = ContentAccessMode.ORG_ENVIRONMENT.toDatabaseValue(); OwnerDTO changes = new OwnerDTO() .setKey("test_owner") .setDisplayName("test_owner") .setContentAccessModeList(entitlementMode + "," + orgEnvMode); OwnerDTO output = this.ownerResource.createOwner(changes); assertNotNull(output); assertEquals(entitlementMode + "," + orgEnvMode, output.getContentAccessModeList()); assertEquals(entitlementMode, output.getContentAccessMode()); }