use of com.serotonin.m2m2.web.mvc.rest.v1.model.MockDataSourceModel 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.web.mvc.rest.v1.model.MockDataSourceModel 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());
}
}
Aggregations