2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.it.dao.model;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
29 import com.google.gson.Gson;
30 import com.google.gson.GsonBuilder;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.onap.clamp.clds.Application;
37 import org.onap.clamp.dao.LoopsRepository;
38 import org.onap.clamp.dao.model.LogType;
39 import org.onap.clamp.dao.model.Loop;
40 import org.onap.clamp.dao.model.LoopLog;
41 import org.onap.clamp.dao.model.LoopState;
42 import org.onap.clamp.dao.model.MicroServicePolicy;
43 import org.onap.clamp.dao.model.OperationalPolicy;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.boot.test.context.SpringBootTest;
46 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
48 @RunWith(SpringJUnit4ClassRunner.class)
49 @SpringBootTest(classes = Application.class)
50 public class LoopItCase {
53 private LoopsRepository loopRepository;
56 public void DecodeEncodeTest() {
57 Loop loopTest = new Loop();
58 loopTest.setName("ClosedLoopTest");
59 loopTest.setSvgRepresentation("representation");
60 loopTest.setBlueprint("blueprint");
61 loopTest.setGlobalPropertiesJson(new Gson().fromJson("{\"testName\":\"testValue\"}", Map.class));
62 loopTest.setLastComputedState(LoopState.DESIGN);
63 loopTest.setBlueprint("yaml");
65 OperationalPolicy opPolicy = new OperationalPolicy();
66 opPolicy.setName("OpPolicyTest");
67 opPolicy.setConfigurationsJson(new Gson().fromJson("{\"testname\":\"testvalue\"}", Map.class));
68 opPolicy.setLoop(loopTest);
69 loopTest.addOperationalPolicy(opPolicy);
71 MicroServicePolicy µService = new MicroServicePolicy();
72 µService.setJsonRepresentation(new Gson().fromJson("{\"testrepresentation\":\"value\"}", Map.class));
73 µService.setPolicyTosca("tosca");
74 µService.setProperties(new Gson().fromJson("{\"testparam\":\"testvalue\"}", Map.class));
75 µService.setShared(true);
77 µService.setName("ConfigPolicyTest");
78 loopTest.addMicroServicePolicy(µService);
80 LoopLog log = new LoopLog();
81 log.setLogType(LogType.INFO);
82 log.setMessage("test message");
86 Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create();
87 String json = gson.toJson(loopTest);
89 Loop loopTestDecoded = gson.fromJson(json, Loop.class);
90 assertNotNull(loopTestDecoded);
91 Loop loop = gson.fromJson(json, Loop.class);
94 Loop loopInDb = loopRepository.save(loopTest);
95 assertNotNull(loopInDb);
96 assertTrue(loopRepository.findById(loopInDb.getName()).get().getName().equals("ClosedLoopTest"));