List of usage examples for java.util EnumSet noneOf
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType)
From source file:org.apache.nifi.admin.service.action.SetUserAuthoritiesActionTest.java
@Before public void setup() throws Exception { // mock the user dao userDao = Mockito.mock(UserDAO.class); Mockito.doAnswer(new Answer<NiFiUser>() { @Override/* w w w . ja v a2 s .co m*/ public NiFiUser answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); String id = (String) args[0]; NiFiUser user = null; if (USER_ID_1.equals(id)) { // leave user uninitialized } else if (USER_ID_2.equals(id)) { user = new NiFiUser(); user.setId(USER_ID_2); user.setIdentity(USER_IDENTITY_2); } else if (USER_ID_3.equals(id)) { user = new NiFiUser(); user.setId(USER_ID_3); user.setIdentity(USER_IDENTITY_3); user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); user.setStatus(AccountStatus.ACTIVE); } return user; } }).when(userDao).findUserById(Mockito.anyString()); Mockito.doAnswer(new Answer<NiFiUser>() { @Override public NiFiUser answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); String dn = (String) args[0]; NiFiUser user = null; if (USER_IDENTITY_3.equals(dn)) { user = new NiFiUser(); user.setId(USER_ID_3); user.setIdentity(USER_IDENTITY_3); user.getAuthorities().addAll(EnumSet.of(Authority.ROLE_MONITOR)); user.setStatus(AccountStatus.ACTIVE); } return user; } }).when(userDao).findUserByDn(Mockito.anyString()); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); NiFiUser user = (NiFiUser) args[0]; // do nothing return null; } }).when(userDao).updateUser(Mockito.any(NiFiUser.class)); // mock the authority dao authorityDao = Mockito.mock(AuthorityDAO.class); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); Set<Authority> authorities = (Set<Authority>) args[0]; String id = (String) args[1]; // do nothing return null; } }).when(authorityDao).createAuthorities(Mockito.anySetOf(Authority.class), Mockito.anyString()); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); Set<Authority> authorities = (Set<Authority>) args[0]; String id = (String) args[1]; // do nothing return null; } }).when(authorityDao).deleteAuthorities(Mockito.anySetOf(Authority.class), Mockito.anyString()); // mock the dao factory daoFactory = Mockito.mock(DAOFactory.class); Mockito.when(daoFactory.getUserDAO()).thenReturn(userDao); Mockito.when(daoFactory.getAuthorityDAO()).thenReturn(authorityDao); // mock the authority provider authorityProvider = Mockito.mock(AuthorityProvider.class); Mockito.doAnswer(new Answer<Set<Authority>>() { @Override public Set<Authority> answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); String dn = (String) args[0]; Set<Authority> authorities = EnumSet.noneOf(Authority.class); if (USER_IDENTITY_3.equals(dn)) { authorities.add(Authority.ROLE_DFM); } return authorities; } }).when(authorityProvider).getAuthorities(Mockito.anyString()); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); String dn = (String) args[0]; Set<Authority> authorites = (Set<Authority>) args[1]; if (USER_IDENTITY_2.equals(dn)) { throw new AuthorityAccessException(StringUtils.EMPTY); } // do nothing return null; } }).when(authorityProvider).setAuthorities(Mockito.anyString(), Mockito.anySet()); }
From source file:com.sg.rest.SpringSecurityTest.java
@Test public void testSecureResourceWithAuthTokenButNonSufficientRights() throws IOException, Exception { String authToken = webSecurityService.generateToken(ACCOUNT_ID, Instant.now(), TokenExpirationStandardDurations.WEB_SESSION_TOKEN_EXPIRATION_DURATION); Set<Role> roles = EnumSet.noneOf(Role.class); when(handler.handle(new GetAccountRolesOperation(ACCOUNT_ID))) .thenReturn(new GetAccountRolesResponse(roles)); mockMvc.perform(get(RequestPath.TEST_SECURE_REQUEST).header(HttpCustomHeaders.AUTH_TOKEN_HEADER.getHeader(), authToken)).andExpect(status().is(HttpServletResponse.SC_FORBIDDEN)) .andExpect(content().contentType(CustomMediaTypes.APPLICATION_JSON_UTF8.getMediatype())) .andExpect(jsonPath("$.eventRef.id", not(isEmptyOrNullString()))); }
From source file:at.ac.univie.isc.asio.platform.FileSystemConfigStore.java
@Override public void clear(final String qualifier) { final FindFiles collector = FindFiles.filter(filesWithQualifier(qualifier)); try {//from w w w. j a v a 2s . co m log.debug(Scope.SYSTEM.marker(), "clearing configuration of <{}>", qualifier); lock(); Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), 1, collector); for (final Path path : collector.found()) { log.debug(Scope.SYSTEM.marker(), "deleting <{}>", path); Files.deleteIfExists(path); } } catch (IOException e) { throw new FileSystemAccessFailure("failed to clear <" + qualifier + ">", e); } finally { lock.unlock(); } }
From source file:org.springframework.cloud.deployer.admin.server.controller.ApplicationDeploymentController.java
private String calculateApplicationState(String name) { Set<DeploymentState> appStates = EnumSet.noneOf(DeploymentState.class); ApplicationDefinition application = this.definitionRepository.findOne(name); return "unknown"; }
From source file:org.photovault.swingui.JAIPhotoViewer.java
/** Set the photo displayed in the component. /*from w w w . ja v a 2s. c om*/ The function tries to search for a suitable instance of the photo to display. If none are found the Photo is set to <code>null</code> and an exception is reported to application. TODO: This function is currently messy, refactor it at the same time as RawImage/image handling is refactored. @param photo The photo to be displayed. @throws FileNotFoundException if the instance file cannot be found. This can happen if e.g. user has deleted an image file from directory indexed as an external volume. */ public void setPhoto(PhotoInfo photo) throws FileNotFoundException { if (this.photo != null) { this.photo.removeChangeListener(this); } this.photo = photo; if (photo == null) { setImage(null); fireViewChangeEvent(); return; } dynOps = EnumSet.noneOf(ImageOperations.class); localRawSettings = null; localChanMap = null; log.debug("JAIPhotoViewer.setPhoto() photo=" + photo.getUuid()); photo.addChangeListener(this); try { showBestInstance(); } catch (PhotovaultException ex) { throw new FileNotFoundException(ex.getMessage()); } }
From source file:edu.uci.ics.hyracks.api.client.HyracksConnection.java
@Override public JobId startJob(DeploymentId deploymentId, JobSpecification jobSpec) throws Exception { return startJob(deploymentId, jobSpec, EnumSet.noneOf(JobFlag.class)); }
From source file:sx.blah.discord.handle.impl.obj.User.java
@Override public EnumSet<Permissions> getPermissionsForGuild(IGuild guild) { if (guild.getOwner().equals(this)) return EnumSet.allOf(Permissions.class); EnumSet<Permissions> permissions = EnumSet.noneOf(Permissions.class); getRolesForGuild(guild).forEach(role -> permissions.addAll(role.getPermissions())); return permissions; }
From source file:plugins.PlayReader.java
private Swagger read(Class<?> cls, String parentPath, String parentMethod, boolean readHidden, String[] parentConsumes, String[] parentProduces, Map<String, Tag> parentTags, List<Parameter> parentParameters, Set<Class<?>> scannedResources) { RouteWrapper routes = RouteFactory.getRoute(); Api api = (Api) cls.getAnnotation(Api.class); Map<String, SecurityScope> globalScopes = new HashMap<String, SecurityScope>(); Map<String, Tag> tags = new HashMap<String, Tag>(); List<SecurityRequirement> securities = new ArrayList<SecurityRequirement>(); String[] consumes = new String[0]; String[] produces = new String[0]; final Set<Scheme> globalSchemes = EnumSet.noneOf(Scheme.class); // only read if allowing hidden apis OR api is not marked as hidden final boolean readable = (api != null && readHidden) || (api != null && !api.hidden()); if (readable) { // the value will be used as a tag for 2.0 UNLESS a Tags annotation is present Set<String> tagStrings = extractTags(api); for (String tagString : tagStrings) { Tag tag = new Tag().name(tagString); tags.put(tagString, tag);//from w w w. j av a 2s. c o m } if (parentTags != null) { tags.putAll(parentTags); } for (String tagName : tags.keySet()) { swagger.tag(tags.get(tagName)); } if (!api.produces().isEmpty()) { produces = new String[] { api.produces() }; } else if (cls.getAnnotation(Produces.class) != null) { produces = ReaderUtils.splitContentValues(cls.getAnnotation(Produces.class).value()); } if (!api.consumes().isEmpty()) { consumes = new String[] { api.consumes() }; } else if (cls.getAnnotation(Consumes.class) != null) { consumes = ReaderUtils.splitContentValues(cls.getAnnotation(Consumes.class).value()); } globalSchemes.addAll(parseSchemes(api.protocols())); Authorization[] authorizations = api.authorizations(); for (Authorization auth : authorizations) { if (auth.value() != null && !"".equals(auth.value())) { SecurityRequirement security = new SecurityRequirement(); security.setName(auth.value()); AuthorizationScope[] scopes = auth.scopes(); for (AuthorizationScope scope : scopes) { if (scope.scope() != null && !"".equals(scope.scope())) { security.addScope(scope.scope()); } } securities.add(security); } } } // allow reading the JAX-RS APIs without @Api annotation if (readable || (api == null && config.isScanAllResources())) { // merge consumes, produces // look for method-level annotated properties // handle sub-resources by looking at return type final List<Parameter> globalParameters = new ArrayList<Parameter>(); // look for constructor-level annotated properties globalParameters.addAll(ReaderUtils.collectConstructorParameters(cls, swagger)); // look for field-level annotated properties globalParameters.addAll(ReaderUtils.collectFieldParameters(cls, swagger)); // parse the method final javax.ws.rs.Path apiPath = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class); Method methods[] = cls.getMethods(); for (Method method : methods) { if (ReflectionUtils.isOverriddenMethod(method, cls)) { continue; } javax.ws.rs.Path methodPath = ReflectionUtils.getAnnotation(method, javax.ws.rs.Path.class); // complete name as stored in route String fullMethodName = getFullMethodName(cls, method); if (!routes.exists(fullMethodName)) { continue; } String operationPath = getPath(apiPath, methodPath, parentPath); Map<String, String> regexMap = new HashMap<String, String>(); operationPath = PathUtils.parsePath(operationPath, regexMap); if (operationPath != null) { if (isIgnored(operationPath)) { continue; } final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); String httpMethod = extractOperationMethod(apiOperation, method, SwaggerExtensions.chain()); Operation operation = null; if (apiOperation != null || config.isScanAllResources() || httpMethod != null || methodPath != null) { operation = parseMethod(cls, method, globalParameters); } if (operation == null) { continue; } if (parentParameters != null) { for (Parameter param : parentParameters) { operation.parameter(param); } } for (Parameter param : operation.getParameters()) { if (regexMap.get(param.getName()) != null) { String pattern = regexMap.get(param.getName()); param.setPattern(pattern); } } if (apiOperation != null) { for (Scheme scheme : parseSchemes(apiOperation.protocols())) { operation.scheme(scheme); } } if (operation.getSchemes() == null || operation.getSchemes().isEmpty()) { for (Scheme scheme : globalSchemes) { operation.scheme(scheme); } } String[] apiConsumes = consumes; if (parentConsumes != null) { Set<String> both = new HashSet<String>(Arrays.asList(apiConsumes)); both.addAll(new HashSet<String>(Arrays.asList(parentConsumes))); if (operation.getConsumes() != null) { both.addAll(new HashSet<String>(operation.getConsumes())); } apiConsumes = both.toArray(new String[both.size()]); } String[] apiProduces = produces; if (parentProduces != null) { Set<String> both = new HashSet<String>(Arrays.asList(apiProduces)); both.addAll(new HashSet<String>(Arrays.asList(parentProduces))); if (operation.getProduces() != null) { both.addAll(new HashSet<String>(operation.getProduces())); } apiProduces = both.toArray(new String[both.size()]); } final Class<?> subResource = getSubResource(method); if (subResource != null && !scannedResources.contains(subResource)) { scannedResources.add(subResource); read(subResource, operationPath, httpMethod, true, apiConsumes, apiProduces, tags, operation.getParameters(), scannedResources); } // can't continue without a valid http method httpMethod = httpMethod == null ? parentMethod : httpMethod; if (httpMethod != null) { if (apiOperation != null) { boolean hasExplicitTag = false; for (String tag : apiOperation.tags()) { if (!"".equals(tag)) { operation.tag(tag); swagger.tag(new Tag().name(tag)); } } if (operation != null) { operation.getVendorExtensions() .putAll(BaseReaderUtils.parseExtensions(apiOperation.extensions())); } } if (operation != null) { if (operation.getConsumes() == null) { for (String mediaType : apiConsumes) { operation.consumes(mediaType); } } if (operation.getProduces() == null) { for (String mediaType : apiProduces) { operation.produces(mediaType); } } if (operation.getTags() == null) { for (String tagString : tags.keySet()) { operation.tag(tagString); } } // Only add global @Api securities if operation doesn't already have more specific securities if (operation.getSecurity() == null) { for (SecurityRequirement security : securities) { operation.security(security); } } Path path = swagger.getPath(operationPath); if (path == null) { path = new Path(); swagger.path(operationPath, path); } path.set(httpMethod, operation); readImplicitParameters(method, operation); } } } } } return swagger; }
From source file:net.ripe.rpki.commons.validation.X509ResourceCertificateBottomUpValidatorTest.java
@Test public void testShouldFailOnInvalidResorceSet() { child = createChildBuilder().withInheritedResourceTypes(EnumSet.noneOf(IpResourceType.class)) .withResources(INVALID_CHILD_RESOURCE_SET).build(); X509ResourceCertificateBottomUpValidator validator = new X509ResourceCertificateBottomUpValidator( new ResourceCertificateLocatorImpl()); validator.validate("child", child); assertTrue(validator.getValidationResult().hasFailures()); assertTrue(validator.getValidationResult().hasFailureForLocation(CHILD_VALIDATION_LOCATION)); assertTrue(ValidationString.RESOURCE_RANGE .equals(validator.getValidationResult().getFailures(CHILD_VALIDATION_LOCATION).get(0).getKey())); }
From source file:org.apereo.portal.xml.stream.IndentingXMLEventWriter.java
/** Note that a document was ended. */ protected void afterEndDocument() { depth = 0;//from ww w . j av a 2 s . co m final Set<StackState> state = scopeState.getFirst(); if (state.contains(StackState.WROTE_MARKUP) && !state.contains(StackState.WROTE_DATA)) { // but not data try { final String indent = getLineSeparator() + StringUtils.repeat(" ", 0); final Characters indentEvent = xmlEventFactory.createCharacters(indent); wrappedWriter.add(indentEvent); } catch (Exception ignored) { } } scopeState.clear(); scopeState.push(EnumSet.noneOf(StackState.class)); // start fresh }