Catalog alignment
[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 fj.data.Either;
24 import junit.framework.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mockito;
28 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
29 import org.openecomp.sdc.be.impl.ComponentsUtils;
30 import org.openecomp.sdc.be.model.DataTypeDefinition;
31 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
32
33 import java.util.HashMap;
34 import java.util.Map;
35
36 import static org.mockito.Mockito.when;
37
38 public class DataTypesServiceTest {
39     ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
40     ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
41
42     DataTypesService dataTypesService = new DataTypesService(componentsUtils);
43     Map<String, DataTypeDefinition> mapreturn = new HashMap<>();
44     JanusGraphOperationStatus janusGraphOperationStatus = JanusGraphOperationStatus.NOT_FOUND;
45     Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes;
46
47     @Before
48     public void setup() {
49         mapreturn.put("Demo",new DataTypeDefinition());
50         allDataTypes = Either.left(mapreturn);
51         when(applicationDataTypeCache.getAll()).thenReturn(allDataTypes);
52
53     }
54
55     @Test
56     public void getAllDataTypes_success() {
57         Assert.assertEquals(true,dataTypesService.getAllDataTypes(applicationDataTypeCache).isLeft());
58     }
59
60     @Test
61     public void getAllDataTypes_failure() {
62         allDataTypes = Either.right(janusGraphOperationStatus);
63         when(applicationDataTypeCache.getAll()).thenReturn(allDataTypes);
64         Assert.assertEquals(true,dataTypesService.getAllDataTypes(applicationDataTypeCache).isRight());
65     }
66
67 }