2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.ccsdk.apps.controllerblueprints.service.rs;
\r
20 import org.junit.runner.RunWith;
\r
21 import org.junit.runners.MethodSorters;
\r
22 import org.onap.ccsdk.apps.controllerblueprints.TestApplication;
\r
23 import org.onap.ccsdk.apps.controllerblueprints.TestConfiguration;
\r
24 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel;
\r
25 import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils;
\r
26 import org.slf4j.Logger;
\r
27 import org.slf4j.LoggerFactory;
\r
28 import org.springframework.beans.factory.annotation.Autowired;
\r
29 import org.springframework.boot.test.context.SpringBootTest;
\r
30 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
\r
31 import org.springframework.test.context.ContextConfiguration;
\r
32 import org.springframework.test.context.junit4.SpringRunner;
\r
34 import java.util.List;
\r
36 @RunWith(SpringRunner.class)
\r
37 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
\r
38 @ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class})
\r
39 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
\r
40 public class ConfigModelRestTest {
\r
42 private static Logger log = LoggerFactory.getLogger(ConfigModelRestTest.class);
\r
45 ConfigModelRest configModelRest;
\r
47 ConfigModel configModel;
\r
49 String name = "vrr-test";
\r
50 String version = "1.0.0";
\r
53 public void setUp() {
\r
59 public void tearDown() {
\r
64 public void test01getInitialConfigModel() throws Exception {
\r
65 log.info("** test01getInitialConfigModel *****************");
\r
67 String name = "default_netconf";
\r
68 ConfigModel configModel = configModelRest.getInitialConfigModel(name);
\r
69 Assert.assertNotNull("Failed to get Initial Config Model , Return object is Null", configModel);
\r
70 Assert.assertNotNull("Failed to get Service Template Content ", configModel.getConfigModelContents());
\r
76 public void test02SaveServiceTemplate() throws Exception {
\r
77 log.info("************************ test02SaveServiceTemplate ******************");
\r
80 configModel = ConfigModelUtils.getConfigModel("load/blueprints/vrr-test");
\r
82 configModel = configModelRest.saveConfigModel(configModel);
\r
83 Assert.assertNotNull("Failed to ConfigModel, Return object is Null", configModel);
\r
84 Assert.assertNotNull("Failed to ConfigModel Id , Return ID object is Null", configModel.getId());
\r
85 Assert.assertNotNull("Failed to ConfigModel Content, Return object is Null",
\r
86 configModel.getConfigModelContents());
\r
87 Assert.assertEquals("Failed in validation of ConfigModel Content count,", 3,
\r
88 configModel.getConfigModelContents().size());
\r
90 ConfigModel dbconfigModel = configModelRest.getConfigModel(configModel.getId());
\r
92 log.info("************************ test02SaveServiceTemplate-2 ******************");
\r
94 dbconfigModel.getConfigModelContents().remove(2);
\r
95 dbconfigModel = configModelRest.saveConfigModel(dbconfigModel);
\r
96 log.info("Saved Config Model " + configModel.getId());
\r
97 Assert.assertNotNull("Failed to ConfigModel, Return object is Null", dbconfigModel);
\r
98 Assert.assertNotNull("Failed to ConfigModel Id ", dbconfigModel.getId());
\r
99 Assert.assertNotNull("Failed to ConfigModel Content",
\r
100 dbconfigModel.getConfigModelContents());
\r
101 Assert.assertEquals("Failed to Remove the ConfigModel Content,", 2,
\r
102 dbconfigModel.getConfigModelContents().size());
\r
109 public void test03PublishServiceTemplate() throws Exception {
\r
110 log.info("** test03PublishServiceTemplate *****************");
\r
112 ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version);
\r
113 log.info("Publishing Config Model " + configModel.getId());
\r
114 configModel = configModelRest.publishConfigModel(configModel.getId());
\r
115 Assert.assertNotNull("Failed to ConfigModel, Return object is Null", configModel);
\r
116 Assert.assertNotNull("Failed to ConfigModel Id ", configModel.getId());
\r
117 Assert.assertNotNull("Failed to ConfigModel Content", configModel.getConfigModelContents());
\r
118 Assert.assertEquals("Failed to update the publish indicator", "Y", configModel.getPublished());
\r
123 public void test04GetConfigModel() throws Exception {
\r
124 log.info("** test04GetConfigModel *****************");
\r
126 ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version);
\r
127 Assert.assertNotNull("Failed to get ConfigModel for the Name (" + configModel.getArtifactName() + ") and ("
\r
128 + configModel.getArtifactVersion() + ")", configModel);
\r
129 Assert.assertNotNull("Failed to get ConfigModel Id", configModel.getId());
\r
131 configModel = configModelRest.getConfigModel(configModel.getId());
\r
132 Assert.assertNotNull("Failed to get ConfigModel for the Id (" + configModel.getId() + ") ", configModel);
\r
137 public void test05GetCloneConfigModel() throws Exception {
\r
138 log.info("** test05GetCloneConfigModel *****************");
\r
140 ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version);
\r
142 Assert.assertNotNull("Failed to get ConfigModel for the Name (" + configModel.getArtifactName() + ") and ("
\r
143 + configModel.getArtifactVersion() + ")", configModel);
\r
144 Assert.assertNotNull("Failed to get ConfigModel Id", configModel.getId());
\r
146 configModel = configModelRest.getCloneConfigModel(configModel.getId());
\r
147 Assert.assertNotNull("Failed to get ConfigModel for the Id (" + configModel.getId() + ") ", configModel);
\r
152 public void test07SearchConfigModels() throws Exception {
\r
153 log.info("** test07SearchConfigModels *****************");
\r
155 List<ConfigModel> configModels = configModelRest.searchConfigModels("vrr-test");
\r
156 Assert.assertNotNull("Failed to search ConfigModel", configModels);
\r
157 Assert.assertTrue("Failed to search ConfigModel with count", configModels.size() > 0);
\r
158 // update the ServiceModelContent
\r
163 public void test08DeleteConfigModels() throws Exception {
\r
164 log.info("** test08DeleteConfigModels *****************");
\r
166 ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version);
\r
167 configModelRest.deleteConfigModel(configModel.getId());
\r