Search in sources :

Example 1 with SaveOtaPackageInfoRequest

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

the class BaseOtaPackageControllerTest method testSaveFirmware.

@Test
public void testSaveFirmware() 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());
}
Also used : OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) SaveOtaPackageInfoRequest(org.thingsboard.server.common.data.SaveOtaPackageInfoRequest) Test(org.junit.Test)

Example 2 with SaveOtaPackageInfoRequest

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

the class BaseOtaPackageControllerTest method testFindTenantFirmwares.

@Test
public void testFindTenantFirmwares() throws Exception {
    List<OtaPackageInfo> otaPackages = new ArrayList<>();
    for (int i = 0; i < 165; i++) {
        SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest();
        firmwareInfo.setDeviceProfileId(deviceProfileId);
        firmwareInfo.setType(FIRMWARE);
        firmwareInfo.setTitle(TITLE);
        firmwareInfo.setVersion(VERSION + i);
        firmwareInfo.setUsesUrl(false);
        OtaPackageInfo savedFirmwareInfo = save(firmwareInfo);
        if (i > 100) {
            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);
            otaPackages.add(savedFirmware);
        } else {
            otaPackages.add(savedFirmwareInfo);
        }
    }
    List<OtaPackageInfo> loadedFirmwares = new ArrayList<>();
    PageLink pageLink = new PageLink(24);
    PageData<OtaPackageInfo> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/otaPackages?", new TypeReference<>() {
        }, pageLink);
        loadedFirmwares.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(otaPackages, idComparator);
    Collections.sort(loadedFirmwares, idComparator);
    Assert.assertEquals(otaPackages, loadedFirmwares);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SaveOtaPackageInfoRequest(org.thingsboard.server.common.data.SaveOtaPackageInfoRequest) Test(org.junit.Test)

Example 3 with SaveOtaPackageInfoRequest

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

the class BaseOtaPackageControllerTest method saveOtaPackageInfoWithViolationOfLengthValidation.

@Test
public void saveOtaPackageInfoWithViolationOfLengthValidation() throws Exception {
    SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest();
    firmwareInfo.setDeviceProfileId(deviceProfileId);
    firmwareInfo.setType(FIRMWARE);
    firmwareInfo.setTitle(RandomStringUtils.randomAlphabetic(300));
    firmwareInfo.setVersion(VERSION);
    firmwareInfo.setUsesUrl(false);
    doPost("/api/otaPackage", firmwareInfo).andExpect(statusReason(containsString("length of title must be equal or less than 255")));
    firmwareInfo.setTitle(TITLE);
    firmwareInfo.setVersion(RandomStringUtils.randomAlphabetic(300));
    doPost("/api/otaPackage", firmwareInfo).andExpect(statusReason(containsString("length of version must be equal or less than 255")));
    firmwareInfo.setVersion(VERSION);
    firmwareInfo.setUsesUrl(true);
    firmwareInfo.setUrl(RandomStringUtils.randomAlphabetic(300));
    doPost("/api/otaPackage", firmwareInfo).andExpect(statusReason(containsString("length of url must be equal or less than 255")));
}
Also used : SaveOtaPackageInfoRequest(org.thingsboard.server.common.data.SaveOtaPackageInfoRequest) Test(org.junit.Test)

Example 4 with SaveOtaPackageInfoRequest

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

the class BaseOtaPackageControllerTest method testFindFirmwareById.

@Test
public void testFindFirmwareById() 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);
    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);
    OtaPackage foundFirmware = doGet("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString(), OtaPackage.class);
    Assert.assertNotNull(foundFirmware);
    Assert.assertEquals(savedFirmware, new OtaPackageInfo(foundFirmware));
    Assert.assertEquals(DATA, foundFirmware.getData());
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) OtaPackage(org.thingsboard.server.common.data.OtaPackage) OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) SaveOtaPackageInfoRequest(org.thingsboard.server.common.data.SaveOtaPackageInfoRequest) Test(org.junit.Test)

Example 5 with SaveOtaPackageInfoRequest

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

the class BaseOtaPackageControllerTest method testFindTenantFirmwaresByHasData.

@Test
public void testFindTenantFirmwaresByHasData() throws Exception {
    List<OtaPackageInfo> otaPackagesWithData = new ArrayList<>();
    List<OtaPackageInfo> allOtaPackages = new ArrayList<>();
    for (int i = 0; i < 165; i++) {
        SaveOtaPackageInfoRequest firmwareInfo = new SaveOtaPackageInfoRequest();
        firmwareInfo.setDeviceProfileId(deviceProfileId);
        firmwareInfo.setType(FIRMWARE);
        firmwareInfo.setTitle(TITLE);
        firmwareInfo.setVersion(VERSION + i);
        firmwareInfo.setUsesUrl(false);
        OtaPackageInfo savedFirmwareInfo = save(firmwareInfo);
        if (i > 100) {
            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);
            savedFirmwareInfo = new OtaPackageInfo(savedFirmware);
            otaPackagesWithData.add(savedFirmwareInfo);
        }
        allOtaPackages.add(savedFirmwareInfo);
    }
    List<OtaPackageInfo> loadedOtaPackagesWithData = new ArrayList<>();
    PageLink pageLink = new PageLink(24);
    PageData<OtaPackageInfo> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/otaPackages/" + deviceProfileId.toString() + "/FIRMWARE?", new TypeReference<>() {
        }, pageLink);
        loadedOtaPackagesWithData.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    List<OtaPackageInfo> allLoadedOtaPackages = new ArrayList<>();
    pageLink = new PageLink(24);
    do {
        pageData = doGetTypedWithPageLink("/api/otaPackages?", new TypeReference<>() {
        }, pageLink);
        allLoadedOtaPackages.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(otaPackagesWithData, idComparator);
    Collections.sort(allOtaPackages, idComparator);
    Collections.sort(loadedOtaPackagesWithData, idComparator);
    Collections.sort(allLoadedOtaPackages, idComparator);
    Assert.assertEquals(otaPackagesWithData, loadedOtaPackagesWithData);
    Assert.assertEquals(allOtaPackages, allLoadedOtaPackages);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SaveOtaPackageInfoRequest(org.thingsboard.server.common.data.SaveOtaPackageInfoRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 SaveOtaPackageInfoRequest (org.thingsboard.server.common.data.SaveOtaPackageInfoRequest)9 OtaPackageInfo (org.thingsboard.server.common.data.OtaPackageInfo)8 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ArrayList (java.util.ArrayList)2 PageLink (org.thingsboard.server.common.data.page.PageLink)2 OtaPackage (org.thingsboard.server.common.data.OtaPackage)1