use of com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO in project ma-modules-public by infiniteautomation.
the class DataSourceFunctionalTests method testAdminUpdate.
/**
* Test udpating a mock data source
*/
public void testAdminUpdate() {
DataSourceVO ds = DataSourceTestData.mockDataSource();
when(dataSourceDao.getByXid(ds.getXid())).thenReturn(ds);
User adminUser = UserTestData.adminUser();
ObjectWriter writer = this.objectMapper.writerWithView(JsonViews.Test.class);
try {
String userJson = writer.writeValueAsString(new MockDataSourceModel((MockDataSourceVO) ds));
this.mockMvc.perform(put("/v1/dataSources/" + ds.getXid()).content(userJson).contentType(MediaType.APPLICATION_JSON).sessionAttr("sessionUser", adminUser).accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isCreated());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO in project ma-core-public by infiniteautomation.
the class DataSourceListDwr method copyDataSource.
@DwrPermission(user = true)
public ProcessResult copyDataSource(int dataSourceId, String name, String xid, String deviceName) {
Permissions.ensureDataSourcePermission(Common.getUser(), dataSourceId);
ProcessResult response = new ProcessResult();
// Create a dummy data source with which to do the validation.
DataSourceVO<?> ds = new MockDataSourceVO();
ds.setName(name);
ds.setXid(xid);
ds.validate(response);
if (!response.getHasMessages()) {
int dsId = DataSourceDao.instance.copyDataSource(dataSourceId, name, xid, deviceName);
response.addData("newId", dsId);
}
return response;
}
use of com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO in project ma-modules-public by infiniteautomation.
the class DataSourceTestData method mockDataSource.
/**
* Get a test data source
* @return
*/
public static DataSourceVO<?> mockDataSource() {
MockDataSourceVO ds = new MockDataSourceVO();
ds.setId(1);
ds.setXid("mock-xid");
ds.setName("Mock Name");
ds.setPurgeOverride(false);
ds.setPurgeType(PurgeTypes.YEARS);
ds.setPurgePeriod(1);
ds.setEnabled(false);
return ds;
}
use of com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO in project ma-modules-public by infiniteautomation.
the class DataSourceFunctionalTests method testAdminCreate.
/**
* Test creating a mock data source
*/
public void testAdminCreate() {
DataSourceVO ds = DataSourceTestData.mockDataSource();
when(dataSourceDao.getByXid(ds.getXid())).thenReturn(ds);
User adminUser = UserTestData.adminUser();
ObjectWriter writer = this.objectMapper.writerWithView(JsonViews.Test.class);
try {
String userJson = writer.writeValueAsString(new MockDataSourceModel((MockDataSourceVO) ds));
this.mockMvc.perform(post("/v1/dataSources/").content(userJson).contentType(MediaType.APPLICATION_JSON).sessionAttr("sessionUser", adminUser).accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isCreated());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO in project ma-core-public by infiniteautomation.
the class DataPointRTTest method testIntervalOnChangeLogging.
/**
* Test Interval Logged Values w/ On Change Option
*/
@Test
public void testIntervalOnChangeLogging() {
PointValueDao dao = Common.databaseProxy.newPointValueDao();
MockPointLocatorVO plVo = new MockPointLocatorVO(DataTypes.NUMERIC, true);
DataPointVO dpVo = new DataPointVO();
dpVo.setId(1);
// Configure Interval on change logging
dpVo.setLoggingType(DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL);
dpVo.setTolerance(0.5);
dpVo.setIntervalLoggingPeriod(5);
dpVo.setIntervalLoggingPeriodType(TimePeriods.SECONDS);
dpVo.setPointLocator(plVo);
dpVo.setLoggingType(DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL);
MockDataSourceVO dsVo = new MockDataSourceVO();
MockPointLocatorRT plRt = new MockPointLocatorRT(plVo);
// Setup some initial data
List<PointValueTime> initialCache = new ArrayList<>();
initialCache.add(new PointValueTime(1.0, 0));
SimulationTimer timer = new SimulationTimer();
DataPointRT rt = new DataPointRT(dpVo, plRt, dsVo, initialCache, timer);
rt.initialize();
rt.initializeIntervalLogging(0, false);
// Test no changes
timer.fastForwardTo(5001);
PointValueTime value = dao.getLatestPointValue(dpVo.getId());
// Ensure database has interval logged value
assertEquals(1.0, value.getDoubleValue(), 0.0001);
assertEquals(5000, value.getTime());
// Ensure cache does not have interval logged value
assertEquals(1.0, rt.getPointValue().getDoubleValue(), 0.0001);
assertEquals(0, rt.getPointValue().getTime());
// Next interval
timer.fastForwardTo(6000);
rt.setPointValue(new PointValueTime(2.0, 6000), null);
// Check Log On Change
value = dao.getLatestPointValue(dpVo.getId());
assertEquals(2.0, value.getDoubleValue(), 0.0001);
assertEquals(6000, value.getTime());
assertEquals(2.0, rt.getPointValue().getDoubleValue(), 0.0001);
assertEquals(6000, rt.getPointValue().getTime());
// Interval is reset for 5000ms from now
timer.fastForwardTo(11001);
// Check Interval Log
value = dao.getLatestPointValue(dpVo.getId());
assertEquals(2.0, value.getDoubleValue(), 0.0001);
assertEquals(11000, value.getTime());
assertEquals(2.0, rt.getPointValue().getDoubleValue(), 0.0001);
assertEquals(6000, rt.getPointValue().getTime());
// Test Tolerance (Should not get logged)
timer.fastForwardTo(12000);
rt.setPointValue(new PointValueTime(2.20, 12000), null);
// Check Log On Change
value = dao.getLatestPointValue(dpVo.getId());
assertEquals(2.0, value.getDoubleValue(), 0.0001);
assertEquals(11000, value.getTime());
// Cache will have the set value
assertEquals(2.2, rt.getPointValue().getDoubleValue(), 0.0001);
assertEquals(12000, rt.getPointValue().getTime());
}
Aggregations