X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Frestclient%2FTestAaiRestClient.java;h=97b30f54a4bf135e99e990dc8873d19c614886f8;hb=refs%2Fchanges%2F27%2F67227%2F1;hp=d3dab2e2e504d9dad8c94c0100285580da30be4f;hpb=7b1f813441f94261f43ec4f5bb0944ad2570fbdf;p=aai%2Fmodel-loader.git diff --git a/src/test/java/org/onap/aai/modelloader/restclient/TestAaiRestClient.java b/src/test/java/org/onap/aai/modelloader/restclient/TestAaiRestClient.java index d3dab2e..97b30f5 100644 --- a/src/test/java/org/onap/aai/modelloader/restclient/TestAaiRestClient.java +++ b/src/test/java/org/onap/aai/modelloader/restclient/TestAaiRestClient.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * Copyright © 2017-2018 European Software Marketing Ltd. + * ================================================================================ * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.restclient; @@ -31,14 +31,11 @@ import java.util.stream.IntStream; import java.util.stream.Stream; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import org.junit.Ignore; import org.onap.aai.modelloader.config.ModelLoaderConfig; +import org.onap.aai.modelloader.entity.ArtifactType; import org.onap.aai.modelloader.entity.model.ModelArtifact; import org.onap.aai.modelloader.entity.model.ModelArtifactParser; -import org.onap.aai.modelloader.restclient.AaiRestClient; -import org.onap.aai.modelloader.entity.ArtifactType; import org.onap.aai.restclient.client.OperationResult; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -46,25 +43,21 @@ import org.w3c.dom.NodeList; public class TestAaiRestClient { + private static final String MODEL_FILE = "src/test/resources/models/l3-network-widget.xml"; + // This test requires a running A&AI system. To test locally, annotate with org.junit.Test - @Ignore public void testRestClient() throws Exception { - final String MODEL_FILE = "src/test/resources/models/l3-network-widget.xml"; - Properties props = new Properties(); props.setProperty("ml.distribution.ARTIFACT_TYPES", "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG"); props.setProperty("ml.aai.BASE_URL", "https://localhost:8443"); props.setProperty("ml.aai.MODEL_URL", "/aai/v9/service-design-and-creation/models/model/"); - props.setProperty("ml.aai.KEYSTORE_FILE", "aai-client-cert.p12"); - props.setProperty("ml.aai.KEYSTORE_PASSWORD", "OBF:1i9a1u2a1unz1lr61wn51wn11lss1unz1u301i6o"); ModelLoaderConfig config = new ModelLoaderConfig(props, "."); File xmlFile = new File(MODEL_FILE); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); - Document doc = dBuilder.parse(xmlFile); + Document doc = dbFactory.newDocumentBuilder().parse(xmlFile); NodeList nodesList = doc.getDocumentElement().getChildNodes(); @@ -98,16 +91,16 @@ public class TestAaiRestClient { // GET model OperationResult opResult = - aaiClient.getResource(getURL(model, config), "example-trans-id-0", MediaType.APPLICATION_XML_TYPE); + aaiClient.getResource(getUrl(model, config), "example-trans-id-0", MediaType.APPLICATION_XML_TYPE); assertTrue(opResult.getResultCode() == Response.Status.NOT_FOUND.getStatusCode()); // PUT the model - opResult = aaiClient.putResource(getURL(model, config), model.getPayload(), "example-trans-id-1", + opResult = aaiClient.putResource(getUrl(model, config), model.getPayload(), "example-trans-id-1", MediaType.APPLICATION_XML_TYPE); assertTrue(opResult.getResultCode() == Response.Status.CREATED.getStatusCode()); // DELETE the model - opResult = aaiClient.getAndDeleteResource(getURL(model, config), "example-trans-id-3"); + opResult = aaiClient.getAndDeleteResource(getUrl(model, config), "example-trans-id-3"); assertTrue(opResult.getResultCode() == Response.Status.NO_CONTENT.getStatusCode()); } catch (Exception e) { e.printStackTrace(); @@ -123,27 +116,27 @@ public class TestAaiRestClient { return new String(encoded); } - private String getURL(ModelArtifact model, ModelLoaderConfig config) { - String baseURL = config.getAaiBaseUrl().trim(); - String subURL = null; + private String getUrl(ModelArtifact model, ModelLoaderConfig config) { + String subUrl; if (model.getType().equals(ArtifactType.MODEL)) { - subURL = config.getAaiModelUrl(model.getModelNamespaceVersion()).trim(); + subUrl = config.getAaiModelUrl(model.getModelNamespaceVersion()).trim(); } else { - subURL = config.getAaiNamedQueryUrl(model.getModelNamespaceVersion()).trim(); + subUrl = config.getAaiNamedQueryUrl(model.getModelNamespaceVersion()).trim(); } - if ((!baseURL.endsWith("/")) && (!subURL.startsWith("/"))) { - baseURL = baseURL + "/"; + String baseUrl = config.getAaiBaseUrl().trim(); + if (!baseUrl.endsWith("/") && !subUrl.startsWith("/")) { + baseUrl = baseUrl + "/"; } - if (baseURL.endsWith("/") && subURL.startsWith("/")) { - baseURL = baseURL.substring(0, baseURL.length() - 1); + if (baseUrl.endsWith("/") && subUrl.startsWith("/")) { + baseUrl = baseUrl.substring(0, baseUrl.length() - 1); } - if (!subURL.endsWith("/")) { - subURL = subURL + "/"; + if (!subUrl.endsWith("/")) { + subUrl = subUrl + "/"; } - return baseURL + subURL + model.getModelInvariantId(); + return baseUrl + subUrl + model.getModelInvariantId(); } }