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 280
 	}
281 281
 
282 282
 	@Test
283
+	public void testMGetLight_ContainerDoesNotExist() throws Exception {
284
+		String uid1 = "junit-" + System.nanoTime();
285
+		String uid2 = "junit-" + System.nanoTime();
286
+
287
+		Container container1 = containerStore.create(Container.create(uid1, "testType", "container 1", "test", true));
288
+		aclStore.store(container1,
289
+				Arrays.asList(AccessControlEntry.create(admin0SecurityContext.getSubject(), Verb.All)));
290
+		Container container2 = containerStore.create(Container.create(uid2, "test2Type", uid2, "test", true));
291
+		aclStore.store(container2,
292
+				Arrays.asList(AccessControlEntry.create(admin0SecurityContext.getSubject(), Verb.All)));
293
+
294
+		List<BaseContainerDescriptor> result = getService(admin0SecurityContext)
295
+				.getContainersLight(Arrays.asList(uid1, uid2, "bang"));
296
+
297
+		assertEquals(2, result.size());
298
+
299
+	}
300
+
301
+	@Test
283 302
 	public void testGetForUser() throws Exception {
284 303
 		// Create user matching user security context
285 304
 		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 256
 		containerIds.forEach(uid -> {
257 257
 			DataSource dataSource = DataSourceRouter.get(context, uid);
258 258
 			ContainerStore containerStore = new ContainerStore(context, dataSource, securityContext);
259
-
260
-			ret.add(asDescriptor(doOrFail(() -> containerStore.get(uid)), securityContext));
259
+			Optional.ofNullable(doOrFail(() -> containerStore.get(uid)))
260
+					.ifPresent(c -> ret.add(asDescriptor(c, securityContext)));
261 261
 		});
262 262
 
263 263
 		return ret;
... ...
@@ -272,8 +273,8 @@ public class Containers implements IContainers {
272 272
 		containerIds.forEach(uid -> {
273 273
 			DataSource dataSource = DataSourceRouter.get(context, uid);
274 274
 			ContainerStore containerStore = new ContainerStore(context, dataSource, securityContext);
275
-
276
-			ret.add(asDescriptorLight(doOrFail(() -> containerStore.get(uid)), securityContext));
275
+			Optional.ofNullable(doOrFail(() -> containerStore.get(uid)))
276
+					.ifPresent(c -> ret.add(asDescriptorLight(c, securityContext)));
277 277
 		});
278 278
 
279 279
 		return ret;