Added some tools for engine instance management
[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.io.InputStream;
27 import java.io.Reader;
28 import java.math.BigDecimal;
29 import java.net.URL;
30 import java.sql.*;
31 import java.util.Calendar;
32 import java.util.Map;
33
34 import static org.easymock.EasyMock.expect;
35 import static org.hamcrest.core.Is.is;
36 import static org.hamcrest.core.IsEqual.equalTo;
37 import static org.junit.Assert.*;
38
39 @RunWith(PowerMockRunner.class)
40 @PrepareForTest({ResultSet.class})
41 public class EngineEntityMapperTest {
42     private EngineEntityMapper mapper = new EngineEntityMapper();
43     @Test
44     public void map() throws Exception {
45         long lastModified = System.currentTimeMillis();
46         ResultSet rsMock = PowerMock.createMock(ResultSet.class);
47         expect(rsMock.getString("ip")).andReturn("127.0.0.1");
48         expect(rsMock.getInt("port")).andReturn(80);
49         expect(rsMock.getLong("lastmodified")).andReturn(lastModified);
50
51         PowerMock.replay(rsMock);
52
53         EngineEntity entity = mapper.map(0, rsMock, null);
54
55         PowerMock.verify(rsMock);
56
57         assertThat(entity.getId(), equalTo("127.0.0.1_80"));
58         assertThat(entity.getIp(), equalTo("127.0.0.1"));
59         assertThat(entity.getPort(), is(80));
60         assertThat(entity.getLastModified(), is(lastModified));
61     }
62 }