Search in sources :

Example 1 with MockDataSourceVO

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());
    }
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) User(com.serotonin.m2m2.vo.User) JsonViews(com.serotonin.m2m2.web.mvc.rest.v1.mapping.JsonViews) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) MockDataSourceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.MockDataSourceModel)

Example 2 with MockDataSourceVO

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;
}
Also used : MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 3 with MockDataSourceVO

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;
}
Also used : MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO)

Example 4 with MockDataSourceVO

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());
    }
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) User(com.serotonin.m2m2.vo.User) JsonViews(com.serotonin.m2m2.web.mvc.rest.v1.mapping.JsonViews) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) MockDataSourceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.MockDataSourceModel)

Example 5 with MockDataSourceVO

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());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) SimulationTimer(com.serotonin.timer.SimulationTimer) MockPointLocatorRT(com.serotonin.m2m2.rt.dataSource.MockPointLocatorRT) ArrayList(java.util.ArrayList) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) Test(org.junit.Test)

Aggregations

MockDataSourceVO (com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO)6 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 User (com.serotonin.m2m2.vo.User)2 MockPointLocatorVO (com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)2 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)2 JsonViews (com.serotonin.m2m2.web.mvc.rest.v1.mapping.JsonViews)2 MockDataSourceModel (com.serotonin.m2m2.web.mvc.rest.v1.model.MockDataSourceModel)2 ArrayList (java.util.ArrayList)2 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 MockPointLocatorRT (com.serotonin.m2m2.rt.dataSource.MockPointLocatorRT)1 MockPublishedPointVO (com.serotonin.m2m2.vo.publish.mock.MockPublishedPointVO)1 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)1 SimulationTimer (com.serotonin.timer.SimulationTimer)1 Test (org.junit.Test)1