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;
31 import javax.transaction.Transactional;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.onap.clamp.clds.Application;
36 import org.onap.clamp.clds.util.JsonUtils;
37 import org.onap.clamp.loop.log.LogType;
38 import org.onap.clamp.loop.log.LoopLog;
39 import org.onap.clamp.loop.log.LoopLogService;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.boot.test.context.SpringBootTest;
42 import org.springframework.test.context.junit4.SpringRunner;
44 @RunWith(SpringRunner.class)
45 @SpringBootTest(classes = Application.class)
46 public class LoopLogServiceTestItCase {
48 private static final String EXAMPLE_LOOP_NAME = "ClosedLoopTest";
49 private static final String EXAMPLE_JSON = "{\"testName\":\"testValue\"}";
50 private static final String CLAMP_COMPONENT = "CLAMP";
51 private static final String SAMPLE_LOG_MESSAGE = "Sample log";
52 private static final String BLUEPRINT = "blueprint";
53 private static final String SVG_REPRESENTATION = "representation";
56 LoopService loopService;
59 LoopsRepository loopsRepository;
62 LoopLogService loopLogService;
64 private void saveTestLoopToDb() {
65 Loop testLoop = new Loop(EXAMPLE_LOOP_NAME, SVG_REPRESENTATION);
66 testLoop.setGlobalPropertiesJson(JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
67 loopService.saveOrUpdateLoop(testLoop);
72 public void testAddLog() {
74 Loop loop = loopService.getLoop(EXAMPLE_LOOP_NAME);
75 loopLogService.addLog(SAMPLE_LOG_MESSAGE, "INFO", loop);
76 Set<LoopLog> loopLogs = loop.getLoopLogs();
77 assertThat(loopLogs).hasSize(1);
78 LoopLog loopLog = loopLogs.iterator().next();
79 assertThat(loopLog.getMessage()).isEqualTo(SAMPLE_LOG_MESSAGE);
84 public void testLoopLog() {
85 LoopLog log = new LoopLog();
86 Long id = Long.valueOf(100);
88 log.setLogComponent(CLAMP_COMPONENT);
89 log.setLogType(LogType.INFO);
90 log.setMessage(SAMPLE_LOG_MESSAGE);
91 Loop testLoop = new Loop(EXAMPLE_LOOP_NAME, SVG_REPRESENTATION);
92 log.setLoop(testLoop);
93 assertThat(log.getMessage()).isEqualTo(SAMPLE_LOG_MESSAGE);
94 assertThat(log.getLogType()).isEqualTo(LogType.INFO);
95 assertThat(log.getLogComponent()).isEqualTo(CLAMP_COMPONENT);
96 assertThat(log.getId()).isEqualTo(id);
97 assertThat(log.getLoop()).isEqualTo(testLoop);