2 * ============LICENSE_START=======================================================
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
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=========================================================
20 package org.openecomp.sdc.externalupload.utils;
22 import org.junit.Test;
25 import java.util.Optional;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertNotEquals;
30 import static org.junit.Assert.assertTrue;
32 public class ServiceUtilsTest {
34 private static final String INVALID_MODEL = "Invalid model";
35 private static final String OBJ_1 = "obj1";
36 private static final String PROP = "prop";
39 public void shouldCreateObjectUsingSetters() throws Exception {
40 TestModel testModel = getTestModel();
41 Optional<TestModel> objectUsingSetters = ServiceUtils.createObjectUsingSetters(testModel, TestModel.class);
42 assertNotEquals(objectUsingSetters.orElseThrow(() -> new Exception(INVALID_MODEL)), testModel);
43 assertEquals(objectUsingSetters.orElseThrow(() -> new Exception(INVALID_MODEL)).getProp(), testModel.getProp());
47 public void shouldGetObjectAsMap() {
48 TestModel testModel = getTestModel();
49 Map<String, Object> objectAsMap = ServiceUtils.getObjectAsMap(testModel);
50 assertEquals(objectAsMap.size(), 1);
51 assertEquals(objectAsMap.get(PROP), OBJ_1);
55 public void shouldGetClassFieldNames() {
56 Set<String> classFieldNames = ServiceUtils.getClassFieldNames(TestModel.class);
57 assertTrue(classFieldNames.contains(PROP));
60 private TestModel getTestModel() {
61 TestModel testModel = new TestModel();
62 testModel.setProp(OBJ_1);