AuditMatrixConfigurer { public Map<AuditScope, Map<AuditType, Boolean>> configure() { Map<AuditScope, Map<AuditType, Boolean>> matrix = new HashMap<>(); for ( AuditScope value : AuditScope.values() ) { Optional<ConfigurationKey> confKey = ConfigurationKey.getByKey( PROPERTY_PREFIX + value.name().toLowerCase() ); if ( confKey.isPresent() && !StringUtils.isEmpty( config.getProperty( confKey.get() ) ) ) { String[] configuredTypes = config.getProperty( confKey.get() ).split( AUDIT_TYPE_STRING_SEPAR ); Map<AuditType, Boolean> matrixAuditTypes = new HashMap<>(); for ( AuditType auditType : AuditType.values() ) { matrixAuditTypes.put( auditType, ArrayUtils.contains( configuredTypes, auditType.name() ) ); } matrix.put( value, matrixAuditTypes ); } else { matrix.put( value, DEFAULT_AUDIT_CONFIGURATION ); } } return matrix; } AuditMatrixConfigurer( DhisConfigurationProvider dhisConfigurationProvider ); Map<AuditScope, Map<AuditType, Boolean>> configure();  }
@Test public void verifyConfigurationForMatrixIsIngested() { when( config.getProperty( ConfigurationKey.AUDIT_METADATA_MATRIX ) ).thenReturn( "READ;" ); when( config.getProperty( ConfigurationKey.AUDIT_TRACKER_MATRIX ) ).thenReturn( "CREATE;READ;UPDATE;DELETE" ); when( config.getProperty( ConfigurationKey.AUDIT_AGGREGATE_MATRIX ) ).thenReturn( "CREATE;UPDATE;DELETE" ); matrix = this.subject.configure(); assertThat( matrix.get( METADATA ).keySet(), hasSize( 6 ) ); assertMatrixEnabled( METADATA, READ ); assertMatrixDisabled( METADATA, CREATE, UPDATE, DELETE ); assertThat( matrix.get( TRACKER ).keySet(), hasSize( 6 ) ); assertMatrixDisabled( TRACKER, SEARCH, SECURITY ); assertMatrixEnabled( TRACKER, CREATE, UPDATE, DELETE, READ ); assertThat( matrix.get( AGGREGATE ).keySet(), hasSize( 6 ) ); assertMatrixDisabled( AGGREGATE, READ, SECURITY, SEARCH ); assertMatrixEnabled( AGGREGATE, CREATE, UPDATE, DELETE ); }
@Test public void allDisabled() { when( config.getProperty( ConfigurationKey.AUDIT_METADATA_MATRIX ) ).thenReturn( "DISABLED" ); when( config.getProperty( ConfigurationKey.AUDIT_TRACKER_MATRIX ) ).thenReturn( "DISABLED" ); when( config.getProperty( ConfigurationKey.AUDIT_AGGREGATE_MATRIX ) ).thenReturn( "DISABLED" ); matrix = this.subject.configure(); assertMatrixAllDisabled( METADATA ); assertMatrixAllDisabled( TRACKER ); assertMatrixAllDisabled( AGGREGATE ); }
@Test public void verifyInvalidConfigurationIsIgnored() { when( config.getProperty( ConfigurationKey.AUDIT_METADATA_MATRIX ) ).thenReturn( "READX;UPDATE" ); matrix = this.subject.configure(); assertThat( matrix.get( METADATA ).keySet(), hasSize( 6 ) ); assertAllFalseBut( matrix.get( METADATA ), UPDATE ); }
@Test public void verifyDefaultAuditingConfiguration() { matrix = this.subject.configure(); assertMatrixDisabled( METADATA, READ ); assertMatrixEnabled( METADATA, CREATE ); assertMatrixEnabled( METADATA, UPDATE ); assertMatrixEnabled( METADATA, DELETE ); assertMatrixDisabled( TRACKER, READ ); assertMatrixEnabled( TRACKER, CREATE ); assertMatrixEnabled( TRACKER, UPDATE ); assertMatrixEnabled( TRACKER, DELETE ); assertMatrixDisabled( AGGREGATE, READ ); assertMatrixEnabled( AGGREGATE, CREATE ); assertMatrixEnabled( AGGREGATE, UPDATE ); assertMatrixEnabled( AGGREGATE, DELETE ); }