summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--BRMSGateway/src/main/java/org/onap/policy/brms/api/nexus/NexusRestSearchParameters.java103
-rw-r--r--BRMSGateway/src/main/java/org/onap/policy/brms/api/nexus/NexusRestWrapper.java83
-rw-r--r--BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/NexusRestWrapperTest.java372
-rw-r--r--BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusArtifactHitTest.java39
-rw-r--r--BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusArtifactLinkTest.java39
-rw-r--r--BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusArtifactTest.java50
-rw-r--r--BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusRepositoryTest.java43
-rw-r--r--BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusSearchResultTest.java45
8 files changed, 690 insertions, 84 deletions
diff --git a/BRMSGateway/src/main/java/org/onap/policy/brms/api/nexus/NexusRestSearchParameters.java b/BRMSGateway/src/main/java/org/onap/policy/brms/api/nexus/NexusRestSearchParameters.java
index eec37392e..1288b5982 100644
--- a/BRMSGateway/src/main/java/org/onap/policy/brms/api/nexus/NexusRestSearchParameters.java
+++ b/BRMSGateway/src/main/java/org/onap/policy/brms/api/nexus/NexusRestSearchParameters.java
@@ -45,11 +45,12 @@ public class NexusRestSearchParameters {
private static final String COUNT_QUERY_PARAM = "count";
private static final String REPOSITORY_ID_QUERY_PARAM = "repositoryId";
- private enum SearchType {
- KEYWORD, // Search using a keyword
- FILTER, // Search using a group ID, artifact ID, version, packaging type, and/or classifier filter
- CLASS_NAME, // Search for a class name
- CHECKSUM // Search for artifacts matching a certain checksum
+ /** The type of searches that can be performed. */
+ public enum SearchType {
+ KEYWORD, /** Search using a keyword. */
+ FILTER, /** Search using a group ID, artifact ID, version, packaging type, and/or classifier filter. */
+ CLASS_NAME, /** Search for a class name. */
+ CHECKSUM /** Search for artifacts matching a certain checksum. */
}
// The type of search to perform
@@ -76,15 +77,19 @@ public class NexusRestSearchParameters {
* Specify searching using a keyword.
*
* @param keyword The keyword to search for
+ * @return this object to allow chaining of methods
* @throws NexusRestWrapperException on invalid keywords
*/
- public void useKeywordSearch(final String keyword) throws NexusRestWrapperException {
+ public NexusRestSearchParameters useKeywordSearch(final String keyword) throws NexusRestWrapperException {
+ clearSearchParameters();
+
if (isNullOrBlank(keyword)) {
throw new NexusRestWrapperException("keyword must be specified for Nexus keyword searches");
}
searchType = SearchType.KEYWORD;
this.keyword = keyword;
+ return this;
}
/**
@@ -95,14 +100,18 @@ public class NexusRestSearchParameters {
* @param version The version to filter on
* @param packagingType The packaging type to filter on
* @param classifier The classifier to filter on
+ * @return this object to allow chaining of methods
* @throws NexusRestWrapperException on invalid filters
*/
- public void useFilterSearch(final String groupId, final String artifactId, final String version,
- final String packagingType, final String classifier) throws NexusRestWrapperException {
+ public NexusRestSearchParameters useFilterSearch(final String groupId, final String artifactId,
+ final String version, final String packagingType, final String classifier)
+ throws NexusRestWrapperException {
+ clearSearchParameters();
+
if (isNullOrBlank(groupId) && isNullOrBlank(artifactId) && isNullOrBlank(version)
- && isNullOrBlank(packagingType) && isNullOrBlank(classifier)) {
+ && isNullOrBlank(packagingType) && isNullOrBlank(classifier)) {
throw new NexusRestWrapperException(
- "at least one filter parameter must be specified for Nexus keyword searches");
+ "at least one filter parameter must be specified for Nexus filter searches");
}
searchType = SearchType.FILTER;
@@ -111,36 +120,45 @@ public class NexusRestSearchParameters {
this.version = version;
this.packagingType = packagingType;
this.classifier = classifier;
+ return this;
}
/**
* Specify searching using a class name.
*
* @param className The class name to search for
+ * @return this object to allow chaining of methods
* @throws NexusRestWrapperException on invalid className
*/
- public void useClassNameSearch(final String className) throws NexusRestWrapperException {
+ public NexusRestSearchParameters useClassNameSearch(final String className) throws NexusRestWrapperException {
+ clearSearchParameters();
+
if (isNullOrBlank(className)) {
- throw new NexusRestWrapperException("className must be specified for Nexus keyword searches");
+ throw new NexusRestWrapperException("className must be specified for Nexus class name searches");
}
searchType = SearchType.CLASS_NAME;
this.className = className;
+ return this;
}
/**
* Specify searching using a checksum.
*
* @param checksum The checksum to search for
+ * @return this object to allow chaining of methods
* @throws NexusRestWrapperException on invalid checksum
*/
- public void useChecksumSearch(final String checksum) throws NexusRestWrapperException {
+ public NexusRestSearchParameters useChecksumSearch(final String checksum) throws NexusRestWrapperException {
+ clearSearchParameters();
+
if (isNullOrBlank(checksum)) {
- throw new NexusRestWrapperException("checksum must be specified for Nexus keyword searches");
+ throw new NexusRestWrapperException("checksum must be specified for Nexus checksum searches");
}
searchType = SearchType.CHECKSUM;
this.checksum = checksum;
+ return this;
}
/**
@@ -152,7 +170,7 @@ public class NexusRestSearchParameters {
*/
public NexusRestSearchParameters setRepositoryId(String repositoryId) throws NexusRestWrapperException {
if (isNullOrBlank(repositoryId)) {
- throw new NexusRestWrapperException("repositoryId must be specified for Nexus keyword searches");
+ throw new NexusRestWrapperException("a repositoryId must be specified");
}
this.repositoryId = repositoryId;
@@ -168,7 +186,7 @@ public class NexusRestSearchParameters {
*/
public NexusRestSearchParameters setFrom(int from) throws NexusRestWrapperException {
if (from < 0) {
- throw new NexusRestWrapperException("from cannot be less than 0 for Nexus keyword searches");
+ throw new NexusRestWrapperException("from cannot be less than 0 when from is specified");
}
this.from = from;
@@ -184,7 +202,7 @@ public class NexusRestSearchParameters {
*/
public NexusRestSearchParameters setCount(int count) throws NexusRestWrapperException {
if (count < 1) {
- throw new NexusRestWrapperException("count cannot be less than 1 for Nexus keyword searches");
+ throw new NexusRestWrapperException("count cannot be less than 1 when count is specified");
}
this.count = count;
@@ -200,13 +218,17 @@ public class NexusRestSearchParameters {
*/
public URI getSearchUri(final String nexusServerUrl) throws NexusRestWrapperException {
if (isNullOrBlank(nexusServerUrl)) {
- throw new NexusRestWrapperException("nexusServerUrl must be specified for Nexus keyword searches");
+ throw new NexusRestWrapperException("nexusServerUrl must be specified for the search URI");
+ }
+
+ if (searchType == null) {
+ throw new NexusRestWrapperException("search parameters have not been set");
}
// Use a URI builder to build up the search URI
UriBuilder uriBuilder = UriBuilder
- .fromPath(nexusServerUrl)
- .path(NEXUS_LUCENE_SEARCH_PATH);
+ .fromPath(nexusServerUrl)
+ .path(NEXUS_LUCENE_SEARCH_PATH);
switch (searchType) {
case KEYWORD:
@@ -226,7 +248,7 @@ public class NexusRestSearchParameters {
break;
default:
- throw new NexusRestWrapperException("search parameters have not been specified for the NExus search");
+ throw new NexusRestWrapperException("search parameters have not been specified for the Nexus search");
}
// Add the repository ID query parameter is required
@@ -258,19 +280,19 @@ public class NexusRestSearchParameters {
* @param uriBuilder The builder to add query parameters to
*/
private void getFitlerSearchUri(UriBuilder uriBuilder) {
- if (null != groupId) {
+ if (!isNullOrBlank(groupId)) {
uriBuilder.queryParam(GROUP_ID_QUERY_PARAM, groupId);
}
- if (null != artifactId) {
+ if (!isNullOrBlank(artifactId)) {
uriBuilder.queryParam(ARTIFACT_ID_QUERY_PARAM, artifactId);
}
- if (null != version) {
+ if (!isNullOrBlank(version)) {
uriBuilder.queryParam(VERSION_QUERY_PARAM, version);
}
- if (null != packagingType) {
+ if (!isNullOrBlank(packagingType)) {
uriBuilder.queryParam(PACKAGING_TYPE_QUERY_PARAM, packagingType);
}
- if (null != classifier) {
+ if (!isNullOrBlank(classifier)) {
uriBuilder.queryParam(CLASSIFIER_QUERY_PARAM, classifier);
}
}
@@ -346,11 +368,34 @@ public class NexusRestSearchParameters {
return null == parameter || parameter.trim().isEmpty();
}
+ /**
+ * Clear all search parameters.
+ *
+ */
+ private void clearSearchParameters() {
+ searchType = null;
+
+ keyword = null;
+ groupId = null;
+ artifactId = null;
+ version = null;
+ packagingType = null;
+ classifier = null;
+ className = null;
+ checksum = null;
+
+ repositoryId = null;
+
+ // Scope filters
+ from = -1;
+ count = -1;
+ }
+
@Override
public String toString() {
return "NexusRestSearchParameters [searchType=" + searchType + ", keyword=" + keyword + ", groupId=" + groupId
- + ", artifactId=" + artifactId + ", version=" + version + ", packagingType=" + packagingType
- + ", classifier=" + classifier + ", className=" + className + ", checksum=" + checksum
- + ", repositoryId=" + repositoryId + ", from=" + from + ", count=" + count + "]";
+ + ", artifactId=" + artifactId + ", version=" + version + ", packagingType=" + packagingType
+ + ", classifier=" + classifier + ", className=" + className + ", checksum=" + checksum
+ + ", repositoryId=" + repositoryId + ", from=" + from + ", count=" + count + "]";
}
}
diff --git a/BRMSGateway/src/main/java/org/onap/policy/brms/api/nexus/NexusRestWrapper.java b/BRMSGateway/src/main/java/org/onap/policy/brms/api/nexus/NexusRestWrapper.java
index afa3e3794..9ee7598fd 100644
--- a/BRMSGateway/src/main/java/org/onap/policy/brms/api/nexus/NexusRestWrapper.java
+++ b/BRMSGateway/src/main/java/org/onap/policy/brms/api/nexus/NexusRestWrapper.java
@@ -54,25 +54,6 @@ public class NexusRestWrapper {
private String nexusPassword;
/**
- * Instantiates a new Nexus REST agent.
- *
- * @param nexusServerUrl the URL of the Nexus server as a string
- * @throws NexusRestWrapperException on errors on the Nexus server URL
- */
- public NexusRestWrapper(final String nexusServerUrl) throws NexusRestWrapperException {
- LOGGER.trace("new NexusRestWrapper: nexusServerUrl=" + nexusServerUrl);
-
- if (isNullOrBlank(nexusServerUrl)) {
- throw new NexusRestWrapperException("nexusServerUrl must be specified for the Nexus server");
- }
-
- this.nexusServerUrl = nexusServerUrl;
-
- // Create a client for RST calls towards the Nexus server
- client = ClientBuilder.newClient();
- }
-
- /**
* Instantiates a new Nexus REST agent with credentials.
*
* @param nexusServerUrl the URL of the Nexus server as a string
@@ -81,15 +62,17 @@ public class NexusRestWrapper {
* @throws NexusRestWrapperException on parameter exceptions
*/
public NexusRestWrapper(final String nexusServerUrl, final String nexusUser, final String nexusPassword)
- throws NexusRestWrapperException {
+ throws NexusRestWrapperException {
LOGGER.trace("new NexusRestWrapper: nexusServerUrl=" + nexusServerUrl);
if (isNullOrBlank(nexusServerUrl)) {
throw new NexusRestWrapperException("nexusServerUrl must be specified for the Nexus server");
}
- if (isNullOrBlank(nexusUser) || isNullOrBlank(nexusPassword)) {
- throw new NexusRestWrapperException("nexuusUser and nexusPassword must both be specified");
+ if ((isNullOrBlank(nexusUser) && !isNullOrBlank(nexusPassword))
+ || (!isNullOrBlank(nexusUser) && isNullOrBlank(nexusPassword))) {
+ throw new NexusRestWrapperException(
+ "if either nexusUser or nexusPassword are specified, both must be specified");
}
this.nexusServerUrl = nexusServerUrl;
@@ -124,10 +107,13 @@ public class NexusRestWrapper {
* Exceptions accessing the Nexus server
*/
public NexusSearchResult findArtifact(final NexusRestSearchParameters searchParameters)
- throws NexusRestWrapperException {
-
+ throws NexusRestWrapperException {
LOGGER.trace("new search with search parameters: " + searchParameters);
+ if (null == searchParameters) {
+ throw new NexusRestWrapperException("searchParameters may not be null");
+ }
+
// Issue the REST request to perform the search
URI searchUri = searchParameters.getSearchUri(nexusServerUrl);
@@ -138,14 +124,22 @@ public class NexusRestWrapper {
getAuthorizationHeader(requestBuilder);
// Issue the REST request
- Response response = requestBuilder.get();
+ Response response = null;
+ try {
+ response = requestBuilder.get();
+ } catch (Exception e) {
+ String message = "search to URI " + searchUri.toString() + " failed with message: " + e.getMessage();
+ LOGGER.warn(message, e);
+ throw new NexusRestWrapperException(message, e);
+ }
LOGGER.debug("search response is: " + response.toString());
// Check the HTTP response code for the search
if (Response.Status.OK.getStatusCode() != response.getStatus()) {
- LOGGER.warn("search to URI " + searchUri.toString() + "failed, response was: " + response.toString());
- throw new NexusRestWrapperException("query to Nexus failed with message: " + response.toString());
+ String message = "search to URI " + searchUri.toString() + " failed, response was: " + response.toString();
+ LOGGER.warn(message);
+ throw new NexusRestWrapperException(message);
}
try {
@@ -160,23 +154,22 @@ public class NexusRestWrapper {
return searchResult;
} catch (Exception e) {
- LOGGER.warn("processing of result from search to URI " + searchUri
- + " failed with message " + e.getMessage());
- throw new NexusRestWrapperException(
- "processing of result from query to Nexus failed with message: " + e.getMessage(), e);
+ String message = "processing of result from query to Nexus failed with message: " + e.getMessage();
+ LOGGER.warn(message, e);
+ throw new NexusRestWrapperException(message, e);
}
}
/**
* Get the authorisation header for the user name and password.
- * @param requestBuilder the request builder to add authorization to
+ * @param requestBuilder the request builder to add authorisation to
* @return the authorisation header
*/
private Builder getAuthorizationHeader(Builder requestBuilder) {
if (null != nexusUser && null != nexusPassword) {
String userPassString = nexusUser + ":" + nexusPassword;
requestBuilder.header("Authorization", "Basic "
- + java.util.Base64.getEncoder().encodeToString(userPassString.getBytes()));
+ + java.util.Base64.getEncoder().encodeToString(userPassString.getBytes()));
}
return requestBuilder;
@@ -210,18 +203,18 @@ public class NexusRestWrapper {
NexusRepository repository = repositoryMap.get(artifact.getArtifactHits().get(0).getRepositoryId());
return new StringBuilder()
- .append(repository.getRepositoryUrl())
- .append("/content/")
- .append(artifact.getGroupId().replace('.', '/'))
- .append('/')
- .append(artifact.getArtifactId())
- .append('/')
- .append(artifact.getVersion())
- .append('/')
- .append(artifact.getArtifactId())
- .append('-')
- .append(artifact.getVersion())
- .toString();
+ .append(repository.getRepositoryUrl())
+ .append("/content/")
+ .append(artifact.getGroupId().replace('.', '/'))
+ .append('/')
+ .append(artifact.getArtifactId())
+ .append('/')
+ .append(artifact.getVersion())
+ .append('/')
+ .append(artifact.getArtifactId())
+ .append('-')
+ .append(artifact.getVersion())
+ .toString();
}
/**
diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/NexusRestWrapperTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/NexusRestWrapperTest.java
index 489014e52..bc666fb08 100644
--- a/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/NexusRestWrapperTest.java
+++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/NexusRestWrapperTest.java
@@ -20,7 +20,10 @@
package org.onap.policy.brms.api.nexus;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.List;
@@ -31,22 +34,371 @@ import org.onap.policy.brms.api.nexus.NexusRestWrapperException;
import org.onap.policy.brms.api.nexus.pojo.NexusArtifact;
public class NexusRestWrapperTest {
+ @Test
+ public void testRestWrapperConstructionErrors() throws NexusRestWrapperException {
+ try {
+ new NexusRestWrapper(null, null, null);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("nexusServerUrl must be specified for the Nexus server", e.getMessage());
+ }
+
+ try {
+ new NexusRestWrapper("", null, null);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("nexusServerUrl must be specified for the Nexus server", e.getMessage());
+ }
+
+ try {
+ new NexusRestWrapper(" ", null, null);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("nexusServerUrl must be specified for the Nexus server", e.getMessage());
+ }
+
+ try {
+ new NexusRestWrapper("\n\t", null, null);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("nexusServerUrl must be specified for the Nexus server", e.getMessage());
+ }
+
+ try {
+ new NexusRestWrapper("server", "user", null);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("if either nexusUser or nexusPassword are specified, both must be specified", e.getMessage());
+ }
+
+ try {
+ new NexusRestWrapper("server", null, "pass");
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("if either nexusUser or nexusPassword are specified, both must be specified", e.getMessage());
+ }
+
+ NexusRestWrapper wrapper = new NexusRestWrapper("http://localhost:99999", "user", "pass");
+ assertNotNull(wrapper);
+
+ try {
+ wrapper.findArtifact(null);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("searchParameters may not be null", e.getMessage());
+ }
+
+ try {
+ wrapper.findArtifact(new NexusRestSearchParameters());
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("search parameters have not been set", e.getMessage());
+ }
+
+ try {
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+
+ searchParameters.useFilterSearch("org.onap.policy.engine", null, null, null, null);
+ wrapper.findArtifact(searchParameters);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("search to URI http://localhost:99999/service/local/lucene/search?g=org.onap.policy.engine "
+ + "failed with message: java.lang.IllegalArgumentException: port out of range:99999",
+ e.getMessage());
+ }
+
+ wrapper.close();
+ wrapper = new NexusRestWrapper("http://localhost:57344", "user", "pass");
+
+ try {
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+
+ searchParameters.useFilterSearch("org.onap.policy.engine", null, null, null, null);
+ wrapper.findArtifact(searchParameters);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("search to URI http://localhost:57344/service/local/lucene/search?g=org.onap.policy.engine "
+ + "failed with message: java.net.ConnectException: Connection refused (Connection refused)",
+ e.getMessage());
+ }
+
+ wrapper.close();
+ wrapper = new NexusRestWrapper("https://nexus.onap.org", "user", "pass");
+
+ try {
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+ searchParameters.useFilterSearch("org.onap.policy.engine", null, "", null, null);
+ wrapper.findArtifact(searchParameters);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("search to URI https://nexus.onap.org/service/local/lucene/search?g=org.onap.policy.engine "
+ + "failed, response was: InboundJaxrsResponse{context=ClientResponse{method=GET, "
+ + "uri=https://nexus.onap.org/service/local/lucene/search?g=org.onap.policy.engine, status=401, reason=Unauthorized}}",
+ e.getMessage());
+ }
+
+ try {
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+ searchParameters.useFilterSearch(null, null, null, null, null);
+ wrapper.findArtifact(searchParameters);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("at least one filter parameter must be specified for Nexus filter searches", e.getMessage());
+ }
+
+ try {
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+ searchParameters.useKeywordSearch(null);
+ wrapper.findArtifact(searchParameters);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("keyword must be specified for Nexus keyword searches", e.getMessage());
+ }
+
+ try {
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+ searchParameters.useClassNameSearch(null);
+ wrapper.findArtifact(searchParameters);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("className must be specified for Nexus class name searches", e.getMessage());
+ }
+
+ try {
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+ searchParameters.useChecksumSearch(null);
+ wrapper.findArtifact(searchParameters);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("checksum must be specified for Nexus checksum searches", e.getMessage());
+ }
+
+ try {
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+ searchParameters.useKeywordSearch("BRMSGateway").setRepositoryId(null);
+ wrapper.findArtifact(searchParameters);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("a repositoryId must be specified", e.getMessage());
+ }
+
+ try {
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+ searchParameters.useKeywordSearch("BRMSGateway").setFrom(-1);
+ wrapper.findArtifact(searchParameters);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("from cannot be less than 0 when from is specified", e.getMessage());
+ }
+
+ try {
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+ searchParameters.useKeywordSearch("BRMSGateway").setCount(0);
+ wrapper.findArtifact(searchParameters);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("count cannot be less than 1 when count is specified", e.getMessage());
+ }
+
+ try {
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+ searchParameters.useKeywordSearch("BRMSGateway");
+ searchParameters.getSearchUri(null);
+ fail("test shold throw an exception here");
+ } catch (NexusRestWrapperException e) {
+ assertEquals("nexusServerUrl must be specified for the search URI", e.getMessage());
+ }
+
+ wrapper.close();
+ }
@Test
- public void test() throws NexusRestWrapperException {
- NexusRestWrapper wrapper = new NexusRestWrapper("https://nexus.onap.org");
-
+ public void testGetters() throws NexusRestWrapperException {
NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
- searchParameters.useFilterSearch("org.onap.policy.engine", "BRMSGateway", null, null, null);
- List<NexusArtifact> foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ searchParameters.useKeywordSearch("BRMSGateway");
+ assertEquals(NexusRestSearchParameters.SearchType.KEYWORD, searchParameters.getSearchType());
+ assertEquals(null, searchParameters.getArtifactId());
+ assertEquals(null, searchParameters.getChecksum());
+ assertEquals(null, searchParameters.getClassName());
+ assertEquals(null, searchParameters.getClassifier());
+ assertEquals(-1, searchParameters.getCount());
+ assertEquals(-1, searchParameters.getFrom());
+ assertEquals(null, searchParameters.getGroupId());
+ assertEquals("BRMSGateway", searchParameters.getKeyword());
+ assertEquals(null, searchParameters.getPackagingType());
+ assertEquals(null, searchParameters.getRepositoryId());
+ assertEquals(null, searchParameters.getVersion());
+ searchParameters.useFilterSearch("org.onap.policy.engine", "BRMSGateway",
+ "1.2.3", "jar", "jar-with-dependencies")
+ .setFrom(100).setCount(10).setRepositoryId("repository");
+ assertEquals(NexusRestSearchParameters.SearchType.FILTER, searchParameters.getSearchType());
+ assertEquals("BRMSGateway", searchParameters.getArtifactId());
+ assertEquals(null, searchParameters.getChecksum());
+ assertEquals(null, searchParameters.getClassName());
+ assertEquals("jar-with-dependencies", searchParameters.getClassifier());
+ assertEquals(10, searchParameters.getCount());
+ assertEquals(100, searchParameters.getFrom());
+ assertEquals("org.onap.policy.engine", searchParameters.getGroupId());
+ assertEquals(null, searchParameters.getKeyword());
+ assertEquals("jar", searchParameters.getPackagingType());
+ assertEquals("repository", searchParameters.getRepositoryId());
+ assertEquals("1.2.3", searchParameters.getVersion());
+
+ searchParameters.useClassNameSearch("BRMSGateway");
+ assertEquals(NexusRestSearchParameters.SearchType.CLASS_NAME, searchParameters.getSearchType());
+ assertEquals(null, searchParameters.getArtifactId());
+ assertEquals(null, searchParameters.getChecksum());
+ assertEquals("BRMSGateway", searchParameters.getClassName());
+ assertEquals(null, searchParameters.getClassifier());
+ assertEquals(-1, searchParameters.getCount());
+ assertEquals(-1, searchParameters.getFrom());
+ assertEquals(null, searchParameters.getGroupId());
+ assertEquals(null, searchParameters.getKeyword());
+ assertEquals(null, searchParameters.getPackagingType());
+ assertEquals(null, searchParameters.getRepositoryId());
+ assertEquals(null, searchParameters.getVersion());
+
+ searchParameters.useChecksumSearch("987654321");
+ assertEquals(NexusRestSearchParameters.SearchType.CHECKSUM, searchParameters.getSearchType());
+ assertEquals(null, searchParameters.getArtifactId());
+ assertEquals("987654321", searchParameters.getChecksum());
+ assertEquals(null, searchParameters.getClassName());
+ assertEquals(null, searchParameters.getClassifier());
+ assertEquals(-1, searchParameters.getCount());
+ assertEquals(-1, searchParameters.getFrom());
+ assertEquals(null, searchParameters.getGroupId());
+ assertEquals(null, searchParameters.getKeyword());
+ assertEquals(null, searchParameters.getPackagingType());
+ assertEquals(null, searchParameters.getRepositoryId());
+ assertEquals(null, searchParameters.getVersion());
+ }
+
+ @Test
+ public void testFilterSearch() throws NexusRestWrapperException {
+ NexusRestWrapper wrapper = new NexusRestWrapper("https://nexus.onap.org", null, null);
+
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+
+ searchParameters.useFilterSearch("org.onap.policy.dorothy", null, null, null, null).setCount(1);
+ List<NexusArtifact> foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
assertNotNull(foundArtifactList);
-
- for (NexusArtifact artifact: foundArtifactList) {
- System.out.println(artifact.getUrlPath());
- }
-
+ assertEquals(0, foundArtifactList.size());
+
+ searchParameters.useFilterSearch("org.onap.policy.engine", null, null, null, null).setCount(1);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(1, foundArtifactList.size());
+
+ searchParameters.useFilterSearch("org.onap.policy.engine", null, null, null, null).setFrom(2).setCount(2);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(2, foundArtifactList.size());
+
+ searchParameters.useFilterSearch("org.onap.policy.engine", null, null, null, null).setFrom(2).setCount(2);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(2, foundArtifactList.size());
+
+ searchParameters.useFilterSearch(null, "BRMSGateway", null, null, null);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertTrue(foundArtifactList.size() > 2);
+
+ searchParameters.useFilterSearch(null, null, "1.2.3", null, null).setCount(1);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(1, foundArtifactList.size());
+
+ searchParameters.useFilterSearch("org.onap.policy.engine", null, "1.1.2", null, null).setCount(1);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(1, foundArtifactList.size());
+
+ searchParameters.useFilterSearch("org.onap.policy.engine", "BRMSGateway", "1.1.2", null, null).setCount(1);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(1, foundArtifactList.size());
+
+ searchParameters.useFilterSearch(null, "BRMSGateway", "1.1.2", null, null).setCount(1);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(1, foundArtifactList.size());
+
+ searchParameters.useFilterSearch(null, "BRMSGateway", "1.1.2", "jar", null).setCount(1);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(1, foundArtifactList.size());
+
+ searchParameters.useFilterSearch(null, "BRMSGateway", "1.1.2", "jar", "jar-with-dependencies").setCount(1);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(1, foundArtifactList.size());
+
+ searchParameters.useFilterSearch(null, "BRMSGateway", "1.1.2", "jar", "jar-with-dependencies")
+ .setCount(1).setRepositoryId("releases");
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(1, foundArtifactList.size());
+
+ wrapper.close();
+ }
+
+ @Test
+ public void testKeywordSearch() throws NexusRestWrapperException {
+ NexusRestWrapper wrapper = new NexusRestWrapper("https://nexus.onap.org", null, null);
+
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+
+ searchParameters.useKeywordSearch("TheWizardOfOz").setCount(1);
+ List<NexusArtifact> foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(0, foundArtifactList.size());
+
+ searchParameters.useKeywordSearch("BRMSGateway").setCount(1);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(1, foundArtifactList.size());
+
+ wrapper.close();
+ }
+
+ @Test
+ public void testClassNameSearch() throws NexusRestWrapperException {
+ NexusRestWrapper wrapper = new NexusRestWrapper("https://nexus.onap.org", null, null);
+
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+
+ searchParameters.useClassNameSearch("TheWizardOfOz").setCount(1);
+ List<NexusArtifact> foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(0, foundArtifactList.size());
+
+ searchParameters.useClassNameSearch("BRMSGateway").setCount(1);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(1, foundArtifactList.size());
+
+ wrapper.close();
+ }
+
+ @Test
+ public void testChecksumSearch() throws NexusRestWrapperException {
+ NexusRestWrapper wrapper = new NexusRestWrapper("https://nexus.onap.org", null, null);
+
+ NexusRestSearchParameters searchParameters = new NexusRestSearchParameters();
+
+ searchParameters.useChecksumSearch("99999999999999").setCount(1);
+ List<NexusArtifact> foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(0, foundArtifactList.size());
+
+ searchParameters.useChecksumSearch("914acda2ce67de9b45d599109d6ad8357d01b217").setCount(1);
+ foundArtifactList = wrapper.findArtifact(searchParameters).getArtifactList();
+ assertNotNull(foundArtifactList);
+ assertEquals(1, foundArtifactList.size());
+
wrapper.close();
}
}
diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusArtifactHitTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusArtifactHitTest.java
new file mode 100644
index 000000000..f04884660
--- /dev/null
+++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusArtifactHitTest.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * Copyright (C) 2018 Ericsson Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.brms.api.nexus.pojo;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class NexusArtifactHitTest {
+
+ @Test
+ public void testNexusArtifactHit() {
+ NexusArtifactHit artifactHit = new NexusArtifactHit();
+
+ assertNull(artifactHit.getArtifactLinks());
+ assertNull(artifactHit.getRepositoryId());
+
+ assertNotNull(artifactHit.toString());
+ }
+}
diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusArtifactLinkTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusArtifactLinkTest.java
new file mode 100644
index 000000000..b0ae02e9c
--- /dev/null
+++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusArtifactLinkTest.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * Copyright (C) 2018 Ericsson Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.brms.api.nexus.pojo;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class NexusArtifactLinkTest {
+
+ @Test
+ public void testNexusArtifactLink() {
+ NexusArtifactLink artifactLink = new NexusArtifactLink();
+
+ assertNull(artifactLink.getClassifier());
+ assertNull(artifactLink.getExtension());
+
+ assertNotNull(artifactLink.toString());
+ }
+}
diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusArtifactTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusArtifactTest.java
new file mode 100644
index 000000000..e8ddaabe9
--- /dev/null
+++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusArtifactTest.java
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * Copyright (C) 2018 Ericsson Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.brms.api.nexus.pojo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class NexusArtifactTest {
+
+ @Test
+ public void testNexusArtifact() {
+ NexusArtifact artifact = new NexusArtifact();
+
+ assertNull(artifact.getGroupId());
+ assertNull(artifact.getArtifactId());
+ assertNull(artifact.getVersion());
+ assertNull(artifact.getHighlightedFragment());
+ assertNull(artifact.getLatestRelease());
+ assertNull(artifact.getLatestReleaseRepositoryId());
+ assertNull(artifact.getLatestSnapshot());
+ assertNull(artifact.getLatestSnapshotRepositoryId());
+ assertNull(artifact.getArtifactHits());
+
+ artifact.setUrlPath("urlPath");
+ assertEquals("urlPath", artifact.getUrlPath());
+
+ assertNotNull(artifact.toString());
+ }
+}
diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusRepositoryTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusRepositoryTest.java
new file mode 100644
index 000000000..41f710386
--- /dev/null
+++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusRepositoryTest.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * Copyright (C) 2018 Ericsson Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.brms.api.nexus.pojo;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class NexusRepositoryTest {
+
+ @Test
+ public void testNexusRepository() {
+ NexusRepository repository = new NexusRepository();
+
+ assertNull(repository.getRepositoryId());
+ assertNull(repository.getRepositoryKind());
+ assertNull(repository.getRepositoryContentClass());
+ assertNull(repository.getRepositoryName());
+ assertNull(repository.getRepositoryPolicy());
+ assertNull(repository.getRepositoryUrl());
+
+ assertNotNull(repository.toString());
+ }
+}
diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusSearchResultTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusSearchResultTest.java
new file mode 100644
index 000000000..ba83a3a27
--- /dev/null
+++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/nexus/pojo/NexusSearchResultTest.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * Copyright (C) 2018 Ericsson Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.brms.api.nexus.pojo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class NexusSearchResultTest {
+
+ @Test
+ public void testNexusSearchResult() {
+ NexusSearchResult result = new NexusSearchResult();
+
+ assertNull(result.getArtifactList());
+ assertEquals(0, result.getCount());
+ assertEquals(0, result.getFrom());
+ assertNull(result.getRepoDetailsList());
+ assertEquals(0, result.getTotalCount());
+ assertEquals(false, result.isCollapsed());
+ assertEquals(false, result.isTooManyResults());
+
+ assertNotNull(result.toString());
+ }
+}