@Test
public void verifyUserHasNoWritePermissionOnCategoryOption()
    throws Exception
{

    OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
    DataSet dataSetA = createDataSet( 'A', new MonthlyPeriodType() );
    CategoryCombo categoryCombo = createCategoryCombo( 'A' );
    CategoryOption categoryOptionA = createCategoryOption( 'A' );
    CategoryOption categoryOptionB = createCategoryOption( 'B' );
    CategoryOptionCombo categoryOptionCombo = createCategoryOptionCombo( categoryCombo, categoryOptionA,
        categoryOptionB );
    Period period = createPeriod( "201907" );
    String payload = createPayload( period, organisationUnit, dataSetA, categoryCombo, categoryOptionA, categoryOptionB );
    whenNew( MetadataCaches.class ).withNoArguments().thenReturn( metaDataCaches );
    when( idObjManager.get( CategoryCombo.class, categoryCombo.getUid() ) ).thenReturn( categoryCombo );
    when( idObjManager.getObject( CategoryOption.class, IdScheme.UID, categoryOptionA.getUid() ) )
        .thenReturn( categoryOptionA );
    when( idObjManager.getObject( CategoryOption.class, IdScheme.UID, categoryOptionB.getUid() ) )
        .thenReturn( categoryOptionB );
    when( categoryService.getCategoryOptionCombo( categoryCombo,
        Sets.newHashSet( categoryOptionA, categoryOptionB ) ) ).thenReturn( categoryOptionCombo );
    when( datasetCache.get( eq( dataSetA.getUid() ), any() ) ).thenReturn( dataSetA );
    when( periodCache.get( eq( period.getIsoDate() ), any() ) ).thenReturn( period );
    when( orgUnitCache.get( eq( organisationUnit.getUid() ), any() ) ).thenReturn( createOrganisationUnit( 'A' ) );
    when( orgUnitInHierarchyCache.get( eq( organisationUnit.getUid() ), any() ) ).thenReturn( Boolean.TRUE );
    when( attrOptComboOrgUnitCache.get( eq( categoryOptionCombo.getUid() + organisationUnit.getUid() ), any() ) )
        .thenReturn( Boolean.TRUE );
    when( categoryService.getCategoryOptionCombo( categoryOptionCombo.getUid() ) )
        .thenReturn( categoryOptionCombo );
    // force error on access check for Category Option Combo
    when( aclService.canDataWrite( user, dataSetA ) ).thenReturn( true );
    when( aclService.canDataWrite( user, categoryOptionA ) ).thenReturn( false );
    when( aclService.canDataWrite( user, categoryOptionB ) ).thenReturn( true );
    // call method under test
    ImportSummary summary = subject.saveCompleteDataSetRegistrationsJson(
        new ByteArrayInputStream( payload.getBytes() ), new ImportOptions() );
    assertThat( summary.getStatus(), is( ImportStatus.ERROR ) );
    assertThat( summary.getImportCount().getIgnored(), is( 1 ) );
    assertThat( summary.getConflicts(), hasSize( 1 ) );
    assertThat( summary.getConflicts().iterator().next().getValue(),
        is( "User has no data write access for CategoryOption: " + categoryOptionA.getUid() ) );
}