AuthoritativeSourceResolver { public AuthoritativenessRating resolve(EntityReference vantagePoint, EntityReference source, String dataTypeCode) { Map<String, Map<Long, Optional<AuthoritativeRatingVantagePoint>>> ouGroup = byOuThenDataTypeThenApp.get(vantagePoint); if(isEmpty(ouGroup)) return AuthoritativenessRating.NO_OPINION; Map<Long, Optional<AuthoritativeRatingVantagePoint>> dataTypeGroup = ouGroup.get(dataTypeCode); if(isEmpty(dataTypeGroup)) return AuthoritativenessRating.NO_OPINION; Optional<AuthoritativeRatingVantagePoint> maybeRating = dataTypeGroup.getOrDefault( source.id(), Optional.empty()); return maybeRating .map(r -> r.rating()) .orElse(AuthoritativenessRating.DISCOURAGED); } AuthoritativeSourceResolver(List<AuthoritativeRatingVantagePoint> authoritativeRatingVantagePoints); AuthoritativenessRating resolve(EntityReference vantagePoint, EntityReference source, String dataTypeCode);  }
@Test public void existingEntriesThenReturnsMostSpecificRating() { List<AuthoritativeRatingVantagePoint> vantagePoints = new ArrayList<>(); vantagePoints.add(ImmutableAuthoritativeRatingVantagePoint.builder() .vantagePoint(vantagePoint) .vantagePointRank(1) .dataTypeCode("REF_DATA") .dataType(EntityReference.mkRef(EntityKind.DATA_TYPE, 20)) .dataTypeRank(2) .applicationId(205L) .rating(AuthoritativenessRating.PRIMARY) .build()); vantagePoints.add(ImmutableAuthoritativeRatingVantagePoint.builder() .vantagePoint(vantagePoint) .vantagePointRank(2) .dataTypeCode("REF_DATA") .dataType(EntityReference.mkRef(EntityKind.DATA_TYPE, 20)) .dataTypeRank(3) .applicationId(200L) .rating(AuthoritativenessRating.SECONDARY) .build()); AuthoritativeSourceResolver authoritativeSourceResolver = new AuthoritativeSourceResolver(vantagePoints); AuthoritativenessRating rating = authoritativeSourceResolver.resolve(vantagePoint, sourceApp, "REF_DATA"); Assert.assertEquals(AuthoritativenessRating.SECONDARY, rating); }
@Test public void whenResolveWithMissingVantagePointThenReturnsNoOpinion() { List<AuthoritativeRatingVantagePoint> vantagePoints = new ArrayList<>(); AuthoritativeSourceResolver authoritativeSourceResolver = new AuthoritativeSourceResolver(vantagePoints); AuthoritativenessRating rating = authoritativeSourceResolver.resolve(vantagePoint, sourceApp, "REF_DATA"); Assert.assertEquals(AuthoritativenessRating.NO_OPINION, rating); }
@Test public void whenResolveWithExistingVantageButMissingDataTypeThenReturnsNoOpinion() { List<AuthoritativeRatingVantagePoint> vantagePoints = new ArrayList<>(); vantagePoints.add(ImmutableAuthoritativeRatingVantagePoint.builder() .vantagePoint(vantagePoint) .vantagePointRank(1) .dataTypeCode("TRADE_DATA") .dataType(EntityReference.mkRef(EntityKind.DATA_TYPE, 10)) .dataTypeRank(1) .applicationId(200L) .rating(AuthoritativenessRating.SECONDARY) .build()); AuthoritativeSourceResolver authoritativeSourceResolver = new AuthoritativeSourceResolver(vantagePoints); AuthoritativenessRating rating = authoritativeSourceResolver.resolve(vantagePoint, sourceApp, "REF_DATA"); Assert.assertEquals(AuthoritativenessRating.NO_OPINION, rating); }
@Test public void existingVantageAndDataTypeAndDifferentSourceThenDiscouraged() { List<AuthoritativeRatingVantagePoint> vantagePoints = new ArrayList<>(); vantagePoints.add(ImmutableAuthoritativeRatingVantagePoint.builder() .vantagePoint(vantagePoint) .vantagePointRank(1) .dataTypeCode("REF_DATA") .dataType(EntityReference.mkRef(EntityKind.DATA_TYPE, 20)) .dataTypeRank(1) .applicationId(205L) .rating(AuthoritativenessRating.PRIMARY) .build()); AuthoritativeSourceResolver authoritativeSourceResolver = new AuthoritativeSourceResolver(vantagePoints); AuthoritativenessRating rating = authoritativeSourceResolver.resolve(vantagePoint, sourceApp, "REF_DATA"); Assert.assertEquals(AuthoritativenessRating.DISCOURAGED, rating); }