OtaPackage improvements
This commit is contained in:
parent
5afc39eb60
commit
c3ab678c1b
@ -128,7 +128,7 @@ public class OtaPackageController extends BaseController {
|
|||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
||||||
@RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.POST)
|
@RequestMapping(value = "/otaPackage/{otaPackageId}", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public OtaPackage saveOtaPackageData(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId,
|
public OtaPackageInfo saveOtaPackageData(@PathVariable(OTA_PACKAGE_ID) String strOtaPackageId,
|
||||||
@RequestParam(required = false) String checksum,
|
@RequestParam(required = false) String checksum,
|
||||||
@RequestParam(CHECKSUM_ALGORITHM) String checksumAlgorithmStr,
|
@RequestParam(CHECKSUM_ALGORITHM) String checksumAlgorithmStr,
|
||||||
@RequestBody MultipartFile file) throws ThingsboardException {
|
@RequestBody MultipartFile file) throws ThingsboardException {
|
||||||
@ -160,7 +160,7 @@ public class OtaPackageController extends BaseController {
|
|||||||
otaPackage.setContentType(file.getContentType());
|
otaPackage.setContentType(file.getContentType());
|
||||||
otaPackage.setData(ByteBuffer.wrap(bytes));
|
otaPackage.setData(ByteBuffer.wrap(bytes));
|
||||||
otaPackage.setDataSize((long) bytes.length);
|
otaPackage.setDataSize((long) bytes.length);
|
||||||
OtaPackage savedOtaPackage = otaPackageService.saveOtaPackage(otaPackage);
|
OtaPackageInfo savedOtaPackage = otaPackageService.saveOtaPackage(otaPackage);
|
||||||
logEntityAction(savedOtaPackage.getId(), savedOtaPackage, null, ActionType.UPDATED, null);
|
logEntityAction(savedOtaPackage.getId(), savedOtaPackage, null, ActionType.UPDATED, null);
|
||||||
return savedOtaPackage;
|
return savedOtaPackage;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@ -141,10 +141,12 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes
|
|||||||
|
|
||||||
MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array());
|
MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array());
|
||||||
|
|
||||||
OtaPackage savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM);
|
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(FILE_NAME, savedFirmware.getFileName());
|
||||||
Assert.assertEquals(CONTENT_TYPE, savedFirmware.getContentType());
|
Assert.assertEquals(CONTENT_TYPE, savedFirmware.getContentType());
|
||||||
|
Assert.assertEquals(CHECKSUM_ALGORITHM, savedFirmware.getChecksumAlgorithm().name());
|
||||||
|
Assert.assertEquals(CHECKSUM, savedFirmware.getChecksum());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -189,11 +191,12 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes
|
|||||||
|
|
||||||
MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array());
|
MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array());
|
||||||
|
|
||||||
OtaPackage savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM);
|
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);
|
OtaPackage foundFirmware = doGet("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString(), OtaPackage.class);
|
||||||
Assert.assertNotNull(foundFirmware);
|
Assert.assertNotNull(foundFirmware);
|
||||||
Assert.assertEquals(savedFirmware, foundFirmware);
|
Assert.assertEquals(savedFirmware, new OtaPackageInfo(foundFirmware));
|
||||||
|
Assert.assertEquals(DATA, foundFirmware.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -228,8 +231,8 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes
|
|||||||
if (i > 100) {
|
if (i > 100) {
|
||||||
MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array());
|
MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array());
|
||||||
|
|
||||||
OtaPackage savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM);
|
OtaPackageInfo savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM);
|
||||||
otaPackages.add(new OtaPackageInfo(savedFirmware));
|
otaPackages.add(savedFirmware);
|
||||||
} else {
|
} else {
|
||||||
otaPackages.add(savedFirmwareInfo);
|
otaPackages.add(savedFirmwareInfo);
|
||||||
}
|
}
|
||||||
@ -271,7 +274,7 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes
|
|||||||
if (i > 100) {
|
if (i > 100) {
|
||||||
MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array());
|
MockMultipartFile testData = new MockMultipartFile("file", FILE_NAME, CONTENT_TYPE, DATA.array());
|
||||||
|
|
||||||
OtaPackage savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM);
|
OtaPackageInfo savedFirmware = savaData("/api/otaPackage/" + savedFirmwareInfo.getId().getId().toString() + "?checksum={checksum}&checksumAlgorithm={checksumAlgorithm}", testData, CHECKSUM, CHECKSUM_ALGORITHM);
|
||||||
savedFirmwareInfo = new OtaPackageInfo(savedFirmware);
|
savedFirmwareInfo = new OtaPackageInfo(savedFirmware);
|
||||||
otaPackagesWithData.add(savedFirmwareInfo);
|
otaPackagesWithData.add(savedFirmwareInfo);
|
||||||
}
|
}
|
||||||
@ -318,11 +321,11 @@ public abstract class BaseOtaPackageControllerTest extends AbstractControllerTes
|
|||||||
return doPost("/api/otaPackage", firmwareInfo, OtaPackageInfo.class);
|
return doPost("/api/otaPackage", firmwareInfo, OtaPackageInfo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected OtaPackage savaData(String urlTemplate, MockMultipartFile content, String... params) throws Exception {
|
protected OtaPackageInfo savaData(String urlTemplate, MockMultipartFile content, String... params) throws Exception {
|
||||||
MockMultipartHttpServletRequestBuilder postRequest = MockMvcRequestBuilders.multipart(urlTemplate, params);
|
MockMultipartHttpServletRequestBuilder postRequest = MockMvcRequestBuilders.multipart(urlTemplate, params);
|
||||||
postRequest.file(content);
|
postRequest.file(content);
|
||||||
setJwtToken(postRequest);
|
setJwtToken(postRequest);
|
||||||
return readResponse(mockMvc.perform(postRequest).andExpect(status().isOk()), OtaPackage.class);
|
return readResponse(mockMvc.perform(postRequest).andExpect(status().isOk()), OtaPackageInfo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2971,7 +2971,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
|||||||
return restTemplate.postForEntity(baseURL + "/api/otaPackage", otaPackageInfo, OtaPackageInfo.class).getBody();
|
return restTemplate.postForEntity(baseURL + "/api/otaPackage", otaPackageInfo, OtaPackageInfo.class).getBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OtaPackage saveOtaPackageData(OtaPackageId otaPackageId, String checkSum, ChecksumAlgorithm checksumAlgorithm, MultipartFile file) throws Exception {
|
public OtaPackageInfo saveOtaPackageData(OtaPackageId otaPackageId, String checkSum, ChecksumAlgorithm checksumAlgorithm, MultipartFile file) throws Exception {
|
||||||
HttpHeaders header = new HttpHeaders();
|
HttpHeaders header = new HttpHeaders();
|
||||||
header.setContentType(MediaType.MULTIPART_FORM_DATA);
|
header.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
|
|
||||||
@ -2993,7 +2993,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return restTemplate.postForEntity(
|
return restTemplate.postForEntity(
|
||||||
baseURL + url, requestEntity, OtaPackage.class, params
|
baseURL + url, requestEntity, OtaPackageInfo.class, params
|
||||||
).getBody();
|
).getBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user