@Test public void processReturnsNoCacheRegions() throws Exception { InternalCache emptyCache = mock(InternalCacheForClientAccess.class); doReturn(emptyCache).when(emptyCache).getCacheForProcessingClientRequests(); when(emptyCache.rootRegions()) .thenReturn(Collections.unmodifiableSet(new HashSet<Region<String, String>>())); Result result = operationHandler.process(serializationService, ProtobufRequestUtilities.createGetRegionNamesRequest(), getNoAuthCacheExecutionContext(emptyCache)); Assert.assertTrue(result instanceof Success); RegionAPI.GetRegionNamesResponse getRegionsResponse = (RegionAPI.GetRegionNamesResponse) result.getMessage(); Assert.assertEquals(0, getRegionsResponse.getRegionsCount()); } }
@Test public void processReturnsCacheRegions() throws Exception { Result result = operationHandler.process(serializationService, ProtobufRequestUtilities.createGetRegionNamesRequest(), getNoAuthCacheExecutionContext(cacheStub)); Assert.assertTrue(result instanceof Success); RegionAPI.GetRegionNamesResponse getRegionsResponse = (RegionAPI.GetRegionNamesResponse) result.getMessage(); Assert.assertEquals(3, getRegionsResponse.getRegionsCount()); // There's no guarantee for what order we receive the regions in from the response String name1 = getRegionsResponse.getRegions(0); String name2 = getRegionsResponse.getRegions(1); String name3 = getRegionsResponse.getRegions(2); Assert.assertTrue("The same region was returned multiple times", !name1.equals(name2) && !name1.equals(name3) && !name2.equals(name3)); ArrayList arrayList = new ArrayList(); arrayList.add(TEST_REGION1); arrayList.add(TEST_REGION2); arrayList.add(TEST_REGION3); assertTrue(arrayList.contains(name1)); assertTrue(arrayList.contains(name2)); assertTrue(arrayList.contains(name3)); }