Browse code

FEATBL-650 Fix: get unknown container

David Phan authored on 05/12/2018 08:34:41
Showing 2 changed files
... ...
@@ -261,6 +261,25 @@ public class ContainersTests {
261 261
 	}
262 262
 
263 263
 	@Test
264
+	public void testMGet_ContainerDoesNotExist() throws Exception {
265
+		String uid1 = "junit-" + System.nanoTime();
266
+		String uid2 = "junit-" + System.nanoTime();
267
+
268
+		Container container1 = containerStore.create(Container.create(uid1, "testType", "container 1", "test", true));
269
+		aclStore.store(container1,
270
+				Arrays.asList(AccessControlEntry.create(admin0SecurityContext.getSubject(), Verb.All)));
271
+		Container container2 = containerStore.create(Container.create(uid2, "test2Type", uid2, "test", true));
272
+		aclStore.store(container2,
273
+				Arrays.asList(AccessControlEntry.create(admin0SecurityContext.getSubject(), Verb.All)));
274
+
275
+		List<ContainerDescriptor> result = getService(admin0SecurityContext)
276
+				.getContainers(Arrays.asList(uid1, uid2, "bang"));
277
+
278
+		assertEquals(2, result.size());
279
+
280
+	}
281
+
282
+	@Test
264 283
 	public void testMGetLight() throws Exception {
265 284
 		String uid1 = "junit-" + System.nanoTime();
266 285
 		String uid2 = "junit-" + System.nanoTime();
... ...
@@ -280,6 +299,25 @@ public class ContainersTests {
280 299
 	}
281 300
 
282 301
 	@Test
302
+	public void testMGetLight_ContainerDoesNotExist() throws Exception {
303
+		String uid1 = "junit-" + System.nanoTime();
304
+		String uid2 = "junit-" + System.nanoTime();
305
+
306
+		Container container1 = containerStore.create(Container.create(uid1, "testType", "container 1", "test", true));
307
+		aclStore.store(container1,
308
+				Arrays.asList(AccessControlEntry.create(admin0SecurityContext.getSubject(), Verb.All)));
309
+		Container container2 = containerStore.create(Container.create(uid2, "test2Type", uid2, "test", true));
310
+		aclStore.store(container2,
311
+				Arrays.asList(AccessControlEntry.create(admin0SecurityContext.getSubject(), Verb.All)));
312
+
313
+		List<BaseContainerDescriptor> result = getService(admin0SecurityContext)
314
+				.getContainersLight(Arrays.asList(uid1, uid2, "bang"));
315
+
316
+		assertEquals(2, result.size());
317
+
318
+	}
319
+
320
+	@Test
283 321
 	public void testGetForUser() throws Exception {
284 322
 		// Create user matching user security context
285 323
 		String uid = "UserContainer";
... ...
@@ -27,6 +27,7 @@ import java.util.Collections;
27 27
 import java.util.HashMap;
28 28
 import java.util.List;
29 29
 import java.util.Map;
30
+import java.util.Optional;
30 31
 import java.util.Set;
31 32
 import java.util.concurrent.ConcurrentHashMap;
32 33
 import java.util.function.Function;
... ...
@@ -256,8 +257,8 @@ public class Containers implements IContainers {
256 257
 		containerIds.forEach(uid -> {
257 258
 			DataSource dataSource = DataSourceRouter.get(context, uid);
258 259
 			ContainerStore containerStore = new ContainerStore(context, dataSource, securityContext);
259
-
260
-			ret.add(asDescriptor(doOrFail(() -> containerStore.get(uid)), securityContext));
260
+			Optional.ofNullable(doOrFail(() -> containerStore.get(uid)))
261
+					.ifPresent(c -> ret.add(asDescriptor(c, securityContext)));
261 262
 		});
262 263
 
263 264
 		return ret;
... ...
@@ -272,8 +273,8 @@ public class Containers implements IContainers {
272 273
 		containerIds.forEach(uid -> {
273 274
 			DataSource dataSource = DataSourceRouter.get(context, uid);
274 275
 			ContainerStore containerStore = new ContainerStore(context, dataSource, securityContext);
275
-
276
-			ret.add(asDescriptorLight(doOrFail(() -> containerStore.get(uid)), securityContext));
276
+			Optional.ofNullable(doOrFail(() -> containerStore.get(uid)))
277
+					.ifPresent(c -> ret.add(asDescriptorLight(c, securityContext)));
277 278
 		});
278 279
 
279 280
 		return ret;