Revisions made to the Model Loader to use Babel
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / restclient / TestBabelServiceClient.java
1 /**
2  * ============LICENSE_START==========================================
3  * org.onap.aai
4  * ===================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ===================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *        http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  */
21 package org.onap.aai.modelloader.restclient;
22
23 import static org.hamcrest.CoreMatchers.equalTo;
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.junit.Assert.assertThat;
26 import static org.junit.Assert.fail;
27
28 import java.io.IOException;
29 import java.net.URISyntaxException;
30 import java.nio.file.Files;
31 import java.nio.file.Paths;
32 import java.util.List;
33 import java.util.Properties;
34 import org.junit.Ignore;
35 import org.onap.aai.babel.service.data.BabelArtifact;
36 import org.onap.aai.modelloader.config.ModelLoaderConfig;
37 import org.onap.aai.modelloader.restclient.BabelServiceClient;
38
39 /**
40  * Local testing of the Babel service
41  *
42  */
43 public class TestBabelServiceClient {
44
45     // Load properties from src/test/resources
46     protected static String CONFIG_FILE = "model-loader.properties";
47
48     // This test requires a running Babel system. To test locally, annotate with org.junit.Test
49     @Ignore
50     public void testRestClient() throws Exception { // NOSONAR
51         Properties configProperties = new Properties();
52         try {
53             configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
54         } catch (IOException e) {
55             fail();
56         }
57         BabelServiceClient client = new BabelServiceClient(new ModelLoaderConfig(configProperties, "."));
58         List<BabelArtifact> result =
59                 client.postArtifact(readBytesFromFile("compressedArtifacts/service-VscpaasTest-csar.csar"),
60                         "service-Vscpass-Test", "1.0", "Test-Transaction-ID-BabelClient");
61
62         assertThat(result.size(), is(equalTo(3)));
63     }
64
65     private byte[] readBytesFromFile(String resourceFile) throws IOException, URISyntaxException {
66         return Files.readAllBytes(Paths.get(ClassLoader.getSystemResource(resourceFile).toURI()));
67     }
68 }