2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Huawei Technologies Co., Ltd.
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============================================
19 * ===================================================================
23 package org.onap.clamp.loop;
25 import static org.assertj.core.api.Assertions.assertThat;
27 import com.google.gson.JsonObject;
29 import javax.transaction.Transactional;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.onap.clamp.clds.Application;
33 import org.onap.clamp.clds.util.JsonUtils;
34 import org.onap.clamp.loop.log.LogType;
35 import org.onap.clamp.loop.log.LoopLog;
36 import org.onap.clamp.loop.log.LoopLogService;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.boot.test.context.SpringBootTest;
39 import org.springframework.test.context.junit4.SpringRunner;
41 @RunWith(SpringRunner.class)
42 @SpringBootTest(classes = Application.class)
43 public class LoopLogServiceTestItCase {
45 private static final String EXAMPLE_LOOP_NAME = "ClosedLoopTest";
46 private static final String EXAMPLE_JSON = "{\"testName\":\"testValue\"}";
47 private static final String CLAMP_COMPONENT = "CLAMP";
48 private static final String SAMPLE_LOG_MESSAGE = "Sample log";
49 private static final String BLUEPRINT = "blueprint";
52 LoopService loopService;
55 LoopsRepository loopsRepository;
58 LoopLogService loopLogService;
60 private void saveTestLoopToDb() {
61 Loop testLoop = new Loop(EXAMPLE_LOOP_NAME);
62 testLoop.setGlobalPropertiesJson(JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
63 loopService.saveOrUpdateLoop(testLoop);
68 public void testAddLog() {
70 Loop loop = loopService.getLoop(EXAMPLE_LOOP_NAME);
71 loopLogService.addLog(SAMPLE_LOG_MESSAGE, "INFO", loop);
72 Set<LoopLog> loopLogs = loop.getLoopLogs();
73 assertThat(loopLogs).hasSize(1);
74 LoopLog loopLog = loopLogs.iterator().next();
75 assertThat(loopLog.getMessage()).isEqualTo(SAMPLE_LOG_MESSAGE);
80 public void testLoopLog() {
81 LoopLog log = new LoopLog();
82 Long id = Long.valueOf(100);
84 log.setLogComponent(CLAMP_COMPONENT);
85 log.setLogType(LogType.INFO);
86 log.setMessage(SAMPLE_LOG_MESSAGE);
87 Loop testLoop = new Loop(EXAMPLE_LOOP_NAME);
88 log.setLoop(testLoop);
89 assertThat(log.getMessage()).isEqualTo(SAMPLE_LOG_MESSAGE);
90 assertThat(log.getLogType()).isEqualTo(LogType.INFO);
91 assertThat(log.getLogComponent()).isEqualTo(CLAMP_COMPONENT);
92 assertThat(log.getId()).isEqualTo(id);
93 assertThat(log.getLoop()).isEqualTo(testLoop);