List of usage examples for org.apache.commons.lang ArrayUtils isEmpty
public static boolean isEmpty(boolean[] array)
Checks if an array of primitive booleans is empty or null
.
From source file:org.ambraproject.annotation.service.AnnotationServiceTest.java
@Test(dataProvider = "storedAnnotation") public void testGetBasicAnnotationViewByURI(Annotation annotation, Map<Long, List<Annotation>> fullReplyMap) { AnnotationView result = annotationService.getBasicAnnotationViewByUri(annotation.getAnnotationUri()); assertNotNull(result, "Returned null annotation view"); String expectedDoi = dummyDataStore.get(Article.class, annotation.getArticleID()).getDoi(); String expectedTitle = dummyDataStore.get(Article.class, annotation.getArticleID()).getTitle(); assertEquals(result.getArticleDoi(), expectedDoi, "AnnotationView had incorrect article doi"); assertEquals(result.getArticleTitle(), expectedTitle, "AnnotationView had incorrect article title"); checkAnnotationProperties(result, annotation); assertTrue(ArrayUtils.isEmpty(result.getReplies()), "Returned annotation with replies"); }
From source file:org.ambraproject.BaseTest.java
protected void checkAnnotationProperties(AnnotationView result, Annotation expected) { if (expected.getType() == AnnotationType.MINOR_CORRECTION) { assertEquals(result.getTitle(), "Minor Correction: " + expected.getTitle(), "Annotation view had incorrect title"); } else if (expected.getType() == AnnotationType.FORMAL_CORRECTION) { assertEquals(result.getTitle(), "Formal Correction: " + expected.getTitle(), "Annotation view had incorrect title"); } else if (expected.getType() == AnnotationType.RETRACTION) { assertEquals(result.getTitle(), "Retraction: " + expected.getTitle(), "Annotation view had incorrect title"); }// w w w .ja v a2s .c om assertEquals(result.getBody(), "<p>" + expected.getBody() + "</p>", "Annotation view had incorrect body"); assertEquals(result.getCompetingInterestStatement(), expected.getCompetingInterestBody() == null ? "" : expected.getCompetingInterestBody(), "Annotation view had incorrect ci statement"); assertEquals(result.getAnnotationUri(), expected.getAnnotationUri(), "Annotation view had incorrect annotation uri"); assertEquals(result.getXpath(), expected.getXpath(), "Annotation view had incorrect xpath"); assertEquals(result.getCreatorID(), expected.getCreator().getID(), "Annotation view had incorrect creator id"); assertEquals(result.getCreatorDisplayName(), expected.getCreator().getDisplayName(), "Annotation view had incorrect creator name"); if (Arrays.asList(AnnotationType.FORMAL_CORRECTION, AnnotationType.MINOR_CORRECTION, AnnotationType.RETRACTION).contains(expected.getType())) { assertTrue(result.isCorrection(), "Result should have been created as a correction"); } else { assertFalse(result.isCorrection(), "Result should not have been created as a correction"); } if (expected.getAnnotationCitation() == null) { assertNull(result.getCitation(), "returned non-null citation when null was expected"); } else { assertNotNull(result.getCitation(), "returned null citation when non-null was expected"); assertEquals(result.getCitation().getTitle(), expected.getAnnotationCitation().getTitle(), "Returned citation with incorrect title"); assertEquals(result.getCitation().geteLocationId(), expected.getAnnotationCitation().getELocationId(), "Returned citation with incorrect eLocationId"); assertEquals(result.getCitation().getJournal(), expected.getAnnotationCitation().getJournal(), "Returned citation with incorrect journal"); assertEquals(result.getCitation().getYear(), expected.getAnnotationCitation().getYear(), "Returned citation with incorrect year"); assertEquals(result.getCitation().getVolume(), expected.getAnnotationCitation().getVolume(), "Returned citation with incorrect volume"); assertEquals(result.getCitation().getIssue(), expected.getAnnotationCitation().getIssue(), "Returned citation with incorrect issue"); assertEquals(result.getCitation().getSummary(), expected.getAnnotationCitation().getSummary(), "Returned citation with incorrect summary"); assertEquals(result.getCitation().getNote(), expected.getAnnotationCitation().getNote(), "Returned citation with incorrect note"); if (expected.getAnnotationCitation().getCollaborativeAuthors() != null) { assertEqualsNoOrder(result.getCitation().getCollabAuthors(), expected.getAnnotationCitation().getCollaborativeAuthors().toArray(), "Returned citation with incorrect collab authors"); } else { assertTrue(ArrayUtils.isEmpty(result.getCitation().getCollabAuthors()), "Returned non-empty collab authors when empty was expected"); } if (expected.getAnnotationCitation().getAuthors() != null) { assertNotNull(result.getCitation().getAuthors(), "Returned null authors when authors were expected"); assertEquals(result.getCitation().getAuthors().length, expected.getAnnotationCitation().getAuthors().size(), "Returned incorrect number of authors"); for (int i = 0; i < result.getCitation().getAuthors().length; i++) { AuthorView actualAuthor = result.getCitation().getAuthors()[i]; CorrectedAuthor expectedAuthor = expected.getAnnotationCitation().getAuthors().get(i); assertEquals(actualAuthor.getGivenNames(), expectedAuthor.getGivenNames(), "Author " + (i + 1) + " had incorrect given names"); assertEquals(actualAuthor.getSurnames(), expectedAuthor.getSurName(), "Author " + (i + 1) + " had incorrect surnames"); assertEquals(actualAuthor.getSuffix(), expectedAuthor.getSuffix(), "Author " + (i + 1) + " had incorrect suffix"); } } } }
From source file:org.ambraproject.models.UserRole.java
public UserRole(String roleName, Permission... permissions) { this();//from w w w. ja v a 2s . c o m this.roleName = roleName; if (!ArrayUtils.isEmpty(permissions)) { this.permissions = new HashSet<Permission>(); Collections.addAll(this.permissions, permissions); } }
From source file:org.ambraproject.service.annotation.AnnotationServiceTest.java
@Test(dataProvider = "articleAnnotations") public void testListAnnotationsNoReplies(final Article article, final Set<AnnotationType> annotationTypes, final AnnotationService.AnnotationOrder order, final AnnotationView[] expectedViews, final Map<Long, List<Annotation>> notUsed) { if (order != AnnotationService.AnnotationOrder.MOST_RECENT_REPLY) { AnnotationView[] resultViews = annotationService.listAnnotationsNoReplies(article.getID(), annotationTypes, order); //Not just calling assertEquals here, so we can give a more informative message (the .toSting() on the arrays is huge) assertNotNull(resultViews, "returned null array of results"); assertEquals(resultViews.length, expectedViews.length, "returned incorrect number of results"); for (int i = 0; i < resultViews.length; i++) { assertEquals(resultViews[i], expectedViews[i], "Result " + (i + 1) + " was incorrect with order " + order); assertTrue(ArrayUtils.isEmpty(resultViews[i].getReplies()), "returned annotation with replies loaded up"); }//from w w w .j a v a 2 s. c om } }
From source file:org.apache.ambari.server.serveraction.kerberos.MITKerberosOperationHandler.java
/** * Invokes the kadmin shell command to issue queries * * @param query a String containing the query to send to the kdamin command * @return a ShellCommandUtil.Result containing the result of the operation * @throws KerberosKDCConnectionException if a connection to the KDC cannot be made * @throws KerberosAdminAuthenticationException if the administrator credentials fail to authenticate * @throws KerberosRealmException if the realm does not map to a KDC * @throws KerberosOperationException if an unexpected error occurred */// ww w. j av a2s .c o m protected ShellCommandUtil.Result invokeKAdmin(String query) throws KerberosOperationException { if (StringUtils.isEmpty(query)) { throw new KerberosOperationException("Missing kadmin query"); } ShellCommandUtil.Result result; PrincipalKeyCredential administratorCredential = getAdministratorCredential(); String defaultRealm = getDefaultRealm(); List<String> command = new ArrayList<String>(); String adminPrincipal = (administratorCredential == null) ? null : administratorCredential.getPrincipal(); if (StringUtils.isEmpty(adminPrincipal)) { // Set the kdamin interface to be kadmin.local if (StringUtils.isEmpty(executableKadminLocal)) { throw new KerberosOperationException( "No path for kadmin.local is available - this KerberosOperationHandler may not have been opened."); } command.add(executableKadminLocal); } else { if (StringUtils.isEmpty(executableKadmin)) { throw new KerberosOperationException( "No path for kadmin is available - this KerberosOperationHandler may not have been opened."); } char[] adminPassword = administratorCredential.getKey(); // Set the kdamin interface to be kadmin command.add(executableKadmin); // Add explicit KDC admin host, if available if (getAdminServerHost() != null) { command.add("-s"); command.add(getAdminServerHost()); } // Add the administrative principal command.add("-p"); command.add(adminPrincipal); if (!ArrayUtils.isEmpty(adminPassword)) { // Add password for administrative principal command.add("-w"); command.add(String.valueOf(adminPassword)); } } if (!StringUtils.isEmpty(defaultRealm)) { // Add default realm clause command.add("-r"); command.add(defaultRealm); } // Add kadmin query command.add("-q"); command.add(query); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Executing: %s", createCleanCommand(command))); } result = executeCommand(command.toArray(new String[command.size()])); if (!result.isSuccessful()) { String message = String.format( "Failed to execute kadmin:\n\tCommand: %s\n\tExitCode: %s\n\tSTDOUT: %s\n\tSTDERR: %s", createCleanCommand(command), result.getExitCode(), result.getStdout(), result.getStderr()); LOG.warn(message); // Test STDERR to see of any "expected" error conditions were encountered... String stdErr = result.getStderr(); // Did admin credentials fail? if (stdErr.contains("Client not found in Kerberos database")) { throw new KerberosAdminAuthenticationException(stdErr); } else if (stdErr.contains("Incorrect password while initializing")) { throw new KerberosAdminAuthenticationException(stdErr); } // Did we fail to connect to the KDC? else if (stdErr.contains("Cannot contact any KDC")) { throw new KerberosKDCConnectionException(stdErr); } else if (stdErr.contains( "Cannot resolve network address for admin server in requested realm while initializing kadmin interface")) { throw new KerberosKDCConnectionException(stdErr); } // Was the realm invalid? else if (stdErr.contains("Missing parameters in krb5.conf required for kadmin client")) { throw new KerberosRealmException(stdErr); } else if (stdErr.contains("Cannot find KDC for requested realm while initializing kadmin interface")) { throw new KerberosRealmException(stdErr); } else { throw new KerberosOperationException("Unexpected error condition executing the kadmin command"); } } return result; }
From source file:org.apache.archiva.webdav.AbstractRepositoryServletProxiedMetadataTestCase.java
protected String createProjectMetadata(String groupId, String artifactId, String latest, String release, String[] versions) {// w w w . j av a 2 s. co m StringBuilder buf = new StringBuilder(); buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"); buf.append("<metadata>\n"); buf.append(" <groupId>").append(groupId).append("</groupId>\n"); buf.append(" <artifactId>").append(artifactId).append("</artifactId>\n"); boolean hasLatest = StringUtils.isNotBlank(latest); boolean hasRelease = StringUtils.isNotBlank(release); boolean hasVersions = !ArrayUtils.isEmpty(versions); if (hasLatest || hasRelease || hasVersions) { buf.append(" <versioning>\n"); if (hasLatest) { buf.append(" <latest>").append(latest).append("</latest>\n"); } if (hasRelease) { buf.append(" <release>").append(release).append("</release>\n"); } if (hasVersions) { buf.append(" <versions>\n"); for (String availVersion : versions) { buf.append(" <version>").append(availVersion).append("</version>\n"); } buf.append(" </versions>\n"); } buf.append(" </versioning>\n"); } buf.append("</metadata>"); return buf.toString(); }
From source file:org.apache.archiva.webdav.AbstractRepositoryServletProxiedMetadataTestCase.java
protected String createGroupMetadata(String groupId, String[] plugins) { StringBuilder buf = new StringBuilder(); buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"); buf.append("<metadata>\n"); buf.append(" <groupId>").append(groupId).append("</groupId>\n"); boolean hasPlugins = !ArrayUtils.isEmpty(plugins); if (hasPlugins) { buf.append(" <plugins>\n"); for (String plugin : plugins) { buf.append(" <plugin>\n"); buf.append(" <prefix>").append(plugin).append("</prefix>\n"); buf.append(" <artifactId>").append(plugin + "-maven-plugin").append("</artifactId>\n"); buf.append(" <name>").append("The " + plugin + " Plugin").append("</name>\n"); buf.append(" </plugin>\n"); }//from ww w . j a va 2s. c o m buf.append(" </plugins>\n"); } buf.append("</metadata>"); return buf.toString(); }
From source file:org.apache.atlas.examples.QuickStartV2.java
static String[] getServerUrl(String[] args) throws AtlasException { if (args.length > 0) { return args[0].split(","); }/*from w w w.j a v a 2 s.c o m*/ Configuration configuration = ApplicationProperties.get(); String[] urls = configuration.getStringArray(ATLAS_REST_ADDRESS); if (ArrayUtils.isEmpty(urls)) { System.out.println( "org.apache.atlas.examples.QuickStartV2 <Atlas REST address <http/https>://<atlas-fqdn>:<atlas-port> like http://localhost:21000>"); System.exit(-1); } return urls; }
From source file:org.apache.click.extras.tree.CheckboxTree.java
/** * Expand / collapse the tree nodes.//from w w w . jav a 2 s. c om * * @return true to continue Page event processing or false otherwise */ @Override boolean postProcess() { if (isJavascriptEnabled()) { javascriptHandler.init(getContext()); } if (!ArrayUtils.isEmpty(expandOrCollapseNodeIds)) { expandOrCollapse(expandOrCollapseNodeIds); } // Try and locate a parent form Form form = ContainerUtils.findForm(this); if (form != null) { // If the form was submitted, invoke bindSelectOrDeselectValues() if (form.isFormSubmission()) { onFormSubmission(); } } return true; }
From source file:org.apache.click.extras.tree.Tree.java
/** * Expand / collapse and select / deselect the tree nodes. * * @return true to continue Page event processing or false otherwise */// ww w . ja va 2 s. co m boolean postProcess() { if (isJavascriptEnabled()) { // Populate the javascript handler with its state. This call will // notify any tree listeners about new values. javascriptHandler.init(getContext()); } if (!ArrayUtils.isEmpty(expandOrCollapseNodeIds)) { expandOrCollapse(expandOrCollapseNodeIds); } if (!ArrayUtils.isEmpty(selectOrDeselectNodeIds)) { selectOrDeselect(selectOrDeselectNodeIds); } return true; }