2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.execute.TODO;
23 import fj.data.Either;
24 import org.apache.http.client.methods.CloseableHttpResponse;
25 import org.apache.http.client.methods.HttpPost;
26 import org.apache.http.entity.mime.MultipartEntityBuilder;
27 import org.apache.http.entity.mime.content.FileBody;
28 import org.apache.http.impl.client.CloseableHttpClient;
29 import org.apache.http.impl.client.HttpClients;
30 import org.apache.tinkerpop.gremlin.structure.Vertex;
31 import org.openecomp.sdc.ci.tests.api.Urls;
32 import org.openecomp.sdc.ci.tests.config.Config;
33 import org.openecomp.sdc.ci.tests.utils.DbUtils;
34 import org.openecomp.sdc.ci.tests.utils.DbUtils.TitanState;
35 import org.openecomp.sdc.ci.tests.utils.Utils;
36 import org.testng.AssertJUnit;
37 import org.testng.annotations.AfterClass;
38 import org.testng.annotations.Test;
41 import java.io.IOException;
43 public class ImportCapabilityTypeCITest {
44 public static final DbUtils DbUtils = new DbUtils();
47 public static void afterClass() {
48 DbUtils.shutDowntitan();
51 static Config config = Config.instance();
53 // private final String IMPORT_CAPABILITY_TYPES_PATH =
54 // "src/test/resources/CI/importResourceTests/import_capabilitiesTypes/";
57 public void testAddingCapabilityTypes() throws IOException {
58 TitanState originalState = DbUtils.getCurrentTitanState();
60 String importResourceDir = config.getImportResourceConfigDir();
62 String capabilityTypes = importResourceDir + File.separator + "capabilityTypesCi.zip";
63 // importCapabilityType("src/test/resources/CI/importResource/capabilityTypesCi.zip");
64 importCapabilityType(capabilityTypes);
65 Either<Vertex, Boolean> eitherVertex = DbUtils.getVertexByUId("tosca.capabilities.Test.Ci");
66 AssertJUnit.assertTrue(eitherVertex.isLeft());
67 DbUtils.restoreToTitanState(originalState);
68 eitherVertex = DbUtils.getVertexByUId("tosca.capabilities.Test.Ci");
69 AssertJUnit.assertTrue(eitherVertex.isRight());
73 public void AddingCapabilityNotFound() throws IOException {
74 TitanState originalState = DbUtils.getCurrentTitanState();
75 String importResourceTestsDir = config.getImportResourceTestsConfigDir();
76 String capabilitiesTests = importResourceTestsDir + File.separator + "capabilityTypesCi.zip";
77 importCapabilityType(capabilitiesTests);
78 Either<Vertex, Boolean> eitherVertex = DbUtils.getVertexByUId("tosca.capabilities.NonExsitingCapability");
79 AssertJUnit.assertTrue(eitherVertex.isRight());
80 DbUtils.restoreToTitanState(originalState);
83 public static Integer importAllCapabilityTypes() throws IOException {
85 String importResourceDir = config.getImportResourceConfigDir() + File.separator + "capabilityTypes.zip";
87 // importCapabilityType("src/test/resources/CI/importResource/capabilityTypes.zip");
88 return importCapabilityType(importResourceDir);
91 private static Integer importCapabilityType(String filePath) throws IOException {
92 Config config = Utils.getConfig();
93 CloseableHttpResponse response = null;
94 MultipartEntityBuilder mpBuilder = MultipartEntityBuilder.create();
96 mpBuilder.addPart("capabilityTypeZip", new FileBody(new File(filePath)));
98 String url = String.format(Urls.IMPORT_CAPABILITY_TYPE, config.getCatalogBeHost(), config.getCatalogBePort());
100 CloseableHttpClient client = HttpClients.createDefault();
102 HttpPost httpPost = new HttpPost(url);
103 httpPost.addHeader("USER_ID", "jh0003");
104 httpPost.setEntity(mpBuilder.build());
105 response = client.execute(httpPost);
106 return response.getStatusLine().getStatusCode();
108 closeResponse(response);
109 closeHttpClient(client);
114 private static void closeHttpClient(CloseableHttpClient client) {
116 if (client != null) {
119 } catch (IOException e) {
120 System.out.println("failed to close client or response: " + e.getMessage());
124 private static void closeResponse(CloseableHttpResponse response) {
126 if (response != null) {
129 } catch (IOException e) {
130 System.out.println("failed to close client or response: " + e.getMessage());