LicenseUtils { public static void grantLicense(Context context, Item item, String licenseText, String acceptanceDate) throws SQLException, IOException, AuthorizeException { byte[] licenseBytes = licenseText.getBytes("UTF-8"); ByteArrayInputStream bais = new ByteArrayInputStream(licenseBytes); Bitstream b = itemService.createSingleBitstream(context, bais, item, "LICENSE"); b.setName(context, "license.txt"); b.setSource(context, "Written by org.dspace.content.LicenseUtils"); DCDate acceptanceDCDate = DCDate.getCurrent(); if (acceptanceDate != null) { acceptanceDCDate = new DCDate(acceptanceDate); } b.setAcceptanceDate(context, acceptanceDCDate); BitstreamFormat bf = bitstreamFormat.findByShortDescription(context, "License"); b.setFormat(bf); bitstreamService.update(context, b); } private  LicenseUtils(); static String getLicenseText(Locale locale, Collection collection,
                                        Item item, EPerson eperson, Map<String, Object> additionalInfo); static String getLicenseText(Locale locale, Collection collection,
                                        Item item, EPerson eperson); static void grantLicense(Context context, Item item,
                                    String licenseText, String acceptanceDate);  }
@Test public void testGrantLicense() throws Exception { context.turnOffAuthorisationSystem(); Collection collection = collectionService.create(context, owningCommunity); Item item = installItemService.installItem(context, workspaceItemService.create(context, collection, false)); String defaultLicense = licenseService.getDefaultSubmissionLicense(); LicenseUtils.grantLicense(context, item, defaultLicense, null); StringWriter writer = new StringWriter(); IOUtils.copy( bitstreamService.retrieve(context, itemService.getBundles(item, "LICENSE").get(0).getBitstreams().get(0)), writer, StandardCharsets.UTF_8); String license = writer.toString(); assertThat("testGrantLicense 0", license, equalTo(defaultLicense)); context.restoreAuthSystemState(); }