Newer
Older
pgdsc / src / com / szpg / db / test / PgAcuRdcmdDaoTest.java
admin on 15 Jan 2018 1 KB 2018-01-15修改
package com.szpg.db.test;

import static org.junit.Assert.assertEquals;

import java.util.Calendar;

import org.junit.Before;
import org.junit.Test;

import com.szpg.db.dao.PgAcuRdcmdDao;
import com.szpg.db.dao.impl.PgAcuRdcmdDaoImpl;
import com.szpg.db.data.PgAcuRdcmd;
import com.szpg.plc.message.AppMessageConstants;
import com.szpg.plc.message.command.read.ReadCH4ParamCommand;
import com.szpg.plc.util.ByteUtil;

public class PgAcuRdcmdDaoTest {
	
	private PgAcuRdcmdDao dao;
	
	@Before
	public void init() {
		dao = new PgAcuRdcmdDaoImpl();
	}

//	@Test
	public void testAdd() {
		ReadCH4ParamCommand ch4 = new ReadCH4ParamCommand();
		ch4.setDestinationId("006B00");
		ch4.setMessageProducerId("00F400");
		ch4.setMemoryArea((byte) 0x82);
		ch4.setStartAddress("012C00");
		ch4.setCount(24);
		
		
		PgAcuRdcmd cmd = new PgAcuRdcmd();
		cmd.setId(ch4.getId());
		cmd.setTm(Calendar.getInstance().getTime());
		cmd.setCmd_type(AppMessageConstants.CMD_TYPE_READCH4STATUS);
		cmd.setDest(ch4.getDestinationId());
		cmd.setMem_area_cd(ByteUtil.binToHexString(new byte[] {ch4.getMemoryArea()}));
		cmd.setStart_mem_word(ch4.getStartAddress().substring(0, 4));
		cmd.setStart_mem_bit(ch4.getStartAddress().substring(4));
		cmd.setCount_word(ch4.getCount());
		
		assertEquals(1, dao.addCmdRecord(cmd));
	}

//	@Test
	public void testFindAll() {
		assertEquals(1, dao.findAll());
	}
	
	@Test
	public void testFindByDestAndCount() {
		assertEquals("11", dao.findLatestCmdByDestAndCount("006B00", 24).getCmd_type());
	}
	
	@Test
	public void testUpdateResponsed() {
		assertEquals(1, dao.updateCmdRecordResponsed("23ff9e2987e64f248823254f0dfe1528"));
	}
}