Added oparent to sdc main
[sdc.git] / asdctool / src / test / java / org / openecomp / sdc / asdctool / impl / VrfObjectFixHandlerTest.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.asdctool.impl;
22
23 import fj.data.Either;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.Mockito;
28 import org.mockito.junit.MockitoJUnitRunner;
29 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
30 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
31 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
32
33 import static org.assertj.core.api.Assertions.assertThat;
34 import static org.mockito.ArgumentMatchers.anyMap;
35 import static org.mockito.ArgumentMatchers.eq;
36 import static org.mockito.Mockito.when;
37
38 @RunWith(MockitoJUnitRunner.class)
39 public class VrfObjectFixHandlerTest {
40
41     private JanusGraphDao janusGraphDao;
42
43     private VrfObjectFixHandler vrfObjectFixHandler;
44
45     @Before
46     public void init(){
47         janusGraphDao = Mockito.mock(JanusGraphDao.class);
48         vrfObjectFixHandler = new VrfObjectFixHandler(janusGraphDao);
49     }
50
51     @Test
52     public void handleInvalidModeTest(){
53         assertThat(vrfObjectFixHandler.handle("invalid mode", null)).isFalse();
54     }
55
56     @Test
57     public void handleDetectNotFoundTest(){
58         when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap())).thenReturn(Either.right(
59             JanusGraphOperationStatus.NOT_FOUND));
60         assertThat(vrfObjectFixHandler.handle("detect", null)).isTrue();
61     }
62
63     @Test
64     public void handleDetectJanusGraphNotConnectedTest(){
65         when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap())).thenReturn(Either.right(
66             JanusGraphOperationStatus.NOT_CONNECTED));
67         assertThat(vrfObjectFixHandler.handle("detect", null)).isFalse();
68     }
69
70     @Test
71     public void handleFixNotFoundTest(){
72         when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap())).thenReturn(Either.right(
73             JanusGraphOperationStatus.NOT_FOUND));
74         assertThat(vrfObjectFixHandler.handle("fix", null)).isTrue();
75     }
76
77     @Test
78     public void handleFixNotCreatedTest(){
79         when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap())).thenReturn(Either.right(
80             JanusGraphOperationStatus.NOT_CREATED));
81         assertThat(vrfObjectFixHandler.handle("fix", null)).isFalse();
82     }
83
84 }