Browse Source

Merge pull request #14408 from thingsboard/lts-4.2

Lts 4.2
pull/14409/head
Viacheslav Klimov 10 months ago
committed by GitHub
parent
commit
4e90c21237
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java
  2. 4
      ui-ngx/src/app/core/interceptors/global-http-interceptor.ts
  3. 8
      ui-ngx/src/app/modules/home/pages/admin/resource/js-resource.component.ts

18
application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java

@ -38,8 +38,6 @@ import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.cache.Cache; import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -53,6 +51,8 @@ import org.springframework.mock.http.MockHttpInputMessage;
import org.springframework.mock.http.MockHttpOutputMessage; import org.springframework.mock.http.MockHttpOutputMessage;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
import org.springframework.mock.web.MockPart; import org.springframework.mock.web.MockPart;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
@ -154,6 +154,7 @@ import org.thingsboard.server.service.entitiy.tenant.profile.TbTenantProfileServ
import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRequest; import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRequest;
import org.thingsboard.server.service.security.auth.rest.LoginRequest; import org.thingsboard.server.service.security.auth.rest.LoginRequest;
import org.thingsboard.server.service.security.model.token.JwtTokenFactory; import org.thingsboard.server.service.security.model.token.JwtTokenFactory;
import org.thingsboard.server.service.system.SystemPatchApplier;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -278,18 +279,21 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest {
@Autowired @Autowired
private JwtTokenFactory jwtTokenFactory; private JwtTokenFactory jwtTokenFactory;
@SpyBean
protected MailService mailService;
@Autowired @Autowired
protected InMemoryStorage storage; protected InMemoryStorage storage;
@Autowired @Autowired
protected JdbcTemplate jdbcTemplate; protected JdbcTemplate jdbcTemplate;
@MockBean @MockitoSpyBean
protected MailService mailService;
@MockitoBean
protected CfRocksDb cfRocksDb; protected CfRocksDb cfRocksDb;
@MockitoBean
protected SystemPatchApplier systemPatchApplier;
@Rule @Rule
public TestRule watcher = new TestWatcher() { public TestRule watcher = new TestWatcher() {
protected void starting(Description description) { protected void starting(Description description) {
@ -1274,7 +1278,7 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest {
protected List<Job> findJobs(List<JobType> types, List<UUID> entities) throws Exception { protected List<Job> findJobs(List<JobType> types, List<UUID> entities) throws Exception {
return doGetTypedWithPageLink("/api/jobs?types=" + types.stream().map(Enum::name).collect(Collectors.joining(",")) + return doGetTypedWithPageLink("/api/jobs?types=" + types.stream().map(Enum::name).collect(Collectors.joining(",")) +
"&entities=" + entities.stream().map(UUID::toString).collect(Collectors.joining(",")) + "&", "&entities=" + entities.stream().map(UUID::toString).collect(Collectors.joining(",")) + "&",
new TypeReference<PageData<Job>>() {}, new PageLink(100, 0, null, new SortOrder("createdTime", SortOrder.Direction.DESC))).getData(); new TypeReference<PageData<Job>>() {}, new PageLink(100, 0, null, new SortOrder("createdTime", SortOrder.Direction.DESC))).getData();
} }

4
ui-ngx/src/app/core/interceptors/global-http-interceptor.ts

@ -125,6 +125,10 @@ export class GlobalHttpInterceptor implements HttpInterceptor {
this.showError(req.method + ': ' + req.url + '<br/>' + this.showError(req.method + ': ' + req.url + '<br/>' +
errorResponse.status + ': ' + errorResponse.statusText); errorResponse.status + ': ' + errorResponse.statusText);
} }
} else if (errorResponse.status === 504) {
if (!ignoreErrors) {
this.showError('Request timeout');
}
} else { } else {
unhandled = true; unhandled = true;
} }

8
ui-ngx/src/app/modules/home/pages/admin/resource/js-resource.component.ts

@ -32,7 +32,7 @@ import {
} from '@shared/models/resource.models'; } from '@shared/models/resource.models';
import { startWith, takeUntil } from 'rxjs/operators'; import { startWith, takeUntil } from 'rxjs/operators';
import { ActionNotificationShow } from '@core/notification/notification.actions'; import { ActionNotificationShow } from '@core/notification/notification.actions';
import { isDefinedAndNotNull } from '@core/utils'; import { base64toString, isDefinedAndNotNull, stringToBase64 } from '@core/utils';
import { getCurrentAuthState } from '@core/auth/auth.selectors'; import { getCurrentAuthState } from '@core/auth/auth.selectors';
@Component({ @Component({
@ -84,13 +84,13 @@ export class JsResourceComponent extends EntityComponent<Resource> implements On
resourceSubType: [entity?.resourceSubType ? entity.resourceSubType : ResourceSubType.EXTENSION, Validators.required], resourceSubType: [entity?.resourceSubType ? entity.resourceSubType : ResourceSubType.EXTENSION, Validators.required],
fileName: [entity ? entity.fileName : null, Validators.required], fileName: [entity ? entity.fileName : null, Validators.required],
data: [entity ? entity.data : null, this.isAdd ? [Validators.required] : []], data: [entity ? entity.data : null, this.isAdd ? [Validators.required] : []],
content: [entity?.data?.length ? window.atob(entity.data) : '', Validators.required] content: [entity?.data?.length ? base64toString(entity.data) : '', Validators.required]
}); });
} }
updateForm(entity: Resource): void { updateForm(entity: Resource): void {
this.entityForm.patchValue(entity); this.entityForm.patchValue(entity);
const content = entity.resourceSubType === ResourceSubType.MODULE && entity?.data?.length ? window.atob(entity.data) : ''; const content = entity.resourceSubType === ResourceSubType.MODULE && entity?.data?.length ? base64toString(entity.data) : '';
this.entityForm.get('content').patchValue(content); this.entityForm.get('content').patchValue(content);
} }
@ -110,7 +110,7 @@ export class JsResourceComponent extends EntityComponent<Resource> implements On
if (!formValue.fileName) { if (!formValue.fileName) {
formValue.fileName = formValue.title + '.js'; formValue.fileName = formValue.title + '.js';
} }
formValue.data = window.btoa((formValue as any).content); formValue.data = stringToBase64((formValue as any).content);
delete (formValue as any).content; delete (formValue as any).content;
} }
return super.prepareFormValue(formValue); return super.prepareFormValue(formValue);

Loading…
Cancel
Save