2 * Copyright 2019 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.cli.fw.store;
18 import org.junit.AfterClass;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.onap.cli.fw.cmd.execution.OnapCommandExceutionListCommandTest;
22 import org.onap.cli.fw.error.OnapCommandException;
23 import org.onap.cli.fw.error.OnapCommandPersistProfileFailed;
24 import org.onap.cli.fw.input.cache.OnapCommandParamEntity;
27 import java.util.ArrayList;
28 import java.util.List;
30 import static org.junit.Assert.*;
31 import java.io.IOException;
32 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
34 public class OnapCommandProfileStoreTest {
35 OnapCommandProfileStore onapCommandProfileStore;
38 public void setUp() throws Exception {
39 onapCommandProfileStore = OnapCommandProfileStore.getInstance();
43 public void includeProfileTest() throws OnapCommandException {
44 onapCommandProfileStore.includeProfile("profiles");
45 assertTrue(new File(System.getProperty("user.dir") + File.separator + "data/profiles").exists());
49 public void persistProfileAndgetProfilesTest() throws OnapCommandPersistProfileFailed {
50 OnapCommandParamEntity onapCommandParamEntity = new OnapCommandParamEntity();
51 onapCommandParamEntity.setName("schema-list");
52 onapCommandParamEntity.setProduct("open-cli");
53 onapCommandParamEntity.setValue("value");
54 List<OnapCommandParamEntity> paramEntityList = new ArrayList<>();
55 paramEntityList.add(onapCommandParamEntity);
56 onapCommandProfileStore.persistProfile(paramEntityList, "abc");
57 assertTrue(new File(System.getProperty("user.dir") + File.separator + "data/profiles/abc-profile.json").exists());
58 assertNotNull(onapCommandProfileStore.getProfiles());
62 public void removeProfileTest() {
63 onapCommandProfileStore.removeProfile("abc");
64 assertFalse(new File(System.getProperty("user.dir") + File.separator + "data/profiles/abc-profile.json").exists());
67 public void removeProfileDeleteTest() throws IOException {
68 new File(System.getProperty("user.dir") + File.separator + "data/profiles/abc-profile.json").createNewFile();
69 onapCommandProfileStore.removeProfile("abc");
70 assertFalse(new File(System.getProperty("user.dir") + File.separator + "data/profiles/abc-profile.json").exists());
74 public void addTest() {
75 onapCommandProfileStore.add("abc", "abc", "abc");
76 assertNotNull(onapCommandProfileStore. getParams("abc"));
80 public void getParamsTest() {
81 assertNotNull(onapCommandProfileStore.getParams("abc"));
85 public void removeTest() {
86 assertDoesNotThrow(() -> onapCommandProfileStore.add("abc", "abc", "abc"));
87 assertDoesNotThrow(() -> onapCommandProfileStore.remove("abc","abc"));
91 public static void tearDown() throws Exception {
92 String dirPathForData = System.getProperty("user.dir") + File.separator + "data";
93 File dataDir = new File(dirPathForData);
94 assertTrue(OnapCommandExceutionListCommandTest.deleteDirectory(dataDir));