Search in sources :

Example 26 with OtaPackageInfo

use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.

the class BaseOtaPackageControllerTest method testFindFirmwareInfoById.

@Test
public void testFindFirmwareInfoById() throws Exception {
    SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest();
    firmwareInfo.setDeviceProfileId(deviceProfileId);
    firmwareInfo.setType(FIRMWARE);
    firmwareInfo.setTitle(TITLE);
    firmwareInfo.setVersion(VERSION);
    firmwareInfo.setUsesUrl(false);
    OtaPackageInfo savedFirmwareInfo = save(firmwareInfo);
    OtaPackageInfo foundFirmware = doGet("/api/otaPackage/info/" + savedFirmwareInfo.getId().getId().toString(), OtaPackageInfo.class);
    Assert.assertNotNull(foundFirmware);
    Assert.assertEquals(savedFirmwareInfo, foundFirmware);
}
Also used : OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) SaveOtaPackageInfoRequest(org.thingsboard.server.common.data.SaveOtaPackageInfoRequest) Test(org.junit.Test)

Example 27 with OtaPackageInfo

use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.

the class BaseOtaPackageControllerTest method testDeleteFirmware.

@Test
public void testDeleteFirmware() throws Exception {
    SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest();
    firmwareInfo.setDeviceProfileId(deviceProfileId);
    firmwareInfo.setType(FIRMWARE);
    firmwareInfo.setTitle(TITLE);
    firmwareInfo.setVersion(VERSION);
    firmwareInfo.setUsesUrl(false);
    OtaPackageInfo savedFirmwareInfo = save(firmwareInfo);
    doDelete("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString()).andExpect(status().isOk());
    doGet("/api/otaPackage/info/" + savedFirmwareInfo.getId().getId().toString()).andExpect(status().isNotFound());
}
Also used : OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) SaveOtaPackageInfoRequest(org.thingsboard.server.common.data.SaveOtaPackageInfoRequest) Test(org.junit.Test)

Example 28 with OtaPackageInfo

use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.

the class BaseOtaPackageControllerTest method testSaveFirmwareData.

@Test
public void testSaveFirmwareData() throws Exception {
    SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest();
    firmwareInfo.setDeviceProfileId(deviceProfileId);
    firmwareInfo.setType(FIRMWARE);
    firmwareInfo.setTitle(TITLE);
    firmwareInfo.setVersion(VERSION);
    firmwareInfo.setUsesUrl(false);
    OtaPackageInfo savedFirmwareInfo = save(firmwareInfo);
    Assert.assertNotNull(savedFirmwareInfo);
    Assert.assertNotNull(savedFirmwareInfo.getId());
    Assert.assertTrue(savedFirmwareInfo.getCreatedTime() > 0);
    Assert.assertEquals(savedTenant.getId(), savedFirmwareInfo.getTenantId());
    Assert.assertEquals(firmwareInfo.getTitle(), savedFirmwareInfo.getTitle());
    Assert.assertEquals(firmwareInfo.getVersion(), savedFirmwareInfo.getVersion());
    savedFirmwareInfo.setAdditionalInfo(JacksonUtil.newObjectNode());
    save(new SaveOtaPackageInfoRequest(savedFirmwareInfo, false));
    OtaPackageInfo foundFirmwareInfo = doGet("/api/otaPackage/info/" + savedFirmwareInfo.getId().getId().toString(), OtaPackageInfo.class);
    Assert.assertEquals(foundFirmwareInfo.getTitle(), savedFirmwareInfo.getTitle());
    MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array());
    OtaPackageInfo savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM);
    Assert.assertEquals(FILE_NAME, savedFirmware.getFileName());
    Assert.assertEquals(CONTENT_TYPE, savedFirmware.getContentType());
    Assert.assertEquals(CHECKSUM_ALGORITHM, savedFirmware.getChecksumAlgorithm().name());
    Assert.assertEquals(CHECKSUM, savedFirmware.getChecksum());
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) SaveOtaPackageInfoRequest(org.thingsboard.server.common.data.SaveOtaPackageInfoRequest) Test(org.junit.Test)

Example 29 with OtaPackageInfo

use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.

the class BaseOtaPackageControllerTest method testUpdateFirmwareFromDifferentTenant.

@Test
public void testUpdateFirmwareFromDifferentTenant() throws Exception {
    SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest();
    firmwareInfo.setDeviceProfileId(deviceProfileId);
    firmwareInfo.setType(FIRMWARE);
    firmwareInfo.setTitle(TITLE);
    firmwareInfo.setVersion(VERSION);
    firmwareInfo.setUsesUrl(false);
    OtaPackageInfo savedFirmwareInfo = save(firmwareInfo);
    loginDifferentTenant();
    doPost("/api/otaPackage", new SaveOtaPackageInfoRequest(savedFirmwareInfo, false), OtaPackageInfo.class, status().isForbidden());
    deleteDifferentTenant();
}
Also used : OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) SaveOtaPackageInfoRequest(org.thingsboard.server.common.data.SaveOtaPackageInfoRequest) Test(org.junit.Test)

Example 30 with OtaPackageInfo

use of org.thingsboard.server.common.data.OtaPackageInfo in project thingsboard by thingsboard.

the class AbstractOtaLwM2MIntegrationTest method createFirmware.

protected OtaPackageInfo createFirmware() throws Exception {
    String CHECKSUM = "4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a";
    OtaPackageInfo firmwareInfo = new OtaPackageInfo();
    firmwareInfo.setDeviceProfileId(deviceProfile.getId());
    firmwareInfo.setType(FIRMWARE);
    firmwareInfo.setTitle("My firmware");
    firmwareInfo.setVersion("v1.0");
    OtaPackageInfo savedFirmwareInfo = doPost("/api/otaPackage", firmwareInfo, OtaPackageInfo.class);
    MockMultipartFile testData = new MockMultipartFile("file", "filename.txt", "text/plain", new byte[] { 1 });
    return savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, "SHA256");
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo)

Aggregations

OtaPackageInfo (org.thingsboard.server.common.data.OtaPackageInfo)31 Test (org.junit.Test)18 SaveOtaPackageInfoRequest (org.thingsboard.server.common.data.SaveOtaPackageInfoRequest)8 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)6 OtaPackageId (org.thingsboard.server.common.data.id.OtaPackageId)6 ArrayList (java.util.ArrayList)5 OtaPackage (org.thingsboard.server.common.data.OtaPackage)5 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)4 PageLink (org.thingsboard.server.common.data.page.PageLink)4 ApiOperation (io.swagger.annotations.ApiOperation)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)2 Cache (org.springframework.cache.Cache)2 OtaPackageDataCache (org.thingsboard.server.cache.ota.OtaPackageDataCache)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HashMap (java.util.HashMap)1