2 * Copyright 2020 ZTE Corporation.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.holmes.common.engine.dao;
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;
26 import java.io.InputStream;
27 import java.io.Reader;
28 import java.math.BigDecimal;
31 import java.util.Calendar;
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.*;
39 @RunWith(PowerMockRunner.class)
40 @PrepareForTest({ResultSet.class})
41 public class EngineEntityMapperTest {
42 private EngineEntityMapper mapper = new EngineEntityMapper();
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);
51 PowerMock.replay(rsMock);
53 EngineEntity entity = mapper.map(0, rsMock, null);
55 PowerMock.verify(rsMock);
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));