CacheResourceImpl implements CacheResource { @Override public Long clear(final String cacheName, final String nodeName) { final Long result; if (nodeName == null) { result = clearCacheOnAllNodes(cacheName); } else { result = clearCache(cacheName, nodeName); } return result; } @Inject  CacheResourceImpl(final NodeService nodeService,
                      final NodeInfo nodeInfo,
                      final WebTargetFactory webTargetFactory,
                      final CacheManagerService cacheManagerService,
                      final TaskContextFactory taskContextFactory); @Override List<String> list(); @Override CacheInfoResponse info(final String cacheName, final String nodeName); @Override Long clear(final String cacheName, final String nodeName);  }
@Test void clear_sameNode() { final String subPath = ""; final Long expectedResponse = 1L; initNodes(); when(cacheManagerServiceMocks.get("node1").clear(Mockito.any(FindCacheInfoCriteria.class))) .thenReturn(1L); doDeleteTest( subPath, Long.class, expectedResponse, webTarget -> webTarget.queryParam("cacheName", "cache1"), webTarget -> webTarget.queryParam("nodeName", "node1")); verify(cacheManagerServiceMocks.get("node1")) .clear(Mockito.any()); verify(cacheManagerServiceMocks.get("node2"), Mockito.never()) .clear(Mockito.any()); verify(cacheManagerServiceMocks.get("node3"), Mockito.never()) .clear(Mockito.any()); }
@Test void clear_otherNode() { final String subPath = ""; final Long expectedResponse = 1L; initNodes(); when(cacheManagerServiceMocks.get("node2").clear(Mockito.any(FindCacheInfoCriteria.class))) .thenReturn(1L); doDeleteTest( subPath, Long.class, expectedResponse, webTarget -> webTarget.queryParam("cacheName", "cache1"), webTarget -> webTarget.queryParam("nodeName", "node2")); verify(cacheManagerServiceMocks.get("node1"), Mockito.never()) .clear(Mockito.any()); verify(cacheManagerServiceMocks.get("node2")) .clear(Mockito.any()); verify(cacheManagerServiceMocks.get("node3"), Mockito.never()) .clear(Mockito.any()); }