Merge "Reorder modifiers"
[so.git] / mso-api-handlers / mso-requests-db / src / test / java / org / openecomp / mso / requestsdb / WatchdogServiceModVerIdLookupDbTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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 /**
22  * 
23  */
24 package org.openecomp.mso.requestsdb;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.mockito.Matchers.any;
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.when;
30
31 import org.hibernate.Query;
32 import org.hibernate.Session;
33 import org.hibernate.SessionFactory;
34 import org.junit.Before;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.rules.ExpectedException;
38 import org.mockito.Mock;
39 import org.mockito.MockitoAnnotations;
40 import org.openecomp.mso.db.AbstractSessionFactoryManager;
41
42
43 public class WatchdogServiceModVerIdLookupDbTest {
44         @Mock
45         private AbstractSessionFactoryManager sessionFactoryRequest;
46         @Mock
47         private SessionFactory sessionFactory;
48         @Mock
49         private Session session;
50
51         @Rule
52         public ExpectedException thrown = ExpectedException.none();
53
54         @Before
55         public void setUp() {
56                 MockitoAnnotations.initMocks(this);
57                 when(sessionFactory.openSession()).thenReturn(session);
58                 when(sessionFactoryRequest.getSessionFactory()).thenReturn(sessionFactory);
59
60         }
61         
62         @Test
63         public void getWatchdogServiceModVerIdTest() {
64                 WatchdogServiceModVerIdLookupDb wds = new WatchdogServiceModVerIdLookupDb(this.sessionFactoryRequest);
65                 Query mockQuery = mock(Query.class);
66                 when(session.createQuery(any(String.class))).thenReturn(mockQuery);
67                 when(mockQuery.uniqueResult()).thenReturn(null);
68                 when(session.isOpen()).thenReturn(true);
69                 assertEquals(null, wds.getWatchdogServiceModVerId("test"));
70         }
71         
72         @Test
73         public void insertWatchdogServiceModVerIdLookupTest() {
74                 WatchdogServiceModVerIdLookupDb wds = new WatchdogServiceModVerIdLookupDb(this.sessionFactoryRequest);
75                 Query mockQuery = mock(Query.class);
76                 when(session.createQuery(any(String.class))).thenReturn(mockQuery);
77                 when(mockQuery.uniqueResult()).thenReturn(null);
78                 when(session.isOpen()).thenReturn(true);
79                 when(session.getTransaction()).thenThrow(Exception.class);
80                 thrown.expect(Exception.class);
81                 
82                 wds.insertWatchdogServiceModVerIdLookup("myId", "myModelVersion");
83         }
84
85         
86 }