2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 package org.openecomp.mso.requestsdb;
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;
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;
43 public class WatchdogServiceModVerIdLookupDbTest {
45 private AbstractSessionFactoryManager sessionFactoryRequest;
47 private SessionFactory sessionFactory;
49 private Session session;
52 public ExpectedException thrown = ExpectedException.none();
56 MockitoAnnotations.initMocks(this);
57 when(sessionFactory.openSession()).thenReturn(session);
58 when(sessionFactoryRequest.getSessionFactory()).thenReturn(sessionFactory);
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"));
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);
82 wds.insertWatchdogServiceModVerIdLookup("myId", "myModelVersion");