+ @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();
+ }