@Override public Service createServiceInstance() throws Throwable { return new RequestBrokerService(); } }
@Test public void testValidateOnStart() throws Throwable { RequestBrokerState request = TestRequestStateFactory.createRequestState(); request.resourceType = "-"; request.resourceDescriptionLink = "-"; RequestBrokerService r = new RequestBrokerService(); Method m = r.getClass().getDeclaredMethod("validateStateOnStart", RequestBrokerState.class); m.setAccessible(true); validateLocalizableException(() -> { try { m.invoke(r, request); } catch (InvocationTargetException e) { throw e.getCause(); } }, "resource type should not be supported"); }
@Test public void testIsUserAuthorized() throws Throwable { RequestBrokerService r = new RequestBrokerService(); Method m = r.getClass().getDeclaredMethod("isUserAuthorized", SecurityContext.ProjectEntry.class, SecurityContext.class); m.setAccessible(true); SecurityContext context = new SecurityContext(); context.projects = new ArrayList<>(); SecurityContext.ProjectEntry project = new SecurityContext.ProjectEntry(); project.documentSelfLink = "link"; project.roles = new HashSet<>(); project.roles.add(AuthRole.PROJECT_ADMIN); DeferredResult<Void> deferred = (DeferredResult<Void>) m.invoke(r, project, context); assertNotNull(deferred); assertTrue(deferred.toCompletionStage().toCompletableFuture().isCompletedExceptionally()); context.projects.add(project); deferred = (DeferredResult<Void>) m.invoke(r, project, context); assertNotNull(deferred); assertTrue(deferred.toCompletionStage().toCompletableFuture().isDone()); assertFalse(deferred.toCompletionStage().toCompletableFuture().isCancelled()); assertFalse(deferred.toCompletionStage().toCompletableFuture().isCompletedExceptionally()); }