Increased code coverage using junits
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / externalupload / utils / ServiceUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. All rights reserved.
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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  */
20 package org.openecomp.sdc.externalupload.utils;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotEquals;
24 import static org.junit.Assert.assertTrue;
25
26 import java.util.Map;
27 import java.util.Optional;
28 import java.util.Set;
29 import org.junit.Test;
30
31 public class ServiceUtilsTest {
32
33     private static final String INVALID_MODEL = "Invalid model";
34     private static final String OBJ_1 = "obj1";
35     private static final String PROP = "prop";
36
37     @Test
38     public void shouldCreateObjectUsingSetters() throws Exception {
39         TestModel testModel = getTestModel();
40         Optional<TestModel> objectUsingSetters = ServiceUtils.createObjectUsingSetters(testModel, TestModel.class);
41         assertNotEquals(objectUsingSetters.orElseThrow(() -> new Exception(INVALID_MODEL)), testModel);
42         assertEquals(objectUsingSetters.orElseThrow(() -> new Exception(INVALID_MODEL)).getProp(), testModel.getProp());
43     }
44
45     @Test
46     public void shouldGetObjectAsMap() {
47         TestModel testModel = getTestModel();
48         Map<String, Object> objectAsMap = ServiceUtils.getObjectAsMap(testModel);
49         assertEquals(1, objectAsMap.size());
50         assertEquals(OBJ_1, objectAsMap.get(PROP));
51     }
52
53     @Test
54     public void shouldGetClassFieldNames() {
55         Set<String> classFieldNames = ServiceUtils.getClassFieldNames(TestModel.class);
56         assertTrue(classFieldNames.contains(PROP));
57     }
58
59     private TestModel getTestModel() {
60         TestModel testModel = new TestModel();
61         testModel.setProp(OBJ_1);
62         return testModel;
63     }
64
65 }