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 org.testng.annotations.AfterClass;
24 import org.testng.annotations.Test;
25 import org.testng.AssertJUnit;
27 import java.io.IOException;
29 import org.apache.http.client.methods.CloseableHttpResponse;
30 import org.apache.http.client.methods.HttpPost;
31 import org.apache.http.entity.mime.MultipartEntityBuilder;
32 import org.apache.http.entity.mime.content.FileBody;
33 import org.apache.http.impl.client.CloseableHttpClient;
34 import org.apache.http.impl.client.HttpClients;
35 import org.apache.tinkerpop.gremlin.structure.Vertex;
36 import org.openecomp.sdc.ci.tests.api.Urls;
37 import org.openecomp.sdc.ci.tests.config.Config;
38 import org.openecomp.sdc.ci.tests.utils.DbUtils;
39 import org.openecomp.sdc.ci.tests.utils.Utils;
40 import org.openecomp.sdc.ci.tests.utils.DbUtils.TitanState;
42 import fj.data.Either;
44 public class ImportCapabilityTypeCITest {
45 public static final DbUtils DbUtils = new DbUtils();
48 public static void afterClass() {
49 DbUtils.shutDowntitan();
52 static Config config = Config.instance();
54 // private final String IMPORT_CAPABILITY_TYPES_PATH =
55 // "src/test/resources/CI/importResourceTests/import_capabilitiesTypes/";
58 public void testAddingCapabilityTypes() throws IOException {
59 TitanState originalState = DbUtils.getCurrentTitanState();
61 String importResourceDir = config.getImportResourceConfigDir();
63 String capabilityTypes = importResourceDir + File.separator + "capabilityTypesCi.zip";
64 // importCapabilityType("src/test/resources/CI/importResource/capabilityTypesCi.zip");
65 importCapabilityType(capabilityTypes);
66 Either<Vertex, Boolean> eitherVertex = DbUtils.getVertexByUId("tosca.capabilities.Test.Ci");
67 AssertJUnit.assertTrue(eitherVertex.isLeft());
68 DbUtils.restoreToTitanState(originalState);
69 eitherVertex = DbUtils.getVertexByUId("tosca.capabilities.Test.Ci");
70 AssertJUnit.assertTrue(eitherVertex.isRight());
74 public void AddingCapabilityNotFound() throws IOException {
75 TitanState originalState = DbUtils.getCurrentTitanState();
76 String importResourceTestsDir = config.getImportResourceTestsConfigDir();
77 String capabilitiesTests = importResourceTestsDir + File.separator + "capabilityTypesCi.zip";
78 importCapabilityType(capabilitiesTests);
79 Either<Vertex, Boolean> eitherVertex = DbUtils.getVertexByUId("tosca.capabilities.NonExsitingCapability");
80 AssertJUnit.assertTrue(eitherVertex.isRight());
81 DbUtils.restoreToTitanState(originalState);
84 public static Integer importAllCapabilityTypes() throws IOException {
86 String importResourceDir = config.getImportResourceConfigDir() + File.separator + "capabilityTypes.zip";
88 // importCapabilityType("src/test/resources/CI/importResource/capabilityTypes.zip");
89 return importCapabilityType(importResourceDir);
92 private static Integer importCapabilityType(String filePath) throws IOException {
93 Config config = Utils.getConfig();
94 CloseableHttpResponse response = null;
95 MultipartEntityBuilder mpBuilder = MultipartEntityBuilder.create();
97 mpBuilder.addPart("capabilityTypeZip", new FileBody(new File(filePath)));
99 String url = String.format(Urls.IMPORT_CAPABILITY_TYPE, config.getCatalogBeHost(), config.getCatalogBePort());
101 CloseableHttpClient client = HttpClients.createDefault();
103 HttpPost httpPost = new HttpPost(url);
104 httpPost.addHeader("USER_ID", "jh0003");
105 httpPost.setEntity(mpBuilder.build());
106 response = client.execute(httpPost);
107 return response.getStatusLine().getStatusCode();
109 closeResponse(response);
110 closeHttpClient(client);
115 private static void closeHttpClient(CloseableHttpClient client) {
117 if (client != null) {
120 } catch (IOException e) {
121 System.out.println("failed to close client or response: " + e.getMessage());
125 private static void closeResponse(CloseableHttpResponse response) {
127 if (response != null) {
130 } catch (IOException e) {
131 System.out.println("failed to close client or response: " + e.getMessage());