@Test
public void testInheritCollectionDefaultPolicies() throws Exception 
{

    context.turnOffAuthorisationSystem();
    Collection c = createCollection();
    List<ResourcePolicy> defaultCollectionPolicies = authorizeService.getPoliciesActionFilter(context, c,
            Constants.DEFAULT_BITSTREAM_READ);
    List<ResourcePolicy> newPolicies = new ArrayList<ResourcePolicy>();
    for(ResourcePolicy collRp : defaultCollectionPolicies)
    {
        ResourcePolicy rp = resourcePolicyService.clone(context, collRp);
        rp.setAction(Constants.READ);
        rp.setRpType(ResourcePolicy.TYPE_INHERITED);
        newPolicies.add(rp);
    }
    //we add some bundles for the test
    String name = "LICENSE";
    Bundle created = bundleService.create(context, it, name);
    created.setName(context, name);
    String bsname = "License";
    File f = new File(testProps.get("test.bitstream").toString());
    Bitstream result = itemService.createSingleBitstream(context, new FileInputStream(f), it, bsname);
    bitstreamService.setFormat(context, result, bitstreamFormatService.findByShortDescription(context, bsname));
    bundleService.addBitstream(context, created, result);
    context.restoreAuthSystemState();
    new NonStrictExpectations(authorizeService.getClass())
    {
        {
            authorizeService.authorizeAction((Context) any, (Item) any,
                    Constants.WRITE, true); result = null;
        }
    };
    itemService.inheritCollectionDefaultPolicies(context, it, c);
    //test item policies
    List<ResourcePolicy> retrieved = authorizeService.getPolicies(context, it);
    boolean equals = true;
    for(int i=0; i < retrieved.size() && equals; i++)
    {
        if(!newPolicies.contains(retrieved.get(i)))
        {
            equals = false;
        }
    }
    assertTrue("testInheritCollectionDefaultPolicies 0", equals);
    retrieved = new ArrayList<ResourcePolicy>();
    List<Bundle> bundles = it.getBundles();
    for(Bundle b: bundles)
    {
        retrieved.addAll(authorizeService.getPolicies(context, b));
        retrieved.addAll(bundleService.getBitstreamPolicies(context, b));
    }
    assertFalse("testInheritCollectionDefaultPolicies 1",retrieved.isEmpty());
    equals = true;
    for(int i=0; i < newPolicies.size() && equals; i++)
    {
        if(!newPolicies.contains(retrieved.get(i)))
        {
            equals = false;
        }
    }
    assertTrue("testInheritCollectionDefaultPolicies 2", equals);
}