AvailabilityScoreAccumulator { public ResourceAvailabilityScore calculateAvailabilityScore(Map<?, CheckedLink> linkStatusMap, int allResourcesCount) { final Supplier<Stream<Integer>> knownStatusStreamProvider = () -> linkStatusMap.values().stream() .map(CheckedLink::getStatus) .filter((status) -> (status != null && status > 0)); if (!knownStatusStreamProvider.get().findAny().isPresent()) { return ResourceAvailabilityScore.UNKNOWN; } else { final Collection<Integer> knownStatus = knownStatusStreamProvider.get().collect(Collectors.toList()); return calculateScore(knownStatus, allResourcesCount); } }  ResourceAvailabilityScore calculateAvailabilityScore(Map<?, CheckedLink> linkStatusMap, int allResourcesCount);  }
@Test public void testCalculateAvailabilityScoreNoData() { assert map.isEmpty(); { final ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size()); assertEquals(ResourceAvailabilityScore.UNKNOWN, result); } { final ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, 100); assertEquals(ResourceAvailabilityScore.UNKNOWN, result); } }
@Test public void testCalculateAvailabilityScoreAllUnknown() { addStatus(0, 0); assert map.size() == 2; { final ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size()); assertEquals(ResourceAvailabilityScore.UNKNOWN, result); } { ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, 100); assertEquals(ResourceAvailabilityScore.UNKNOWN, result); } }
@Test public void testCalculateAvailabilityScoreEffecitvelyUnknown() { addStatus(200, 200); assert map.size() == 2; { final ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, 100); assertEquals(ResourceAvailabilityScore.UNKNOWN, result); } addStatus(0, 0, 0); { final ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size()); assertEquals(ResourceAvailabilityScore.UNKNOWN, result); } }
@Test public void testCalculateAvailabilityScoreAllAvailable() { addStatus(200, 200, 301, 302, 303); assert map.size() == 5; { ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size()); assertEquals(ResourceAvailabilityScore.ALL_AVAILABLE, result); } { ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size() * 2); assertNotEquals(ResourceAvailabilityScore.ALL_AVAILABLE, result); } }
@Test public void testCalculateAvailabilityScoreAllUnavailable() { addStatus(400, 403, 404, 500); assert map.size() == 4; { ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size()); assertEquals(ResourceAvailabilityScore.ALL_UNAVAILABLE, result); } { ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size() + 1); assertNotEquals(ResourceAvailabilityScore.ALL_UNAVAILABLE, result); } }
@Test public void testCalculateAvailabilityScoreMostUnavailable() { addStatus(400, 403, 500, 200, 301); assert map.size() == 5; { ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size()); assertEquals(ResourceAvailabilityScore.MOST_UNAVAILABLE, result); } { ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size() + 1); assertNotEquals(ResourceAvailabilityScore.MOST_UNAVAILABLE, result); } }
@Test public void testCalculateAvailabilityScoreMostRestricted() { addStatus(401, 401, 403, 200, 200); assert map.size() == 5; { ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size()); assertEquals(ResourceAvailabilityScore.MOST_RESTRICTED_ACCESS, result); } { ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size() + 1); assertNotEquals(ResourceAvailabilityScore.MOST_RESTRICTED_ACCESS, result); } }
@Test public void testCalculateAvailabilityScoreMostUnavailableWithRestricted() { addStatus(401, 401, 403, 404, 200); assert map.size() == 5; ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size()); assertEquals(ResourceAvailabilityScore.MOST_UNAVAILABLE, result); }
@Test public void testCalculateAvailabilityScoreSomeUnavailable() { addStatus(400, 404, 200, 301); assert map.size() == 4; ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size()); assertEquals(ResourceAvailabilityScore.SOME_UNAVAILABLE, result); }
@Test public void testCalculateAvailabilityScoreSomeUnavailableWithRestricted() { addStatus(400, 403, 200, 301); assert map.size() == 4; ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size()); assertEquals(ResourceAvailabilityScore.SOME_UNAVAILABLE, result); }
@Test public void testCalculateAvailabilityScoreSomeRestricted() { addStatus(401, 403, 200, 301, 303); assert map.size() == 5; ResourceAvailabilityScore result = instance.calculateAvailabilityScore(map, map.size()); assertEquals(ResourceAvailabilityScore.SOME_RESTRICTED_ACCESS, result); }