Retrieve data types based on component model
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / DataTypesServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. 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
21 package org.openecomp.sdc.be.components.impl;
22
23 import static org.mockito.Mockito.when;
24
25 import fj.data.Either;
26 import java.util.HashMap;
27 import java.util.Map;
28 import junit.framework.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mockito;
32 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
33 import org.openecomp.sdc.be.impl.ComponentsUtils;
34 import org.openecomp.sdc.be.model.DataTypeDefinition;
35 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
36
37 public class DataTypesServiceTest {
38     ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
39     ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
40
41     DataTypesService dataTypesService = new DataTypesService(componentsUtils);
42     Map<String, DataTypeDefinition> mapreturn = new HashMap<>();
43     JanusGraphOperationStatus janusGraphOperationStatus = JanusGraphOperationStatus.NOT_FOUND;
44     Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes;
45
46     @Before
47     public void setup() {
48         mapreturn.put("Demo",new DataTypeDefinition());
49         allDataTypes = Either.left(mapreturn);
50         when(applicationDataTypeCache.getAll(null)).thenReturn(allDataTypes);
51
52     }
53
54     @Test
55     public void getAllDataTypes_success() {
56         Assert.assertEquals(true,dataTypesService.getAllDataTypes(applicationDataTypeCache).isLeft());
57     }
58
59     @Test
60     public void getAllDataTypes_failure() {
61         allDataTypes = Either.right(janusGraphOperationStatus);
62         when(applicationDataTypeCache.getAll(null)).thenReturn(allDataTypes);
63         Assert.assertEquals(true,dataTypesService.getAllDataTypes(applicationDataTypeCache).isRight());
64     }
65
66 }