Fixed MSB Registration Failure
[holmes/common.git] / holmes-actions / src / test / java / org / onap / holmes / common / engine / dao / EngineEntityMapperTest.java
1 /**
2  * Copyright 2020 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.holmes.common.engine.dao;
18
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.onap.holmes.common.engine.entity.EngineEntity;
22 import org.powermock.api.easymock.PowerMock;
23 import org.powermock.core.classloader.annotations.PrepareForTest;
24 import org.powermock.modules.junit4.PowerMockRunner;
25
26 import java.sql.ResultSet;
27
28 import static org.easymock.EasyMock.expect;
29 import static org.hamcrest.core.Is.is;
30 import static org.hamcrest.core.IsEqual.equalTo;
31 import static org.junit.Assert.assertThat;
32
33 @RunWith(PowerMockRunner.class)
34 @PrepareForTest({ResultSet.class})
35 public class EngineEntityMapperTest {
36     private EngineEntityMapper mapper = new EngineEntityMapper();
37     @Test
38     public void map() throws Exception {
39         long lastModified = System.currentTimeMillis();
40         ResultSet rsMock = PowerMock.createMock(ResultSet.class);
41         expect(rsMock.getString("ip")).andReturn("127.0.0.1");
42         expect(rsMock.getInt("port")).andReturn(80);
43         expect(rsMock.getLong("lastmodified")).andReturn(lastModified);
44
45         PowerMock.replay(rsMock);
46
47         EngineEntity entity = mapper.map(0, rsMock, null);
48
49         PowerMock.verify(rsMock);
50
51         assertThat(entity.getId(), equalTo("127.0.0.1_80"));
52         assertThat(entity.getIp(), equalTo("127.0.0.1"));
53         assertThat(entity.getPort(), is(80));
54         assertThat(entity.getLastModified(), is(lastModified));
55     }
56 }