aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypesServiceTest.java
blob: 5cf3ef3a95fde1a99bc21a0a68bf027188107bed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package org.openecomp.sdc.be.components.impl;

import fj.data.Either;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import org.mockito.Mockito;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;


import java.util.HashMap;
import java.util.Map;

public class DataTypesServiceTest {
    ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
    ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);

    DataTypesService dataTypesService = new DataTypesService(componentsUtils);
    Map<String, DataTypeDefinition> mapreturn = new HashMap<>();
    TitanOperationStatus titanOperationStatus = TitanOperationStatus.NOT_FOUND;
    Either<Map<String, DataTypeDefinition>, TitanOperationStatus> allDataTypes;

    @Before
    public void setup() {
        mapreturn.put("Demo",new DataTypeDefinition());
        allDataTypes = Either.left(mapreturn);
        when(applicationDataTypeCache.getAll()).thenReturn(allDataTypes);

    }

    @Test
    public void getAllDataTypes_success() {
        Assert.assertEquals(true,dataTypesService.getAllDataTypes(applicationDataTypeCache).isLeft());
    }

    @Test
    public void getAllDataTypes_failure() {
        allDataTypes = Either.right(titanOperationStatus);
        when(applicationDataTypeCache.getAll()).thenReturn(allDataTypes);
        Assert.assertEquals(true,dataTypesService.getAllDataTypes(applicationDataTypeCache).isRight());
    }

}